Repository navigation
fix(table): move rows to their new bucket when UPDATE changes the bucket key - #1319
Merged
Merged
Conversation
…ket key A fixed-bucket append table places each row by hashing its bucket-key columns, and scans prune buckets by that hash. The copy-on-write writer used by UPDATE and MERGE INTO rewrote every touched file back into the file's original bucket, so a row whose bucket key was updated stayed in the bucket of its old value. Any query filtering on the new value read only the new value's bucket and missed the row. When the update touches a bucket-key column, compute each rewritten row's bucket with the table's bucket function and write the rows of each bucket separately, like the regular write path and Java's Spark writer.
JeonDaehong
approved these changes
Nov 3, 2026
JeonDaehong
left a comment
Contributor
There was a problem hiding this comment.
Checked a two-column bucket key with one of them updated, and the moved row lands in the same bucket as an INSERT of the new value. LGTM.
JingsongLi
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Linked issue: close #1318
On a fixed-bucket append table (
'bucket' = 'N','bucket-key' = '...'),UPDATEor a matchedMERGE INTOupdate that changes a bucket-key column leaves the row in the bucket of its old value. Scans prune buckets by the bucket-key hash, so any query filtering on the new value skips the row, while a full scan still returns it.Before this change, on main:
After:
The table is
CREATE TABLE db.orders (id INT, customer STRING, amount INT) WITH ('bucket' = '4', 'bucket-key' = 'customer')with rows(1, 'alice', 10), (2, 'bob', 20), (3, 'carol', 30), (4, 'dave', 40). Before the fix,orders$filesshows the rewritten file still inbucket-2(wherealicehashes), while a newINSERTof'erin'goes tobucket-1.Brief change log
CopyOnWriteMergeWriter::prepare_commit: when the updated columns include abucket-keycolumn and the table has a fixed bucket count above 1, compute the bucket of each rewritten row with the table's bucket function and bucket count, asTableWritedoes for inserts, and write each bucket's rows into that bucket. The deleted file stays in the commit message of its original bucket; rows that moved are added in the message of their new bucket.This matches Java: Spark's
UPDATEon an append table writes the updated rows throughPaimonSparkWriter, which assignsHASH_FIXEDbuckets from the bucket keys of each row.Assumptions worth checking:
bucketoption.TableWriteuses it too, and the commit records it as the files' total bucket count. A partition still holding files with an older bucket count (rescaled without overwrite) gets the rewritten rows hashed with the current count.Tests
update_tests::test_update_bucket_key_moves_row_to_new_bucket: UPDATE of the bucket key, then a filter on the new value returns the row.append_merge_into::test_update_bucket_key_moves_row_to_new_bucket: the same throughMERGE INTO, with one updated row moving out of a file that also keeps an unchanged row.cow_writer.rs, both tests fail with the filtered query returning[]instead of the updated rows.RUST_MIN_STACK=16777216 cargo test -p paimon-datafusion --test update_tests --test append_merge_into --test delete_tests --test merge_into_tests(21, 35, 25 and 29 tests) pass.cargo fmt --all -- --checkandcargo clippy --locked -p paimon -p paimon-datafusion --all-targets -- -D warningspass.NULL,'bucket-function.type' = 'mod', and a MERGE mixing matched DELETE, matched UPDATE and NOT MATCHED INSERT.The full
paimonunit-test suite and the vortex feature are left to CI.API and Format
No API or storage format change.
Documentation
No.