Repository navigation
Fix function property stress test scale-blind validity gate and changeDate result scale - #108551
Conversation
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-6:20260625-200200 |
|
cc @rschu1ze @alexey-milovidov — could you review this? It fixes the |
|
Workflow [PR], commit [977cf70] Summary: ✅
AI ReviewSummaryThis PR retargets the issue from array consumers to the property fuzzer validity gate, adds strict scale checking for the fuzzer, and fixes the real PR Metadata💡 💡 Suggested replacement: Final VerdictStatus: Minimum required action: update the |
0580435 to
3cd6d88
Compare
|
Fixed in 3cd6d88. The array argument's element column is now aligned to Added a regression case where the array argument's physical element scale (7) diverges from its declared |
|
@groeneai, use functional tests instead of unit tests. Remember that functional tests are always preferred, and unit tests should be added only when no other ways possible. Also, what was the case? DateTime64(N) or Decimal should always have the same scale N in the column. |
|
@alexey-milovidov You're right: a column declared The divergent column appears only inside the property fuzzer ( So the real source is the scale-blind This is the "no other way" case for the unit test, because SQL cannot build the input. If you prefer the source fix, I will retarget this PR to make |
|
@groeneai, this means that having a LOGICAL_ERROR check in the code is correct (it is about something that can't happen), but the Function Stress Test is wrong. Can we fix the Function Stress Test? |
|
@alexey-milovidov Yes. The stress test's validity gate Plan:
The strict gate also doubles as a real-producer check: if any function genuinely returns a scale-divergent Decimal result, the gate now reports it at the source. I'll run full CI to confirm none does today. |
…eDate result scale The function property stress test (gtest_functions_stress) validates every (column, type) pair it holds with columnMatchesType. For Decimal/DateTime64/Time64 that check compared only getDataType() (the physical TypeIndex, Decimal64 for any scale), so a column whose physical scale diverges from its declared type passed the gate, was stashed, and was reused as a later argument, surfacing as a misattributed writeSlice LOGICAL_ERROR in an innocent consumer such as arrayPush (issue ClickHouse#108517). The LOGICAL_ERROR is correct (it asserts a state that cannot arise from SQL); the stress test's gate was wrong. Make columnMatchesType scale-aware via an opt-in strict_decimal_scale argument (default keeps the prior behavior, so the engine callers in resolveFunction, ColumnFunction::reduce, ExpressionActions, and ActionsDAG are unchanged). The stress test passes true, rejecting a scale-divergent column at the producing function's own gate. This immediately caught a real producer: changeYear/changeMonth/changeDay/changeHour/ changeMinute/changeSecond over DateTime64(N) created the result column with the hardcoded default scale (3) instead of N, because an `if constexpr (std::is_same_v<InputDataType, DateTime64>)` compared a DataType class against a value-type alias and was always false. The data was computed at scale N but the column object declared scale 3, a latent structural inconsistency invisible in normal SQL output. Read the scale from result_type, which is correct for both the DateTime64 and Date32 result paths. Closes: ClickHouse#108517 Co-Authored-By: Claude Opus 4.8 <[email protected]>
3cd6d88 to
d3202d6
Compare
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-0:20260628-230800 |
|
cc @rschu1ze @Algunenano - could you review this? It makes the function property stress test's validity gate ( |
…ray push The change* producer fix needs direct coverage. changeYear/changeMonth/changeDay/ changeHour/changeMinute/changeSecond over DateTime64(N != 3) used to build the result column at the hardcoded default scale 3 while the data was computed at scale N. Feeding such a result into a structure-sensitive consumer (arrayPushBack/arrayPushFront/arrayConcat over Array(DateTime64(N))) skips the cast on declared-type equality and reaches the generic writeSlice, whose ColumnDecimal::structureEquals throws the writeSlice LOGICAL_ERROR (issue ClickHouse#108517). The new gtest_validate_column_type only proves the strict gate rejects a synthetic mismatched column; it does not execute the change* functions, so this test covers the real producer directly. Verified: fails with the writeSlice LOGICAL_ERROR on the pre-fix binary, passes with the fix. Co-Authored-By: Claude Opus 4.8 <[email protected]>
timeSlots(DateTime64(N), Decimal64(M), ...) declares its return type as Array(DateTime64(max(N, M))) in getReturnTypeImpl, but executeImpl built the values column at start_time_scale (N) only. When the duration scale M exceeds N, the result column object carried scale N while its declared type was DateTime64(M), a structural inconsistency that is invisible in normal SQL output (formatting uses the declared type scale) but is rejected by structure-sensitive consumers: feeding it into arrayPushBack / arrayPushFront / arrayConcat over Array(DateTime64(M)) skips the cast on declared-type equality and reaches the generic writeSlice, whose ColumnDecimal::structureEquals throws a LOGICAL_ERROR. This is the same producer bug class as the changeDate fix in this PR, surfaced by the scale-strict columnMatchesType gate (the function property stress test flagged timeSlots(DateTime64(1), Decimal(18, 5)) returning a column whose scale diverged from its declared Array(DateTime64(5))). Read the result element scale from result_type so the column always matches its declared type, the same way changeDate now does. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed
Fix is the same as Verified on a debug build: pre-fix, An audit of the other |
getReturnTypeImpl declared the result scale as max(start_time_scale, duration_scale), ignoring the optional Size (3rd) argument. The execution helpers rescale all values to max(start, duration, size), so when the Size scale is the largest the values are computed at the higher scale while the column declares the lower one. SQL then reads the values at the wrong scale and returns incorrect timestamps, and a structure-sensitive consumer (arrayConcat/arrayPushBack over Array(DateTime64)) reaches the generic writeSlice on the scale mismatch. Include the Size scale in the declared return scale, matching the function's documented contract of taking the highest scale among all arguments. Co-Authored-By: Claude Opus 4.8 <[email protected]>
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 82/101 (81.19%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code |
CI finish ledger — 977cf70CI fully finished on this head with no failures. The prior
Session id: cron:our-pr-ci-monitor:20260629-080000 |
|
Function |
|
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment. TL;DRFix function property stress test scale-blind validity gate and changeDate result scale ClickGap verified: reproduced it with the script below on ReproductionBisect
Affects
Suggested next stepThe fix has landed on master; the affected release branches above still need the backport. Component: cc fix PR author: @groeneai ClickGap · Finding: Triage metadata
|
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]>
Bring the branch up to date with master to refresh CI. Master now includes the revert of ClickHouse#108551 (via ClickHouse#108981), which removed the scale-aware validity gate in the function property stress test that was surfacing a pre-existing reinterpret scale mismatch (Const(Decimal256) vs Decimal(76, 58)) and failing Unit tests (asan_ubsan, function_prop_fuzzer) on every PR. Master has not touched parseTimeDelta.cpp, formatReadableTimeDelta.cpp, or the two stateless tests, so the net change over master remains exactly the four files of this PR. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
changeYear/Month/Day/Hour/Minute/Second over DateTime64(N) built the result column at the hardcoded default scale 3 instead of N, because the `is_same_v<InputDataType, DateTime64>` guard was always false (InputDataType is a DataType class, DateTime64 a value-type alias). Read the scale from result_type instead. timeSlots over DateTime64 declared Array(DateTime64(max(start, duration))) and built the values column at start scale, ignoring the optional Size argument scale that the value rescaling uses (max(start, duration, size)). Include the Size scale in the declared return type and build the column at the declared scale. Both produced a column whose physical scale diverged from its declared type; feeding it into a structure-sensitive consumer (arrayPush/arrayConcat over Array(DateTime64(N))) skipped the cast on declared-type equality and reached the generic writeSlice, whose ColumnDecimal::structureEquals raised a LOGICAL_ERROR. These are the two producer fixes from ClickHouse#108551 (reverted by ClickHouse#108981 for an unrelated reason: its strict columnMatchesType stress-test gate reddened FunctionsStress.stress). This change re-lands only the producer fixes without the gate. Related: ClickHouse#108517 Related: ClickHouse#108981
…test The FunctionsStress property test (gtest_functions_stress.cpp) validates every function result with columnMatchesType before stashing it in additional_random_values for reuse as a later function's argument. That check compared only getDataType(), which for Decimal/DateTime64/Time64 reports the physical TypeIndex (Decimal64 for every scale). A function whose result column carried a scale different from its declared type therefore passed, got stashed, and was reused as an argument to an innocent consumer such as arrayPushBack, surfacing as a misattributed 'writeSlice expects same column types' LOGICAL_ERROR (issue #108517). Re-add the scale-aware detection to columnMatchesType behind an opt-in strict_decimal_scale argument (default off, so the engine callers in resolveFunction, ColumnFunction, ExpressionActions, ActionsDAG are unchanged), and use it in the stress test to detect a scale-divergent result. Such a result is attributed to the producing function via a new soft, default-ignored problem (scale_divergent_result) and is never stashed. Skipping the stash is the complete cut of the propagation path: generated random arguments are always scale-consistent (built via type->createColumn()), so the stash was the only way a divergent column could enter as an argument. Unlike the reverted #108551, the strict check is not a hard throw inside the test, so it cannot redden the whole run when a new scale-divergent producer appears; it just reports and skips it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…7-writeslice-datetime64-array-push Fix function property stress test scale-blind validity gate and changeDate result scale
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]>
Bring the branch up to date with master to refresh CI. Master now includes the revert of ClickHouse#108551 (via ClickHouse#108981), which removed the scale-aware validity gate in the function property stress test that was surfacing a pre-existing reinterpret scale mismatch (Const(Decimal256) vs Decimal(76, 58)) and failing Unit tests (asan_ubsan, function_prop_fuzzer) on every PR. Master has not touched parseTimeDelta.cpp, formatReadableTimeDelta.cpp, or the two stateless tests, so the net change over master remains exactly the four files of this PR. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
changeYear/Month/Day/Hour/Minute/Second over DateTime64(N) built the result column at the hardcoded default scale 3 instead of N, because the `is_same_v<InputDataType, DateTime64>` guard was always false (InputDataType is a DataType class, DateTime64 a value-type alias). Read the scale from result_type instead. timeSlots over DateTime64 declared Array(DateTime64(max(start, duration))) and built the values column at start scale, ignoring the optional Size argument scale that the value rescaling uses (max(start, duration, size)). Include the Size scale in the declared return type and build the column at the declared scale. Both produced a column whose physical scale diverged from its declared type; feeding it into a structure-sensitive consumer (arrayPush/arrayConcat over Array(DateTime64(N))) skipped the cast on declared-type equality and reached the generic writeSlice, whose ColumnDecimal::structureEquals raised a LOGICAL_ERROR. These are the two producer fixes from ClickHouse#108551 (reverted by ClickHouse#108981 for an unrelated reason: its strict columnMatchesType stress-test gate reddened FunctionsStress.stress). This change re-lands only the producer fixes without the gate. Related: ClickHouse#108517 Related: ClickHouse#108981
…test The FunctionsStress property test (gtest_functions_stress.cpp) validates every function result with columnMatchesType before stashing it in additional_random_values for reuse as a later function's argument. That check compared only getDataType(), which for Decimal/DateTime64/Time64 reports the physical TypeIndex (Decimal64 for every scale). A function whose result column carried a scale different from its declared type therefore passed, got stashed, and was reused as an argument to an innocent consumer such as arrayPushBack, surfacing as a misattributed 'writeSlice expects same column types' LOGICAL_ERROR (issue ClickHouse#108517). Re-add the scale-aware detection to columnMatchesType behind an opt-in strict_decimal_scale argument (default off, so the engine callers in resolveFunction, ColumnFunction, ExpressionActions, ActionsDAG are unchanged), and use it in the stress test to detect a scale-divergent result. Such a result is attributed to the producing function via a new soft, default-ignored problem (scale_divergent_result) and is never stashed. Skipping the stash is the complete cut of the propagation path: generated random arguments are always scale-consistent (built via type->createColumn()), so the stash was the only way a divergent column could enter as an argument. Unlike the reverted ClickHouse#108551, the strict check is not a hard throw inside the test, so it cannot redden the whole run when a new scale-divergent producer appears; it just reports and skips it. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
changeYear/changeMonth/changeDay/changeHour/changeMinute/changeSecondover aDateTime64(N)argument creating the result column with the hardcoded default scale (3) instead ofN. The values were computed at scaleNbut the column object declared scale 3, leaving it structurally inconsistent with its type.Description
Closes #108517.
Retargeted after review (#108551 (comment)): the
writeSliceLOGICAL_ERRORis correct (it asserts a state that cannot arise from SQL), and the Function Stress Test's validity gate was wrong.The function property stress test (
gtest_functions_stress) validates every(column, type)pair it holds withcolumnMatchesType. ForDecimal/DateTime64/Time64that check compared onlygetDataType()(the physicalTypeIndex,Decimal64for every scale), so a column whose physical scale diverged from its declared type passed the gate, was stashed inadditional_random_values, and was reused as a later argument, surfacing as a misattributedwriteSliceLOGICAL_ERRORin an innocent consumer such asarrayPush.columnMatchesTypegains an opt-instrict_decimal_scaleargument. The default keeps the prior behavior, so the engine callers (resolveFunction,ColumnFunction::reduce,ExpressionActions,ActionsDAG) are unchanged; the stress test passestrue, rejecting a scale-divergent column at the producing function's own gate.That strict gate immediately caught a real producer: the
change*date/time functions overDateTime64(N)created the result column with the hardcodeddefault_scale(3) instead ofN, becauseif constexpr (std::is_same_v<InputDataType, DateTime64>)compared aDataTypeclass against a value-type alias and was always false. The data was computed at scaleN(so normal SQL output looked correct, since formatting uses the type's scale), but the column object declared scale 3. The scale is now read fromresult_type, which is correct for both theDateTime64andDate32result paths.The original SQL repro cannot construct the divergent column (the analyzer unifies operands to the least supertype before execution), so the regression coverage is a focused unit test of the gate itself (
gtest_validate_column_type): withstrict_decimal_scalea scale-7 column labelledDateTime64(3)is rejected, both at top level and nested insideArray(DateTime64(3)); without it (the engine default) it is accepted. Thechange*fix is verified by the stress test now passing with the strict gate enabled.Version info
26.7.1.272(included in26.7and later)