Skip to content

Parquet: map TIME logical type to Time64 - #106019

Merged
alexey-milovidov merged 65 commits into
ClickHouse:masterfrom
tiandiwonder:parquet-time-of-day-type
Sep 19, 2026
Merged

alexey-milovidov merged 65 commits into
ClickHouse:masterfrom
tiandiwonder:parquet-time-of-day-type

Conversation

@tiandiwonder

@tiandiwonder tiandiwonder commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

The native Parquet reader currently maps both logical.TIMESTAMP and logical.TIME (and the deprecated converted types TIMESTAMP_MILLIS/TIMESTAMP_MICROS/TIME_MILLIS/TIME_MICROS) to DataTypeDateTime64. That was fine before ClickHouse 25.6, when there was no time-of-day type, but it now produces the Parquet analogue of #104038: when the target column is Time64 and session_timezone is non-UTC, the DateTime64 -> Time64 cast (PR #90310) shifts the value by the timezone — silent data corruption for a value that has no date/timezone to begin with.

This PR splits the schema-converter branch so that:

  • logical.TIME / TIME_MILLIS / TIME_MICROS → DataTypeTime64(scale) (timezone-unaware).
  • logical.TIMESTAMP → DataTypeDateTime64(scale, timezone) (unchanged).

It also extends the min/max stats allowlist to recognize Time64, so stats-based row-group and page pruning stays enabled when a parquet TIME column is read as Time64. The allowlist is deliberately keyed off the decoded semantic type: for parquet TIMESTAMP read with a Time64 hint the values are decoded as DateTime64 and the cast to Time64 wraps by day, so stats are not order-preserving there and pruning stays disabled (test 05054_parquet_timestamp_to_time64_no_stats_pruning). It also removes the stale comment that claimed ClickHouse has no time-of-day type.

While covering explicit type hints in the test (SELECT * FROM file(..., 'Parquet', 't Time')), I hit a second pre-existing gap from 25.6: Time64 -> Time was never registered as a cast — it threw CANNOT_CONVERT_TYPE because IsDataTypeNumber<DataTypeTime> is false (it inherits DataTypeNumberBase<Int32>, not DataTypeNumber<Int32>). Before this PR the path went DateTime64 -> Time and returned a wrong, timezone-shifted value; after the Parquet fix it would have thrown. The second commit adds an inline Time64 -> Time branch in ConvertImpl that divides by the scale multiplier — no timezone offset, because both Time64 and Time are timezone-unaware seconds-of-day.

A new stateless test 04277_parquet_time_of_day covers:

  • Schema-less inference (Parquet time32[ms]/time64[us]/time64[ns] → Nullable(Time64(3/6/9)); TIMESTAMP stays Nullable(DateTime64(6, 'UTC'))).
  • Import into Time64(scale) columns under session_timezone = 'Asia/Shanghai' (values must not shift).
  • Explicit type hints under non-UTC session: Time64(3) / Time / DateTime64(3, 'UTC') / Int64.

Review follow-up: making Time64 -> DateTime legal also exposed that ToDateTimeMonotonicity treated Time64 sources as monotonic, while the cast wraps negative time-of-day values with the default date_time_overflow_behavior = 'ignore' (-00:00:01 -> 2106-02-07 06:28:15), i.e. it drops at zero. toDateTime now reports non-monotonic for Time/Time64 sources; the regression test 04828_time64_to_datetime_not_monotonic shows that without the guard the key condition prunes every granule and range/point queries over a Time64 key silently return empty results. The Parquet docs (docs/reference/formats/Parquet/Parquet.mdx) are updated for the new TIME -> Time64 mapping.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix Parquet time32/time64 columns being read as DateTime64 and then silently shifted by session_timezone when inserted into a Time64 target column. Parquet TIME logical types now map directly to Time64, and a previously-missing Time64 -> Time cast is added.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

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

tiandiwonder and others added 2 commits May 27, 2026 11:42
Parquet `TIME_MILLIS` / `TIME_MICROS` (logical type `TIME`) is a
timezone-unaware time-of-day, but the native reader was wrapping it as
`DataTypeDateTime64`. When the target column was `Time64`, the
subsequent `DateTime64 -> Time64` cast offset values by
`session_timezone` -- the Parquet analogue of ClickHouse#104038 in the Arrow
reader.

Route `logical.TIME` and the deprecated `TIME_MILLIS` / `TIME_MICROS`
converted types to `DataTypeTime64(scale)` instead. Keep
`logical.TIMESTAMP` -> `DataTypeDateTime64` unchanged. The
`field_timestamp_from_millis` shortcut is now only taken for the
`TIMESTAMP_MILLIS` -> `DateTime` hint case. Extend
`is_output_type_decimal` to recognize `Time64` so min/max stats stay
enabled when the output is `Time64`.

Drop the stale comment that claimed ClickHouse has no time-of-day type
(it has had `Time` / `Time64` since 25.6).

Add 04277_parquet_time_of_day stateless test covering schema-less
inference and import under a non-UTC `session_timezone`.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ClickHouse 25.6 introduced `Time` / `Time64` but only registered a
`DateTime64 -> Time` cast, leaving `Time64 -> Time` to fall through to
the generic Decimal -> Number path -- where `DataTypeTime` does not
satisfy `IsDataTypeNumber` (it inherits `DataTypeNumberBase<Int32>`,
not `DataTypeNumber<Int32>`), so the cast threw `CANNOT_CONVERT_TYPE`.

This is what made the previous Parquet commit visible as a regression
when reading TIME_MILLIS / TIME_MICROS with an explicit `t Time` hint:
before, the value went through `DataTypeDateTime64 -> Time` (returning
a wrong, timezone-shifted value); after the Parquet fix it went
through `DataTypeTime64 -> Time` which had no registered cast.

Add an inline `Time64 -> Time` branch in ConvertImpl that divides by
the scale multiplier. Unlike `DateTime64 -> Time`, no timezone offset
is applied -- both Time64 and Time are timezone-unaware seconds-of-day,
so the cast is a pure scale conversion. (Applying session timezone
here would silently shift values; see issue ClickHouse#104038 for the Arrow
analogue.)

Extend 04277_parquet_time_of_day to read the same TIME_MILLIS column
under `session_timezone = 'Asia/Shanghai'` with four explicit hints
(Time64(3) / Time / DateTime64(3, 'UTC') / Int64) and assert each path.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e55470]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR fixes the Parquet TIME -> Time64 mapping and the follow-up Time / Time64 conversion bugs that surfaced during review. The remaining issue I found is documentation: the structured conversion docs were updated for toTime / toDateTime, but the sibling toDate / DATE / toDate32 registrations still do not describe the Time / Time64 behavior this PR changes.

Findings

💡 Nits

  • [src/Functions/FunctionsConversion_reg.cpp:1283] Time / Time64 now have user-visible toDate / DATE / toDate32 behavior changes (src/Functions/FunctionsConversion.h:2378-2405; tests 03365_time_time64_conversions.sql and 05026_time64_values_date_overflow_behavior.sql), but their FunctionDocumentation registrations at src/Functions/FunctionsConversion_reg.cpp:1053-1157 still list only string/date-time/numeric inputs and omit the epoch-based interpretation plus toDate overflow behavior. Update those structured docs so the generated reference matches the implementation.
Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 3e55470.

Metric Baseline Current Δ
Lines 88.50% 88.50% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 299/333 (89.79%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label May 28, 2026
@tiandiwonder tiandiwonder added the can be tested Allows running workflows for external contributors label May 28, 2026
@tiandiwonder tiandiwonder changed the title Parquet: map TIME logical type to Time64 (fixes #104038 analogue) Parquet: map TIME logical type to Time64 May 28, 2026
@Diskein Diskein self-assigned this May 28, 2026
@clickhouse-gh pointed out that mapping Parquet `TIME` logical type to
`Time64` (PR commit c3de271) broke
`tests/queries/0_stateless/00900_parquet_time_to_ch_date_time.sh`,
which inserts `time32_test.parquet` / `time64_test.parquet` into a
`DateTime('UTC')` column. Before this PR the decoded input type was
`DataTypeDateTime64`, and `castColumn(DateTime64 -> DateTime)` was
registered, so the existing insert produced `1970-01-01 01:23:20`
etc.

After the Parquet schema-converter change the decoded type is
`DataTypeTime64`, but `FunctionsConversion` only had `Time64 -> Time`
and `Time64 -> DateTime64` -- not `Time64 -> DateTime` -- so that
existing insert would have thrown `CANNOT_CONVERT_TYPE`.

Register a no-timezone `Time64 -> DateTime` cast in `ConvertImpl`,
mirroring the `Time64 -> Time` branch added in commit f779202:
divide the Time64 value by its scale multiplier and reinterpret the
integer seconds as seconds-since-epoch, producing a 1970-01-01
wall-clock timestamp. The result is byte-for-byte the same as what
the legacy `DateTime64 -> DateTime` path produced, so
`00900_parquet_time_to_ch_date_time` continues to pass unchanged.

Extend `04277_parquet_time_of_day.sh` with an explicit
`DateTime('UTC')` hint over the same Parquet `TIME_MILLIS` column to
guard the cast going forward.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Comment thread src/Functions/FunctionsConversion.h Resolved
Comment thread src/Functions/FunctionsConversion.h Resolved
Comment thread src/Functions/FunctionsConversion.h Resolved
alexey-milovidov and others added 4 commits June 3, 2026 05:45
…rmTime64

The hand-written `Time64 -> Time` / `Time64 -> DateTime` conversions divided the
raw decimal value by the scale multiplier directly. Integer division truncates
towards zero, so negative `Time64` values lost a second (`-00:00:00.5` became
`00:00:00` instead of `-00:00:01`), and the loops bypassed the `Time` /
`DateTime` range handling, ignoring `date_time_overflow_behavior` (a negative
`Time64 -> DateTime` wrapped through `UInt32` even under `throw`).

Route both casts through the existing `TransformTime64` wrapper, which extracts
the whole-second part flooring towards negative infinity, with
`ToTimeTransform64Signed` clamping to `[-MAX_TIME_TIMESTAMP, MAX_TIME_TIMESTAMP]`
and `ToDateTimeImpl` applying the `DateTime` range handling, both honoring
`date_time_overflow_behavior`. The source scale is read from the argument type
and passed to the transform. `ToTimeImpl` is intentionally not reused: it applies
`% 86400` plus a timezone offset (the `DateTime64 -> Time` time-of-day semantics),
which would corrupt `Time64`'s timezone-unaware duration semantics.

Add `04305_time64_to_time_datetime_cast` covering negative flooring and the
`saturate` / `throw` overflow behaviors under a non-UTC `session_timezone`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Trim the `Time64 -> Time` / `Time64 -> DateTime` comments to the essential
rationale (timezone-unaware so no offset, cf. ClickHouse#104038; floor-towards-negative;
range handling honoring `date_time_overflow_behavior`). No logic change.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This PR maps the Parquet `TIME` logical type to ClickHouse `Time64` instead
of `DateTime64`. The catch-all loader test `00900_long_parquet_load_2` reads
`time32_test.parquet` and `time64_test.parquet`, whose reference still showed
the old `DateTime64` rendering (`1970-01-01 01:23:20.000`). With the new
mapping these columns render as a time of day (`01:23:20.000`).

Only the rendering changed: the `cityHash64` sums are identical because the
stored integer value is the same — so the regenerated reference differs from
the committed one only on those time-of-day lines, confirming no other
behavior changed.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Dear @Diskein, 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.

@clickhouse-gh

clickhouse-gh Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Dear @Diskein, 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.

@alexey-milovidov alexey-milovidov self-assigned this Jul 31, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.50% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.80% +0.10%

Changed lines: Changed C/C++ lines covered: 33/34 (97.06%) · Uncovered code

Full report · Diff report

The AI review flagged that switching the decoded type from `DateTime64` to
`Time64` could make `Reader::formOutputColumn`'s `castColumn` throw
`CANNOT_CONVERT_TYPE` for `Date` / `Date32` targets, because this change only
adds sibling `Time64 -> Time` and `Time64 -> DateTime` conversions.

That does not happen: `Time64 -> Date` and `Time64 -> Date32` are already
supported and both yield `1970-01-01`, exactly what the pre-change
`DateTime64 -> Date` / `Date32` path produced. Verified locally:

    SELECT CAST(toTime64('12:34:56.789', 3) AS Date),
           CAST(toTime64('12:34:56.789', 3) AS Date32)
    -- 1970-01-01   1970-01-01

Extend `04277_parquet_time_of_day` with the missing coverage so the cast
surface is pinned: explicit `Date` / `Date32` hints on both the `TIME_MILLIS`
and `TIME_MICROS` columns, and an insert into `Date` / `Date32` table columns.
Comment thread src/Functions/FunctionsConversion.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing commit 3e55470de2582f4a926d0d2066cd84cd2e56f8f5 with master failed: RuntimeError: CI logs cluster query failed: SELECT count() AS c FROM binary_sizes W….

See the job log for details.

`05054_parquet_timestamp_to_time64_no_stats_pruning` writes one row group
with two timestamps straddling midnight, reads the column as `Time64(3)` and
checks that the row whose time of day falls outside the raw min/max bounds is
still returned and that no row group is pruned. With the stats guard removed
the query returns `0` and `ParquetPrunedRowGroups` is `1`.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (2026-08-31):

AI Review blocker (parquet min/max stats for TIMESTAMP -> Time64) — fixed in d0e9fe64148a. allow_decimal_stats now takes a decoded_is_time_of_day flag, and the Time64 stats branch is enabled only when the decoded semantic type is already Time64 (the parquet TIME path). For parquet TIMESTAMP read with a Time64 hint the runtime cast wraps by day, so stats are left disabled and neither the row-group nor the page-index filter can prune matching rows.

Regression test — 05054_parquet_timestamp_to_time64_no_stats_pruning (e9c33e28c76c): one row group holding 1970-01-01 23:00:00 and 1970-01-02 01:00:00, read as Time64(3) with WHERE t = toTime64('01:00:00', 3), asserting the row is returned and ParquetPrunedRowGroups is 0. Verified as a real regression test: with the guard disabled the same query returns 0 rows and ParquetPrunedRowGroups is 1.

Merged master (b2f01e1616fe, clean, single merge base); the net diff against master still matches the pull request's file list exactly.

Previous CI reds — both look like infrastructure, and are re-run by this push:

  • Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6): Unknown error (exit status: None) with the job labelled ram-pressure, no failing test in the report (839 passed, 1 job-level error).
  • Finish Workflow / new_tests_check.py: all four per-arch Bugfix validation jobs were DROPPED/SKIPPED, so none of them could validate the fix.

Rebuilt (ninja clickhouse, no errors) and re-ran the pull request's tests against a local server: 03365, 04277, 04305, 04545 (parquet min/max stats), 04828, 04892, 04893, 04903, 04926, 05024, 05025, 05026, 05044, 05048 and the new 05054 all pass.

@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (2026-09-03): head is now ae90572b41b0.

AI Review is ✅ Approve on e9c33e28, and there are no unresolved review threads.

Real CI red — fixed by merging master. 03707_autopr_unsupported_cases failed in Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, parallel, 1/3). It is unrelated to this pull request: it was fleet-wide on 2026-08-31 (102 failures across 89 pull requests, including master itself) and is fixed by #117364 ("Force the analyzer in 03707_autopr_unsupported_cases", merged as 054e61604430 on 2026-08-31 16:25 UTC), which landed about two hours after this branch's previous head was pushed. Merged origin/master (181ba1437c3a, clean, single merge base) to pull the fix in; the net diff against master still matches the pull request's file list exactly.

Test renumbering. master has since added tests up to 05058, so the regression test added here was renamed 05054_parquet_timestamp_to_time64_no_stats_pruning -> 05059_parquet_timestamp_to_time64_no_stats_pruning (including its log_comment and file names).

Unrelated infrastructure red. Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6): Container memory budget exceeded (/docker). This is fleet-wide (576 occurrences over 261 pull requests on 2026-08-31 alone, still 34 on 2026-09-03) and already has fixes in flight — #117564 and #115785 — so nothing to do here.

Rebuilt (ninja clickhouse, exit 0) and re-ran the pull request's tests against a local server: 03365, 04277, 04305, 04545 (parquet min/max stats), 04828, 04892, 04893, 04903, 04926, 05024, 05025, 05026, 05044, 05048 and 05059 — 15/15 pass.

…quet `TIME`

`05059_parquet_timestamp_to_time64_no_stats_pruning` only pins the negative half
of the new stats contract (parquet `TIMESTAMP` read with a `Time64` hint must not
be pruned by min/max statistics, because the `DateTime64 -> Time64` cast wraps by
day). The other half — a real parquet `TIME` column read as `Time64` still uses
its statistics for row group pruning after the decoded type changed from
`DateTime64` to `Time64` — had no focused test, so leaving `allow_stats` off for
`TIME` would keep the suite green.

The new `05141_parquet_time_stats_pruning` writes a four row group parquet file
per time-of-day physical layout (`TIME_MICROS` on INT64 and `TIME_MILLIS` on
INT32; the ClickHouse writer cannot write `Time64`, so the files come from
pyarrow) and asserts both the returned values and
`ParquetReadRowGroups`/`ParquetPrunedRowGroups` for a range predicate, an
equality predicate and a predicate matching nothing.

Verified as a real regression test: with `decoded_is_time_of_day` forced to false
in `SchemaConverter`, every case reads all four row groups and prunes none.
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (2026-09-08): head is now fdad70eb40f3.

AI Review request (positive pruning regression) — implemented. The verdict on ae90572b was "needs one more focused regression": 05059_parquet_timestamp_to_time64_no_stats_pruning pinned only that parquet TIMESTAMP read with a Time64 hint must not be pruned by min/max statistics, and nothing pinned that a real parquet TIME column read as Time64 still does prune. Added 05141_parquet_time_stats_pruning — a shell test, because the ClickHouse parquet writer cannot write Time64, so the files come from pyarrow as in 04277_parquet_time_of_day. It covers both time-of-day physical layouts (TIME_MICROS on INT64 and TIME_MILLIS on INT32), 4 row groups of 100 rows each, and asserts the values plus ParquetReadRowGroups / ParquetPrunedRowGroups for a range predicate (2 read / 2 pruned), an equality predicate (1 read / 3 pruned) and a predicate matching nothing (4 pruned). Negative control: with decoded_is_time_of_day forced to false in SchemaConverter, all six cases read all 4 row groups and prune none, so the test fails.

Real CI red — fixed by merging master. Stress test (arm_tsan): Logical error: 'Cannot add ZooKeeper operation because query is executed. It's a bug.' (STID 4181-5776). It is unrelated to this pull request and fleet-wide (22 occurrences across 22 pull requests between 2026-09-02 and 2026-09-05), tracked in #117900 and fixed by #117902 ("Fix logical error on TRUNCATE of a TimeSeries table in a Replicated database", merged as bcaec2e0581b on 2026-09-05), which landed after this branch's previous head. Merged origin/master (266945034e24, clean, single merge base) to pull the fix in; the net diff against master still matches the pull request's file list exactly.

Unrelated infrastructure red. Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6): Container memory budget exceeded (/docker) — fleet-wide, with fixes in flight (#117564, #115785), so nothing to do here.

Rebuilt (ninja clickhouse, exit 0) and re-ran the pull request's tests against a local server: 03365, 04277, 04305, 04545, 04828, 04892, 04893, 04903, 04926, 05024, 05025, 05026, 05044, 05048, 05059 and the new 05141 — 16/16 pass.

Comment thread src/Interpreters/convertFieldToType.cpp Resolved
alexey-milovidov and others added 2 commits September 17, 2026 02:01
…-type

# Conflicts:
#	src/Functions/FunctionsConversion_reg.cpp
…e reductions

The `Decimal64 -> Time64` and `Decimal64 -> DateTime64` branches of `convertFieldToType`
rescaled a set element by integer division regardless of `strict`, so
`toTime64('00:00:00', 0) IN (CAST('00:00:00.5', 'Time64(1)'))` truncated the right-hand
side to `00:00:00` and returned 1, contrary to the Decimal -> Decimal exactness contract
documented in `convertFieldToType.h`.

Both branches now share `rescaleDecimal64Field`, which under `strict` returns Null for a
value whose sub-tick digits do not survive the scale reduction. The `Time64 -> DateTime64`
branch no longer needs its own `accurateEquals` round-trip gate because the shared helper
already rejects the lossy case. Non-strict conversions (`CAST`, `INSERT`) still truncate.

Regression test `05223_time64_strict_in_scale_reduction` covers inexact and exact
scale-reducing, widening and equal-scale `Time64` set elements, the `DateTime64` sibling,
non-strict `CAST`, and a `MergeTree` key condition over a `Time64(0)` key.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 Status update (2026-09-17): head is now 3e55470de258.

AI Review blocker (strict IN for scale-reducing Time64 -> Time64) — fixed. The pre-existing Decimal64 -> Time64 and Decimal64 -> DateTime64 rescaling branches in convertFieldToType integer-divided the set element regardless of strict, so toTime64('00:00:00', 0) IN (CAST('00:00:00.5', 'Time64(1)')) returned 1. Both branches now share rescaleDecimal64Field, which under strict rejects (Null) a value whose sub-tick digits do not survive the scale reduction, per the Decimal -> Decimal exactness contract in convertFieldToType.h. The Time64 -> DateTime64 branch dropped its own accurateEquals gate, since the shared helper covers it. Non-strict CAST / INSERT still truncate. New regression test 05223_time64_strict_in_scale_reduction.

Merged master (2dc4e6c620c3, single merge base). One conflict, in the embedded toDateTime / toDateTime32 documentation of FunctionsConversion_reg.cpp: master migrated :::note admonitions to <Note> and made (U)Int128 / (U)Int256 saturating (#117682), while this branch documents Time / Time64 support. Resolved by keeping both: <Note> markup and the saturating wide-integer list from master, plus the Time / Time64 sentences from this branch. The net diff against master is exactly the pull request's files plus the new test.

Rebuilt (ninja clickhouse, exit 0) and re-ran the pull request's server-less tests against the fresh binary: 03365, 04277, 04305, 04828, 04892, 04893, 04903, 04926, 05024, 05025, 05026, 05044, 05048, 05141 and the new 05223 — 15/15 match their references.

Thus, parsing of short numbers' string representations (up to 4 digits) is explicitly disabled due to ambiguity, e.g. a string `'1999'` may be both a year (an incomplete string representation of Date / DateTime) or a unix timestamp. Longer numeric strings are allowed.
</Note>

If `expr` is a [Time](/reference/data-types/time) or [Time64](/reference/data-types/time64) value, it is interpreted as the number of seconds since the beginning of the Unix Epoch: the fractional part of a `Time64` is floored towards negative infinity, and values outside of the `DateTime` range follow the `date_time_overflow_behavior` setting.

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.

The structured conversion docs are still missing the sibling Date surfaces changed by this PR. Time / Time64 now have user-visible behavior in toDate, DATE, and toDate32 as well (src/Functions/FunctionsConversion.h:2378-2405, plus 03365_time_time64_conversions.sql and 05026_time64_values_date_overflow_behavior.sql), but the registrations at src/Functions/FunctionsConversion_reg.cpp:1053-1157 still list only string/date-time/numeric inputs and do not describe the epoch-based interpretation or the toDate overflow behavior.

That leaves the generated docs telling users these inputs are unsupported or behave differently than the implementation. Please update those source registrations in the same PR.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 19, 2026
Merged via the queue into ClickHouse:master with commit 2307fa0 Sep 19, 2026
176 of 178 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 19, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@tiandiwonder @alexey-milovidov — this PR looks backward incompatible but is categorized as Bug Fix (user-visible misbehavior in an official stable release).

Why: Two released, non-experimental behaviors change silently. FunctionsConversion.h:2383/2389/2395/2403 re-route toDate/toDate32 of Time/Time64 from the constant-zero branch to ToDateImpl/ToDate32Impl - the PR's own 03365_time_time64_conversions.reference diff turns twelve 1970-01-01 lines into 1970-01-01/1970-01-02/1970-02-11. enable_time_time64_type is tier Production with default 1. Separately rescaleDecimal64Field (convertFieldToType.cpp:255) adds a strict rejection that applies to DateTime64 -> DateTime64 too, changing IN set membership for a type the PR title does not mention.

Suggested category: Backward Incompatible Change. Ignore if the change is intentionally non-breaking.

otselnik pushed a commit to otselnik/ClickHouse that referenced this pull request Oct 2, 2026
`convertFieldToType` had no branch for narrowing a `DateTime64` constant to
`DateTime`, so the round trip in `LogicalExpressionOptimizerPass` threw
`TYPE_MISMATCH` on every query that compared a `DateTime64` column with a
`DateTime` constant inside `AND`, and `system.errors` counted it. The branch
joins the `Time64` one from ClickHouse#106019: whole seconds as `CAST` produces them, a
strict conversion rejecting a fraction or a value out of range. The source
type hint is unwrapped once on entry, a `Variant` hint standing for the one
alternative that matches the field, and it now reaches the elements of `Array`,
`Tuple` and `Map` values.

A constant that becomes an exact bound or key is converted with
`tryConvertFieldToTypeExact`, which also has to convert back, because `strict`
still truncates a `DateTime` to a `Date` and a `DateTime64` to a lower scale:
`k_date IN (toDateTime('1999-02-28 12:00:00'))` was pushed down to MongoDB as
midnight, and a KV key lookup probed the day where `=` compares as `DateTime`.
A KV filter that fails it is left to a full scan; a MongoDB predicate is refused
like any other one MongoDB cannot take. A KV set member converts as `IN`
converts it, strictly but to the key type, so a `DateTime` with a time of day
still probes the day of a `Date` key. The MongoDB `IN` list arrives as an
`Array` value under a `Tuple` type and is converted element by element, every
element, since the list is written with the column's type.

ClickHouse#117903
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-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). pr-autogenerated-docs PR that regenerates docs artifacts from source; exempt from the autogenerated-region edit guard pr-bugfix Pull request with bugfix, not backported by default 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.

7 participants