Skip to content

[Iceberg] Fix Iceberg sort order id for empty tuple - #124910

Merged
scanhex12 merged 4 commits into
ClickHouse:masterfrom
mihaizegheru:fix-iceberg-empty-sort-order
Nov 2, 2026
Merged

scanhex12 merged 4 commits into
ClickHouse:masterfrom
mihaizegheru:fix-iceberg-empty-sort-order

Conversation

@mihaizegheru

@mihaizegheru mihaizegheru commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category:

  • Not for changelog (changelog entry is not required)

Changelog entry:

Not for changelog.

Closes #123754

Details

Commit 1e8ae5f11ad ("Forward table properties in CreateTable, fix initial sort id") started assigning sort order ID 1 whenever an ORDER BY AST is present. However, ORDER BY tuple() has a non-null order_by AST while producing no sorting fields. This resulted in metadata containing an empty sort order with ID 1. Iceberg reserves sort order ID 0 for the unsorted order, so such metadata is rejected by Iceberg implementations that validate this requirement.

This change determines the sort order ID from the generated sorting fields instead: empty sort orders use ID 0, while non-empty sort orders use ID 1.

Test

Added test_create_table_order_by_empty_tuple, covering ORDER BY tuple():

  • through the Iceberg REST catalog;
  • through a plain IcebergS3 table whose generated metadata is subsequently registered in the catalog.

The existing test_create_table_order_by continues to cover non-empty sort orders.

Verification

  • The regression was introduced by 1e8ae5f11ad.
  • 26.9.13.15-stable is not affected and generates an empty sort order with ID 0.
  • The regression test passes with the patched master.

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

Version info

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

@CLAassistant

CLAassistant commented Oct 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@scanhex12 scanhex12 self-assigned this Oct 9, 2026
@scanhex12 scanhex12 added the can be tested Allows running workflows for external contributors label Oct 9, 2026
@@ -1721,6 +1563,43 @@ def test_create_table_order_by(started_cluster):
assert all(isinstance(field.transform, IdentityTransform) for field in sort_fields), sort_fields


def test_create_table_order_by_empty_tuple(started_cluster):

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.

Could you please add a check that spark can read your table?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Hope this is what you meant

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ddb4a9c]

Summary: ✅


AI Review

Summary

PR #124910 fixes metadata generated for ORDER BY tuple() by assigning empty sort orders ID 0, consistent with the Iceberg specification. The new REST catalog and Spark regression tests passed in targeted CI for d342941c4. Review of the current code and all prior discussion found no actionable issues.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Oct 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit ddb4a9c73394c02a2624586acdd5688c30084307 was not compared: the CI logs cluster did not answer (exception 241, code 500: { "meta": [ { "name": "file", "type": "LowCardinality(String)" …).

See the job log for details.

@clickhouse-gh clickhouse-gh Bot added the external Author is not a member of the ClickHouse organization label Oct 10, 2026
@scanhex12
scanhex12 added this pull request to the merge queue Nov 2, 2026
Merged via the queue into ClickHouse:master with commit f2187aa Nov 2, 2026
178 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 Nov 2, 2026
@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-not-for-changelog This PR should not be mentioned in the changelog 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.

ORDER BY tuple() gets unsorted sort order id 1; Java Iceberg rejects it

4 participants