Repository navigation
[spark] Prune Data Evolution row-level scans by row ID range - #11432
XiaoHongbo-Hope wants to merge 6 commits into
Conversation
| if (coreOptions.dataEvolutionEnabled()) { | ||
| PaimonRowLevelCommand | ||
| .conjunctiveRowIdRange(condition, relation.output ++ relation.metadataOutput) | ||
| .foreach(range => snapshotReader.withRowRanges(Collections.singletonList(range))) |
There was a problem hiding this comment.
[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) |
There was a problem hiding this comment.
[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.
Spark row-level commands on Data Evolution tables can plan unrelated files for a physical
_ROW_IDpredicate because the bound is not applied before candidate splits are materialized. This change passes guaranteed conjunctive bounds toSnapshotReader.withRowRanges. It recognizes the canonical metadata attribute byexprId, including case-insensitive SQL references such as_row_id; a legal user column named_row_idhas a differentexprIdand cannot trigger physical row-ID pruning. Predicates underORand 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 plainDataSplitthat 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 anIndexedSplit. 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 lowercaseDELETE FROM t WHERE _row_id = 550(12 candidate files reduced to 1), a BLOB comparison inDELETE ... 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:
PaimonRowLevelCommandTest: 3 passed; focusedRowTrackingTestlowercase DELETE: 1 passed.-Pspark4 -Pfast-build: passed; focused lowercase DELETERowTrackingTest: 1 passed after clean rebuilding the Spark 4 shaded dependencies.spotless:checkfor the changed Spark common and test modules: passed.0f08933, Spark 3.5RowTrackingTest: 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.