Repository navigation
[Iceberg spec fix part 1]: Compute the Iceberg date partition transforms in UTC - #118583
Conversation
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]>
|
Workflow [PR], commit [b79c31a] Summary: ❌
AI ReviewSummaryThis PR introduces Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit b79c31a.
Changed lines: Changed C/C++ lines covered: 128/150 (85.33%) · Uncovered code |
|
|
||
| if (transform_name == "year" || transform_name == "years") | ||
| return TransformAndArgument{"toYearNumSinceEpoch", std::nullopt}; | ||
| return TransformAndArgument{"icebergYear", std::nullopt}; |
There was a problem hiding this comment.
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*.
…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]>
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]>
…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]>
The
year,month,dayandhourpartition transforms were computed withtoYearNumSinceEpoch,toMonthNumSinceEpoch,toRelativeDayNumandtoRelativeHourNum. 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
timestampis a date and time of day whose value is independent of zone adjustments, and atimestamptzis already stored in UTC, so no zone may enter the transform. The result type is a signedint, which is negative for a value before 1970. ClickHouse instead put the same stored value in partition19722underUTCand19723underAsia/Kolkata, and clamped a value from 1969 to0, both when writing the partition value and when pruning by it.New functions
icebergYear,icebergMonth,icebergDayandicebergHourcompute the units from the stored value in UTC and returnInt32.PARTITION BYkeeps 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):
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
26.10.1.290-master(included in26.10and later)