Skip to content

Add nanosecond timestamp support for Iceberg tables - #97132

Merged
alesapin merged 16 commits into
ClickHouse:masterfrom
dk-github:issue-97015-add-iceberg-nanosecond-support
Mar 23, 2026
Merged

alesapin merged 16 commits into
ClickHouse:masterfrom
dk-github:issue-97015-add-iceberg-nanosecond-support

Conversation

@dk-github

@dk-github dk-github commented Feb 16, 2026 •

Copy link
Copy Markdown
Contributor

Support timestamp_ns and timestamptz_ns Iceberg types by mapping them to DateTime64(9) in ClickHouse. Closes #97015

Changelog category (leave one):

  • New Feature

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

Support reading Iceberg v3 nanosecond timestamp types (timestamp_ns and timestamptz_ns), mapped to DateTime64(9) and DateTime64(9, 'UTC'). Note: this does not constitute full Iceberg v3 feature set support, nor does it include support for writing Iceberg v3 with these new types - this just enables Clickhouse to read Iceberg data with these types in the schema.

Documentation entry for user-facing changes

  • [ x] Documentation is written (mandatory for new features)

Motivation:
While full Iceberg v3 support is being worked on, this is a self-contained small change which solves a real usability problem today: users working with high-frequency data (trading, telemetry, scientific measurements) need nanosecond precision but are forced to store timestamps as plain Int64 (epoch nanos) in their Iceberg tables to remain compatible with ClickHouse. This loses all type semantics — no automatic timezone handling, no date arithmetic, no proper formatting by default.

Type mappings:

  • timestamp_ns → DateTime64(9) (nanoseconds, no timezone)
  • timestamptz_ns → DateTime64(9, 'UTC') (nanoseconds, UTC)

Example:

DESCRIBE TABLE icebergS3('s3://bucket/iceberg-v3-table/');
-- ts_nano      Nullable(DateTime64(9))
-- ts_nano_tz   Nullable(DateTime64(9, 'UTC'))

Note

Medium Risk
Changes Iceberg schema inference and Glue catalog type resolution for timestamp columns, which can affect inferred column types for existing tables. Scope is limited to read-side type mapping and adds tests to reduce regression risk.

Overview
Adds read-side support for Iceberg v3 nanosecond timestamp types by mapping timestamp_ns/timestamptz_ns to DateTime64(9) (UTC for timestamptz_ns) during schema inference.

Improves AWS Glue catalog handling of timestamp columns by resolving the exact Iceberg timestamp variant from the table metadata (including Glue’s timestamp_nano fallback), and reuses Iceberg metadata JSON loading utilities (including compressed metadata detection).

Updates user docs with an explicit Iceberg→ClickHouse type mapping table, and adds unit + stateless query tests covering the new timestamp mappings and Glue resolution behavior.

Written by Cursor Bugbot for commit 682530b. This will update automatically on new commits. Configure here.

Support `timestamp_ns` and `timestamptz_ns` Iceberg types by mapping them to `DateTime64(9)` in ClickHouse, gated behind the `iceberg_allow_nanosecond_timestamps` setting.
Closes ClickHouse#97015
@Algunenano Algunenano added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Feb 17, 2026
@alesapin alesapin self-assigned this Mar 5, 2026
@alesapin alesapin added the can be tested Allows running workflows for external contributors label Mar 5, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e7759b3]

Summary: ✅


AI Review

Summary

This PR adds read-side support for Iceberg v3 nanosecond timestamp types by mapping timestamp_ns/timestamptz_ns to DateTime64(9) variants, improves Glue timestamp resolution via Iceberg metadata, and adds docs/tests. I did not find high-confidence correctness, safety, or performance issues in the patch itself.

Missing context

  • ⚠️ No CI logs/results were provided in this review context, so validation here is code-centric.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Mar 5, 2026
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
Support `timestamp_ns` and `timestamptz_ns` Iceberg types by mapping them to `DateTime64(9)` in ClickHouse, gated behind the `iceberg_allow_nanosecond_timestamps` setting.
Closes ClickHouse#97015
@dk-github
dk-github force-pushed the issue-97015-add-iceberg-nanosecond-support branch from c8a76d0 to 64c5689 Compare March 7, 2026 21:57
…implementation based on Iceberg changes merged from main
@dk-github
dk-github force-pushed the issue-97015-add-iceberg-nanosecond-support branch from 2d898a3 to 76bbac2 Compare March 8, 2026 00:08

String column_type = column.GetType();
if (column_type == "timestamp")
if (column_type == "timestamp" || column_type == "timestamp_nano")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wrong string literal "timestamp_nano" instead of "timestamp_ns"

Medium Severity

The condition checks for "timestamp_nano" but everywhere else in the codebase — Constant.h, SchemaProcessor.cpp, the Iceberg spec, and the test metadata JSON — the type is "timestamp_ns". The string "timestamp_nano" appears nowhere else in the entire repository. If AWS Glue returns "timestamp_ns" for nanosecond timestamp columns, the condition won't match, so getActualTimestampType won't be called. This means for a timestamptz_ns column that Glue reports without timezone info (as it does for regular timestamptz → "timestamp"), the metadata lookup that recovers the timezone would be skipped, resulting in a DateTime64(9) instead of the correct DateTime64(9, 'UTC').

Fix in Cursor Fix in Web

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.

actually "timestamp_nano" is correct, as in - this is what AWS Glue actually returns. This is the Glue catalog column type, not the Iceberg spec type.

As to why it does that - it looks like a bit of a mess TBH, but this is the current behaviour:
The Iceberg Java library's https://github.com/apache/iceberg/blob/main/aws/src/main/java/org/apache/iceberg/aws/glue/IcebergToGlueConverter.java has an explicit case TIMESTAMP: return "timestamp" but no case for TIMESTAMP_NANO. The default branch does
type.typeId().name().toLowerCase(Locale.ENGLISH), and the enum value is https://github.com/apache/iceberg/blob/main/api/src/main/java/org/apache/iceberg/types/Type.java, producing "timestamp_nano".

"timestamp_ns" is the type string in Iceberg metadata JSON — a different namespace.

@dk-github dk-github changed the title Add nanosecond timestamp support for Iceberg tables: Add nanosecond timestamp support for Iceberg tables Mar 8, 2026
…ssing documentation on current mappings from Iceberg types to ClickHouse types, during schema inference, including new nanosecond types

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
@dk-github

Copy link
Copy Markdown
Contributor Author

@alesapin cursor's review comments addressed, test coverage fixed, the only test failure seems unrelated to the changes - so it looks ready to go from my side.

Please have a look when you have time and let me know if there's anything else required to get it over the line.

Thanks!

@dk-github

Copy link
Copy Markdown
Contributor Author

@alesapin @Algunenano all tests pass, please have a look when you have time

@clickhouse-gh

clickhouse-gh Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 24.00% 24.00% +0.00%
Branches 76.40% 76.30% -0.10%

PR changed lines: PR changed-lines coverage: 84.97% (147/173, 0 noise lines excluded)
Diff coverage report
Uncovered code

@dk-github

Copy link
Copy Markdown
Contributor Author

@alesapin , @Algunenano please could you have a look?

or provide an approximate ETA for when you will have time for this?

Also, anything else I need to do to get this over the line?..

or if there are any concerns about applicability as a whole, or internal implementation is cooking - just let me know

@Algunenano

Copy link
Copy Markdown
Member

@alesapin , @Algunenano please could you have a look?

Either @alesapin or somebody with experience in the datalake code will review it once they have time

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-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. pr-feature Pull request with new product feature 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.

Support reading Iceberg v3 nanosecond timestamp types (timestamp_ns, timestamptz_ns)

4 participants