Skip to content

[Iceberg spec fix part 3]: Support timestamptz in iceberg tables in write path - #118601

Open
scanhex12 wants to merge 2 commits into
masterfrom
iceberg_timestamptz
Open

scanhex12 wants to merge 2 commits into
masterfrom
iceberg_timestamptz

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Every DateTime and DateTime64 column was declared as Iceberg timestamp, which the specification defines as a date and time of day without a timezone, even when the ClickHouse type carried an explicit one. At the same time the data file said the opposite: the Parquet writer always set isAdjustedToUTC = true, which is the annotation the specification reserves for timestamptz.

A ClickHouse timestamp is always an instant and the timezone parameter only selects how it is rendered, so an explicitly specified timezone is exactly the "point in time" semantics of timestamptz, and its absence is the zone-less timestamp. The schema now says that, and the data file agrees: Parquet emits isAdjustedToUTC = false for timestamp, and ORC distinguishes timestamp from timestamp_instant.

Both writers learn which paths are zone-less from the Iceberg schema through the column mapper, so a write without one keeps declaring its timestamps UTC-adjusted and nothing changes outside Iceberg. Avro data files cannot carry the annotation, because it is an Iceberg convention on top of the Avro logical type and avro-cpp has no way to attach it; that is documented as a limitation.

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

Support timestamptz in iceberg tables


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

Every `DateTime` and `DateTime64` column was declared as Iceberg `timestamp`,
which the specification defines as a date and time of day without a timezone,
even when the ClickHouse type carried an explicit one. At the same time the
data file said the opposite: the Parquet writer always set
`isAdjustedToUTC = true`, which is the annotation the specification reserves
for `timestamptz`.

A ClickHouse timestamp is always an instant and the timezone parameter only
selects how it is rendered, so an explicitly specified timezone is exactly the
"point in time" semantics of `timestamptz`, and its absence is the zone-less
`timestamp`. The schema now says that, and the data file agrees: Parquet emits
`isAdjustedToUTC = false` for `timestamp`, and ORC distinguishes `timestamp`
from `timestamp_instant`.

Both writers learn which paths are zone-less from the Iceberg schema through
the column mapper, so a write without one keeps declaring its timestamps
UTC-adjusted and nothing changes outside Iceberg. Avro data files cannot carry
the annotation, because it is an Iceberg convention on top of the Avro logical
type and avro-cpp has no way to attach it; that is documented as a limitation.

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

mintlify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Sep 26, 2026, 2:05 AM

@scanhex12 scanhex12 changed the title [Iceberg spec fix part 3]: Support timestamptz in iceberg tables [Iceberg spec fix part 3]: Support timestamptz in iceberg tables in write path Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ecc1e95]

Summary: ❌

job_name test_name status info comment
Docs check (Mintlify) FAIL
No direct edits to generated or read-only docs FAIL cidb
Integration tests (amd_asan_ubsan, targeted) FAIL
test_storage_iceberg_with_trino/test.py::test_v3_primitive_types FAIL cidb
Integration tests (amd_asan_ubsan, db disk, 7/8) FAIL
test_storage_iceberg_with_trino/test.py::test_v3_primitive_types FAIL cidb
Integration tests (arm_binary, distributed plan, 3/4) FAIL
test_storage_iceberg_with_trino/test.py::test_v3_primitive_types FAIL cidb
Integration tests (amd_tsan, 5/6) FAIL
test_storage_iceberg_with_trino/test.py::test_v3_primitive_types FAIL cidb
Integration tests (amd_msan, 7/8) FAIL
test_storage_iceberg_with_trino/test.py::test_v3_primitive_types FAIL cidb
Integration tests (amd_llvm_coverage, 1/8) FAIL
test_storage_iceberg_with_trino/test.py::test_v3_primitive_types FAIL cidb

AI Review

Summary

This PR updates the Iceberg write path so DateTime and DateTime64 columns with an explicit timezone are emitted as Iceberg timestamptz, and it aligns the Parquet/ORC file annotations with that schema. The direction is correct, but the round-trip contract is still broken for non-UTC explicit timezones, and the docs change was made in generated output instead of the engine doc source, so I cannot approve it yet.

Findings

❌ Blockers

  • src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:625 The new write-side mapping accepts every explicit timezone as Iceberg timestamptz, but the read path still reconstructs every timestamptz as DateTime64(..., 'UTC') in src/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.cpp:620. A column declared as DateTime64(6, 'Europe/Berlin') therefore writes successfully here and then comes back after ATTACH, restart, or read on another node as DateTime64(6, 'UTC'), changing its rendered values even though the PR now documents and advertises support. The safe fix is either to persist and recover the original ClickHouse timezone alongside the Iceberg type, or to reject non-UTC explicit timezones on the Iceberg write/evolve path instead of silently accepting them.

💡 Nits

Tests
  • ⚠️ Add an integration test with a non-UTC explicit timezone such as DateTime64(6, 'Europe/Berlin'), and verify the type/value after re-attaching the table or reading it from a fresh node. The new test only exercises 'UTC', so it cannot catch the broken round-trip above.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: preserve or reject non-UTC explicit timezones on the Iceberg write path; move the docs text change to the autogenerated source; add a regression that covers a non-UTC explicit timezone round-trip.

LLVM Coverage Report

Measured on commit ecc1e95.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 80/82 (97.56%) · 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
Comment on lines 597 to +602
case TypeIndex::DateTime:
return {
assert_cast<const DataTypeDateTime &>(*type).hasExplicitTimeZone() ? Iceberg::f_timestamptz : Iceberg::f_timestamp, true};
case TypeIndex::DateTime64:
return {"timestamp", true};
return {
assert_cast<const DataTypeDateTime64 &>(*type).hasExplicitTimeZone() ? Iceberg::f_timestamptz : Iceberg::f_timestamp,

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 makes every explicit timezone look like an Iceberg timestamptz, but our read path can only recover that as DateTime64(..., 'UTC') (IcebergSchemaProcessor::getSimpleType in SchemaProcessor.cpp). For example, DateTime64(6, 'Europe/Berlin') will write successfully here, then come back after ATTACH/restart/on another node as DateTime64(6, 'UTC'), so the same stored instants start rendering different strings. The new test only covers 'UTC', which hides the problem.

Unless we also persist the original ClickHouse timezone somewhere outside the Iceberg type, this needs to reject non-UTC explicit timezones on the Iceberg write path instead of silently claiming full timestamptz support.


- ClickHouse cannot create an Iceberg schema containing `Bool`, `Decimal`, `FixedString`, `Int8`, `UInt8`, `Int16`, or `UInt16`, or add or modify a column to one of these types. The operation fails with an unsupported-type exception. This does not prevent inserting `Bool` or `Decimal` values into existing Iceberg columns.
- When ClickHouse creates or evolves an Iceberg schema, it maps every `DateTime` and `DateTime64` column to Iceberg `timestamp`, which has microsecond precision and no timezone. ClickHouse cannot generate `timestamptz`, `timestamp_ns`, or `timestamptz_ns` schema types, so higher precision and timezone semantics are not represented in the Iceberg schema.
- When ClickHouse creates or evolves an Iceberg schema, it maps a `DateTime` or `DateTime64` column with an explicitly specified timezone to Iceberg `timestamptz`, and one without to the zone-less `timestamp`. Both have microsecond precision: ClickHouse cannot generate the `timestamp_ns` or `timestamptz_ns` schema types, so nanosecond precision is not represented in the Iceberg schema.

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 page is generated from the engine's structured docs, so editing the .mdx output inside the {/*AUTOGENERATED_START*/} block will keep failing the docs check and will be overwritten on the next generation pass. Please move this wording change to the source of truth in src/Storages/ObjectStorage/registerStorageObjectStorage.cpp (around the existing Iceberg "Schema and write compatibility limitations" section), or route it through the dedicated autogenerated-docs workflow.

alexey-milovidov pushed a commit to niyue/ClickHouse that referenced this pull request Oct 12, 2026
An INSERT into a Delta table whose schema declares a timestamp_ntz column
committed a data file that annotated the column
Timestamp(isAdjustedToUTC=true, MICROS). Delta defines timestamp_ntz as an
unadjusted wall clock timestamp, so Spark refused every later read of the
table with

  java.lang.RuntimeException: Unable to create Parquet converter for data
  type "timestamp_ntz" whose Parquet type is int64 time(TIMESTAMP(MICROS,true))

Two independent facts produced this. The kernel schema visitor wired
visit_timestamp and visit_timestamp_ntz to the same visitor, so both Delta
types became DateTime64(6) and the distinction was gone before the writer saw
it; ClickHouse has no wall clock type that could carry it either. The Parquet
writer then hardcoded isAdjustedToUTC=true at both timestamp branches, which
is right for the general Parquet format because a DateTime64 is an instant,
but wrong for a column the Delta log declares timestamp_ntz.

Rather than consult the DateTime64 timezone parameter, which would change
every general-format write and contradict the rule settled in ClickHouse#87872, the
distinction is kept where it is produced and delivered where it is needed.
The visitor records is_timestamp_ntz on its field, the traversal collects the
dotted paths of those leaves, TableSnapshot caches them with the rest of the
schema, and the Delta write path hands them to the writer through
ColumnMapper, which already carries per-path lake facts that a ClickHouse
type cannot express (iceberg_string_paths, iceberg_optional_paths).

Nested paths are spelled the way the Parquet writer spells a column path (a
struct field's own name, element for an array child, key and value for a
map's) rather than reusing the kernel's child names, which are not guaranteed
to be those words.

Only the annotation changes; the stored int64 is identical, so the ClickHouse
round trip stays lossless. This is the inverse of the documented read-side
rule that reads an unadjusted timestamp as DateTime64(N, 'UTC').

The mapper is attached only when the table actually has a timestamp_ntz
column and only for Parquet, so a Delta table without one keeps its exact
current behaviour, and ORC and Avro never see a mapper they would read as
Iceberg metadata. ParquetBlockOutputFormat now passes std::nullopt when the
mapper's field-id map is empty: an engaged but empty optional makes
convertSchema report the first column as having no Iceberg field id, so a
mapper carrying only timestamp paths would otherwise break every Delta
INSERT. An Iceberg mapper always has an id per field, so Iceberg is
unaffected.

The shared annotation seam is shaped identically to the in-flight ClickHouse#118601,
which adds it for Iceberg but does nothing for Delta, so either merge order
is a mechanical rebase.

Tests: two integration tests in test_storage_delta covering the flat case
(with Nullable, a Delta timestamp control and a char/varchar column) and the
nested case (struct field, array element, map value, plus a Delta timestamp
sibling inside the same struct), both asserting the _delta_log types first so
they cannot pass vacuously, the written annotation, a Spark read and the
ClickHouse round trip. 02735_parquet_encoder gains a logical_type assertion
because desc file() reports DateTime64(N, 'UTC') for both flag values, so
nothing on master would have caught a global flip of the default.

Closes ClickHouse#120653.
@alesapin

Copy link
Copy Markdown
Member

fixes #125202

@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

This branch was successfully deployed

1 active deployment
staging - docs — ecc1e956 Deployed Sep 26, 2026 by mintlify[bot]
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants