Repository navigation
Parquet: map TIME logical type to Time64 - #106019
Conversation
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]>
|
Workflow [PR], commit [3e55470] Summary: ❌
AI ReviewSummaryThis PR fixes the Parquet Findings💡 Nits
Final Verdict
LLVM Coverage ReportMeasured on commit 3e55470.
Changed lines: Changed C/C++ lines covered: 299/333 (89.79%) · Uncovered code |
@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]>
…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]>
|
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. |
|
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. |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 33/34 (97.06%) · Uncovered code |
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.
Build profile diff (arm_release)Comparing commit 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`.
|
🕵 Status update (2026-08-31): AI Review blocker (parquet min/max stats for Regression test — Merged Previous CI reds — both look like infrastructure, and are re-run by this push:
Rebuilt ( |
Master added `05054`-`05058` tests since the branch was last updated.
|
🕵 Status update (2026-09-03): head is now AI Review is ✅ Approve on Real CI red — fixed by merging Test renumbering. Unrelated infrastructure red. Rebuilt ( |
…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.
|
🕵 Status update (2026-09-08): head is now AI Review request (positive pruning regression) — implemented. The verdict on Real CI red — fixed by merging Unrelated infrastructure red. Rebuilt ( |
…-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]>
|
🕵 Status update (2026-09-17): head is now AI Review blocker (strict Merged Rebuilt ( |
| 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. |
There was a problem hiding this comment.
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.
2307fa0
|
@tiandiwonder @alexey-milovidov — this PR looks backward incompatible but is categorized as Why: Two released, non-experimental behaviors change silently. Suggested category: |
`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
The native Parquet reader currently maps both
logical.TIMESTAMPandlogical.TIME(and the deprecated converted typesTIMESTAMP_MILLIS/TIMESTAMP_MICROS/TIME_MILLIS/TIME_MICROS) toDataTypeDateTime64. 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 isTime64andsession_timezoneis non-UTC, theDateTime64 -> Time64cast (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 parquetTIMEcolumn is read asTime64. The allowlist is deliberately keyed off the decoded semantic type: for parquetTIMESTAMPread with aTime64hint the values are decoded asDateTime64and the cast toTime64wraps by day, so stats are not order-preserving there and pruning stays disabled (test05054_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 -> Timewas never registered as a cast — it threwCANNOT_CONVERT_TYPEbecauseIsDataTypeNumber<DataTypeTime>isfalse(it inheritsDataTypeNumberBase<Int32>, notDataTypeNumber<Int32>). Before this PR the path wentDateTime64 -> Timeand returned a wrong, timezone-shifted value; after the Parquet fix it would have thrown. The second commit adds an inlineTime64 -> Timebranch inConvertImplthat 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_daycovers:time32[ms]/time64[us]/time64[ns]→Nullable(Time64(3/6/9));TIMESTAMPstaysNullable(DateTime64(6, 'UTC'))).Time64(scale)columns undersession_timezone = 'Asia/Shanghai'(values must not shift).Time64(3)/Time/DateTime64(3, 'UTC')/Int64.Review follow-up: making
Time64 -> DateTimelegal also exposed thatToDateTimeMonotonicitytreatedTime64sources as monotonic, while the cast wraps negative time-of-day values with the defaultdate_time_overflow_behavior = 'ignore'(-00:00:01->2106-02-07 06:28:15), i.e. it drops at zero.toDateTimenow reports non-monotonic forTime/Time64sources; the regression test04828_time64_to_datetime_not_monotonicshows that without the guard the key condition prunes every granule and range/point queries over aTime64key silently return empty results. The Parquet docs (docs/reference/formats/Parquet/Parquet.mdx) are updated for the newTIME->Time64mapping.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix Parquet
time32/time64columns being read asDateTime64and then silently shifted bysession_timezonewhen inserted into aTime64target column. ParquetTIMElogical types now map directly toTime64, and a previously-missingTime64 -> Timecast is added.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/106019]