Repository navigation
Reject Iceberg ALTER DELETE/UPDATE on non-Parquet tables - #105893
PedroTadim merged 6 commits into
Conversation
`ALTER TABLE ... DELETE` and `ALTER TABLE ... UPDATE` on Iceberg tables whose data file format is not Parquet either aborted the server (`Unexpected null _row_number` LOGICAL_ERROR on ORC) or silently corrupted the table (Avro write succeeded but produced position-delete files that the read path then rejected with `NOT_IMPLEMENTED`). Mutations write position-delete files using the table's `write_format`. The read side only accepts Parquet there (`IcebergDataObjectInfo::addPositionDeleteObject`), and the ORC/Avro write paths do not match that contract. PR ClickHouse#87277 (introducer) enabled non-Parquet table formats in `FileNamesGenerator` without gating the mutation paths. Validate the format up front with a single helper `Iceberg::validateMutationWriteFormat`. It is called from both `IcebergMetadata::checkMutationIsPossible` (early rejection during analysis) and `Iceberg::mutate` (defence in depth for any direct caller). Parquet tables continue to work; `ALTER ... ADD/DROP/MODIFY/RENAME COLUMN` are unaffected. Closes ClickHouse#102508.
Pre-PR validation gateSession: a) Deterministic repro? Yes. SET allow_experimental_insert_into_iceberg = 1;
CREATE TABLE t (id Int32, val String) ENGINE = IcebergLocal('/tmp/...', 'ORC')
SETTINGS iceberg_format_version = 2;
INSERT INTO t VALUES (1, 'a'), (2, 'b');
ALTER TABLE t DELETE WHERE id = 2;
b) Root cause explained? Yes. c) Fix matches root cause? Yes. d) Test intent preserved? / New tests added? Yes.
e) Demonstrated in both directions? Yes.
f) Fix is general, not a narrow patch? Yes. I also considered Option B (always write position-delete files as Parquet regardless of the data file format). That is permissible per the Iceberg v2 spec, but it would touch the read path and is a larger change. Option A (this PR) closes the crash and the data-corruption window immediately; Option B can be a follow-up improvement if mixed-format support is desired. |
|
cc @alesapin @scanhex12 @Michicosun could you review this? It rejects ALTER DELETE/UPDATE on Iceberg tables whose data file format is not Parquet (ORC aborts, Avro corrupts the table) with a clean NOT_IMPLEMENTED at the entry to mutate / checkMutationIsPossible. |
|
Workflow [PR], commit [25f3acf] Summary: ❌
AI ReviewSummaryThis PR closes the ORC/Avro mutation failure modes by rejecting non- Findings
Final Verdict
|
Address the inline review comment on PR ClickHouse#105893 by `clickhouse-gh[bot]`: the previous validation only looked at the table's configured `write_format`, but Iceberg permits mixed-format tables, so a table mounted with default `Parquet` config can still contain `ORC`/`Avro` data files. In that case `ALTER ... DELETE`/`UPDATE` would write position-delete files referencing those non-Parquet data files, and reads then fail in `IcebergDataObjectInfo::addPositionDeleteObject` (which requires `info.file_format == "PARQUET"`), leaving the table unreadable. Add a deeper per-data-file check in `IcebergMetadata::mutate` that walks the current snapshot's manifests and throws `NOT_IMPLEMENTED` if any data file is not Parquet. The fast configured-format check in `checkMutationIsPossible` is kept as an early reject for the obvious case. This also corrects the regression in `04092_iceberg_update_low_cardinality` Test 2: that test verified an Avro `ALTER UPDATE` did not crash, but per issue ClickHouse#102508 the previous outcome silently corrupted the table. The test now verifies the rejection itself, which still demonstrates that the original LowCardinality issue (ClickHouse#101916) does not crash the server. For ClickHouse#102508.
|
Pre-PR validation gate (followup commit cfaf9a5): a. Deterministic repro. The Avro Session: cron:clickhouse-ci-task-worker:20260526-184500. |
Moves the per-data-file Parquet validation from a pre-check in IcebergMetadata::mutate into DB::Iceberg::mutate's retry loop. The pre-check validated the snapshot at the moment it ran, but the retry loop re-fetches metadata with force_fetch_latest_metadata = true and writes position deletes against whatever snapshot it sees next. A concurrent writer that committed non-Parquet data files in that window could leave the table unreadable (IcebergDataObjectInfo::addPositionDeleteObject rejects non-Parquet data files). Validating after each metadata fetch closes that TOCTOU gap and keeps the mixed-format protection. Per the PR review at ClickHouse#105893
This commit reverts the materialization change in src/Processors/Transforms/FinishSortingTransform.cpp added by the previous commit, and keeps only the documentation test under tests/queries/0_stateless/04300_stid_3336_finishsorting_columnreplicated.sql. The reported "Bad cast from type DB::ColumnReplicated to DB::ColumnString" exception captured in CI on PR ClickHouse#102882, PR ClickHouse#104478, PR ClickHouse#105893 does not reproduce deterministically on master HEAD on a debug build, so the preceding source change was speculative and is dropped. The test stays as a name-anchored reproducer for the query shape captured in CI. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=102882&sha=1de47ad4469490e183bd76c5dad2eddd82d61422&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%201%2F2%29
|
@groeneai merge with master for one more CI run |
…-iceberg-mutate-non-parquet
|
@PedroTadim merged master in |
|
Dear @alesapin, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
CI finish ledger — b85c34aCI fully finished (Finish Workflow pass). The sole failure is the chronic
Session id: cron:our-pr-ci-monitor:20260703-053000 |
…o groeneai/fix-102508-iceberg-mutate-non-parquet
| for (const auto & file_entry : files_handle.getFilesWithoutDeleted(FileContentType::DATA)) | ||
| { | ||
| const String & file_format = file_entry->parsed_entry->file_format; | ||
| if (Poco::toLower(file_format) != "parquet") |
There was a problem hiding this comment.
This now rejects a mutation if any file in the current snapshot is non-Parquet. That is broader than the actual safety boundary: writeDataFiles creates position-delete files per touched partition, and IcebergIterator::defineDeletesSpan only applies them to data files with the same partition spec/value. A table mounted from an external writer can legitimately have Avro in partition p=1 and Parquet in partition p=2; ALTER ... DELETE WHERE p = 2 should still be safe, but this check turns it into blanket NOT_IMPLEMENTED. The validation needs to be scoped to the files or partitions the mutation can actually touch, or the broader behavior change needs to be made explicit.
There was a problem hiding this comment.
Verified the mechanism: defineDeletesSpan (IcebergIterator.cpp:110-111) matches position deletes to data files by partition spec + value, so ALTER ... DELETE WHERE p = 2 on an Avro(p=1)/Parquet(p=2) table would write position deletes only against the Parquet partition and could indeed be safe. This check is intentionally broader.
It is the conservative, fail-closed boundary for the crash/corruption in #102508: rejecting the whole mutation is always safe (it can never leave the table unreadable via the read-side check in addPositionDeleteObject, IcebergDataObjectInfo.cpp:100), whereas per-partition scoping requires pruning the mutation predicate against each data file's partition spec/value and handling partition-spec evolution, which is a materially larger change.
I would prefer to land the safe reject for the crash fix here and track the per-partition narrowing as a follow-up rather than block this PR on it. I can open a follow-up issue for the narrowing.
|
@alesapin I think this is in good shape to be merged? |
CI finish ledger - 44d6991Every failure below has an owner: a fixing PR. Only
Config Workflow, Finish Workflow green. @alexey-milovidov (on #110705) confirmed this PR covers the Session id: cron:our-pr-ci-monitor:20260717-193000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 46/56 (82.14%) · Uncovered code |
CI finish ledger — 25f3acfEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260721-003000 |
|
Ledger follow-up for the "Stress test (amd_debug) / Cannot start clickhouse-server" line (SHA 25f3acf; the "fixing-PR link to follow here" promised above). Recovered inner error: Fixing PR: #110999 (pins the 4 part_loading_tree_rollback tests to the local |
104b5ac
Address the inline review comment on PR ClickHouse#105893 by `clickhouse-gh[bot]`: the previous validation only looked at the table's configured `write_format`, but Iceberg permits mixed-format tables, so a table mounted with default `Parquet` config can still contain `ORC`/`Avro` data files. In that case `ALTER ... DELETE`/`UPDATE` would write position-delete files referencing those non-Parquet data files, and reads then fail in `IcebergDataObjectInfo::addPositionDeleteObject` (which requires `info.file_format == "PARQUET"`), leaving the table unreadable. Add a deeper per-data-file check in `IcebergMetadata::mutate` that walks the current snapshot's manifests and throws `NOT_IMPLEMENTED` if any data file is not Parquet. The fast configured-format check in `checkMutationIsPossible` is kept as an early reject for the obvious case. This also corrects the regression in `04092_iceberg_update_low_cardinality` Test 2: that test verified an Avro `ALTER UPDATE` did not crash, but per issue ClickHouse#102508 the previous outcome silently corrupted the table. The test now verifies the rejection itself, which still demonstrates that the original LowCardinality issue (ClickHouse#101916) does not crash the server. For ClickHouse#102508.
Moves the per-data-file Parquet validation from a pre-check in IcebergMetadata::mutate into DB::Iceberg::mutate's retry loop. The pre-check validated the snapshot at the moment it ran, but the retry loop re-fetches metadata with force_fetch_latest_metadata = true and writes position deletes against whatever snapshot it sees next. A concurrent writer that committed non-Parquet data files in that window could leave the table unreadable (IcebergDataObjectInfo::addPositionDeleteObject rejects non-Parquet data files). Validating after each metadata fetch closes that TOCTOU gap and keeps the mixed-format protection. Per the PR review at ClickHouse#105893
…8-iceberg-mutate-non-parquet Reject Iceberg ALTER DELETE/UPDATE on non-Parquet tables
`OPTIMIZE TABLE` on an Iceberg v2 table failed with
Code: 48. DB::Exception: Position deletes are only supported for data files
of Parquet format in Iceberg, but got ORC. (NOT_IMPLEMENTED)
on a snapshot that `SELECT` reads correctly. The carrier is a current snapshot
holding, in one partition, a non-Parquet data file whose sequence number is not
above a position delete's, where that delete references only Parquet data files.
Such a table has to be written by another engine, because ClickHouse's own
DELETE and UPDATE refuse while a non-Parquet data file is live in the current
snapshot (`validateSnapshotDataFileFormatsForMutation`).
Compaction and the read path both decide whether a position delete applies to a
data file, and compaction's decision had one term fewer. `IcebergIterator::next`
also tests the delete's `lower_reference_data_file_path` and
`upper_reference_data_file_path` against the data file's own
`data_object_file_path_key`; `getPlan` tested only the partition value and the
sequence number, so it handed a delete that provably does not name a data file to
`addPositionDeleteObject`, which rejects a non-Parquet data file. This adds that
bounds test, and only it, so the per-pair decision matches the read path's. As on
read, absent bounds mean no pruning, so a delete recording no bounds still
reports the same error a `SELECT` reports.
Results were never wrong: both delete transforms call
`filterChunkToCurrentDataFile`, so an over-attached delete could not delete
another file's rows. The change only shrinks the attachment set, and compaction's
candidate set is a superset of the read path's, so no delete the read path
applies can be lost. `writeDataFiles`' precondition still holds: a previously
over-attached non-Parquet file now takes the already-exercised no-deletes branch.
Equality deletes are unaffected. `getPlan` collects only position deletes, an
OVERWRITE snapshot carrying equality deletes is refused earlier by
`overwriteIsPositionDeleteOnly`, and `addEqualityDeleteObject` has no format
precondition.
The pass still buckets deletes by partition value without
`common_partition_specification`, so the two predicates match per pair, not as a
whole. That is left alone: data compaction resolves one default partition spec
and rewrites every manifest under it, so narrowing the bucket per spec would fix
one term of a path that then collapses all specs to one.
The regression test is an integration test because the snapshot needs an
external writer. It builds the mixed-format table with Spark and asserts the row
set is unchanged across the `OPTIMIZE`. Its arming conditions are asserted
separately, and they hold on the unfixed build, so a green run measures the fix
rather than the fixture.
Related: ClickHouse#110069, where this was reported, and ClickHouse#102508 / ClickHouse#105893, which fixed the
mutation half of the same restriction.
Closes #102508.
ALTER TABLE ... DELETE(andUPDATE) on Iceberg tables whose data file format is not Parquet either crashed the server (LOGICAL_ERROR"Unexpected null _row_number" on ORC; abort inAvroSerializerfor some schemas) or silently corrupted the table (Avro write succeeds, all subsequentSELECTs fail withNOT_IMPLEMENTEDbecause the read path rejects non-Parquet data files when position deletes are present).Mutations write position-delete files using the table's
write_format. The read path inIcebergDataObjectInfo::addPositionDeleteObjectonly accepts Parquet there, and the ORC/Avro write paths do not match that contract. PR #87277 enabled non-Parquet table formats inFileNamesGeneratorwithout gating the mutation paths.This PR rejects the mutation up front with
NOT_IMPLEMENTEDso the user gets a clear error and the table is not left in a broken state. Validation lives in a single helperIceberg::validateMutationWriteFormatand is called from bothIcebergMetadata::checkMutationIsPossible(early rejection during analysis) andIceberg::mutate(defence in depth for any direct caller).Parquet tables continue to work;
ALTER ... ADD/DROP/MODIFY/RENAME COLUMNare unaffected (they don't depend on the data file format).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Reject
ALTER TABLE ... DELETEandALTER TABLE ... UPDATEon Iceberg tables whose data file format is notParquetwith a clearNOT_IMPLEMENTEDerror instead of crashing the server or silently corrupting the table.Documentation entry for user-facing changes
Version info
26.7.1.1265(included in26.7and later)