Skip to content

Fix _row_id and _last_updated_sequence_number of Iceberg ORC and Avro data files - #130140

Merged
alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-row-lineage-orc-avro
Nov 8, 2026
Merged

alexey-milovidov merged 6 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-row-lineage-orc-avro

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130032
Related: #130093
Related: #130100
Related: #130028

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed _row_id and _last_updated_sequence_number of 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_id from first_row_id (it was NULL). A filter on these columns no longer skips rows by the values stored in the data file. The _row_number virtual 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 i returns 1 \N 3 / 2 \N 3 / 3 \N 3 instead of 1 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_id of ORC rows was NULL.

Changes:

Data files without first_row_id (#130021) are handled for every format by #130117.

Validation: 05613 reads the Impala table (as in #130028); 05614 checks 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-write UPDATE; the ORC pruning tests stop expecting NULL row ids. All fail on master and pass repeated randomized runs.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/130140]

Version info

  • Merged into: 26.11.1.1677-master (included in 26.11 and later)

groeneai and others added 6 commits November 8, 2026 08:12
`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]>
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (2 rounds): 1 fixed, 3 not applied, nits noted; round 2 found nothing new
Finding Verdict
❌ ORC row-number tests read only single-stripe files Fixed: 05570 (the test of the same commit in #130093, identical files) covers 3 stripes and a skipped row group
⚠️ ORC files are still not pruned by _row_id manifest bounds Not applied: for files whose lineage statistics are missing or have NULLs the bound does not contain stored ids above the file's own block (#130022), so this would lose ORC rows as it does Parquet rows today; it goes after #130100
⚠️ No Parquet test for lineage conjuncts not reaching the format Not applied: the change is format-independent and the ORC push-down arm fails when it is reverted; #130100 has the Parquet arm
💡 Compaction comment says only Parquet attaches row numbers Noted: #130093 rewrites these lines
💡 input_format_orc_allow_missing_columns = 0 + _row_id on files without stored lineage throws Noted: same as Parquet with its setting

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes: the issue's query on the Impala table returns 1 \N 3 / 2 \N 3 / 3 \N 3 on the official 26.10.2.103 image and on master, 1 0 1 / 2 1 2 / 3 2 3 with the fix (also with time travel).
b Root cause explained? Only Parquet data files had their stored _row_id / _last_updated_sequence_number read; the native ORC reader attached no row numbers, so the inherited _row_id of ORC rows was NULL.
c Fix matches root cause? Yes: ORC and Avro files read the stored columns, ORC attaches physical row numbers at the reader, and lineage conjuncts no longer reach the format filter (the stored statistics do not cover inherited values).
d Test intent preserved / new tests added? New: 05613 (Impala table), 05614 (inherited ORC/Avro lineage, schema change, skipped row group), 05570 (ORC row numbers across stripes and skipped row groups, shared with #130093), a Spark ORC/Avro integration test; the two ORC pruning tests stop pinning NULL row ids.
e Both directions demonstrated? Yes: all new and updated checks fail on master and pass with the fix; mutations of each part redden a check. Randomized runs green.
f Fix is general across code paths? Yes: every Iceberg data file format (Parquet unchanged), the schema-evolution read path, ORC stripe and row-group skipping, and the push-down of every format.
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes: files with and without stored lineage, either lineage column alone or both, small batches, a column added by ALTER.
h Backward compatible? (maintainer-approved exception only) Yes: no setting or on-disk change; _row_number of ORC files becomes non-NULL, and lineage filters no longer skip row groups by stored statistics (manifest pruning unchanged).
i Invariants and contracts preserved? Yes: lineage columns follow the Parquet path through the header and generate; one row-number offset per ORC chunk is exact because a batch never spans a skipped region; Avro marks only the two reserved lineage names absent.

Session id: cron:clickhouse-impl-slot-5:20261108-122800

@clickhouse-gh clickhouse-gh Bot added the can be tested Allows running workflows for external contributors label Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [05e7670]

Summary: ✅


AI Review

Summary

PR #130140, reviewed at 05e76702322282d795e9547f8ce181ca13a2f6e0, reads stored Iceberg row lineage from ORC and Avro files, supplies physical ORC row numbers for inherited values, and prevents lineage predicates from pruning by incomplete stored-column statistics. No actionable findings. The focused regression tests cover stored and inherited values, schema evolution, multiple stripes, skipped row groups, and Spark-written files.

Missing context / blind spots
  • ⚠️ I did not rerun the tests: this checkout has no compiled ClickHouse binary. The author reports successful regression runs. The published Fast test report skips the new format-specific tests, and the full-format and integration reports currently contain no test results; completed runs of 05570, 05613, 05614, and test_row_lineage_of_orc_and_avro_data_files would provide independent runtime confirmation.
Final Verdict

Status: ✅ Approve. No new inline findings to post.

@groeneai

groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @al13n321, could you review this? Iceberg ORC and Avro data files now read their stored _row_id / _last_updated_sequence_number (rows that do not store them inherit the values), and the native ORC reader attaches ChunkInfoRowNumbers, so the inherited ORC _row_id is first_row_id + position instead of NULL.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 8, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 05e767023 with master 7b5f2bf32 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

12 object files changed (+27.68 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/NativeORCBlockInputFormat.cpp.o 871.04 KiB 892.71 KiB +21.68 KiB (+2.49%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

139 translation units recompiled, 1401 s compile time in total, 139 of them have a recent master baseline.

Job report

@alexey-milovidov alexey-milovidov self-assigned this Nov 8, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
Merged via the queue into ClickHouse:master with commit 817039b Nov 8, 2026
193 of 194 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 8, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 8, 2026
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]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 9, 2026
…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]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg v3: row lineage (_row_id, _last_updated_sequence_number) is wrong for ORC data files

3 participants