← Back to Pull requests

fix(table): move rows to their new bucket when UPDATE changes the bucket key #1319

Closed
unknown closed this pull request without merging on Nov 03, 2026 15:41 UTC
View on GitHub
unknown unknown commented on Nov 03, 2026 11:48 UTC
Author

Purpose

Linked issue: close #1318

On a fixed-bucket append table ('bucket' = 'N', 'bucket-key' = '...'), UPDATE or a matched MERGE INTO update 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:

>>> UPDATE db.orders SET customer = 'erin' WHERE id = 1
>>> SELECT * FROM db.orders ORDER BY id
+----+----------+--------+
| id | customer | amount |
+----+----------+--------+
| 1  | erin     | 10     |
| 2  | bob      | 20     |
| 3  | carol    | 30     |
| 4  | dave     | 40     |
+----+----------+--------+
>>> SELECT * FROM db.orders WHERE customer = 'erin'
++
++

After:

>>> SELECT * FROM db.orders WHERE customer = 'erin'
+----+----------+--------+
| id | customer | amount |
+----+----------+--------+
| 1  | erin     | 10     |
+----+----------+--------+

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$files shows the rewritten file still in bucket-2 (where alice hashes), while a new INSERT of 'erin' goes to bucket-1.

Brief change log

  • CopyOnWriteMergeWriter::prepare_commit: when the updated columns include a bucket-key column 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, as TableWrite does 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.

  • Updates that do not touch a bucket key, and tables without a fixed bucket count, keep the existing path unchanged.
  • This matches Java: Spark's UPDATE on an append table writes the updated rows through PaimonSparkWriter, which assigns HASH_FIXED buckets from the bucket keys of each row.

    Assumptions worth checking:

  • The new buckets use the table's current bucket option. TableWrite uses 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.

  • When a bucket key is updated, every surviving row of a touched file is hashed again. Rows whose key did not change hash to the bucket they were already in.
  • 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 through MERGE INTO, with one updated row moving out of a file that also keeps an unchanged row.

  • Without the change in 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 -- --check and cargo clippy --locked -p paimon -p paimon-datafusion --all-targets -- -D warnings pass.

  • I also checked by hand a partitioned bucketed table, an update to NULL, 'bucket-function.type' = 'mod', and a MERGE mixing matched DELETE, matched UPDATE and NOT MATCHED INSERT.
  • The full paimon unit-test suite and the vortex feature are left to CI.

    API and Format

    No API or storage format change.

    Documentation

    No.

    Diff: 460 lines (+345 / -115) across 5 files Reviewer: JeonDaehong Review duration: 232m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 460 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.367
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #1319"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.0% · Safe to merge
    18.0%