Skip to content

Time zone for Iceberg partitioning - #95659

Open
ianton-ru wants to merge 28 commits into
ClickHouse:masterfrom
ianton-ru:timezone_for_partitioning
Open

ianton-ru wants to merge 28 commits into
ClickHouse:masterfrom
ianton-ru:timezone_for_partitioning

Conversation

@ianton-ru

@ianton-ru ianton-ru commented Jan 30, 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 iceberg_partition_timezone to set time zone by which partitioning of Iceberg tables was performed

Documentation entry for user-facing changes

When Iceberg table created with third-party tools, data are split on partitions with specific time zone, UTC in most cases.
But ClickHouse tries to make partition pruning based on server time zone, and when server time zone is not UTC, some data can be incorrectly pruned during select queries.

Example: Iceberg table is partitioned by days by column time. It has value 2025-12-31 22:00:00 UTC. and placed in partition 20251231. ClickHouse has server time zone UTC+3, in ClickHouse time zone this value is 2026-01-01 01:00:00 UTC+3. If query has condition SELECT ... WHERE time >= '2026-01-01 00:00:00', partition pruning makes decision that value can be only in partitions 20260101 and later, and prunes partition 20251231 with this value.

This PR introduces new setting iceberg_partition_timezone, which contains time zone used for partitions. This time zone can be different from server time zone, session time zone or column time zone.

Default value is empty for backward compatibility. Empty value means 'use current time zone' as before PR.

  • Documentation is written (mandatory for new features)

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

@ianton-ru
ianton-ru marked this pull request as ready for review January 30, 2026 15:17
@scanhex12 scanhex12 self-assigned this Jan 30, 2026
@scanhex12 scanhex12 added the can be tested Allows running workflows for external contributors label Jan 30, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [289b40a]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, flaky) FAIL
test_database_glue/test_partition_default_timezone.py::test_partition_default_timezone FAIL cidb
test_database_iceberg/test_partition_default_timezone.py::test_partition_default_timezone FAIL cidb
test_database_iceberg/test_partition_timezone.py::test_partition_timezone FAIL cidb
test_storage_iceberg_no_spark/test_writes_partition_timezone.py::test_writes_partition_timezone_session_default[local] FAIL cidb
Integration tests (amd_asan_ubsan, db disk, 1/8) FAIL
test_database_iceberg/test_partition_default_timezone.py::test_partition_default_timezone FAIL cidb
test_database_iceberg/test_partition_timezone.py::test_partition_timezone FAIL cidb
Integration tests (amd_asan_ubsan, db disk, 2/8) FAIL
test_database_glue/test_partition_default_timezone.py::test_partition_default_timezone FAIL cidb
Integration tests (amd_asan_ubsan, db disk, 8/8) FAIL
test_storage_iceberg_no_spark/test_writes_partition_timezone.py::test_writes_partition_timezone_session_default[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

AI Review

Summary

This PR introduces iceberg_partition_timezone and threads it through Iceberg partition pruning, write partitioning, and sort-key decoding so ClickHouse can interpret temporal Iceberg transforms in a non-default time zone. The main read/write carriers are covered, but one destructive sibling path (ALTER TABLE ... DROP PARTITION) still interprets temporal partition expressions in the session/server time zone, and the sort-order carrier still lacks focused regression evidence.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:462] iceberg_partition_timezone changes the partition-value contract for temporal transforms, but ALTER TABLE ... DROP PARTITION still folds user expressions with plain evaluateConstantExpression (AlterDropPartitionExecutor.cpp:164) while resolvePartitionTypes derives manifest partition types through ChunkPartitioner (AlterDropPartitionExecutor.cpp:206). With session_timezone='Asia/Istanbul' and iceberg_partition_timezone='UTC', DROP PARTITION tuple(toRelativeDayNum(toDateTime('2024-01-02 01:00:00'))) evaluates to the Istanbul day even though the manifest keys are UTC days, so the command can delete the wrong partition. Suggested fix: normalize temporal DROP PARTITION expressions through the same transform mapping as reads/writes (or reject them when the setting is set) and add a focused regression.

⚠️ Majors

  • [src/Core/Settings.cpp:9817] [dismissed by author -- https://github.com/Time zone for Iceberg partitioning #95659#discussion_r3633025603] iceberg_partition_timezone is modeled as a query-global setting even though it describes table semantics. I still consider this real because a single query over two Iceberg tables with different partition time zones can only prune one of them correctly, and a forgotten session override on INSERT/OPTIMIZE rewrites the same table under a different partition mapping without any error. Suggested fix: persist the partition time zone with the table/catalog configuration and keep the session setting only as an explicit override, or explicitly reject mixed-table / mutating use that cannot be represented safely.
Tests
  • ⚠️ [src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:1729] getSortingKeyDescriptionFromMetadata still lacks a focused regression for the temporal-transform carrier. The new tests prove partition pruning and write partitioning, but they never exercise optimize_read_in_order or write sorting with a DayTransform/HourTransform sort order under a non-empty iceberg_partition_timezone.
Final Verdict
  • Status: ❌ Block
  1. Make temporal DROP PARTITION evaluation use the same time-zone contract as the manifest/write paths, and cover it with a regression.
  2. Add focused coverage for the sort-order path.
  3. Resolve the table-scoped contract issue for iceberg_partition_timezone, or explicitly reject the unsafe cases it currently leaves silent.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jan 30, 2026
)


def create_clickhouse_iceberg_database(

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.

Can we add the same test for glue?

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.

Done



std::optional<TransformAndArgument> parseTransformAndArgument(const String & transform_name_src)
std::optional<TransformAndArgument> parseTransformAndArgument(const String & transform_name_src, const String & time_zone)

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.

Let's make this argument optional everywhere

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.

Done

@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 7 commits June 29, 2026 09:38
…tests.

Run the server in Asia/Istanbul with the setting unset so pruning follows the session timezone, proving empty is not hardwired to UTC.

Co-authored-by: Cursor <[email protected]>
Insert day-partitioned rows across a UTC boundary with session TZ Asia/Istanbul and assert partition file counts for UTC vs empty setting.

Co-authored-by: Cursor <[email protected]>
Comment thread src/Core/Settings.cpp
)", BETA, enable_nullable_tuple_type) \
DECLARE(UInt64, archive_adaptive_buffer_max_size_bytes, 8 * DBMS_DEFAULT_BUFFER_SIZE, R"(
Limits the maximum size of the adaptive buffer used when writing to archive files (for example, tar archives)", 0) \
DECLARE(Timezone, iceberg_partition_timezone, "", R"(

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.

iceberg_partition_timezone describes a property of the Iceberg table, but this wires it up as a query-global Settings entry and every execution path then reads it from Context (ManifestFileIterator.cpp:314, ChunkPartitioner.cpp:59, Utils.cpp:1473).

That creates a correctness hole:

  • one query cannot read two Iceberg tables that were partitioned in different time zones, because both tables will be pruned with the same timezone;
  • INSERT, ALTER ... UPDATE/DELETE, and OPTIMIZE only stay consistent if every caller remembers to re-set the same session setting, otherwise the same table can be rewritten under a different partition mapping.

Since the mismatched-timezone case already drops rows during pruning, this needs to be table-scoped state rather than a per-query knob. I think this should live in DataLakeStorageSettings / the table configuration (with a query override only as an escape hatch), so each Iceberg table carries its own partition-timezone contract.

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.

Thanks for the review. I agree that query-global scoping has limitations, but I don’t think this should block the PR.
iceberg_partition_timezone follows the same pattern as other Iceberg query settings (use_iceberg_partition_pruning, iceberg_snapshot_id, iceberg_timestamp_ms, etc.). The motivating case is reading externally written Iceberg tables (often via DataLakeCatalog) whose temporal partitions use UTC, while the ClickHouse server/session timezone is not UTC. Iceberg’s own temporal transforms are defined on UTC boundaries, so the common fix is a profile/session default of iceberg_partition_timezone='UTC', not a different timezone per table.
For that catalog use case, a table-only DataLakeStorageSettings value is awkward: catalog tables are not individually created with engine SETTINGS, and a single session default of UTC is the practical configuration.
Empty default preserves historical behavior (use server/session timezone) for both reads and writes. The write-path footgun when the setting is omitted is therefore the same as today; the setting is an opt-in override, not a change to the default write contract.

int direction = field->getValue<String>(f_direction) == "asc" ? 1 : -1;
auto iceberg_transform_name = field->getValue<String>(f_transform);
auto clickhouse_transform_name = parseTransformAndArgument(iceberg_transform_name);
auto clickhouse_transform_name = parseTransformAndArgument(iceberg_transform_name,

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.

getSortingKeyDescriptionFromMetadata now routes temporal sort transforms through iceberg_partition_timezone, but the added coverage still never exercises that carrier.

The new external-table tests create a DayTransform sort order and only do plain reads / partition-pruning checks, so they would still pass if this line silently kept using the session timezone. The new write-path test does not cover it either, because it creates ClickHouse tables without ORDER BY, so sort_description stays empty there.

Please add one focused regression for the changed sort-order path, for example by extending test_read_in_order_with_pyiceberg.py with a table sorted by DayTransform(timestamp) under server Asia/Istanbul plus iceberg_partition_timezone='UTC', and asserting optimize_read_in_order=1 (or ClickHouse write sorting) still behaves according to the UTC transform.

@clickhouse-gh

clickhouse-gh Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.30% 86.20% -0.10%
Functions 92.00% 92.00% +0.00%
Branches 78.40% 78.30% -0.10%

Changed lines: Changed C/C++ lines covered: 69/90 (76.67%) · Uncovered code

Full report · Diff report

…ioning

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/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp

Also resolved conflicts in:
- `src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFileIterator.cpp`
- `src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp`

`buildPartitionKeyFromSpec`, which master moved into `ManifestFilesPruning.cpp`, passes `iceberg_partition_timezone` too, so partition pruning honors the setting.

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


std::optional<TransformAndArgument> parseTransformAndArgument(const String & transform_name_src)
std::optional<TransformAndArgument> parseTransformAndArgument(const String & transform_name_src, std::optional<String> time_zone)

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.

iceberg_partition_timezone now changes how temporal Iceberg transforms are interpreted on the read and write paths, but ALTER TABLE ... DROP PARTITION is still on the old contract.

AlterDropPartitionExecutor::resolvePartitionTypes builds the partition types through ChunkPartitioner (AlterDropPartitionExecutor.cpp:206), so a day(ts) spec under iceberg_partition_timezone='UTC' expects UTC partition values. But parsePartitionTuple still just evaluateConstantExpression on the user expression (AlterDropPartitionExecutor.cpp:164). With session_timezone='Asia/Istanbul', DROP PARTITION tuple(toRelativeDayNum(toDateTime('2024-01-02 01:00:00'))) folds to the Istanbul day even though the manifest keys were written as UTC days, so we can target and delete the wrong partition.

Please route temporal DROP PARTITION expressions through the same transform mapping as reads/writes (or reject them when iceberg_partition_timezone is set) and add a focused regression for the UTC override case.

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
@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-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants