Skip to content

Iceberg: ignore unparsable sort-order transform instead of aborting the server - #121687

Merged
alexey-milovidov merged 15 commits into
ClickHouse:masterfrom
iliasabk:fix/iceberg-sort-order-unparsed-transform
Oct 7, 2026
Merged

alexey-milovidov merged 15 commits into
ClickHouse:masterfrom
iliasabk:fix/iceberg-sort-order-unparsed-transform

Conversation

@iliasabk

@iliasabk iliasabk commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fix a server abort when reading an Iceberg table whose sort order names a transform ClickHouse cannot parse (e.g. bucket[xyz]); ClickHouse now ignores that sort-order hint and keeps the table readable.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Motivation / issue

Iceberg::getSortingKeyDescriptionFromMetadata stores the std::optional returned by parseTransformAndArgument and dereferences it unconditionally. For unsupported transforms and malformed truncate[...]/bucket[...] arguments the parser returns std::nullopt, so a single bad transform string in metadata.json aborts the whole server during query analysis — before any data is read — and every retry/replica pointed at the same table crashes again.

Fix

Check has_value() on the parsed transform. If a sort-order field names a transform that parseTransformAndArgument cannot handle, getSortingKeyDescriptionFromMetadata returns an empty KeyDescription: an Iceberg sort order is only an optimization hint, so reads treat the table as unsorted (hasSortingKey is false, no read-in-order optimization on a misdescribed order) and writes skip sortBlockByKeyDescription. An earlier revision threw BAD_ARGUMENTS instead; that was replaced after review because it made every SELECT/DESCRIBE/INSERT on such a table fail.

Regression test

tests/queries/0_stateless/05237_iceberg_sort_order_unknown_transform.sh creates an IcebergLocal v2 table with ORDER BY icebergTruncate(3, x), inserts rows, rewrites the transform in the latest v*.metadata.json to bucket[xyz], then asserts that SELECT ... FROM icebergLocal(...) still returns the rows and that the server still answers SELECT 1.

Verification

The change is one has_value() guard plus the stateless test; the new test passes in CI.


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

Version info

  • Merged into: 26.10.1.1727-master (included in 26.10 and later)
  • Backported to: 26.9.13.8, 26.8.20.10, 26.7.24.10, 26.3.45.3

@alexey-milovidov alexey-milovidov self-assigned this Sep 23, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Sep 23, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [70d9691]

Summary: ✅


AI Review

Summary

This PR changes Iceberg::getSortingKeyDescriptionFromMetadata to drop an unparseable Iceberg sort order and treat the table as unsorted instead of dereferencing or rejecting it, which keeps the table readable and writable when metadata.json contains an unsupported or malformed sort-order transform. The current diff also hardens the regression test so it exercises both the std::nullopt and BAD_ARGUMENTS parser paths and the attached-table INSERT path with use_iceberg_metadata_files_cache = 0 applied early enough to force a fresh metadata read. I do not see any remaining correctness, compatibility, or test-coverage issues in the current version.

Final Verdict

✅ Approve

LLVM Coverage Report

Measured on commit 70d9691.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 92.10% 92.10% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. external Author is not a member of the ClickHouse organization labels Sep 23, 2026
…error lines

In the private CI (`CH Inc sync`) the client output of the failing
`SELECT` contains `BAD_ARGUMENTS` on two lines, so `grep -c` printed `2`
instead of the expected `1` in every run of the test. The test only needs
to check that the error is raised, so count at most one matching line.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 CH Inc sync was red because the new test 05237_iceberg_sort_order_unknown_transform failed in every private run: the client output there contains BAD_ARGUMENTS on two lines, so grep -c printed 2 instead of 1. The test now uses grep -m1 -c, so it only checks that the error is raised (94e2763). The other private reds are Integration tests E2E, where GCP auth expired (RefreshError: Reauthentication is needed), which is infrastructure and unrelated to this PR. The previous public CI run had 0 failures.

…ting the table

An unknown transform in a table's sort order made every read and write fail with
BAD_ARGUMENTS, which turns an optimization-level incompatibility into an unusable
table. Iceberg sort orders are only an optimization hint, so return an empty
KeyDescription: reads then treat the table as unsorted and writes skip
sortBlockByKeyDescription. The regression test asserts that the table stays
readable instead of checking for the error.
@iliasabk

Copy link
Copy Markdown
Contributor Author

Implemented the suggested fallback: getSortingKeyDescriptionFromMetadata now returns an empty KeyDescription when a sort-order field names a transform that parseTransformAndArgument cannot handle, so reads treat the table as unsorted (hasSortingKey() is false) and writes skip sortBlockByKeyDescription, instead of rejecting every query on such a table.

The regression test now asserts that the table stays readable without the sorted-read optimization (and that the server is alive) rather than checking for BAD_ARGUMENTS.

@iliasabk

Copy link
Copy Markdown
Contributor Author

Status on e9bdc14: all stateless, functional, integration and stress checks are green, including the reworked 05237_iceberg_sort_order_unknown_transform test. The two remaining reds are unrelated to this change — the arm_release performance-comparison shard (benchmark diff on the hits_100m queries, no Iceberg code path) and the upgrade check, which fails on an unrelated test_1.t4 startup-load ARGUMENT_OUT_OF_BOUND flake. Since the fallback changed the behavior after your earlier approval, a re-review would be needed whenever you have a moment — happy to adjust if you'd rather keep the strict BAD_ARGUMENTS semantics instead.

@alexey-milovidov alexey-milovidov changed the title Iceberg: throw on unparsable sort-order transform instead of aborting the server Iceberg: ignore unparsable sort-order transform instead of aborting the server Sep 27, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged current master (clean, no conflicts; Utils.cpp compiles) and updated the PR title, changelog entry and Fix/Regression test sections to describe the final behavior (unknown sort-order transform → empty KeyDescription, table read as unsorted) instead of the superseded BAD_ARGUMENTS, as the AI review requested. The reds on e9bdc14 are unrelated: the Upgrade check countResample ARGUMENT_OUT_OF_BOUND on startup comes from the previous release and is fixed by #121590 (clears once a 26.9 patch release ships), and the arm perf shard regressions are in timeseries_to_grid_aggregation_functions/order_by_read_in_order, which do not touch Iceberg code. The switch from throwing to ignoring the sort order happened after the earlier approval, so it needs a human re-review.

`parseTransformAndArgument` throws BAD_ARGUMENTS for spellings like
`bucket]` or `truncate42]` (a `bucket`/`truncate` prefix, a trailing `]`,
but no `[`). Those inputs rejected the whole table even though an
Iceberg sort order is only an optimization hint. Catch that error code
in `getSortingKeyDescriptionFromMetadata` and treat it the same as the
`nullopt` case: drop the sort order and read the table as unsorted.

Extend the regression test with the `bucket]` spelling so it covers
the throwing path too, not only the `bucket[xyz]` nullopt path.
With use_iceberg_metadata_files_cache=1 (the default) the second
icebergLocal() read can reuse the metadata.json cached by the first
read because the cache key does not change on an in-place rewrite of
the same file, so the throwing 'bucket]' path might never reach
parseTransformAndArgument. Disable the cache on both reads so the test
really exercises the nullopt and the BAD_ARGUMENTS branches.
Extend 05237_iceberg_sort_order_unknown_transform: after rewriting
metadata.json, recreate the table and INSERT a row, then read it back.
IcebergStorageSink resolves the sort order through
getSortingKeyDescriptionFromMetadata, so the write entrypoint must
tolerate the dropped sort order the same way reads do.
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 70d9691f2 with master 8c713943c (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

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

Job report

alexey-milovidov and others added 2 commits September 28, 2026 03:42
Recreating the `IcebergLocal` table over the path that already holds
Iceberg metadata throws `TABLE_ALREADY_EXISTS`, so the write-path part of
the test failed in every run. `IcebergStorageSink` re-reads the latest
metadata on each `INSERT`, so inserting into the still-attached table
exercises the same `getSortingKeyDescriptionFromMetadata` call. Also pass
`use_iceberg_metadata_files_cache` as a client option, because a trailing
`SETTINGS` after inline `VALUES` data is parsed as data.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121687&sha=4686a70cd062c1eb96129f43bc5acc467f1b1539&name_0=PR
ClickHouse#121687

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The new write-path part of 05237_iceberg_sort_order_unknown_transform (4686a70) failed in every run: CREATE TABLE ... ENGINE = IcebergLocal(path) over a path that already has Iceberg metadata throws TABLE_ALREADY_EXISTS, so the table was never recreated and the following INSERT hit UNKNOWN_TABLE. Fixed in bb79ae8: the test now inserts into the still-attached table (IcebergStorageSink re-reads the latest metadata and calls getSortingKeyDescriptionFromMetadata on every INSERT, so the same path is covered), and use_iceberg_metadata_files_cache=0 is passed as a client option because a trailing SETTINGS after inline VALUES is parsed as data. Locally the old test reproduces the TABLE_ALREADY_EXISTS failure and the fixed one passes 5/5. Also merged current master (clean, Utils.cpp compiles).

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failures unrelated to this PR: 05237_with_expression_alias_scope_descendant (https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121687&sha=5b174b89d1e3cc800e5658dbb70c47174c8f0147&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29), 02354_vector_search_assign_centroid and 05257_sql_security_view_sealed (https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121687&sha=5b174b89d1e3cc800e5658dbb70c47174c8f0147&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29), and provide a fix in a separate PR. If the fix is already in progress, link it here (possibly #123711 for assignCentroid and #123729 for the SQL SECURITY view). The Build (amd_fuzzers) failure is addressed by merging master, which contains #123738.

@groeneai

groeneai commented Oct 4, 2026

Copy link
Copy Markdown
Collaborator

All three already have fixes in progress:

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Thanks, @groeneai. Those three failures were on 5b174b8; the current head 70d9691 (with fresh master merged) has no failed jobs so far, and the remaining jobs and CH Inc sync are still running.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 4, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 4, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 The merge queue removed this PR on 2026-10-04 only because check_sync_pr_mergeable.py saw conflicts in the private sync PR at that moment; no test failed. The sync was regenerated afterwards: CH Inc sync on 70d9691 finished green (2026-10-05T04:42) and the sync PR is now MERGEABLE. Public CI is green and no review threads are open, so the PR can go back into the merge queue. It still needs a human re-review of the switch from BAD_ARGUMENTS to ignoring the unparsable sort order.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into ClickHouse:master with commit 2c6e37b Oct 7, 2026
149 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 7, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 7, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 7, 2026
Backport #121687 to 26.9: Iceberg: ignore unparsable sort-order transform instead of aborting the server
clickhouse-gh Bot added a commit that referenced this pull request Oct 7, 2026
Backport #121687 to 26.8: Iceberg: ignore unparsable sort-order transform instead of aborting the server
clickhouse-gh Bot added a commit that referenced this pull request Oct 7, 2026
Backport #121687 to 26.7: Iceberg: ignore unparsable sort-order transform instead of aborting the server
PedroTadim added a commit that referenced this pull request Oct 8, 2026
Backport #121687 to 26.3: Iceberg: ignore unparsable sort-order transform instead of aborting the server
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 8, 2026
…rder transform instead of aborting the server
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
…rder transform instead of aborting the server
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
…rder transform instead of aborting the server
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
…rder transform instead of aborting the server
@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... external Author is not a member of the ClickHouse organization pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants