-
Notifications
You must be signed in to change notification settings - Fork 0
Implement AlterTableRecreateStatements for primary key column changes
#98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Warning Rate limit exceeded@amotl has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 44 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
WalkthroughAdds a recreate-via-temporary-table alter flow (AlterTableRecreateStatements and TableAddress), refactors table creation/reflection into helpers, updates type/field mappings and test fixtures, adjusts test expectations and startup cleanup, and exposes a WriteHistoryBatch stub. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Server as main.py
participant Engine as engine.py
participant DB as CrateDB
Client->>Server: Request AlterTable
Server->>Server: Reflect table (fresh MetaData)
alt Primary key changed
Server->>Server: _create_table(temp: name_alter_tmp)
Server->>Engine: Build AlterTableRecreateStatements(address_effective, address_temporary, columns_old, columns_new)
Engine->>Engine: to_sql() -> SqlBag (set read-only → INSERT mapped cols into temp → unset read-only → swap/rename → DROP temp)
Server->>DB: Execute SqlBag steps
DB-->>Server: Success
Server-->>Client: AlterTable succeeded (recreated)
else Primary key unchanged
Server->>Engine: Build/execute AlterTableInplaceStatements
Server->>DB: Execute ALTER statements
DB-->>Server: Success
Server-->>Client: AlterTable succeeded (in-place)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related issues
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The procedure will create a new table, transfer data, and swap tables. This will make the machinery fully complete the canonical `input.json` file provided by Fivetran. https://github.com/fivetran/fivetran_partner_sdk/blob/main/tools/destination-connector-tester/input-files/input.json
seut
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really a good idea to automate the support of PK changes by recreating the table?
This may end up in data loss, when writes are continue to happen on the source table while the INSERT INTO into the target table is already ongoing/done.
There should be at least a big warning somewhere.
|
Hi @seut. Thanks for the review.
The Fivetran SDK tester provides the trajectory of the API surface to implement within our adapter, so we don't really have any options not implementing it. There will be other even more exciting features ahead, for example GH-86 and GH-89. We are looking at typical (advanced) data warehouse operations here, even if we don't like them.
I hear you, let's do it. |
But we should not implement such things to make the API/testers happy but then it may result in data loss. Noone will be aware of this and scream later on.
Didn't see any changes in this regard, do I miss some? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One solution to avoid any data loss by this automation is to put the source table into read-only at the beginning of the operations.
ALTER TABLE ... SET ("blocks.write"=true);
No, I haven't added anything yet, but will also use your |
seut
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some more minor suggestions.
…edures Co-authored-by: Sebastian Utz <[email protected]>
Co-authored-by: Sebastian Utz <[email protected]>
About
Adding a missing item from the backlog:
AlterTableRecreateStatementsis needed when Fivetran propagates changes to primary key columns, which CrateDB can't handle withALTER TABLEoperations, but needs to re-create the tables instead.Details
The Fivetran SDK tester now runs to completion using the vanilla
input.jsonfile.Review
This PR includes unresolved conversations with CodeRabbit (FYI) that mostly refer to tickets about subsequent iterations to improve relevant spots. Please collapse/resolve them progressively as you process them. Thanks!The patch yielded a few backlog items, mostly coming from conversations with CodeRabbit: I've collapsed relevant threads to reduce noise, but please consider them when you find the same code smells. We will tackle them with subsequent iterations.
Backlog
AlterTableRecreateStatements: Improve column mapping #102References