Skip to content

Fix Iceberg writer timestamp metadata - #114859

Open
ylw510 wants to merge 18 commits into
ClickHouse:masterfrom
ylw510:fix-iceberg-timestamp-metadata
Open

ylw510 wants to merge 18 commits into
ClickHouse:masterfrom
ylw510:fix-iceberg-timestamp-metadata

Conversation

@ylw510

@ylw510 ylw510 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #114854

When ClickHouse creates or evolves an Iceberg schema, it declared every DateTime and DateTime64 column as timestamp, while the Parquet writer marks the data as isAdjustedToUTC=true. Spec-following readers such as pyiceberg then refuse to scan the table. New columns are now declared as timestamptz:

  • Parquet and ORC data files match it. ORC writes TIMESTAMP_INSTANT for timestamptz and keeps TIMESTAMP for timestamp columns.
  • A timestamp column of an existing table keeps its type on ALTER TABLE ... MODIFY COLUMN, because Iceberg does not allow timestamp to become timestamptz.

Writes are converted to the table's read-back type, DateTime64(6, 'UTC'), before they reach the format writer. So DateTime64(7..9) columns and output_format_parquet_datetime_as_uint32 cannot produce a data file that disagrees with timestamptz.

Avro data files are not changed yet. The Avro writer still emits timestamp-micros without the adjust-to-utc annotation, which needs a change in the Avro library; it is left for a follow-up and documented.

Changelog category (leave one):

  • Backward Incompatible Change

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Iceberg tables created or evolved by ClickHouse now declare DateTime and DateTime64 columns as timestamptz instead of timestamp, matching the UTC-adjusted timestamps in the Parquet and ORC data files. Before, spec-following readers such as pyiceberg could not scan these tables. Such columns are now read back as DateTime64(6, 'UTC') instead of DateTime64(6). Values are displayed in UTC, and string literals compared with or inserted into them are parsed in UTC instead of the session time zone. To keep the previous interpretation, give the time zone explicitly, for example toDateTime64('2026-01-01 00:00:00', 6, 'Europe/Amsterdam'), or convert on read with toTimeZone. Existing timestamp columns keep their type and behavior.


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

ylw510 added 2 commits August 14, 2026 16:48
Iceberg tables written with DateTime/DateTime64 declared `timestamp` in
metadata while Parquet files used isAdjustedToUTC=true, breaking
spec-following readers such as pyiceberg. Map these columns to
`timestamptz` (or `timestamptz_ns` for DateTime64(9)) instead.

Closes: ClickHouse#114854
@ylw510 ylw510 changed the title Fix Iceberg writer timestamp metadata to match Parquet isAdjustedToUTC Fix Iceberg writer timestamp metadata Aug 14, 2026
@zlareb1 zlareb1 added the can be tested Allows running workflows for external contributors label Aug 15, 2026
@zlareb1
zlareb1 requested a review from arsenmuk August 15, 2026 08:12
@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6d6c768]

Summary: ✅


AI Review

Summary

Reviewed PR head 6d6c7684588b7842463995e68c65358df381254f and all prior discussion. The change declares new Iceberg timestamp columns as timestamptz, aligns ORC output with that type, and preserves legacy timestamp columns during MODIFY COLUMN. The earlier Parquet precision/settings and ORC findings are addressed. One previously reported Avro interoperability concern remains, explicitly deferred by the author; there are no new inline findings.

Consumer tracing covered insert conversion to the read-back schema; insert, mutation, and compaction writers receiving the schema-derived mapper; recursive Parquet timestamp annotations; ORC instant encoding, schema inference, and decoding; and manifest partition serialization using the explicit timezone. The Avro data-file serializer remains the divergent consumer described below.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary/build was available, so runtime checks were not executed locally. Current-head functional/integration CI was still pending in the workflow snapshot; completed results for the added Parquet, legacy-column, and ORC regression tests would close this validation gap.
Findings

⚠️ Majors

  • src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:807 — Avro data files still contradict the new table schema. [dismissed by author -- https://github.com/Fix Iceberg writer timestamp metadata #114859#discussion_r4441122379] The author requested a follow-up and documented the limitation, but the emitted schema still disagrees with the table metadata. For IcebergLocal(..., 'Avro') with a DateTime64(6) column, metadata now declares timestamptz, while AvroSerializer::createSchemaWithSerializeFn emits timestamp-micros without adjust-to-utc. Its absence means false under the Iceberg Avro mapping, describing a zone-less timestamp and leaving external schema conversion/projection inconsistent. Emit the annotation from the column mapper, retaining local semantics for legacy timestamp fields, or prevent incompatible writes until that support exists. No duplicate inline comment or thread reply was posted.
Tests
  • ⚠️ The retained Avro issue needs a focused data-file schema assertion for adjust-to-utc: true on timestamptz and local semantics on legacy timestamp. ClickHouse-only value round-trips do not establish this external format contract.
Final Verdict

Status: ⚠️ Request changes. Align Avro data-file timestamp semantics with the table schema, or reject the unsupported writes, and cover that boundary with a schema assertion. The author's deferral is respected: the concern remains only in this summary and the existing thread.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 15, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@ylw510 can you fix the tidy build?

@clickhouse-gh

clickhouse-gh Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6d6c76845 with master 28cd3f355 (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.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
@subkanthi subkanthi mentioned this pull request Sep 16, 2026
11 of 17 tasks
fm4v added 6 commits November 1, 2026 10:46
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
The writer creates format version 2 tables by default, and timestamptz_ns is a format version 3 type, which spec-following readers reject in older tables. The insert path converts the block to the live Iceberg schema type, so DateTime64(9) is written with microsecond precision, exactly as before the change. This also restores the expected output of 04652_iceberg_mv_target_stale_schema_write, which failed with the nanosecond mapping.

Related: ClickHouse#114854
A ClickHouse-written DateTime column is now declared as timestamptz and read back as DateTime64(6, 'UTC'). The new test 04894_iceberg_timestamp_metadata_parquet_consistency printed the values in the server time zone, so it failed whenever that was not UTC; its columns now carry an explicit UTC zone. test_v3_primitive_types expects Trino to render the zone. 05212_iceberg_manifest_compaction_conflicting_manifest_schema builds its schema conflict by flipping timestamptz to timestamp instead of the other way around. 05213_iceberg_partition_pruning_timezone names the instants of its non-UTC arms with zoned constants, because a string literal is now parsed in the column's UTC zone.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=114859&sha=a2683bac44c7393ade577a6f3d66f17937904fef&name_0=PR
PR: ClickHouse#114859
Tables written before DateTime and DateTime64 were declared as timestamptz have timestamp columns. generateModifyColumnMetadata regenerated the type as timestamptz, and checkValidSchemaEvolution rejected timestamp to timestamptz, so even a no-op MODIFY COLUMN or a change to Nullable failed on such tables. The existing timestamp type is now kept and only the nullability changes. The new test builds such a table by rewriting the metadata file before any data is written.
…ng_timezone

Issue ClickHouse#119173 is about a string literal against an Iceberg timestamp column under a non-UTC session, and ClickHouse no longer writes such columns. The original string-literal arms now run against a table whose column really is a timestamp, produced by rewriting the metadata file before any data is written, in separate clickhouse-local processes so that no metadata cache can hide the rewrite. The zoned-constant arms on the timestamptz table stay, since they cover pruning of the type ClickHouse now writes.
The documentation of the Iceberg engine still said that every DateTime and DateTime64 column is written as timestamp and that ClickHouse cannot generate timestamptz. Also fix a comment in 05315_iceberg_drop_partition_date_transform_aliases that described the old read-back type.
The Iceberg spec maps timestamptz to the ORC timestamp with local time zone kind and timestamp to the ORC timestamp kind, and Java Iceberg rejects a data file whose ORC kind differs from the schema. Since DateTime and DateTime64 are declared as timestamptz, the ORC writer, which always wrote TIMESTAMP, produced such a mismatch.

The Iceberg column mapper now lists the timestamp and timestamp_ns paths as local timestamp paths, the mechanism Delta already uses for timestamp_ntz. The ORC writer uses TIMESTAMP_INSTANT for a lake column that is not a local timestamp and keeps TIMESTAMP otherwise, so plain ORC output is unchanged and a timestamp column of an older table, including one kept by MODIFY COLUMN, still gets TIMESTAMP. The ORC writer already encodes TIMESTAMP_INSTANT as UTC seconds. The Parquet writer consults the same paths, so a timestamp column of an older table is now written with isAdjustedToUTC=false, as the spec requires, instead of true.

Review comment: ClickHouse#114859 (comment)
return {"timestamp", true};
/// The Parquet writer sets `isAdjustedToUTC=true`, so declare `timestamptz` instead of `timestamp`.
/// `timestamptz_ns` is a format version 3 type, so `DateTime64(9)` keeps the microsecond type, as before.
return {Iceberg::f_timestamptz, true};

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.

[P2] Emit the Avro UTC annotation for the new timestamp mapping

This shared mapping also applies to IcebergLocal(..., 'Avro'). Creating an Avro table with ts DateTime64(6) and inserting a row now declares timestamptz in table metadata, but AvroSerializer::createSchemaWithSerializeFn (AvroRowOutputFormat.cpp:209–225) still writes only long plus logicalType: timestamp-micros; it never emits adjust-to-utc. The Iceberg Avro mapping defines the absent annotation as false, so the data file describes a zone-less timestamp. Iceberg Java's schema conversion consequently reconstructs TimestampType.withoutZone, contradicting the table's new type. The Parquet and ORC fixes therefore introduce the same schema/data mismatch for Avro output.

Please have the Avro data writer emit adjust-to-utc: true for timestamptz paths using the column mapper, retain false for legacy timestamp paths, and add a focused data-file schema assertion. Updating Iceberg::getAvroType alone would only affect manifest partition schemas, not these data files.

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.

@fm4v we should leave this as a follow-up PR

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @ylw510

  1. The Avro data writer still doesn't write the adjust-to-utc property, so it's read as false. Now that new tables declare timestamptz, IcebergLocal(..., 'Avro') data files describe a zone-less timestamp that contradicts the table schema, the mismatch this PR fixes for Parquet and ORC. As the bot suggested, the Avro writer should emit adjust-to-utc: true for timestamptz columns (and false for legacy timestamp ones), with a test that checks the data file's schema.
  2. New tables now read DateTime/DateTime64 columns back as DateTime64(6, 'UTC'). Values display in UTC, and string literals in WHERE and INSERT ... VALUES are parsed in UTC whatever session_timezone is. In a non-UTC session the same INSERT stores a different instant than on a table created before this change. That's the right model for DateTime, but it's a user-visible incompatibility: please use the "Backward Incompatible Change" category, or at least describe it and the workaround in the changelog entry. For example, the private-only test 05431_iceberg_compaction_sort_key_not_prefix fails in the sync PR for this reason (max(t) prints in UTC under session_timezone = America/Hermosillo).
  3. Minor: the gtest duplicates what the functional tests already check; consider dropping it.

PedroTadim and others added 2 commits November 3, 2026 20:31
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.cpp
The functional tests already check the `timestamptz` mapping. Avro data files
still lack the `adjust-to-utc` annotation, which needs a change in the Avro
library, so the documentation says so until a follow-up adds it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-bugfix Pull request with bugfix, not backported by default labels Nov 3, 2026
@ylw510
ylw510 requested a review from PedroTadim November 10, 2026 05:37
@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 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... external Author is not a member of the ClickHouse organization pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

6 participants