Skip to content

[core] Fix Data Evolution incremental DIFF reads - #11285

Open
JustinBinber wants to merge 11 commits into
apache:masterfrom
JustinBinber:codex/de-incremental-diff-20261120
Open

JustinBinber wants to merge 11 commits into
apache:masterfrom
JustinBinber:codex/de-incremental-diff-20261120

Conversation

@JustinBinber

@JustinBinber JustinBinber commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Data Evolution batch DIFF scans produce IncrementalSplit objects that the DE reader cannot read, causing nonempty snapshot and tag differences to fail with ClassCastException. Reading only newly added column files would also lose untouched columns and the shared deletion-vector anchor.

Plan the complete end-snapshot dependency groups for added manifest-entry RowID ranges, and reuse existing IndexedSplit reads. Both metadata inventories are computed without projection, data-statistics or LIMIT pruning; caller scan settings are restored afterward. Shared files reconstruct unchanged columns and provide the end-snapshot DV anchor. Requested RowID ranges further restrict each split, including strict subsets, empty selections and clearing/replacing ranges through either SnapshotReader setter.

Do not report an exact visible row count when an indexed split has deletion vectors: LIMIT must be able to read past an entirely deleted split.

Automatic global-index lookup is disabled for incremental reads until index evaluation, coverage and the data plan can use the same resolved historical endpoint. This covers eager and reader-side index modes, including tag ranges. DIFF rejects unbound external results and accepts explicit RowID selections through withRowRanges. DELTA and AUTO resolved to DELTA preserve caller-supplied RowIDs and scores. Ordinary latest/time-travel snapshot index optimizations and latest-snapshot external selections remain available.

Existing compaction-race fixtures inspect the latest commit's ADD entries directly instead of depending on a query split implementation. Their retry, file-identity, concurrency and nested-field assertions are retained.

The documented contract is file incremental: return visible end-snapshot rows in ranges covered by added file entries. Compaction may repeat rows, and deletion-only changes produce no positive rows. This is not row-level CDC and does not introduce streaming metadata planning. Ordinary append and primary-key DIFF paths remain unchanged. This correctness fix is independent of the memory optimization in #11156.

Changed RowID ranges are indexed once per partition/bucket. Each split queries only its actual intervals and intersects caller selections through the existing RowRangeIndex; gaps are preserved. Indexed readers retain both physical file metadata and score/RowID metadata through filtering and projection. Unscored row fetching used by lateral vector search keeps its existing ScoreRecordReader contract, including the NaN placeholder; scored reads retain their existing mapping.

Tests

Current CI for 3bc3b0c016: automatic run. The final version integrated with upstream 8d704811cb passed 17 focused Core tests and 3 Spark 3.5.9 SQL tests locally. These cover the original file path, physical positions 0 and 2 after deleting the middle row, full row reconstruction, and a reader score of 0.42 through DELTA and AUTO.

Historical Spark 4.3 validation: an earlier run exposed an unchanged upstream Spark 4.3 test-compilation defect (VariantTestBase missing), also reproduced on clean upstream 71082ea86a. A separate build-only commit adds the same test-scope shared UT tests-jar dependency already used by Spark 4.2, with all transitive dependencies excluded. On JDK 17 / Scala 2.13 / Spark 4.3, normal Maven compiled the shared UT and Spark 4.3 test sources and passed normal formatting/checkstyle/enforcer checks. All 152 Variant cases passed in a bounded 1.5 GiB JVM using that exact reactor test classpath. The previous PR head also passed a clean 28-module Maven package with -DskipTests, compiling all shared UT and Spark 4.3 tests; this is build validation and does not add executed test cases to the counts above. Broader local compatibility runs encountered existing Windows file-URI and missing-winutils failures, and one was stopped by the memory-reserve guard; those are not reported as passing full suites. No tests were removed or excluded. Upstream now includes the equivalent Spark 4.3 build fix in #11313.

JDK 8 / Scala 2.12 / Spark 3.5.9 current-source verification after merging upstream 71082ea86a:

  • 44 Core cases passed through normal Maven (DE DIFF, indexed splits, DE batch scans, physical metadata and score-reader regressions).
  • 8 targeted Spark cases passed on the normal reactor runtime: two actual DIFF SQL cases, lateral vector-search score+data control for FLOAT/DOUBLE query vectors, and five compaction-race controls. Current Core code locations were checked ahead of bundled copies in the additional controls' JVM.
  • Normal formatting/checkstyle/enforcer/licensing checks and git diff --check passed.

A metadata-only JDK 8 range-intersection microbenchmark includes index construction and checks the same results. At 25k/50k/100k gapped intervals, three alternating-repeat medians change from 333/1355/5368 ms to 6.84/7.71/12.48 ms. With sparse caller selections, 100k changes from 10151 ms to 26.11 ms. This measures only range intersection, not complete planning, SQL or distributed performance.

The real-table tests cover duplicate/NULL rows, implicit tag DIFF, multiple partial updates, unchanged-column projection, predicates, end-snapshot DVs on shared anchors, a dedicated BLOB subrange inside a wider normal range, serialized splits, deletion-only/empty results and LIMIT across a fully deleted split. Ordinary append and primary-key reads are controls.

Review regressions assert strict requested RowIDs after append/partial updates, no unrequested live rows around a deleted selection, and both SnapshotReader range setters including empty/null resets. The B-tree regression returns historical (200,20) for end snapshot 2 after the latest row became (200,30), in both eager/reader index modes and snapshot/tag ranges; the latest read still uses its index and returns (200,30).

RED/GREEN evidence uses the same fixtures and runtime: the initial clean upstream 3a8e01f35d baseline failed 8 of 17 original Core cases while 9 controls passed; the reported range/historical-index cases reproduced wrong results on adad80e295 and pass after this follow-up. Removing only the DV row-count fix also reproduces an empty LIMIT result where a later live row is required.

The prior JDK-install failure was superseded by a successful run on the unchanged source tree.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Data Evolution DIFF fix addresses a real read failure, and all 27 submitted and related Core tests passed on the current-master integration. A separate real-table test found one incorrect result through the public Java API.

[P1] Intersect DIFF file ranges with the caller's requested RowIDs. I appended [100] in snapshot 1 and [200, 300] in one Parquet file in snapshot 2. A regular scan with withRowRanges([2,2]) returned [300]. Applying the same range to DIFF 1,2 still planned [1,2] and returned both rows. A second test using partial-column updates reproduced the same behavior.

SnapshotReaderImpl.toDataEvolutionIncrementalPlan constructs an IndexedSplit covering the added file range. The manifest scan only checks range overlap at file level, and DataEvolutionBatchScan.wrap returns the existing IndexedSplit without applying the exact row-range restriction. Please intersect the already-selected DIFF ranges with the active row-range index and suppress empty intersections. Cover a requested range that selects a strict subset of one changed file.

@JingsongLi

Copy link
Copy Markdown
Contributor

[P1] Resolve the historical end snapshot before using a global index. In a Parquet Data Evolution table, snapshot 1 contained (100,10) and snapshot 2 appended (200,20). Snapshot 3 updated that row to (200,30), and I built a complete B-tree on v over the current snapshot. DIFF 1→2 with v=20 returned zero rows with default index settings and returned (200,20) with global-index.enabled=false. The current index successfully found (200,30) in an ordinary latest-snapshot read.

DataEvolutionBatchScan.planEager evaluates the index before the DIFF scanner selects the historical end snapshot. DataEvolutionGlobalIndexScanner.create resolves latest in this case, allowing newer index data to discard rows from an older snapshot. This persists independently of the earlier row-range finding. Please bypass scalar index pruning for DIFF, or resolve the end snapshot before evaluating its index and coverage.

@JustinBinber

Copy link
Copy Markdown
Contributor Author

Reproduced and addressed both P1 reports in 8a51ed6ac5.

  • DIFF now intersects its selected file ranges with the active RowRangeIndex and suppresses empty intersections. Both SnapshotReader range setters share state, including replacing ranges, empty selections and null resets. Real-table regressions cover strict append/partial-update subsets, DVs and a dedicated BLOB subrange; a deleted requested row cannot expose an unrequested live row.
  • Incremental reads bypass automatic global-index lookup until the index, coverage and data plan can share a resolved historical endpoint. This covers eager/deferred index modes and tag ranges. The regression returns (200,20) for historical end snapshot 2 after the current value became (200,30), while the latest read still uses its index and returns (200,30).
  • Explicit external index results have selection/scoring semantics and no endpoint provenance, so incremental reads reject them clearly rather than ignoring them. Explicit RowID selection remains supported through withRowRanges; latest external selections remain unchanged.

The normal Maven Core reactor passes all 32 focused tests; six targeted Spark cases also pass with the current Core classes. Fresh upstream CI is automatic for this new head and is still pending; the earlier green run belongs to adad80e.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two earlier findings are addressed. I tested this head integrated with current master. All 32 focused Core tests passed, and Spark 3.5.9 passed the DE DIFF SQL case and the five affected compaction race cases. Two additional checks showed gaps in the new split path.

@JustinBinber

JustinBinber commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

CI infrastructure follow-up for f54602c46d: the Spark 3 / Scala 2.13 job failed in Set up JDK 8, before Maven or any Paimon tests ran. actions/setup-java resolved Temurin 8.0.514+1, but extraction of the downloaded archive failed with gzip: stdin: not in gzip format.

The run has now completed: all other 17 selected checks passed, including Core/JDK 8 and 11, Spark 3/Scala 2.12, Spark 4/4.2/4.3 and Flink integrations. The second failed check is the dependent CI result, which reports the same Java matrix failure.

I attempted the single-job rerun endpoint, which returned 403: Must have admin rights to Repository. Could a repository maintainer rerun the JDK setup job and its dependent result check? CI acceptance remains pending; this setup failure is not counted as a pass.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two P2 findings reproduced locally on e5c67566ca.

@JingsongLi

Copy link
Copy Markdown
Contributor

The changes are becoming increasingly extensive; does this requirement stem from actual production needs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants