Skip to content

Read Iceberg timestamp without time zone as DateTime64(6, 'UTC') - #130123

Open
groeneai wants to merge 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-timestamp-without-time-zone-utc
Open

groeneai wants to merge 5 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-timestamp-without-time-zone-utc

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130025
Related: #130016

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

Iceberg timestamp and timestamp_ns columns (without time zone) are now read as DateTime64(6, 'UTC') and DateTime64(9, 'UTC'), so their values are shown as stored and compared with string literals the same way in any session_timezone, and an INSERT under a non-UTC session stores the value as written. toUTCTimestamp/fromUTCTimestamp now reject them (use reinterpret(ts, 'DateTime64(6)')). Closes #130025.

Description

On 26.10.2.103-stable, with session_timezone = 'Asia/Shanghai', SELECT ts FROM icebergLocal(...) over a Spark TIMESTAMP_NTZ column holding 2024-06-11 12:34:56.123456 returns 2024-06-11 20:34:56.123456, and WHERE ts = '2024-06-11 12:34:56.123456' returns 0 rows.

An Iceberg timestamp stores a wall-clock reading, but it was mapped to a zone-less DateTime64(6) (timestamp_ns to DateTime64(9)), so values were rendered and literals parsed in the session time zone. IcebergSchemaProcessor::getSimpleType now adds 'UTC', where the stored ticks and their rendering coincide, as Paimon maps TIMESTAMP WITHOUT TIME ZONE. DESCRIBE shows the new type; under a UTC session values and filters are unchanged. Rows ClickHouse inserted from literals under a non-UTC session were stored shifted and now read back as Spark reads them. Perf test utc_timestamp_transform skips Iceberg: toUTCTimestamp rejects the new type.

timestamptz keeps following iceberg_timezone_for_timestamptz (#130772). A DataLakeCatalog database applied it to every 'UTC' DateTime64 of the catalog schema, which would now move timestamp too; the catalogs now apply it when converting the Iceberg types.

Written manifests took a timestamp partition field's adjust-to-utc from the ClickHouse type's zone; it now follows the Iceberg type of the source field.

Validation: new test 05569 (Spark- and ClickHouse-written identity-partitioned tables under Asia/Shanghai, pruning on/off, the manifest flag, also of a field promoted from unknown); 05213 uses the stored values as literals; types updated in 04029, 05477, 05616, 05620, the gtest and the Glue/REST/Nessie integration tests, REST also checking a Berlin database. All fail on master and pass here. 05743 pins UTC for its timestamp() bound.

Open #114859 and #118601 touch adjacent code.


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

An Iceberg `timestamp` / `timestamp_ns` stores a wall-clock reading (Spark
`TIMESTAMP_NTZ`). It was mapped to a zone-less `DateTime64(6)` / `DateTime64(9)`,
so the value was rendered, and string literals were parsed, in the session time
zone: under `Asia/Shanghai` a stored `2024-06-11 12:34:56.123456` showed as
`20:34:56.123456`, `WHERE ts = '2024-06-11 12:34:56.123456'` returned 0 rows, and
an INSERT under a non-UTC session stored the literal shifted by the session offset.

Map both types to an explicit `'UTC'` zone, where the stored ticks and their
rendering coincide, as Paimon does for `TIMESTAMP WITHOUT TIME ZONE` and as the
Parquet reader does for `isAdjustedToUTC = false`. `timestamptz` keeps its mapping.

The Avro type of a manifest partition field took `adjust-to-utc` from whether the
ClickHouse type has an explicit time zone; with the new mapping every identity
`timestamp` partition would be declared `timestamptz` in the manifests ClickHouse
writes. Take the flag from the Iceberg type of the partition's source field instead
(field ids are table-global, so the union over all schemas resolves it for any
schema a manifest is written for).

Rewrite 05213 (its literals were instants in the session zone, which no longer
name the stored rows), update the type expectations of 04029, 05477, the gtest and
the catalog integration tests, and add 05569.

Closes ClickHouse#130025

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 4 findings) plus my own cold review (3 nits).

# Sev Finding Verdict Evidence / action
1 ❌ ClickHouse-written Parquet files mark Iceberg timestamp columns isAdjustedToUTC=true DISAGREE (separate defect) Unchanged by this PR: PrepareForWrite.cpp:270 keys the flag on the column mapper's local-timestamp paths, never on the DateTime64 zone, and Iceberg never sets them on master. Tracked in #114854, fixed by open #114859.
2 ⚠️ Spark-table pruning arms run on an unpartitioned table DISAGREE use_iceberg_partition_pruning = 1 also enables min/max pruning; the single data file has ts_ntz bounds 0..104400000029, so a literal shifted by the session offset would prune the file and the on/off pair would differ. Identity-partition pruning is covered by the ClickHouse-written arm and 05213.
3 ⚠️ No test for adjust-to-utc: true on a timestamptz identity partition DISAGREE Measured true locally on a timestamptz source; no test covered the flag before. ClickHouse cannot create a timestamptz column, so a test needs a foreign writer for a header annotation readers do not use.
4 ⚠️ timestamp_ns covered only by its type name DISAGREE The only timestamp_ns change is the mapped type, which 04029 pins (fails on master); rendering and parsing follow from DateTime64(9, 'UTC'), and the read path is untouched. No timestamp_ns data fixture exists.
5 💡 collectIcebergTimestamptzFieldIds repeats the walk of collectIcebergTimeFieldIds noted Kept separate to stay clear of open #105540, which works on the time paths.
6 💡 PR body did not name #114859 AGREE, fixed in the description none
7 💡 Rows ClickHouse inserted under a non-UTC session before this change read back differently AGREE, disclosed in the description CAST(ts AS DateTime64(6)) gives the old rendering.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The issue's query on the Doris table from #130016 with session_timezone = 'Asia/Shanghai': master and official 26.10.2.103 return 2024-06-11 20:34:56.123456 and 0 rows for WHERE ts = '2024-06-11 12:34:56.123456', every run.
b Root cause explained? Iceberg timestamp / timestamp_ns hold a wall-clock reading, but were mapped to a zone-less DateTime64, i.e. an instant in the session zone, so rendering and literal parsing shifted by the session offset. In 'UTC' the stored ticks and their rendering coincide.
c Fix matches root cause? Yes. The type mapping is fixed in getSimpleType, which every Iceberg table engine, table function and catalog uses; no special case in literal parsing or pruning. The manifest adjust-to-utc flag, which read the ClickHouse zone, now follows the source field's Iceberg type.
d Test intent preserved / new tests added? New 05569 (Spark-written and ClickHouse-written tables, both table shapes, pruning on and off, manifest flag). 05213 keeps its pruning-vs-execution oracle with literals that name the stored rows. Type expectations updated in 04029, 05477, the gtest and the Glue/REST/Nessie integration tests.
e Both directions demonstrated? All changed stateless tests and the changed integration tests fail on master and pass with the fix; 50 randomized runs x 4 tests 200/200. Reverting only the type mapping fails 05569, 05213, 04029, 05477 and 3 gtests; reverting only the manifest change fails only the manifest arm of 05569.
f Fix is general across code paths? Reads: one mapping shared by tables, table functions and the REST, Glue, Hive and Nessie catalogs. Writes: the only zone-dependent carrier (manifest partition type) is fixed; data files, statistics and partition transforms store raw ticks. Delta Lake timestamp_ntz has the same zone-less mapping and is a separate reader, not changed here.
g Fix generalizes across inputs (params/datatypes/wrappers)? timestamp and timestamp_ns, Nullable and non-Nullable, identity, day and hour partitions, session zones with whole and fractional offsets and UTC; a timestamptz identity partition still gets adjust-to-utc: true.
h Backward compatible? (maintainer-approved exception only) The column type changes from DateTime64(6) to DateTime64(6, 'UTC') (stated in the changelog entry); in UTC sessions values and filter results are unchanged. Data files, statistics and manifests written for timestamp columns are unchanged. No compatibility setting, as for the Iceberg date -> Date32 fix #95322.
i Invariants and contracts preserved? Schema conflict detection still compares Iceberg type strings; the manifest Avro schema keeps its shape; the new LOGICAL_ERROR fires only for a DateTime64 partition field without a source in the spec; field ids are table-global, so the union of timestamptz ids over all schemas cannot misclassify a field.

Session id: cron:clickhouse-impl-slot-41:20261108-080200

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @alesapin, could you review this and add the can be tested label so CI runs? It maps Iceberg timestamp / timestamp_ns to DateTime64(6, 'UTC') / DateTime64(9, 'UTC'), so wall-clock values and string-literal filters no longer shift with session_timezone (the column type shown by DESCRIBE changes), and the adjust-to-utc flag of manifest partition fields now follows the source field's Iceberg type.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d53742]

Summary: ✅


AI Review

Summary

The PR maps Iceberg timestamp and timestamp_ns to explicitly UTC DateTime64 types, keeping displayed values and string-literal comparisons independent of session_timezone. Catalog schema conversion preserves the distinction from timestamptz, and manifest partition annotations follow the Iceberg source type. No actionable findings remain at 3d53742a12a52ff9f2a15fceb430fde4dac09abd. The previous schema-history finding is fixed and its thread has been resolved; test 05569 covers promotion from unknown to timestamptz.

Consumer tracing covered IcebergMetadata schema inference, schema evolution, and equality deletes; Parquet, Avro, and ORC readers/writers; partition transforms, pruning, and identity projection; insert, mutation, and compaction manifest generation; and REST, Glue, Hive, and inherited S3 Tables catalog schemas. The timezone change retains the numeric timestamp representation. The documented toUTCTimestamp/fromUTCTimestamp restriction and the separately tracked Parquet annotation issue in #114854 are acknowledged in the prior discussion.

Missing context / blind spots
  • ⚠️ Full validation is pending in the current CI workflow. Live checks show successful fast tests, style, and tidy builds, with other builds still running; focused Iceberg test results are not yet available. The report helper's zero-test job entries do not establish that those tests passed. No local tests were run, as instructed; completed stateless and catalog integration jobs will close this validation gap.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3d53742a1 with master a7735deb4 (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.

Object file sizes

19 object files changed (-20.37 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Databases/DataLake/DatabaseDataLake.cpp.o 2.07 MiB 2.04 MiB -28.62 KiB (-1.35%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +44.0 s (+5%) in total before that adjustment.

Job report

…ormance tests

The Iceberg configuration rewrites the test's `DateTime` and `DateTime64`
Memory tables as Iceberg tables, whose `timestamp` columns are now read
back as `DateTime64(6, 'UTC')`. `toUTCTimestamp` and `fromUTCTimestamp`
reject an argument with an explicit time zone, so every query of the test
failed on the new server (`Performance Comparison (arm_release,
master_head, iceberg_local|iceberg_s3, 2/3)`). The MergeTree configuration
still runs the test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ianton-ru

Copy link
Copy Markdown
Contributor

Am I right than this PR makes type timestamp the same as timestamptz in ClickHouse interpretation?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Yes, for the ClickHouse type: with this PR both are read as DateTime64(6, 'UTC') (timestamp_ns and timestamptz_ns as DateTime64(9, 'UTC')), so they render and compare with string literals the same way in any session_timezone. For timestamp this shows the stored wall-clock reading as written: ClickHouse has no zone-less wall-clock type, and UTC is the zone in which the stored ticks and their rendering coincide.

They stay distinct on the Iceberg side. An existing table keeps its declared Iceberg types, and in manifests ClickHouse writes, the adjust-to-utc flag of a timestamp partition field now follows the source field's Iceberg type instead of the ClickHouse type's zone (true for timestamptz, false for timestamp, the same output as master). The Parquet isAdjustedToUTC flag on write is not changed here (#114854).

On your PRs: with #94025, iceberg_timezone_for_timestamptz would change only timestamptz, which fits, since only it is an instant. Both PRs edit adjacent lines of getSimpleType, so whichever merges second needs a trivial rebase. #95659 does not interact: with the setting empty it keeps icebergDay and the other UTC transforms, which compute on the stored ticks regardless of the column zone, and with it set, toRelativeDayNum(ts, tz) and the others ignore the column zone too.

@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 19, 2026
groeneai and others added 2 commits November 23, 2026 14:45
…mestamp-without-time-zone-utc

Conflicts:
- SchemaProcessor.{cpp,h}: master added collectIcebergPrimitiveTypesById, so the manifest
  `adjust-to-utc` lookup in IcebergWrites.cpp uses it and the PR's own
  collectIcebergTimestamptzFieldIds is dropped; master also removed updateLastColumnId.
- getSimpleType: timestamptz now takes master's `timezone_for_timestamptz`, timestamp and
  timestamp_ns keep `DateTime64(6|9, 'UTC')`.
- Utils.{cpp,h}: master's new variant helpers next to the `adjust_to_utc` parameter of getAvroType.
- registerStorageObjectStorage.cpp: type table rows combine both changes.
- test_database_glue: master removed test_timestamp_types_cache_does_not_keep_metadata with the
  Glue schema cache.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e by the Iceberg type

The database rewrote every `DateTime64` with an explicit 'UTC' zone in the catalog schema to the
configured zone. With Iceberg `timestamp` now read as `DateTime64(6, 'UTC')` too, that also moved
`timestamp` columns: under `iceberg_timezone_for_timestamptz = 'Europe/Berlin'` a REST catalog table
declared `timestamp Nullable(DateTime64(6, 'Europe/Berlin'))` in SHOW CREATE TABLE, while SELECT,
which reads the type from the Iceberg metadata, returned 'UTC'.

Pass the zone to the catalog with the table metadata request instead, so the REST, Hive and Glue
catalogs give it to `IcebergSchemaProcessor` when they convert the Iceberg types, as the table engine
already does through the same table setting.

Update 05616 and 05620 for the `timestamp` mapping (only the type lines change; in 05620 the
`timestamp` column now stays `DateTime64(6, 'UTC')` under the Berlin setting), and check the
`timestamp` column of the Berlin database in test_database_iceberg.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s written for

The flag of a timestamp partition field was looked up in a union of all historical schemas that kept
the first type seen for each field id. Iceberg v3 lets an `unknown` field be promoted to any type, so a
field that was `unknown` in schema 0 and is `timestamptz` now got `adjust-to-utc: false` in the
manifests of a ClickHouse INSERT (master writes `true`). Read the source type from the schema the
manifest declares instead: `schema_to_serialize` when given, else the current schema. 05569 covers the
promoted field.

05743 compares an Iceberg `timestamp` column, now read in UTC, with a `timestamp()` bound built in the
session time zone, so a randomized non-UTC session changed the pruned-file count (CI: 2 instead of 3
under America/Mazatlan). Pin its session time zone to UTC.

Update the comments of 05212 and 05315 that still described `timestamp` as read in the session time zone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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... pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Iceberg timestamp without time zone is read in the session time zone: wall-clock values and filters change with session_timezone

2 participants