Repository navigation
Fix reinterpret to Decimal/DateTime64 with a different scale - #108878
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-5:20260630-011500 |
|
cc @rschu1ze @Algunenano — could you review this? |
|
Workflow [PR], commit [aa27ce7] Summary: ✅
AI ReviewSummaryThis PR fixes Final VerdictStatus: ✅ Approve |
reinterpret dispatches on the physical TypeIndex, so reinterpret to a same-physical-type target with a different scale (e.g. reinterpret(Decimal(38, 33), 'Decimal128(2)')) hit the std::is_same_v<FromType, ToType> branch and returned the source column verbatim. The returned ColumnDecimal kept the source scale while the declared result_type had the target scale, leaving the column structurally inconsistent with its type. Rebuild the column with the target scale (raw values preserved) when the scales differ; keep the verbatim return when they match. Covers Decimal32/64/128/256, DateTime64 and Time64. Found by the function property fuzzer after ClickHouse#108551 added the strict scale gate to columnMatchesType. Co-Authored-By: Claude Opus 4.8 <[email protected]>
85c5e19 to
3f1842d
Compare
CI finish ledger — 3f1842dEvery failure below has an owner: a fixing PR (ours or external). Only
Note: the earlier Session id: cron:our-pr-ci-monitor:20260630-073000 |
CI finish ledger - 3f1842dEvery failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
The reinterpret-to-Decimal/DateTime64 scale fix cannot cause a TSan shutdown deadlock; the earlier PR-caused arm_tidy lint and the function_prop_fuzzer Time64 finding are both resolved on this head. Both stress failures are the chronic hung-check family across unrelated PRs and master. Session id: cron:our-pr-ci-monitor:20260630-083000 |
|
@groeneai |
DateTime64 and Time64 both satisfy IsDataTypeDecimal, so the scale-rebuild branch at reinterpretAs.cpp:163 is instantiated for both. DateTime64 is a reachable reinterpret target (canBeReinterpretedAsNumeric accepts it), so add a positive test: DateTime64(9) -> DateTime64(2) relabels the scale and preserves the raw value. Time64 is not in the gate, so reinterpret rejects it in getReturnTypeImpl before the branch is reached; add a negative test asserting it throws ILLEGAL_TYPE_OF_ARGUMENT. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Added both in 7f1fcfc (
All 6 tests in the suite pass with the fix. |
CI finish ledger — 7f1fcfcEvery failure below has an owner: a fixing PR (ours or external), or the private sync check. No PR-caused failures.
This PR (reinterpret to Decimal/DateTime64 with a different scale) is a Functions/reinterpretAs change plus a unit + DateTime64/Time64 test; it cannot cause a distributed connection-pool desync or a TSan stress-shutdown deadlock. The 04204 failure is the well-tracked Code-102 distributed-desync family converging on external fix #108854. Session id: cron:our-pr-ci-monitor:20260630-203000 |
|
@groeneai, fix |
|
@alexey-milovidov Resolved on master:
So there is no separate code bug to fix here, and a test-side patch would only mask the engine bug for 04204 while the other victims stay exposed. If you are seeing a specific residual failure on a branch that already includes #108854, point me at it and I will open a separate PR. |
…/fix-reinterpret-decimal-scale
|
Merged current master (675d38f) so this branch now contains #108854 (the connection-pool desync fix, merged 07-01 13:22Z). The prior CI ran on a base 1026 commits behind that merge, which is why |
Master reverted the strict_decimal_scale parameter of columnMatchesType (commit 9bbbb45, revert of the function-property stress-test scale gate), so the 3-argument call in this test no longer compiles and broke the arm_tidy build after the branch was merged with master. columnMatchesType is now purely structural. Drop the removed strict_decimal_scale argument; the per-test getScale() assertions already verify the declared scale, so the scale-regression coverage is unchanged.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 55/55 (100.00%) · Uncovered code |
CI finish ledger - aa27ce7CI fully finished and green. Every stress test passed (no hung-check recurrence this run), and Build (arm_tidy) - the originating failure - is SUCCESS on this head. This head adapts the reinterpret scale test to the scale-blind
No PR-caused failure. Session id: cron:our-pr-ci-monitor:20260702-143000 |
|
For future PRs, let's ask Groene to write SQL-based tests instead of C++ unit tests. Unit tests are much harder to maintain in the long run. |
|
Understood. Going forward I will default to SQL-based stateless tests for regression coverage, and reserve C++ unit tests only for behavior that is not observable from SQL (e.g. internal column-structure invariants like the scale-vs-declared-type check here, which does not surface in query output). Noted as a standing preference. |
…erpret-decimal-scale Fix reinterpret to Decimal/DateTime64 with a different scale
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
reinterpret(x, 'Decimal128(scale)')(andDecimal32/Decimal64/Decimal256/DateTime64targets) producing a result column whose internal scale was the source scale instead of the requested target scale when the source and target had the same physical type. The values were correct but the column object was structurally inconsistent with its declared type.Description
FunctionReinterpret::executeImpldispatches on the physicalTypeIndexof the source and target types. When both sides are the same physical type but have a different scale, for examplereinterpret(Decimal(38, 33), 'Decimal128(2)')(bothDecimal128), thestd::is_same_v<FromType, ToType>branch returned the source column verbatim. That column carries the source scale (33), while the declaredresult_typeisDecimal(38, 2), so the result column's scale diverged from its type.reinterpretis a bit-level relabel of the scale, so the visible SQL output was unaffected, but the column was structurally inconsistent with its type.The same-type branch now rebuilds the column with the target scale (preserving the raw values) when the scales differ, and keeps the verbatim return when they match. This covers the scale-bearing physical types that are reachable as
reinterprettargets and routed through that branch:Decimal32/Decimal64/Decimal128/Decimal256andDateTime64.Found by the function property fuzzer (
gtest_functions_stress) after #108551 added the strict scale gate tocolumnMatchesType;reinterpretwas a second producer of a scale-divergent column. Public reproducer:Regression coverage: a new unit test (
gtest_reinterpret_decimal_scale) runsreinterpretthroughFunctionFactoryand asserts the result column matches its declared type with the strict scale gate, forDecimal128/Decimal64/Decimal256same-width-different-scale and the same-scale passthrough. The test fails without this fix (the result column reports the source scale) and passes with it.