Skip to content

Iceberg 'time' type support - #105540

Open
ianton-ru wants to merge 77 commits into
ClickHouse:masterfrom
ianton-ru:iceberg_time_type_support
Open

ianton-ru wants to merge 77 commits into
ClickHouse:masterfrom
ianton-ru:iceberg_time_type_support

Conversation

@ianton-ru

@ianton-ru ianton-ru commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Map the Iceberg time type to Time64(6) instead of Int64. The Iceberg spec defines time as a time of day of microsecond precision without a date or time zone, which is exactly Time64(6), and Time64 stores the same microseconds, so manifest bounds, partition values, bucket hashes and data files keep their values.

What changes:

  • Reading: the schema maps time to Time64(6) (in the table metadata and in the schemas from the REST, Glue and Hive catalogs). Parquet TIME(MICROS) is decoded natively, ORC long columns with the Iceberg attribute iceberg.long-type = TIME are read as the stored microseconds (before, the cast took them as seconds), Avro time-millis/time-micros are rescaled to the requested Time/Time64 scale. Partition values stored as time-micros or as a plain long are brought to the type of the column.
  • Writing: Time and Time64 up to scale 6 are written as Iceberg time into Parquet (TIME(MICROS)), ORC (long with iceberg.long-type = TIME) and Avro (long with time-micros) data files, into the manifest partition values and the column bounds. Values outside of [00:00:00, 24:00:00) are rejected. Before, a Time column was declared as Iceberg time but written as a plain integer of seconds.
  • Creating or altering an Iceberg table with Time or Time64 (scale up to 6) columns is allowed again: the refusal added as a stopgap in 51eb6ae (and its test 05361_iceberg_create_time_column_rejected) is replaced by the proper support. Time64 with a larger scale is still refused.
  • icebergHash/icebergBucket support Time and Time64, hashing the microseconds as the spec requires.
  • Formats: the Parquet, ORC and Avro writers support Time and Time64, and schema inference reads Parquet TIME, Avro time-millis/time-micros and the ORC time-of-day long as Time64.
  • Compatibility: setting iceberg_time_as_int64 (enabled by compatibility up to 26.10) reads time as Int64 microseconds, as after Read Iceberg time columns of Parquet data files as microseconds #126079. Writing a time field from an Int64 column under this setting is refused instead of producing a file that spec-compliant readers reject.

Interoperability is checked with Trino reading Parquet, ORC and Avro data files written by ClickHouse (Spark has no time type), and with pyiceberg-written tables in test_iceberg_time_column.py.

Closes: #118806
Related: #126079
Related: #88063

Changelog category (leave one):

  • Backward Incompatible Change

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

Iceberg time columns are read as Time64(6) instead of Int64 microseconds since midnight, and ClickHouse Time and Time64 columns are written as Iceberg time in Parquet, ORC and Avro data files. To read time as Int64 as before, enable setting iceberg_time_as_int64. The Parquet, ORC and Avro formats support writing Time and Time64 as a time of day, and Avro time-millis/time-micros are read as Time64.

Documentation entry for user-facing changes

Before:

SELECT t FROM iceberg_table  -- 43200000000

Now:

SELECT t FROM iceberg_table  -- 12:00:00.000000

🤖 Generated with Claude Code


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

@scanhex12 scanhex12 added the can be tested Allows running workflows for external contributors label May 21, 2026
@scanhex12 scanhex12 self-assigned this May 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7a0989d]

Summary: ❌

job_name test_name status info comment
Style check FAIL
settings_changes_history FAIL cidb
Build (arm_tidy, 1/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 2/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 3/4) FAIL
Build ClickHouse FAIL cidb
Build (arm_tidy, 4/4) FAIL
Build ClickHouse FAIL cidb
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL
Code Review DROPPED
Build (amd_asan_ubsan) DROPPED
Build (arm_asan_ubsan) DROPPED
Integration tests (amd_asan_ubsan, db disk, targeted) DROPPED

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label May 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 91.40% 91.40% +0.00%
Branches 77.00% 76.90% -0.10%

Changed lines: Changed C/C++ lines covered by tests: 98/222 (44.14%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 6 line(s) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-backward-incompatible Pull request with backwards incompatible changes and removed pr-improvement Pull request with some product improvements labels Jun 1, 2026
@mintlify

mintlify Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 7a0989d.

Approve preview

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026
alexey-milovidov and others added 9 commits November 3, 2026 11:24
…upport

Master replaced the `apache/orc` library with a native ORC reader and writer
(`ORC::` instead of `orc::`) and moved the writing of the values from
`ORCBlockOutputFormat` into `ORC/Writer.cpp`. The time-of-day support of this PR
is ported accordingly: `IntegerColumnWriter` writes `Time` and `Time64` as an
ORC `LONG` of microseconds since midnight and checks the range, and the reader
uses the `ORC::` API for the `iceberg.long-type` attribute.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Avro writer writes a `Map` as an Avro `map`, whose keys are strings, while
the Iceberg Avro mapping requires a map with non-string keys to be an array of
key-value records, with a `time` key as a `long` annotated `time-micros`. A data
file written that way would not match the Iceberg schema for other readers.
Reject writing a `Map` with `Time` or `Time64` keys into an Iceberg Avro data
file (inserts, mutations and compaction) instead of committing such a file.
Parquet and ORC data files keep the type of the keys.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…xception messages

The error of the Parquet writer can be rethrown with the original message
inside, so the error code appears twice in the text. Print it once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… `avro` Python package

The package is not installed in the CI image, so the test failed with `ModuleNotFoundError`.
The object container file with the `time-millis` and `time-micros` columns is now written by hand.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test ran more than 200 client processes and exceeded 180 seconds in the flaky check with sanitizers.
The queries of each table are now batched into a few client calls, and `log_comment` is used instead of
`query_id` to find the pruning queries in `system.query_log`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ime64(6)`

The corpus test was added on master and pinned the old `Int64` type of the `tm` columns.
This PR intentionally reads Iceberg `time` as `Time64(6)`; the content checks still pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Merged master and fixed the CI failures of the previous run:

  • Build (amd_msan): added the missing DataTypes/DataTypesDecimal.h include in IcebergWrites.cpp (getDecimalScale).
  • 04546_avro_logical_time_rescale: the avro Python package is not in the CI image, so the test file is now encoded by hand.
  • 05406_iceberg_time_write_formats: exceeded 180 s in the flaky checks. The queries are now batched into a few client calls, and the test takes about 9 s locally.
  • 05477_iceberg_corpus (new on master): its reference pinned Int64 for Iceberg time. I updated it to Time64(6), the type this PR intends. The content checks still pass.

@clickhouse-gh

clickhouse-gh Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing e7e0ab25f with master b51e7acfe (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 86abc2f7f; 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.

Object file sizes

31 object files changed (+234.51 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/Parquet/Write.cpp.o 1.43 MiB 1.50 MiB +71.50 KiB (+4.87%)
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ORC/Writer.cpp.o 338.84 KiB 376.42 KiB +37.58 KiB (+11.09%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp.o 1.09 MiB 1.12 MiB +26.37 KiB (+2.36%)
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/AvroRowInputFormat.cpp.o 1.08 MiB 1.10 MiB +24.48 KiB (+2.22%)
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/AvroRowOutputFormat.cpp.o 462.75 KiB 485.28 KiB +22.53 KiB (+4.87%)
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/icebergBucketTransform.cpp.o 305.01 KiB 322.66 KiB +17.64 KiB (+5.78%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

alexey-milovidov and others added 5 commits November 12, 2026 02:23
# Conflicts:
#	src/Databases/DataLake/RestCatalog.cpp
#	src/Processors/Formats/Impl/AvroRowInputFormat.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.cpp
…aster

Master removed Arrow from the native Parquet writer, so `parquet::Int64Type` no longer exists there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g Avro data files

The Avro writer serializes the whole map key as a string, so `Map(Tuple(tm Time64(6)), Int64)` hit the
same problem as a direct `Time64` key. Check the key type recursively in `checkIcebergTimeColumnIsWritable`
and add the case to `05493_iceberg_avro_time_map_key`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts: master added a `timezone_for_timestamptz` parameter to `IcebergSchemaProcessor`
and `getSimpleType`, while this PR added `time_as_int64`; both are kept, with
`time_as_int64` before `timezone_for_timestamptz`.
{
/// The microseconds of an Iceberg `time` are the ticks of `Time64(6)`, while the cast of an
/// integer to `Time64` would take them as seconds. An integer type is still read as is.
if (isIcebergTimeLong(*orc_type) && !(type_hint && WhichDataType(type_hint).isNativeInteger()))

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.

[Blocker] Preserve stored microseconds for every integer target

isNativeInteger excludes Int128/UInt128/Int256/UInt256, and inspecting the outer hint also misses LowCardinality(Int64). These explicit integer schemas therefore enter the new Time64(6) branch. The final castColumnToRequestedType converts that time to an integer in seconds, silently changing the stored value; the ordinary Int64 target still returns microseconds.

For example, write SELECT toTime64('12:34:56.123456', 6) AS t FORMAT ORC, then read the file with file('time.orc', ORC, 't Int128'): this path produces 45296, whereas reading the same file as t Int64 produces 45296123456. This follows from the current decoder and decimal-to-integer conversion; I could not execute it locally because this checkout has no ClickHouse binary/build. The same scalar reader is used inside containers and union branches, where orcIntegerBranchWidensTo explicitly accepts wide integer hints.

Please classify the unwrapped target once at this decoding boundary and preserve the raw Int64 representation for all integer targets before the final widening/dictionary cast. Add a focused stateless regression comparing Int64, Int128, and LowCardinality(Int64) reads of a tagged time column with a nonzero fractional part.

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.

🕵 Fixed in 7a0989d: the ORC scalar reader now classifies the target after removing Nullable and LowCardinality and keeps the raw Int64 for every integer type (isInteger instead of isNativeInteger), so Int128, UInt128, Int256 and UInt256 return the stored microseconds like Int64 does. Added 05872_orc_time_of_day_integer_targets, which reads a tagged time column with a fractional part as Int64, UInt64, the wide integers, Nullable(Int128), LowCardinality(Int64), LowCardinality(Nullable(Int64)), and inside Tuple and Array; all return 45296123456.

@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
alexey-milovidov and others added 3 commits November 23, 2026 23:02
# Conflicts:
#	src/Databases/DataLake/GlueCatalog.cpp
#	src/Processors/Formats/Impl/AvroRowInputFormat.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.h
…tType`

The test was added on master and calls `DataLake::getType` with two arguments, while this branch added
the `time_as_int64` parameter. This broke the `Build (arm_tidy, 4/4)` job:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=105540&sha=74711314b5d1a472c2e5e4e38c6f0ed5c2cbe573&name_0=PR&name_1=Build%20%28arm_tidy%2C%204%2F4%29
ClickHouse#105540

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…r every integer target

The ORC reader decoded a `long` with the attribute `iceberg.long-type` = `TIME` as `Time64(6)` unless the
requested type was a native integer. `isNativeInteger` excludes `Int128`, `UInt128`, `Int256` and `UInt256`,
so for these the final cast converted the time to seconds (`45296`), while `Int64` returned the stored
microseconds (`45296123456`). Now every integer type, also inside `Nullable` or `LowCardinality`, is read as is.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

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 manual approve Manual approve required to run CI pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

5 participants