Skip to content

Support Iceberg position deletes and deletion vectors on ORC and Avro data files - #130093

Merged
alexey-milovidov merged 13 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-position-deletes-orc-avro
Nov 23, 2026
Merged

alexey-milovidov merged 13 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-position-deletes-orc-avro

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130001
Related: #130140

Changelog category (leave one):

  • Improvement

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

Iceberg position deletes and deletion vectors are now applied to ORC and Avro data files (reading such tables failed with NOT_IMPLEMENTED). Closes #130001.

Description

Merge-on-read Iceberg tables written by Spark, Flink, Hive or Impala with write.format.default = orc / avro could not be read: Position deletes are only supported for data files of Parquet format in Iceberg, but got ORC (#130001). This was never supported, so the category is Improvement.

The delete transforms only need ChunkInfoRowNumbers (the file row number of each chunk) from the data file's reader. Avro (an IRowInputFormat) already attaches it, and the native ORC reader does since #130140, which carried this PR's first commit (with 05570); after merging master, that part is no longer in this diff. This PR makes the two Parquet-only checks (data file, and the delete file itself, which Spark writes in the table format) accept Parquet, ORC and Avro.

OPTIMIZE still refuses ORC and Avro position delete files, and position deletes on ORC and Avro data files (tested): compaction rewrites ORC and Avro data files by column name under the current schema, losing renamed columns.

Tests: the issue's Spark tables from ice-lens (unmodified, both bitmap modes, one row per chunk) and a Spark integration test for position deletes and v3 deletion vectors on ORC and Avro. The Doris Flink ORC tables of #130016 now give the Doris expected results.


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

Version info

  • Merged into: 26.12.1.303-master (included in 26.12 and later)

groeneai and others added 3 commits November 8, 2026 04:26
`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.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reading an Iceberg table with position deletes or deletion vectors on ORC or Avro data files
failed with `NOT_IMPLEMENTED` ("Position deletes are only supported for data files of Parquet
format"), and a position delete file in ORC or Avro format (Spark and Flink write the delete
files in the table's write format) was rejected with `BAD_ARGUMENTS`.

The delete transforms only need `ChunkInfoRowNumbers` on every chunk of the data file. The
Avro reader (an `IRowInputFormat`) already attaches it, and the native ORC reader does since
the previous commit, so both checks now accept Parquet, ORC and Avro. Reading the delete files
themselves is format-agnostic, as for equality deletes.

ORC chunks now carry row numbers, which would make `_row_id` of Iceberg v3 ORC data files
derived from `first_row_id + position`. The stored row ids of ORC files are not read, so a
rewritten file would return wrong ids; keep `_row_id` NULL for ORC as before.

Closes ClickHouse#130001

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`max_rows_to_read` is not checked for `file()` reads, so the test reads the `SelectedRows` profile event instead.

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: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (3 findings). No blocker or major; nothing changed for them.

# Sev Finding Verdict Evidence / action
1 💡 Comments outside the diff still call position deletes Parquet-only (IcebergDataObjectInfo.h:109, IcebergMetadata.cpp:2025) or blame missing ORC row numbers for the NULL ORC _row_id (test_row_lineage_pruning.py:295) AGREE noted, not blocking: no behaviour depends on them
2 💡 The rationale of the Parquet-only DELETE/UPDATE check in Mutations.cpp no longer holds AGREE noted, not blocking: the check itself stays correct (write side)
3 💡 04513_iceberg_optimize_orc_position_delete_88123.sh says ORC provides no ChunkInfoRowNumbers AGREE noted, not blocking: the test scenario and reference stay valid
4 💡 Experimental compaction (OPTIMIZE) now also accepts ORC/Avro data files with position deletes AGREE noted, not blocking: same reader and transform as the tested read path

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-11:20261108-064300

@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 SELECT count() FROM icebergLocal('orcfmt') / ('avrofmt') (ice-lens Spark tables, now test fixtures) fails with Code: 48 NOT_IMPLEMENTED on every run before the change, returns 4 after.
b Root cause explained? The delete transforms need ChunkInfoRowNumbers on each chunk. The native ORC reader did not attach it, so the data-file check and the delete-file check only admitted Parquet. Avro already attached it.
c Fix matches root cause? Yes: the ORC reader now produces exact file row numbers (stripe first row + row in stripe, correct under row-group and stripe skipping), and both checks admit Parquet, ORC and Avro.
d Test intent preserved / new tests added? New: 05569 (issue tables, both bitmap modes, one row per chunk), 05570 (3-stripe ORC _row_number, also under a filter push-down that skips a stripe and row groups, armed by SelectedRows: 200 of 10000), integration test for position deletes and v3 deletion vectors on Spark ORC/Avro tables. No existing test changed.
e Both directions demonstrated? Before: 05569 fails NOT_IMPLEMENTED, 05570 returns 10000 0 / 22 0, the integration test fails 2/2. After: all pass; 50 randomized runs of each stateless test pass. A skip-unaware row numbering (mutation) fails only 05570's push-down query.
f Fix is general across code paths? Data-file check, delete-file check and the deletion-vector path share the producer; compaction gets ORC/Avro too; _row_number now works for ORC in file/s3/url; Parquet/Vortex unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? ORC and Avro, v2 and v3, partitioned tables, batch sizes 1 / 37 / default across stripes and row groups, push-down on and off.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; ORC _row_number goes from NULL to the row number (in the changelog); ORC _row_id stays NULL.
i Invariants and contracts preserved? One consecutive offset per chunk (a batch never spans a skipped region), chunks in increasing row order, stripe row prefix sums checked for overflow when the footer is read.

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

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @al13n321, could you review this and add the can be tested label so CI runs? The native ORC reader now attaches ChunkInfoRowNumbers (stripe first row from the footer plus the row in the stripe, exact when stripes or row groups are skipped), and the Iceberg data-file and delete-file checks accept ORC and Avro besides Parquet, so position deletes and deletion vectors now apply to ORC and Avro tables.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [de90c8f]

Summary: ✅


AI Review

Summary

The PR enables Iceberg position deletes and deletion vectors for ORC and Avro data files while retaining compaction restrictions. No unresolved blockers or majors found at de90c8f9e5cf8e890a1d623a2cbfe2e0b340a276; the previous compaction findings are addressed in the current code.

Missing context / blind spots
  • ⚠️ Full stateless and Spark integration results for this head were not available during review. Runtime evidence comes from the author's recorded earlier validation; no build or tests were run locally.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 8, 2026
…files

Compaction reads every data file with the current schema as the header.
The Parquet reader resolves the columns by field id, but the ORC and Avro
readers resolve them by name, so after a column rename compaction cannot
read the renamed column from older ORC/Avro files. Before this PR,
`addPositionDeleteFile` refused position deletes on non-Parquet data
files, which also kept compaction away from such tables. Now that reads
accept ORC and Avro, `getPlan` has to refuse them itself.

Measured on a Spark ORC table with one position delete, after
`ALTER TABLE t RENAME COLUMN name TO renamed_name`: `OPTIMIZE` returned
success, removed the original ORC files and wrote Parquet files where
`renamed_name` is NULL in every row. The Avro twin failed with
`THERE_IS_NO_COLUMN`. With this check both are refused with
`NOT_IMPLEMENTED` before anything is written, as on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing de90c8f9e with master df93bed59 (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.

Compile time of recompiled translation units

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

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All good.

@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
alexey-milovidov pushed a commit to punithns97/ClickHouse that referenced this pull request Nov 8, 2026
`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]>
alexey-milovidov pushed a commit to punithns97/ClickHouse that referenced this pull request Nov 8, 2026
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]>
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]>
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 8, 2026
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

The merge queue run failed in 3 row-lineage integration tests (test_row_lineage_of_orc_and_avro_data_files[s3-orc], test_row_id_pruning_is_skipped_for_orc[s3] and its _clickhouse variant). This PR kept the _row_id of ORC files NULL, and that became wrong once #130140, now on master, started reading the stored ORC lineage. 745c7ae drops the exclusion, so the PR no longer touches StorageObjectStorageSource.cpp. On master plus this PR, the 3 tests pass locally and fail without that commit. The PR needs to be added to the merge queue again.

groeneai and others added 2 commits November 8, 2026 22:07
Compaction rewrites every data file of the table under the current
schema, and the ORC and Avro readers resolve the columns by name. Before
this PR the position delete reader accepted only Parquet delete files, so
compaction of a table with ORC or Avro delete files failed before it
committed anything. Now that reads accept them, such a table reached the
rewrite whenever its ORC or Avro data files had no delete attached (newer
than the deletes, or outside their bounds), because only attached data
files are checked. After a column rename, `OPTIMIZE` then succeeded and
rewrote those files without the renamed column's values.

`getPlan` now also refuses a position delete file that is not Parquet, so
compaction accepts the same tables as before this PR. The test writes,
with Spark, a Parquet data file with an ORC or Avro position delete and a
newer ORC data file, renames a column, and checks that `OPTIMIZE` is
refused and the renamed column survives. The ORC data file is newer than
the delete, because Spark's Avro delete files record no bounds.

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]>
@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merged master to resolve the conflict in ORC/Reader.h: the first commit of this PR (ORC file row numbers) reached master via #130140 and was then changed there by the VectorWithMemoryTracking refactor, so I took master's version of the ORC reader files. The rest of the diff is unchanged, and it no longer touches the ORC reader. On the merged tree, the ORC/Avro position-delete and row-lineage tests (stateless and Spark integration) pass locally. The PR needs to be added to the merge queue again.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (b271a92907b4) to refresh the PR. The previous run was fully green, but CH Inc sync had been stuck on "GitHub doesn't know if the PR is mergeable" since 2026-11-09. The merge was clean; Compaction.cpp was the only file touched by both sides, and the PR's three changed translation units (Compaction.cpp, IcebergDataObjectInfo.cpp, PositionDeleteTransform.cpp) compile on the merged tree. The PR diff is unchanged.

# Conflicts:
#	tests/integration/test_storage_iceberg_with_spark/test_optimize.py
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (51764aa30c06) to fix the merge conflict in tests/integration/test_storage_iceberg_with_spark/test_optimize.py. Master added a get_latest_metadata helper in the same spot where this PR adds test_optimize_refuses_orc_avro_position_deletes, so I kept both. The changed Iceberg translation units (Compaction.cpp, IcebergDataObjectInfo.cpp, PositionDeleteTransform.cpp) build cleanly on the merged tree.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (0eb6d22f1b61) to refresh the PR again. CI was green apart from CH Inc sync, which had been stuck on "GitHub doesn't know if the PR is mergeable" since 2026-11-14. The merge was clean. Compaction.cpp and PositionDeleteTransform.cpp were changed on both sides; master only switched is_remote_fs to object_storage->isRemote() and added a [[nodiscard]]. Both files compile locally. The PR's diff against master is unchanged.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged the latest master (e62fb6c0ff84) to refresh the PR again. CI was green apart from CH Inc sync, which was stuck on "GitHub doesn't know if the PR is mergeable". The merge was clean; PositionDeleteTransform.cpp was the only PR file also changed on master (an unrelated fix of the file_path schema field). The PR diff against master is unchanged, and the three changed Iceberg translation units (Compaction.cpp, IcebergDataObjectInfo.cpp, PositionDeleteTransform.cpp) compile on the merged tree.

@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 19, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 CH Inc sync was stuck on "GitHub doesn't know if the PR is mergeable" because the sync PR had a merge conflict in tests/integration/test_storage_iceberg_with_spark/test_optimize.py, so the earlier merges of master here could not help. I resolved the conflict on the sync branch; the sync PR is mergeable now and its CI has started. No change to this PR was needed: its CI is green and there are no unresolved review threads.

@stresshouse

stresshouse Bot commented Nov 22, 2026

Copy link
Copy Markdown

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 29 queries analysed

no significant changes detected. K_source=4 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 94c880fe-3ce9-43ee-8ebd-dfe619d83adb
  • MIRAI run: e9ae3244-d2d3-4d73-8f73-1c6dcdba9c31
  • PR check IDs:
    • clickbench_857427_1795381497
    • clickbench_857441_1795381497
    • tpch_adapted_1_official_857470_1795381497
    • tpch_adapted_1_official_857492_1795381497

alexey-milovidov and others added 2 commits November 23, 2026 04:07
`CH Inc sync` failed in the flaky check of
`05569_iceberg_position_deletes_orc_avro`: on the cloud build `OPTIMIZE`
goes through a different code path, which starts the background compaction
jobs of the table. `clickhouse-local` does not create the background
executors unless a `MergeTree` table exists, so the shutdown of the table
called a method on a null executor in `BackgroundJobsAssignee::finish`
and UBSan reported it.

The test already ignored the result of `OPTIMIZE` on the cloud build, so
do not run it there at all. The check on the open-source build is unchanged.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 CH Inc sync failed with "tests failed (8 new, 2 known)": the new failures were all 05569_iceberg_position_deletes_orc_avro in the flaky check of the cloud build. There OPTIMIZE goes through a different code path that starts the background compaction jobs of the table, and clickhouse-local has no background executors unless a MergeTree table exists, so the shutdown of the table called a method on a null executor in BackgroundJobsAssignee::finish and UBSan reported it. The test output itself matched the reference.

The test already ignored the result of OPTIMIZE on the cloud build, so a922f13 no longer runs it there; the check on the open-source build is unchanged (verified against the arm_release binary of 081d3be). The null executor is an existing problem of the cloud-only code, not of this PR, and still needs a fix there.

Also merged the latest master (b04c4d810830). The merge was clean; Compaction.cpp was changed on both sides and still compiles.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 23, 2026
Merged via the queue into ClickHouse:master with commit 949dfff Nov 23, 2026
195 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 23, 2026
alexey-milovidov added a commit that referenced this pull request Nov 24, 2026
… on ORC are supported now

Position deletes against ORC data files were implemented in
#130093
(#130001), so after merging
`master` the test passes and the comment about the expected failure is stale.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
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-improvement Pull request with some product improvements 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: position deletes on ORC and Avro data files are not supported (NOT_IMPLEMENTED)

3 participants