Skip to content

[Iceberg spec fix part 1]: Compute the Iceberg date partition transforms in UTC - #118583

Merged
scanhex12 merged 1 commit into
masterfrom
iceberg_utc_partition_transforms
Sep 20, 2026
Merged

scanhex12 merged 1 commit into
masterfrom
iceberg_utc_partition_transforms

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

The year, month, day and hour partition transforms were computed with toYearNumSinceEpoch, toMonthNumSinceEpoch, toRelativeDayNum and toRelativeHourNum. Those interpret the value in the column's timezone, or in the server's when the column has none, and return an unsigned type.

The specification counts the units from 1970 on the stored value itself: a timestamp is a date and time of day whose value is independent of zone adjustments, and a timestamptz is already stored in UTC, so no zone may enter the transform. The result type is a signed int, which is negative for a value before 1970. ClickHouse instead put the same stored value in partition 19722 under UTC and 19723 under Asia/Kolkata, and clamped a value from 1969 to 0, both when writing the partition value and when pruning by it.

New functions icebergYear, icebergMonth, icebergDay and icebergHour compute the units from the stored value in UTC and return Int32. PARTITION BY keeps accepting the old spellings so existing DDL still works, and maps them to the same Iceberg transform.

Note that a table written before this change by a server in a non-UTC timezone holds shifted partition values, and pruning now derives the correct ones, so such files can be pruned away.

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):

Compute the Iceberg date partition transforms in UTC


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

Version info

  • Merged into: 26.10.1.290-master (included in 26.10 and later)

The `year`, `month`, `day` and `hour` partition transforms were computed with
`toYearNumSinceEpoch`, `toMonthNumSinceEpoch`, `toRelativeDayNum` and
`toRelativeHourNum`. Those interpret the value in the column's timezone, or in
the server's when the column has none, and return an unsigned type.

The specification counts the units from 1970 on the stored value itself: a
`timestamp` is a date and time of day whose value is independent of zone
adjustments, and a `timestamptz` is already stored in UTC, so no zone may enter
the transform. The result type is a signed `int`, which is negative for a value
before 1970. ClickHouse instead put the same stored value in partition `19722`
under `UTC` and `19723` under `Asia/Kolkata`, and clamped a value from 1969 to
`0`, both when writing the partition value and when pruning by it.

New functions `icebergYear`, `icebergMonth`, `icebergDay` and `icebergHour`
compute the units from the stored value in UTC and return `Int32`. `PARTITION
BY` keeps accepting the old spellings so existing DDL still works, and maps
them to the same Iceberg transform.

Note that a table written before this change by a server in a non-UTC timezone
holds shifted partition values, and pruning now derives the correct ones, so
such files can be pruned away.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b79c31a]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, sequential) FAIL
04648_distributed_plan_task_error_propagation FAIL cidb
04340_distributed_plan_status_reenqueue_fault FAIL cidb
Build profile diff ERROR

AI Review

Summary

This PR introduces icebergYear, icebergMonth, icebergDay, and icebergHour, rewires Iceberg partition transforms to use them, and adds integration coverage for freshly written UTC partition values. The new semantics look reasonable for new metadata, but the current change is not safe for existing ClickHouse-written Iceberg tables because it reinterprets already materialized year / month / day / hour partition values.

Missing context / blind spots
  • ⚠️ As of 2026-09-07, the PR jobs are still pending and only Style check is green, so there is no completed integration-run evidence yet beyond the new test file.
Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:439-449] parseTransformAndArgument is used on existing Iceberg metadata in both ChunkPartitioner and ManifestFilesPruning. Switching "year" / "month" / "day" / "hour" to iceberg* unconditionally changes the meaning of already-persisted partition values: older ClickHouse builds wrote local-time-based values for non-UTC tables and clamped pre-1970 values to 0. After this patch, filters and new inserts derive UTC / negative values instead, so matching legacy files can be pruned away and one logical partition can split across legacy and new partition values.
    Suggested fix: version or mark the new semantics in metadata and keep legacy specs on the old transforms (or reject / migrate old tables explicitly) instead of globally reinterpreting the same Iceberg transform names.
Tests
  • ⚠️ Add a focused regression that opens a table or manifest written with the pre-change transforms (a non-UTC session and a pre-1970 timestamp are enough) and proves either compatibility or explicit rejection. The new test only exercises freshly written metadata, so it does not cover the surface this PR makes backward-incompatible.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit b79c31a.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 128/150 (85.33%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 7, 2026

if (transform_name == "year" || transform_name == "years")
return TransformAndArgument{"toYearNumSinceEpoch", std::nullopt};
return TransformAndArgument{"icebergYear", std::nullopt};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This helper is used on existing Iceberg metadata in both ChunkPartitioner (future inserts) and ManifestFilesPruning. Unconditionally mapping "year" / "month" / "day" / "hour" to iceberg* therefore changes the meaning of every table that was already written by older ClickHouse builds: non-UTC tables stored legacy local-time partition values, and pre-1970 values were clamped to 0. After this patch the same metadata is interpreted with UTC / signed semantics instead, so matching legacy files can be pruned away and new inserts can split one logical partition across legacy and new partition values.

We need a persisted compatibility signal here (new spec / table property / explicit migration or rejection path) so existing metadata keeps using the legacy transforms while only newly-written tables opt into iceberg*.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 7, 2026
@scanhex12
scanhex12 added this pull request to the merge queue Sep 20, 2026
@scanhex12
scanhex12 removed this pull request from the merge queue due to a manual request Sep 20, 2026
@scanhex12
scanhex12 added this pull request to the merge queue Sep 20, 2026
Merged via the queue into master with commit e3b9196 Sep 20, 2026
172 of 175 checks passed
@scanhex12
scanhex12 deleted the iceberg_utc_partition_transforms branch September 20, 2026 17:32
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 20, 2026
alexey-milovidov pushed a commit to Libao-Yang/ClickHouse that referenced this pull request Oct 2, 2026
…s the Iceberg transforms

`PARTITION BY` accepts `toYearNumSinceEpoch`, `toMonthNumSinceEpoch`, `toRelativeDayNum` and
`toRelativeHourNum` as spellings of the Iceberg `year`/`month`/`day`/`hour` transforms, and since
ClickHouse#118583 the partition values of those transforms are computed by `icebergYear`/`icebergMonth`/
`icebergDay`/`icebergHour` (UTC, negative before 1970). `ALTER TABLE ... DROP PARTITION tuple(...)`
evaluated the user's expression as written, so the old spellings produced the ClickHouse function
values (saturated to 0 before 1970, `toRelativeHourNum` offset by 24, local-time for a zoned value)
and the operation removed the data files of a different partition.

The alias list now lives in one helper, `normalizeIcebergTransformFunctionName`, used by
`getPartitionField` (PARTITION BY), `parseFunction` (sort order) and `parsePartitionTuple`
(DROP PARTITION, top-level function of each tuple element). The DROP PARTITION docs of the engine
and the table function list the `iceberg*` functions and mention the aliases.

Tests: a stateless test drops pre-1970 day/hour/month/year partitions and a zoned day value with
the old spellings (and checks that the two-argument `toRelativeDayNum(x, tz)` is rejected); a Spark
test reads a pre-1970 table with `<column> = <value>` filters for all four transforms, the shape
reported in ClickHouse#119579, which no existing test covered for `hours`/`months`.

Related: ClickHouse#119579, ClickHouse#118583, ClickHouse#111219

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 3, 2026
ClickHouse#118583 made the `year`, `month`, `day` and `hour` partition transforms
return `Int32`, so after merging master the claim that they publish an
unsigned type no longer holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov pushed a commit to raimannma/ClickHouse that referenced this pull request Oct 30, 2026
…zer dictionary

src/Functions/icebergDateTransforms.cpp (ClickHouse#118583) names each specialization
of its class template with an immediately-invoked lambda:

    static constexpr const char * name = []
    {
        if constexpr (transform == IcebergDateTransform::Year)
            return "icebergYear";
        else if constexpr (transform == IcebergDateTransform::Month)
            return "icebergMonth";
        ...
    }();

The name-constant pass of tests/fuzz/generate_source_dict.sh takes an
initializer up to its first ';', which here ends the lambda's first return
statement, so only icebergYear reached the source-derived dictionary. The
binary also registers icebergMonth, icebergDay and icebergHour, so the
coverage check in tests/fuzz/update_dict.sh exits 1 and the nightly
libFuzzer tests job stops before any fuzzer runs. The 2026-09-28 master run,
which already has ClickHouse#121242, failed on exactly those three names.

The pass now also accepts an immediately-invoked lambda with a brace-free
body, taken up to its closing '}();'. The same alternation goes into the
copy of the pattern that collects aggregate function names for the
combinator expansion, so a lambda-named aggregate function also gets its
<name><combinator> tokens. dictionaries/old.dict is not used: it holds names
composed at compile time, and these are plain literals.

Measured on this tree: the dictionary goes from 6995 to 6998 tokens, the
added lines are exactly those three names and nothing is removed; of the
pass's 1643 matches only the iceberg one changes, and the aggregate copy's
output is unchanged. With a master debug binary the coverage check goes from
exit 1 to exit 0; the failing job's log shows the same 6995 tokens and the
same three names with the release binary CI runs. A lambda body with braces
still falls back to the first ';', and the coverage check names what is
missing, as it did here.

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

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.

2 participants