Skip to content

Change and document handling of Parquet local-timezone timestamps - #87872

Merged
al13n321 merged 9 commits into
masterfrom
youteasee
Nov 5, 2025
Merged

al13n321 merged 9 commits into
masterfrom
youteasee

Conversation

@al13n321

@al13n321 al13n321 commented Sep 30, 2025 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Improvement

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

Parquet no-timezone timestamps (isAdjustedToUTC=false) are now read as DateTime64(..., 'UTC') instead of DateTime64(...). This is less incorrect as converting such UTC timestamp to string produces a representation of the correct local time. Use input_format_parquet_local_time_as_utc=0 to get the old behavior. Resolves #87469.

Details

Closes #87469

What clickhouse type should we use for parquet timestamps with isAdjustedToUTC=false? DateTime64(3) or DateTime64(3, 'UTC')? Copying explanation from #87469 (comment) :

AFAIU, neither behavior is actually correct, and the new behavior seems less incorrect.

https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#local-semantics-timestamps-not-normalized-to-utc says:

A TIMESTAMP with isAdjustedToUTC=false represents year, month, day, hour, minute, second and subsecond fields in a local timezone, regardless of what specific time zone is considered local.

ClickHouse doesn't have a data type like that. Both DateTime64(3) and DateTime64(3, 'UTC') are the number of milliseconds since Unix epoch, representing a specific point in time. The timezone parameter only affects parsing and formatting.

DateTime64(3, 'UTC') seems more correct: if converted to string, it'll show the correct "year, month, day, hour, minute, second and subsecond" that the parquet file had in mind. Like in this paragraph in parquet documentation:

Another way to get to the same definition is to treat the local timestamp value as if it were in UTC and store it as an instant. For example, if we treat the local timestamp 1970-01-03 00:00:00 as if it were the instant 1970-01-03 00:00:00 UTC, we can store it as 172800000. When reading 172800000 back, we can reconstruct the instant 1970-01-03 00:00:00 UTC and convert it to a local timestamp as if we were in the UTC time zone, resulting in 1970-01-03 00:00:00. In Java, this can be achieved by calling LocalDateTime.ofEpochSecond(172800, 0, ZoneOffset.UTC).

So, this PR changes it from DateTime64(3) to DateTime64(3, 'UTC'), behind a compatibility setting. Or maybe we should use String instead?

Also rewrote most of type mapping information in docs/en/interfaces/formats/Parquet/Parquet.md.

@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a25195b]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan, old analyzer, 4/6) failure
test_replicated_database_recover_digest_mismatch/test.py::test_recover_digest_mismatch FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 30, 2025
Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@al13n321
al13n321 enabled auto-merge November 3, 2025 18:55
@al13n321
al13n321 added this pull request to the merge queue Nov 5, 2025
Merged via the queue into master with commit ec78b28 Nov 5, 2025
@al13n321
al13n321 deleted the youteasee branch November 5, 2025 02:25
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 5, 2025
@alsugiliazova

Copy link
Copy Markdown
Contributor

@al13n321 is that expected?

25.8.13:

SELECT
    timestamp_x2Ecolumn,
    timestamptz_x2Ecol
FROM s3('http://minio:9000/warehouse/data/data/**.parquet', 'admin', 'password')
ORDER BY tuple(*) ASC
LIMIT 1
SETTINGS input_format_parquet_use_native_reader_v3 = 0
Query id: a619d9a8-9194-489a-ae6a-5fdeea9998ef

   ┌────────timestamp_x2Ecolumn─┬─────────timestamptz_x2Ecol─┐
1. │ 2020-01-01 13:00:00.000000 │ 2020-01-01 12:00:00.000000 │
   └────────────────────────────┴────────────────────────────┘

1 row in set. Elapsed: 0.024 sec. 
SELECT
    timestamp_x2Ecolumn,
    timestamptz_x2Ecol
FROM s3('http://minio:9000/warehouse/data/data/**.parquet', 'admin', 'password')
ORDER BY tuple(*) ASC
LIMIT 1
SETTINGS input_format_parquet_use_native_reader_v3 = 1
Query id: ce1cf1f0-3ee2-4e1e-af3d-eb1de282fb5e

   ┌────────timestamp_x2Ecolumn─┬─────────timestamptz_x2Ecol─┐
1. │ 2020-01-01 12:00:00.000000 │ 2020-01-01 12:00:00.000000 │
   └────────────────────────────┴────────────────────────────┘

1 row in set. Elapsed: 0.016 sec.

alexey-milovidov pushed a commit to niyue/ClickHouse that referenced this pull request Oct 12, 2026
An INSERT into a Delta table whose schema declares a timestamp_ntz column
committed a data file that annotated the column
Timestamp(isAdjustedToUTC=true, MICROS). Delta defines timestamp_ntz as an
unadjusted wall clock timestamp, so Spark refused every later read of the
table with

  java.lang.RuntimeException: Unable to create Parquet converter for data
  type "timestamp_ntz" whose Parquet type is int64 time(TIMESTAMP(MICROS,true))

Two independent facts produced this. The kernel schema visitor wired
visit_timestamp and visit_timestamp_ntz to the same visitor, so both Delta
types became DateTime64(6) and the distinction was gone before the writer saw
it; ClickHouse has no wall clock type that could carry it either. The Parquet
writer then hardcoded isAdjustedToUTC=true at both timestamp branches, which
is right for the general Parquet format because a DateTime64 is an instant,
but wrong for a column the Delta log declares timestamp_ntz.

Rather than consult the DateTime64 timezone parameter, which would change
every general-format write and contradict the rule settled in ClickHouse#87872, the
distinction is kept where it is produced and delivered where it is needed.
The visitor records is_timestamp_ntz on its field, the traversal collects the
dotted paths of those leaves, TableSnapshot caches them with the rest of the
schema, and the Delta write path hands them to the writer through
ColumnMapper, which already carries per-path lake facts that a ClickHouse
type cannot express (iceberg_string_paths, iceberg_optional_paths).

Nested paths are spelled the way the Parquet writer spells a column path (a
struct field's own name, element for an array child, key and value for a
map's) rather than reusing the kernel's child names, which are not guaranteed
to be those words.

Only the annotation changes; the stored int64 is identical, so the ClickHouse
round trip stays lossless. This is the inverse of the documented read-side
rule that reads an unadjusted timestamp as DateTime64(N, 'UTC').

The mapper is attached only when the table actually has a timestamp_ntz
column and only for Parquet, so a Delta table without one keeps its exact
current behaviour, and ORC and Avro never see a mapper they would read as
Iceberg metadata. ParquetBlockOutputFormat now passes std::nullopt when the
mapper's field-id map is empty: an engaged but empty optional makes
convertSchema report the first column as having no Iceberg field id, so a
mapper carrying only timestamp paths would otherwise break every Delta
INSERT. An Iceberg mapper always has an id per field, so Iceberg is
unaffected.

The shared annotation seam is shaped identically to the in-flight ClickHouse#118601,
which adds it for Iceberg but does nothing for Delta, so either merge order
is a mechanical rebase.

Tests: two integration tests in test_storage_delta covering the flat case
(with Nullable, a Delta timestamp control and a char/varchar column) and the
nested case (struct field, array element, map value, plus a Delta timestamp
sibling inside the same struct), both asserting the _delta_log types first so
they cannot pass vacuously, the written annotation, a Spark read and the
ClickHouse round trip. 02735_parquet_encoder gains a logical_type assertion
because desc file() reports DateTime64(N, 'UTC') for both flag values, so
nothing on master would have caught a global flip of the default.

Closes ClickHouse#120653.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

DateTime64(3) turns into DateTime64(3, UTC) with native parquet reader v3

5 participants