Skip to content

Fix ORC timestamp pruning for UTC aliases and Iceberg ORC timestamps - #132657

Merged
Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:orc-timestamp-fixes
Nov 21, 2026
Merged

Algunenano merged 5 commits into
ClickHouse:masterfrom
Algunenano:orc-timestamp-fixes

Conversation

@Algunenano

@Algunenano Algunenano commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

ORC TIMESTAMP fixes for regressions that are only on master, plus the Iceberg ORC time zones:

  • Filter push down treated only the zones named UTC and GMT as UTC, so Etc/UTC, Zulu and the other aliases read every row group. The reader and the writer now decide by the zone file: no transitions and a zero offset. The column reader also skips the wall clock conversion between two zones without transitions and with the same offset (hasFixedOffset is not enough, it only covers the years 1900-2299).
  • ORC stores the timestamps between -1 and 0 seconds as the epoch, but the Iceberg bounds and partitions came from the original values, so pruning skipped data files whose rows a full read returns at the epoch. The Iceberg inserts now replace those values before deriving the partitions and the bounds, and the compaction before computing the bounds. The compaction keeps the partition values of the source files, so compacting a partitioned table into ORC can still keep a stale partition for such a value, as before this PR: no writer (ClickHouse, Java, Python) produces these values correctly in ORC, so it is not worth the complexity.
  • The Iceberg timestamps are UTC instants and the reference implementation reads and writes ORC with useUTCTimestamp, but output_format_orc_writer_time_zone_name and input_format_orc_reader_time_zone_name shifted them while the bounds stayed in UTC, so pruning skipped rows. The Iceberg reads, inserts and compaction now use UTC for both. Iceberg ORC files written by ClickHouse before this change with a non-UTC writer time zone are now read as the reference implementation reads them, shifted by that offset, even when the reader time zone matches.

Closes: #132383
Closes: #131492
Related: #131274
Related: #131036

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Version info

  • Merged into: 26.12.1.127-master (included in 26.12 and later)

Algunenano and others added 2 commits November 18, 2026 14:00
Filter push down disabled the `TIMESTAMP` statistics unless the writer and reader zones were named `UTC` or `GMT`,
so `Etc/UTC` and the other aliases read every row group. Decide by the offset, as `hasFixedOffset` does elsewhere.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ORC stores the timestamps between -1 and 0 seconds as the epoch, while the Iceberg bounds came from the original
values, so pruning skipped data files whose rows a full read returns at the epoch.

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

clickhouse-gh Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a7e5a3e]

Summary: ✅


AI Review

Summary

The PR enables ORC timestamp pruning for UTC aliases, normalizes timestamps before Iceberg insert metadata is derived, and forces UTC for Iceberg ORC reads and writes. Reviewed head a7e5a3e75ccd4827a3b3fff83450a7cd0f779c3c. No new inline findings; two previously discussed correctness concerns remain in cases the author explicitly deferred. Their threads remain resolved, without further replies.

Findings

❌ Blockers

  1. Compaction can still publish partitions that contradict stored rows. Compaction.cpp:444 [dismissed by author -- https://github.com/Fix ORC timestamp pruning for UTC aliases and Iceberg ORC timestamps #132657#discussion_r4614636696]

    Rewriting Parquet data containing 1969-12-31 23:59:59.5 into ORC now normalizes the timestamp to the epoch before collecting bounds, but writeMetadataFiles copies the original partition tuple and its summary at lines 1268–1271. With PARTITION BY icebergDay(ts), the stored row belongs to day 0 while metadata still says -1; WHERE icebergDay(ts) = 0 can therefore omit it with pruning enabled. The insert case is fixed. The author deliberately excludes this compaction case, but it still violates the invariant that partitions describe stored rows. Repartition after normalization, or reject a rewrite that changes the partition.

  2. Forced UTC reads can invalidate existing Iceberg bounds. IcebergMetadata.cpp:2053 [dismissed by author -- https://github.com/Fix ORC timestamp pruning for UTC aliases and Iceberg ORC timestamps #132657#discussion_r4617700032]

    A pre-patch file written with output_format_orc_writer_time_zone_name = 'Europe/Berlin' from a UTC instant at 2024-01-01 00:00:00 retains Iceberg bounds at that instant. The override makes a full read return 2024-01-01 01:00:00, while pruning still consults the original bounds. Filtering for the returned instant can consequently lose the row. The author intentionally adopts reference-reader semantics without compatibility handling; that does not make the retained pruning metadata valid. Handle the incompatible metadata or explicitly reject affected legacy files before returning inconsistent results.

Tests
  • ⚠️ Add the partitioned Parquet-to-ORC variant of 05831, comparing matching row sets with pruning enabled and disabled after compaction.
  • ⚠️ Add an upgrade fixture written by the previous non-UTC writer; verify the supported read behavior and pruning agree, or verify explicit rejection. 05832 creates files through the corrected writer and cannot cover this case.
Missing context / blind spots
  • ⚠️ The Cloud compaction implementation is absent from this public checkout; equivalent UTC enforcement and normalization there need confirmation through its implementation or the Cloud run of 05831.
  • ⚠️ No local ClickHouse executable/build was available. The fetched targeted CI report exposed no individual regression-test results, so their execution was not independently verified.
Final Verdict

Status: ❌ Block. Minimum required actions: prevent partition-changing compaction from publishing stale tuples, and prevent legacy non-UTC files from being pruned with bounds that disagree with their interpreted values, with the focused regression coverage above.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Nov 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a7e5a3e75 with master a2c6c5559 (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

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Nov 18, 2026
…lues

Decide whether an ORC time zone is UTC or has a fixed offset by the absence of transitions, since `hasFixedOffset`
only covers the years 1900-2299 and the wall clock conversion of older timestamps depends on the older offsets.

Replace the timestamps that ORC stores as the epoch before the Iceberg inserts derive the partitions and the bounds,
and before the compaction computes the bounds, instead of only raising the upper bounds.

The Iceberg timestamps are UTC instants and the reference implementation reads and writes ORC with
`useUTCTimestamp`, but the ORC time zone settings shifted them while the bounds stayed in UTC. Use UTC for both
time zones in the Iceberg reads, inserts and compaction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano Algunenano changed the title Fix ORC timestamp pruning for Etc/UTC and Iceberg bounds before the epoch Fix ORC timestamp pruning for UTC aliases and Iceberg ORC timestamps Nov 18, 2026
…build

The Cloud build reads `allow_experimental_iceberg_compaction` when the table is created, not on `OPTIMIZE`.

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-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). labels Nov 20, 2026
@stresshouse

stresshouse Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 29 queries analysed

No performance change can be attributed to this PR. The tested build changes only how ORC files handle timestamp time zones and how Iceberg tables read, write and compact ORC files, and none of the clickbench or tpch_adapted_1_official queries use that code. Two clickbench queries were slower and are marked not sure, not regressions: Q30 (+18.5%, 186 ms vs 157 ms) and Q31 (+18.1%, 254 ms vs 215 ms). Both are GROUP BY ... ClientIP aggregations on the MergeTree hits table, both new medians fall inside master's own current range for those queries, and both queries have a noisy history, so leaving them as not sure is consistent with the diff.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 30 not_sure 157 186 +18.5% <0.0001 aggregation: The +18.5% shift stays inside master's current range for this query, and the history is noisy. This MergeTree GROUP BY never runs the ORC or Iceberg code that this PR changes.
⚠️ 31 not_sure 215 254 +18.1% <0.0001 aggregation: The +18.1% shift stays inside master's current range for this query, and the history is noisy. This MergeTree GROUP BY never runs the ORC or Iceberg code that this PR changes.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 8e2648ec-fa63-4aab-a5ec-f6652b78036b
  • MIRAI run: 18f333c4-7580-4d0d-9b41-24a3c5c181ff
  • PR check IDs:
    • clickbench_680221_1795280034
    • clickbench_680227_1795280034
    • tpch_adapted_1_official_680265_1795280034
    • tpch_adapted_1_official_680288_1795280034

@Algunenano
Algunenano added this pull request to the merge queue Nov 21, 2026
Merged via the queue into ClickHouse:master with commit 873a218 Nov 21, 2026
387 of 388 checks passed
@Algunenano
Algunenano deleted the orc-timestamp-fixes branch November 21, 2026 15:55
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 21, 2026
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-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ORC TIMESTAMP pruning disabled for Etc/UTC writer or reader zones Iceberg ORC bounds keep timestamps the writer stores as the epoch: rows pruned

2 participants