Repository navigation
Conversation
…64/Time64 numeric casts
|
Workflow [PR], commit [34ea9f2] Summary: ❌
|
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
|
The failures of "Flaky check" in "functions_bad_arguments" will be fixed by #101994. |
|
This was fixed by #105146. Let's update the branch. |
The previous fix only routed `DataTypeUInt64` through `ToTime64TransformUnsigned` and `ToDateTime64TransformUnsigned`, so `DataTypeUInt8`/`UInt16`/`UInt32` fell back to the generic decimal conversion path and bypassed the `date_time_overflow_behavior` check. This meant cases like `CAST(3600000::UInt32, 'Time64') SETTINGS date_time_overflow_behavior='throw'` silently saturated instead of raising `VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE`. Extend the dispatch to include all narrower unsigned integer sources and template the transforms on `FromDataType::FieldType`. Guard the overflow check with a `constexpr` predicate so widths whose entire range fits inside the target bounds (UInt8/UInt16 to Time64, UInt8/UInt16/UInt32 to DateTime64) skip it entirely. Addresses a review comment on #101512
…_overflow_behavior-ignored
Extend the explicit ConvertImpl branches for `DateTime64`/`Time64` to cover `Int128`/`Int256` and `UInt128`/`UInt256` source types, so that `date_time_overflow_behavior` is honored when casting wide integers through `CAST`. Previously these sources fell through to the generic decimal path and silently ignored the setting. The transforms now compare and clamp in the source type's domain so values above `INT64_MAX` are not truncated before the bounds check. The constexpr skip is reformulated in terms of `sizeof(FromType)` so it correctly identifies wide ints as requiring a bounds check. Includes `base/wide_integer_to_string.h` to make the `fmt::formatter` specialization for `wide::integer` visible to the `Exception` message.
Without this, casts from `Int128`/`Int256`/`UInt128`/`UInt256` to `DateTime64`/`Time64` were rejected at the wrapper-construction stage with `CANNOT_CONVERT_TYPE` (code 70), so the routing into the overflow-aware `ToDateTime64Transform*` / `ToTime64Transform*` paths added in `bce5fc0` was never reached. The `serverError VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE` assertions in `04050_time64_cast_uint64_no_wrap.sql` therefore observed the wrong error code in Fast test. Allow the wide unsigned/signed integer source families through the `DataTypeDateTime64`/`DataTypeTime64` wrapper so `date_time_overflow_behavior` applies uniformly, matching the dispatch in `ConvertImpl`.
…_overflow_behavior-ignored
…_overflow_behavior-ignored
…_overflow_behavior-ignored
The float conversion paths `ToDateTime64TransformFloat` and `ToTime64TransformFloat` compared the source value against whole-second bounds (`MAX_DATETIME64_TIMESTAMP` / `MAX_TIME_TIMESTAMP`). However, `DateTime64` and `Time64` can represent fractional seconds within the boundary second, so valid values such as `10413791999.1` (a valid `DateTime64(1)` = `2299-12-31 23:59:59.1`) and `3599999.1` (a valid `Time64(1)` = `999:59:59.1`) were incorrectly rejected with `VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE` under `date_time_overflow_behavior = 'throw'`, and clamped down to the whole second under the other modes. Extend the bounds by the largest fraction representable at the target scale (`MAX + (1 - 10^-scale)`) so boundary-second fractions are accepted, and out-of-range values saturate to the maximum representable value rather than to the truncated whole second. This addresses the review feedback at `src/Functions/FunctionsConversion.h:605` and `:742`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`ToDateTime64TransformFloat`/`Signed`/`Unsigned` computed overflow bounds from the calendar maximum second (`MAX_DATETIME64_TIMESTAMP`), but at scale 9 that second does not fit in the `Int64` native storage once multiplied by the scale (`10413791999 * 1e9 > Int64::max`). As a result a value that passed the bound check could still raise `DECIMAL_OVERFLOW` inside the conversion even with `date_time_overflow_behavior = 'saturate'`, where it should clamp instead. Derive the bounds from the maximum representable native value, capped at `Int64::max`, so scale 9 saturates to the largest representable value. The float path now also produces saturated values directly in the native domain to avoid `Float64` rounding losing the last representable fraction (e.g. `CAST(1e20 AS DateTime64(6))` now yields `...59.999999` instead of the imprecise `...59.999998`). Also initialize `clamped` in the signed transforms (fixes `cppcoreguidelines-init-variables` in the `arm_tidy` build) and apply the same native-domain saturation to `ToTime64TransformFloat` for consistency. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…_overflow_behavior-ignored
`03011_definitive_guide_to_cast`: `CAST(1e20 AS DateTime64(6))` now saturates to the exact maximum fraction (`...59.999999`) instead of the float-imprecise `...59.999998`, and `CAST(1e20 AS DateTime64(9))` now saturates to the maximum representable value instead of raising `DECIMAL_OVERFLOW` (the comment is updated accordingly). `04050_time64_cast_uint64_no_wrap`: add `throw`/`saturate` coverage for `DateTime64(9)` with `Float64`, `UInt64` and `Int64` sources, proving `throw` raises `VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE` (not `DECIMAL_OVERFLOW`) and `saturate` clamps to the maximum representable value. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Picked up the branch: merged latest
I updated the Built on ARM and verified locally: I did not approve, since this is not my own PR. |
…_overflow_behavior-ignored # Conflicts: # src/Core/FormatFactorySettings.h # src/Functions/FunctionsConversion.cpp # src/Functions/FunctionsConversion_reg.cpp
…r clang-tidy `Build (arm_tidy)` failed with `cppcoreguidelines-init-variables` on the bounds and the `representable` flag. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101512&sha=181a71736ed35820b4d041a18182ae0c80c28097&name_0=PR PR: #101512 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 Merged
This is still @yariks5s' draft, so I'm leaving the review and merge to a human. |
…havior` Integer and floating-point conversions into `Date`, `Date32` and `DateTime` still always clamp and do not consult the setting, so do not claim that the setting applies to them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`master` merged #117667, which honours `date_time_overflow_behavior` for every numeric conversion to the date and time types, including the integer and floating-point casts to `DateTime64` / `Time64` this PR fixes, and also restores the `accurateCast*` contract. All conflicts in `FunctionsConversion.h`, `FunctionsConversion.cpp`, `FunctionsConversion_reg.cpp`, `FormatFactorySettings.h` and the conflicting tests are therefore resolved to `master`'s version. The PR's tests that still pass on `master` (`04050`, `05055`, `05218`) are kept; the comments the PR changed in `01734` and `03011` are reverted to `master`'s, because they describe a whole-second clamp that `master` no longer does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`master` already honours `date_time_overflow_behavior` for these conversions, but it still computed the tick count of a `Float32` source in `Float32`. Its 24-bit mantissa rounds the product with the scale multiplier: `toDateTime64(toFloat32(1665519700), 3)` came out 30 seconds early, and `CAST(9223371776::Float32, 'DateTime64(9)')` - in range, since it is exactly `9223371776` seconds - rounded to 2^63 ticks and was clamped to the last tick, or rejected in the `throw` mode and by `accurateCast` / `accurateCastOrNull`. The transforms and the window check of the accurate casts now compute in `Float64` for every floating-point source; `BFloat16` and `Float32` values are exact there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
date_time_overflow_behavior being ignored for integer and float casts to DateTime64/Time64Float32 sources of DateTime64 / Time64 in Float64 precision
…ime64` in `05218` `accurateCast` rejects an out-of-range number with `CANNOT_CONVERT_TYPE`, the same code it uses for every other target type, so the test expecting `VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE` failed in the Fast test: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101512&sha=latest&name_0=PR&name_1=Fast%20test #101512 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged
|
Both tests describe behaviour that `master` already has, so they pass on `master` and make `Bugfix validation (functional tests)` fail: that check requires every test added by a bug-fix PR to fail on `master`. They are proposed in a separate test-only PR instead. The regression test of this PR, `05406_float32_to_datetime64_precision`, still reproduces the bug. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101512&sha=latest&name_0=PR&name_1=Bugfix%20validation%20(functional%20tests%2C%20amd64) #101512 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Fixed the only CI red, |
…boundaries The tests were written in ClickHouse#101512 and moved out of it because they describe behaviour that `master` already has: - `05055_datetime64_numeric_min_native_boundary`: the lower `Int64` tick boundary of `DateTime64(9)` under every `date_time_overflow_behavior` mode; - `05218_accurate_cast_numeric_to_datetime64_time64`: `accurateCast`, `accurateCastOrNull` and `accurateCastOrDefault` to `DateTime64` / `Time64` decide on representability alone, regardless of the setting. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged |
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=101512&sha=d284f2d26324b321cb4f6b543861eac495fef590&name_0=PR&name_1=Build%20profile%20diff ( |
|
The The fix in progress is my open PR #126200: a readiness probe that the server rejects for its own load (exception code 202 or 241) ends the job green with |
|
🕵 Merged @groeneai, thanks for the analysis. The only red on |
|
🕵 Merged |
# Conflicts: # src/Functions/FunctionsConversion.h
|
🕵 Merged |
|
🕵 The only red on @yariks5s, the PR has been a draft since 2026-04-01. If you consider it finished, please mark it ready for review - that starts the full CI (alternatively, the |
The original goal of this PR - making integer and
Float32/Float64casts toDateTime64andTime64honourdate_time_overflow_behavior- was implemented onmasterby #117667. After mergingmaster, this PR keeps only what is still missing there: aFloat32source is now scaled to ticks inFloat64instead ofFloat32.The 24-bit mantissa of a
Float32rounds the product with the scale multiplier, so:toDateTime64(toFloat32(1665519700), 3)returned2022-10-11 20:21:54.304instead of20:22:24.000(the value is exact inFloat32);CAST(9223371776::Float32, 'DateTime64(9)')is in range (exactly9223371776seconds), but its product rounded to 2^63 ticks. In theignore/saturatemodes it was clamped to the last tick. In thethrowmode it was rejected, andaccurateCast/accurateCastOrNullrejected it too.The transforms and the window check of the accurate casts now compute in
Float64for every floating-point source.BFloat16andFloat32values are exactly representable inFloat64. The PR also keeps its extra coverage of the overflow modes in04050. The coverage tests that pass on currentmaster(05055,05218) moved to #127309.Related: #117667
Related: #127309
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Conversions of
Float32values toDateTime64andTime64are now computed inFloat64precision. Previously the result could be off by tens of seconds, and an in-range value near the upper end ofDateTime64(9)was treated as out of range.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/101512]