Skip to content

[spark] Prune Data Evolution row-level scans by row ID range - #11432

Open
XiaoHongbo-Hope wants to merge 6 commits into
apache:masterfrom
XiaoHongbo-Hope:codex/spark-delete-rowid-pruning-latest
Open

XiaoHongbo-Hope wants to merge 6 commits into
apache:masterfrom
XiaoHongbo-Hope:codex/spark-delete-rowid-pruning-latest

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Spark row-level commands on Data Evolution tables can plan unrelated files for a physical _ROW_ID predicate because the bound is not applied before candidate splits are materialized. This change passes guaranteed conjunctive bounds to SnapshotReader.withRowRanges. It recognizes the canonical metadata attribute by exprId, including case-insensitive SQL references such as _row_id; a legal user column named _row_id has a different exprId and cannot trigger physical row-ID pruning. Predicates under OR and unsupported expressions keep the existing scan behavior.

A file group can have one normal file covering rows [0, 1249] while dedicated BLOB or vector files cover smaller ranges. Pruning those files without passing the selected range to the reader leaves a plain DataSplit that reads the full normal range, which can cause a missing BLOB value or a row-count mismatch. The row-level read carries the intersected range in an IndexedSplit. Candidate file metadata, anchor selection, and commit conflict checks remain unchanged.

Regressions cover candidate-file pruning, a legal user column named _row_id, a real lowercase DELETE FROM t WHERE _row_id = 550 (12 candidate files reduced to 1), a BLOB comparison in DELETE ... WHERE picture = expected AND _ROW_ID = 0, and deletion from a split vector-file group. They verify the target row is removed and other rows remain.

Validation:

  • Spark 3.5 PaimonRowLevelCommandTest: 3 passed; focused RowTrackingTest lowercase DELETE: 1 passed.
  • Spark 4.1 module compile with -Pspark4 -Pfast-build: passed; focused lowercase DELETE RowTrackingTest: 1 passed after clean rebuilding the Spark 4 shaded dependencies.
  • spotless:check for the changed Spark common and test modules: passed.
  • Earlier at 0f08933, Spark 3.5 RowTrackingTest: 82 passed and Spark 4.0 module package passed.

A separate pre-existing metadata-resolution issue remains for end-to-end DML on a table with a user column named _row_id: case-insensitive lookup in deletion-vector generation can resolve the user column instead of metadata _ROW_ID. This PR ensures that column cannot trigger physical row-ID file pruning.

@XiaoHongbo-Hope
XiaoHongbo-Hope marked this pull request as ready for review November 25, 2026 04:25
if (coreOptions.dataEvolutionEnabled()) {
PaimonRowLevelCommand
.conjunctiveRowIdRange(condition, relation.output ++ relation.metadataOutput)
.foreach(range => snapshotReader.withRowRanges(Collections.singletonList(range)))

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.

[P1] Carry the selected row range through to the reader

A valid Data Evolution table can have one normal file covering [0, 1249] and two dedicated vector files covering [0, 999] and [1000, 1249]. I reproduced this on Spark 3.5 with deletion vectors enabled, a single-partition INSERT of 1,250 rows, and vector.target-file-size='1 b'. Data Evolution file layout

DELETE FROM t WHERE _ROW_ID = 1050 prunes the first vector file here. The reader receives a plain DataSplit and checks the file group before choosing which columns to read. It compares 250 vector rows with 1,250 normal rows and fails with All files in a field merge split should have the same row count. The same SQL deletes one row at the PR base (4dc01acd).

Please pass the same selected row ranges to the reader, following the existing IndexedSplit path, and add a regression test for a row-ID delete on this layout. Existing range-aware read path

val rowIdExprIds = targetAttributes.filter(_.name == ROW_ID_COLUMN).map(_.exprId).toSet
def isRowId(expression: Expression): Boolean = expression match {
case attribute: Attribute =>
attribute.name == ROW_ID_COLUMN && rowIdExprIds.contains(attribute.exprId)

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.

[P2] Prune row IDs resolved case-insensitively

With Spark's default case-insensitive resolution, _row_id can resolve to the physical _ROW_ID metadata column with the same exprId while retaining the spelling from the SQL. The exact name check here skips pruning in that case. On Spark 3.5, DELETE FROM t WHERE _row_id = 550 planned all 12 files in a Data Evolution table with deletion vectors enabled. The same predicate spelled _ROW_ID = 550 planned one file. The lowercase statement still deleted the intended row.

Please match the predicate reference against rowIdExprIds by exprId. The set is already built from the canonical metadata name, and a user column named _row_id has a different exprId. A regression test should check the candidate file count for an actual lowercase SQL predicate.

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