Skip to content

Timezone for iceberg timestamptz - #94025

Closed
ianton-ru wants to merge 33 commits into
ClickHouse:masterfrom
ianton-ru:timezone_for_iceberg_timestamptz
Closed

ianton-ru wants to merge 33 commits into
ClickHouse:masterfrom
ianton-ru:timezone_for_iceberg_timestamptz

Conversation

@ianton-ru

@ianton-ru ianton-ru commented Jan 13, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • New Feature

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

Setting timezone_for_iceberg_timestamptz for Iceberg timestamptz type.

Documentation entry for user-facing changes

Solved #86641
Setting timezone_for_iceberg_timestamptz for Iceberg timestamptz type.
Possible values:

  • Any valid timezone, e.g. Europe/Berlin, UTC or Zulu

  • Empty string to use session time zone.
    Default value is UTC.

  • Documentation is written (mandatory for new features)


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

@ianton-ru
ianton-ru marked this pull request as ready for review January 13, 2026 11:33
@scanhex12 scanhex12 self-assigned this Jan 13, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jan 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5e9c9dc]

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, flaky) FAIL
test_storage_iceberg_with_spark/test_optimize.py::test_optimize_timestamptz_adjust_to_utc_despite_stale_sample[local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_writes_reject_non_utc_timestamptz_timezone[tz_settings0-local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_writes_reject_non_utc_timestamptz_timezone[tz_settings1-local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_partition_pruning_uses_utc_despite_presentation_timezone[tz_settings0-local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_partition_pruning_uses_utc_despite_presentation_timezone[tz_settings2-local] FAIL cidb
Integration tests (amd_asan_ubsan, db disk, 8/8) FAIL
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_writes_reject_non_utc_timestamptz_timezone[tz_settings0-local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_writes_reject_non_utc_timestamptz_timezone[tz_settings1-local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_partition_pruning_uses_utc_despite_presentation_timezone[tz_settings0-local] FAIL cidb
test_storage_iceberg_with_spark/test_writes_create_partitioned_table.py::test_partition_pruning_uses_utc_despite_presentation_timezone[tz_settings2-local] FAIL cidb
test_storage_iceberg_with_spark/test_optimize.py::test_optimize_timestamptz_adjust_to_utc_despite_stale_sample[local] FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_darwin) DROPPED
Build (arm_darwin) DROPPED
Build (arm_v80compat) DROPPED
Build (amd_freebsd) DROPPED
Build (ppc64le) DROPPED
Build (amd_compat) DROPPED

AI Review

Summary

This PR adds iceberg_timezone_for_timestamptz and fixes most of the earlier timezone leaks by keying schema materialization by timezone and forcing UTC on pruning / compaction paths. I still see one correctness hole in the direct INSERT INTO materialized_view path, so this is not ready to merge yet.

PR Metadata
  • Changelog category: New Feature is correct for this change.
  • Changelog entry: required, but the current text is incorrect and too vague because it names timezone_for_iceberg_timestamptz instead of iceberg_timezone_for_timestamptz and does not say the setting is read-presentation-only. Replace it with: Add setting iceberg_timezone_for_timestamptz to control how Iceberg timestamptz columns are presented on reads.
Findings

❌ Blockers

  • [src/Storages/StorageMaterializedView.cpp:593, src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:1063] StorageMaterializedView::write still takes the Iceberg target's cached metadata without updateExternalDynamicMetadataIfExists. After a prior SELECT / SHOW CREATE with iceberg_timezone_for_timestamptz='' or iceberg_timezone_for_timestamptz='Europe/Berlin', the target can keep a non-UTC sample_block in memory. IcebergStorageSink only validates the current query setting before feeding that stale header into ChunkPartitioner and manifest Avro serialization, so direct inserts into a materialized view can still place rows into the wrong partitions or rewrite timestamptz metadata with adjust-to-utc=false.
    Suggested fix: refresh the target storage metadata inside StorageMaterializedView::write before getInMemoryMetadataPtr, or rebuild a physical UTC header in IcebergStorageSink instead of trusting the caller-provided sample_block.
Tests
  • ⚠️ The new coverage exercises REST / Glue reads, partition pruning, and OPTIMIZE, but there is still no regression that inserts through a MaterializedView target, which is the remaining path that bypasses the metadata refresh.
Final Verdict

❌ Request changes until the MaterializedView insert path refreshes Iceberg target metadata (or recreates a physical UTC header) and the changelog entry is corrected.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jan 13, 2026
@scanhex12 scanhex12 added the can be tested Allows running workflows for external contributors label Jan 13, 2026

@scanhex12 scanhex12 left a comment

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.

Looks good, but we need to test it with Glue catalog

Comment thread src/Core/SettingsChangesHistory.cpp Outdated
{"lock_object_storage_task_distribution_ms", 500, 500, "Raised the value to 500 to avoid hoping tasks between executors."},
{"allow_retries_in_cluster_requests", false, false, "New setting"},
{"object_storage_remote_initiator", false, false, "New setting."},
{"allow_experimental_export_merge_tree_part", false, true, "Turned ON by default for Antalya."},

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.

Unrelated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks!
Fixed.

assert node.query(f"SHOW CREATE TABLE {CATALOG_NAME}.`{root_namespace}.{table_name}`") == f"CREATE TABLE {CATALOG_NAME}.`{root_namespace}.{table_name}`\\n(\\n `timestamp` Nullable(DateTime64(6)),\\n `timestamptz` Nullable(DateTime64(6, \\'UTC\\'))\\n)\\nENGINE = Iceberg(\\'http://minio:9000/warehouse-rest/data/\\', \\'minio\\', \\'[HIDDEN]\\')\n"
assert node.query(f"SELECT * FROM {CATALOG_NAME}.`{root_namespace}.{table_name}`") == "2024-01-01 12:00:00.000000\t2024-01-01 12:00:00.000000\n"

# Berlin - UTC+1 at winter

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.

Could you also add a test for glue catalog, because we have separate implementation for timestamp type there?

@ianton-ru

Copy link
Copy Markdown
Contributor Author

@scanhex12 All tests passed except CH Inc sync, as I understand PR has conflicts with ClickHouse.cloud version, and I can't solve it myself.

@clickhouse-gh

clickhouse-gh Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.00% -0.10%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.50% -0.10%

Changed lines: 78.08% (203/260) | lost baseline coverage: 12 line(s) · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Dear @scanhex12, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself.

ianton-ru and others added 8 commits June 11, 2026 18:04
Persistent IcebergSchemaProcessor instances cached ClickHouse DateTime64
timezones by schema-id only, so the first query or background prefetch
could pin UTC for later queries with a different iceberg_timezone_for_timestamptz.

https: //github.com/ClickHouse/pull/94025
Co-authored-by: Cursor <[email protected]>
A single schema-id slot could still be overwritten by concurrent queries with
different iceberg_timezone_for_timestamptz values. Cache CH types and transform
DAGs by (schema_id, timezone) so sessions keep independent DateTime64 timezones.

https: //github.com/ClickHouse/pull/94025
Co-authored-by: Cursor <[email protected]>
Materialization only runs when `(schema_id, timezone)` is missing, so clearing artifacts first was unnecessary.

Co-authored-by: Cursor <[email protected]>
ianton-ru and others added 4 commits July 30, 2026 12:53
Partition transforms and timestamptz Avro typing are UTC-based; a non-default
presentation timezone must not leak into INSERT, mutations, or OPTIMIZE MANIFEST.

Co-authored-by: Cursor <[email protected]>
…nes.

iceberg_timezone_for_timestamptz must not shift hour/day prune keys or
min-max bounds relative to UTC-written partitions.

Co-authored-by: Cursor <[email protected]>
A prior SELECT with an empty presentation timezone could leave a non-explicit
DateTime64 sample that flipped adjust-to-utc and partition calendars.

Co-authored-by: Cursor <[email protected]>
, data_lake_settings(configuration_->getDataLakeSettings())
, write_format(configuration_->format)
{
checkIcebergTimezoneSettingForWrite(context_);

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.

checkIcebergTimezoneSettingForWrite only validates the current query setting, but this sink still trusts the sample_block_ it was handed from storage metadata. That leaves a remaining hole for INSERT through a materialized-view target: StorageMaterializedView::write does not call updateExternalDynamicMetadataIfExists on the target, so metadata_snapshot->getSampleBlock() can still reflect whatever presentation timezone a previous SELECT / SHOW CREATE cached.

If the target was last materialized under SETTINGS iceberg_timezone_for_timestamptz='', sample_block_ reaches ChunkPartitioner / generateManifestFile here as non-explicit DateTime64, even though the current insert query is UTC. That reintroduces the wrong-partition / adjust-to-utc=false manifest bug for MV inserts.

Can we rebuild a physical UTC header here (like createIcebergPhysicalSampleBlock now does in compaction) or refresh the target metadata before MV writes?

`master` moved the documentation from the Docusaurus tree under
`docs/en/**/*.md` to the Mintlify tree at `docs/**/*.mdx`, deleting every
file this branch edits. The edits are replayed at the new paths:

- `docs/en/engines/table-engines/integrations/iceberg.md` -> `docs/reference/engines/table-engines/integrations/iceberg.mdx`
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label Aug 5, 2026
@abashkeev abashkeev added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 3, 2026
@subkanthi subkanthi mentioned this pull request Sep 16, 2026
11 of 17 tasks
…g_timestamptz

Resolve the conflict with the move of the settings changes history into the setting declarations
(ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as
trailing arguments of the `DECLARE` of each setting.

- retargeted PR record [email protected] to 26.10 (settings-history check rule)
- semantic merge fixes in non-conflicting files: src/Databases/DataLake/GlueCatalog.cpp, src/Databases/DataLake/S3TablesCatalog.cpp, src/Databases/DataLake/S3TablesCatalog.h, src/Databases/DataLake/UnityV2Catalog.cpp, src/Databases/DataLake/UnityV2Catalog.h, src/Storages/ObjectStorage/DataLakes/DeltaLake/DeltaLakeCatalogRegistration.cpp, src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp, src/Storages/ObjectStorage/DataLakes/Iceberg/tests/gtest_iceberg_schema_processor.cpp

Also resolved conflicts in:
- `src/Databases/DataLake/RestCatalog.cpp`
- `src/Databases/DataLake/tests/gtest_rest_catalog.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.h`
- `src/Core/Settings.cpp`

The remaining `ICatalog` callers (`GlueCatalog`, `S3TablesCatalog`, `UnityV2Catalog`, `DeltaLakeCatalogRegistration`) are updated to the `ContextPtr`-taking signatures.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@scanhex12 scanhex12 self-assigned this Nov 10, 2026
@scanhex12

Copy link
Copy Markdown
Member

Thanks for the contribution, I'll continue there: #130772

@scanhex12 scanhex12 closed this Nov 11, 2026
middas-0706 pushed a commit to middas-0706/ClickHouse that referenced this pull request Nov 12, 2026
The setting sets the time zone of the `DateTime64` type that Iceberg
`timestamptz` and `timestamptz_ns` columns are mapped to. The schema
processor keeps producing `DateTime64(p, 'UTC')`, and the time zone is
applied only to the table schema exposed to queries (`IcebergMetadata`
table schema, storage metadata, sorting key, and the schema of Iceberg
tables in a data lake catalog database). Partition transforms are UTC
based and `adjust-to-utc` depends only on the time zone being explicit,
so writes and pruning are not affected.

A simplified version of ClickHouse#94025

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

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 manual approve Manual approve required to run CI pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants