Repository navigation
Fix _row_id and _last_updated_sequence_number of Iceberg ORC and Avro data files - #130140
alexey-milovidov merged 6 commits into
Conversation
`NativeORCBlockInputFormat` attached no `ChunkInfoRowNumbers`, so `_row_number` was NULL for ORC files and every consumer of physical row numbers (Iceberg position deletes and deletion vectors, `_row_id`) could not work with ORC data files. The row number of a batch is not the count of rows delivered so far: `RowReader` skips row groups inside a stripe and whole stripes (search argument, stripe statistics, `skip_stripes`). `Reader::readTail` now records the first row of every stripe (prefix sums of the footer's `number_of_rows`, checked for overflow in the existing stripe validation loop), and `RowReader::next` remembers `stripe first row + current row in stripe` of the batch it fills. A batch never spans a skipped region (`computeBatchSize` stops at the next skipped row), so one offset per chunk is exact. The format attaches it only when `need_row_numbers` is set, like the Parquet and Vortex readers. Also remove the `USE_PARQUET || USE_VORTEX` guards around the `_row_number` and `_row_id` extraction in `VirtualColumnUtils`: `ChunkInfoRowNumbers` is declared in `IInputFormat.h` and is produced by ORC and every `IRowInputFormat`, so a build without Parquet and Vortex must not return NULL row numbers for them. The same change as the first commit of ClickHouse#130093 (ClickHouse#130001). Co-Authored-By: Claude Opus 5.5 <[email protected]>
`getFormatFilter` kept the conjuncts on `_row_id` and `_last_updated_sequence_number` for Iceberg, so the Parquet reader pruned row groups, pages and dictionaries by the statistics of the column stored in the data file. Those statistics do not cover rows that store NULL and inherit the value, so a filter above the stored maximum skipped row groups with matching inherited values. After a Spark copy-on-write `UPDATE` the rewritten file stores `_last_updated_sequence_number` [1, NULL, 1, 1], and `WHERE _last_updated_sequence_number = 2` lost the updated row with the default `input_format_parquet_filter_push_down = 1`. The lineage columns are now treated like every other virtual column added after the format; the filter is still applied after the source, and the manifest-level pruning keeps skipping whole files where declared bounds allow it. This is needed here because ORC data files now read the stored lineage columns too, and the ORC search argument would prune stripes and row groups by them the same way. The same change as in the fix of ClickHouse#130022. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_row_id` and `_last_updated_sequence_number` are stored in the data files a writer rewrites (compaction, copy-on-write UPDATE/DELETE/MERGE). The source asked the reader for them only for Parquet files, so for ORC and Avro files the stored values were ignored and every row got the inherited values: the new file's `first_row_id` + position and its data sequence number. For ORC the inherited `_row_id` was also NULL, because the ORC reader attached no row numbers (fixed in the previous commit). Request the stored columns for ORC and Avro data files too. The ORC reader binds columns by name and reads a missing one as NULL. The Avro reader throws on a missing field, so for an Iceberg read the row lineage columns absent from the file's record are marked absent, like the table columns whose field id is not in the file. Any other missing field still fails. Closes ClickHouse#130032 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`05613` reads the Impala `iceberg_v3_row_lineage_orc` table (Spark, three appends and a compaction that stores the lineage columns), byte-identical to the copy in ClickHouse#130028. `05614` checks the inherited lineage of ClickHouse-written v3 tables with ORC and Avro data files, also after a schema change, and reads ORC files after a skipped row group. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`test_row_lineage_of_orc_and_avro_data_files` reads tables with ORC and Avro data files after a copy-on-write UPDATE and an append. Spark (Iceberg 1.11) reads the row lineage of ORC files without the row position, so its lineage is compared for Avro only; for ORC the test checks the sequence numbers and the inherited row ids of the appended file, and both formats check that a filter on `_last_updated_sequence_number` keeps the updated row. The ORC tests of `test_row_lineage_pruning.py` no longer pin `_row_id` NULL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every ORC file the other tests of this branch read has a single stripe, so the stripe prefix sums behind the ORC row numbers were not exercised: `row_numbers_multi_stripe.orc` has three stripes of 1500, 2500 and 6000 rows with a row index stride of 100, and 05570 checks `_row_number` with batches that do not align with stripes or row groups, and with a filter push-down that skips a whole stripe and most row groups of the others. 05570 and its fixture are taken byte-identically from ClickHouse#130093, which adds the same ORC row-number commit, so either merge order adds the same files. The 05614 echo prints the number of data files, so its label says so. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (2 rounds): 1 fixed, 3 not applied, nits noted; round 2 found nothing new
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261108-122800 |
|
Workflow [PR], commit [05e7670] Summary: ✅
AI ReviewSummaryPR #130140, reviewed at Missing context / blind spots
Final VerdictStatus: ✅ Approve. No new inline findings to post. |
|
cc @scanhex12 @al13n321, could you review this? Iceberg ORC and Avro data files now read their stored |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes12 object files changed (+27.68 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units139 translation units recompiled, 1401 s compile time in total, 139 of them have a recent master baseline. |
817039b
This PR kept `_row_id` of v3 ORC data files NULL, because the ORC reader did not read the stored row lineage columns, so deriving `first_row_id + _row_number` would have been wrong for rewritten files. ClickHouse#130140 (merged) reads the stored ORC lineage now, so that exclusion turned into a regression on master: inherited ORC row ids were NULL again, and test_row_lineage_of_orc_and_avro_data_files[s3-orc], test_row_id_pruning_is_skipped_for_orc[s3] and test_row_id_pruning_is_skipped_for_orc_clickhouse[s3] failed in the merge queue. Restore the master code in StorageObjectStorageSource::generate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…sition-deletes-orc-avro The native ORC reader row-number commit of this PR reached master via ClickHouse#130140; the conflict in `ORC/Reader.h` is resolved to master's version. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #130032
Related: #130093
Related: #130100
Related: #130028
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
_row_idand_last_updated_sequence_numberof Iceberg v3 tables with ORC and Avro data files: the values stored in the data file are used, and ORC rows without them inherit_row_idfromfirst_row_id(it wasNULL). A filter on these columns no longer skips rows by the values stored in the data file. The_row_numbervirtual column now returns row numbers for ORC files. Closes #130032.Description
On
v26.10.2.103-stable,SELECT i, _row_id, _last_updated_sequence_number FROM icebergLocal('iceberg_v3/iceberg_v3_row_lineage_orc') ORDER BY ireturns1 \N 3 / 2 \N 3 / 3 \N 3instead of1 0 1 / 2 1 2 / 3 2 3, as for its Parquet copy.Only Parquet data files had their stored lineage columns read, so ORC and Avro rows always got the inherited values; and the native ORC reader attached no row numbers, so the inherited
_row_idof ORC rows wasNULL.Changes:
_row_id/_last_updated_sequence_numberare read for ORC and Avro data files too; a file that does not store them reads them asNULL.first_row_id+ position_row_idthis PR makes unnecessary: whichever of the two merges second removes it._row_idand_last_updated_sequence_numberfilters losing rows of files that store lineage values #130100): the stored column's statistics do not cover rows that storeNULLand inherit the value, so ORC stripes and Parquet row groups with matching rows could be skipped.Data files without
first_row_id(#130021) are handled for every format by #130117.Validation:
05613reads the Impala table (as in #130028);05614checks the inherited lineage of ClickHouse-written ORC and Avro tables;05570(from #130093) checks ORC row numbers across stripes and skipped row groups; a Spark integration test covers ORC and Avro files rewritten by a copy-on-writeUPDATE; the ORC pruning tests stop expectingNULLrow ids. All fail on master and pass repeated randomized runs.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130140]
Version info
26.11.1.1677-master(included in26.11and later)