Skip to content

Revert "Fix function property stress test scale-blind validity gate and changeDate result scale" - #108981

Merged
alexey-milovidov merged 1 commit into
masterfrom
revert-108551-groeneai/fix-108517-writeslice-datetime64-array-push
Jun 30, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
revert-108551-groeneai/fix-108517-writeslice-datetime64-array-push

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Jun 30, 2026 •

Copy link
Copy Markdown
Member

Reverts #108551

Wrecked havoc to FunctionsStress.stress. Example:

src/Functions/tests/gtest_functions_stress.cpp:2427
Value of: failure_details.empty()
  Actual: false
Expected: true

unexpected_error:
  executing: SELECT reinterpret(a, CAST('Decimal32(8)' AS LowCardinality(Nullable(String)))) FROM system.one ARRAY JOIN CAST([0,-42771761.9,-69672.7,-5335873.5,1,-1241552.8,-0.1,3798.3,42.1,8639.9,90772593,20288.2,-7918002.5,0.3,267907.9,3250.5,34.8,-488.6,192754254.2,39596700.9,0.5,-0.1,91581.1,-45972.2,-123.3,179753.8,-88234586.5,779.2,-1187725,268.6,-0.2,-2.8] AS Array(Decimal(9, 1))) AS a; Code: 117. DB::Exception: function returned column of unexpected type or scale: Nullable(Decimal32) instead of Nullable(Decimal(9, 8)). (INCORRECT_DATA), Stack trace (when copying this message, always include the lines below):

0. contrib/llvm-project/libcxx/include/__exception/exception.h:115: Poco::Exception::Exception(String&&, int) @ 0x000000003c1e3a20
1. src/Common/Exception.cpp:139:7: DB::Exception::Exception(DB::Exception::MessageMasked&&, int, bool) @ 0x000000003b7320b8
2. src/Common/Exception.h:171:100: DB::Exception::Exception(String&&, int, String, bool) @ 0x000000000c44b42e
3. src/Common/Exception.h:57:54: DB::Exception::Exception(PreformattedMessage&&, int) @ 0x000000000c44a9ca
4. src/Common/Exception.h:189:77: DB::Exception::Exception<String, String>(int, FormatStringHelperImpl<std::type_identity<String>::type, std::type_identity<String>::type>, String&&, String&&) @ 0x000000000d28be86
5. src/Functions/tests/gtest_functions_stress.cpp:1675:19: FunctionsStressTestThread::checkAndFixupColumn(COW<DB::IColumn>::immutable_ptr<DB::IColumn>&, DB::IDataType const*, unsigned long, (anonymous namespace)::FunctionStats*) @ 0x000000000d253e2c
6. src/Functions/tests/gtest_functions_stress.cpp:1759:13: FunctionsStressTestThread::executeFunction() @ 0x000000000d27d093
7. src/Functions/tests/gtest_functions_stress.cpp:1336:52: FunctionsStressTestThread::run() @ 0x000000000d2777be
8. src/Functions/tests/gtest_functions_stress.cpp:2360:70: void* std::__thread_proxy[abi:fqe220101]<std::tuple<std::unique_ptr<std::__thread_struct, std::default_delete<std::__thread_struct>>, FunctionsStress_stress_Test::TestBody()::$_5>>(void*) @ 0x000000000d2500d9
9. __tsan_thread_start_func @ 0x000000000c2ea5d3
10. start_thread @ 0x0000000000094ac3
11. __GI___clone3 @ 0x00000000001268d0
 (version 26.7.1.1)

All failures: https://play.clickhouse.com/play?user=play&run=1#V0lUSAogICAgOTAgQVMgaW50ZXJ2YWxfZGF5cwpTRUxFQ1QKICAgIHRvU3RhcnRPZkRheShjaGVja19zdGFydF90aW1lKSBBUyBkYXksCiAgICBjb3VudCgpIEFTIGZhaWx1cmVzLAogICAgZ3JvdXBVbmlxQXJyYXkocHVsbF9yZXF1ZXN0X251bWJlcikgQVMgcHJzLAogICAgYW55KHJlcG9ydF91cmwpIEFTIHJlcG9ydF91cmwKRlJPTSBjaGVja3MKV0hFUkUgKG5vdygpIC0gdG9JbnRlcnZhbERheShpbnRlcnZhbF9kYXlzKSkgPD0gY2hlY2tfc3RhcnRfdGltZQogICAgQU5EIHRlc3RfbmFtZSA9ICdGdW5jdGlvbnNTdHJlc3Muc3RyZXNzJwogICAgLS0gQU5EIGNoZWNrX25hbWUgPSAnVW5pdCB0ZXN0cyAodHNhbiwgZnVuY3Rpb25fcHJvcF9mdXp6ZXIpJwogICAgQU5EIHRlc3Rfc3RhdHVzIElOICgnRkFJTCcsICdFUlJPUicpCiAgICBBTkQgKHB1bGxfcmVxdWVzdF9udW1iZXIgPSAwIE9SIGJhc2VfcmVmIElOICgnbWFzdGVyJykpCiAgICBBTkQgdGVzdF9jb250ZXh0X3JhdyBMSUtFICclQ29kZTolJwpHUk9VUCBCWSBkYXkKT1JERVIgQlkgZGF5IERFU0MK

Version info

  • Merged into: 26.7.1.296 (included in 26.7 and later)

@clickhouse-gh

clickhouse-gh Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9bbbb45]


AI Review

Summary

This PR reverts #108551 to remove the strict decimal-scale validation that broke FunctionsStress.stress, but it also reverts two independent producer fixes for DateTime64 scale consistency. Those producer fixes should be kept or re-applied selectively; otherwise the PR restores wrong internal column scales and user-visible timeSlots results.

Findings

❌ Blockers

  • [src/Functions/changeDate.cpp:111] InputDataType is a DataTypeDateTime64, not the underlying DateTime64 field type, so the condition is false for changeYear, changeMonth, changeDay, changeHour, changeMinute, and changeSecond over DateTime64(N). The result column is created at default_scale 3 while values are computed at the declared scale N, leaving the column structurally inconsistent with its DateTime64(N) type and still allowing downstream arrayPushBack or arrayConcat to throw LOGICAL_ERROR. Keep the Fix function property stress test scale-blind validity gate and changeDate result scale #108551 producer fix by creating the column with the scale from result_type whenever ResultDataType is DataTypeDateTime64.
  • [src/Functions/timeSlots.cpp:355] TimeSlotsImpl computes values at max({dt_scale, duration_scale, time_slot_scale}), but the reverted code declares the return type from only StartTime/Duration and creates the nested column at only start_time_scale. When Size has the largest scale, for example timeSlots(toDateTime64(..., 1), toDecimal64(1, 1), toDecimal64(0.5, 4)), values are produced in scale 4 units but exposed as Array(DateTime64(1)), producing wrong timestamps and violating the documented "highest scale among all given arguments" contract. Keep the timeSlots scale fix: include the third argument in getReturnTypeImpl and build the result column using the declared nested DateTime64 scale from result_type.
Tests
  • ⚠️ The PR deletes the focused regression coverage for the changeDate/timeSlots scale cases. After making the revert selective, keep or replace those tests so they prove the producer scale fixes independently of the strict fuzzer gate.
Final Verdict

Status: ❌ Block

Minimum required actions: keep the changeDate and timeSlots producer scale fixes while reverting the strict columnMatchesType stress-test gate, and retain focused regression coverage for those producer behaviors.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 30, 2026
/// structurally inconsistent with its type (a scale-3 column labelled DateTime64(8)).
const auto scale = typeid_cast<const DataTypeDateTime64 &>(*result_type).getScale();
auto scale = DataTypeDateTime64::default_scale;
if constexpr (std::is_same_v<InputDataType, DateTime64>)

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.

InputDataType here is DataTypeDateTime64, not the underlying DateTime64 field type, so this condition is always false for the change* functions over DateTime64(N). The result column is created with default_scale 3 while the values below are computed using result_type's scale N, leaving a column whose physical scale disagrees with its declared DateTime64(N) type. That still reaches structure-sensitive consumers such as arrayPushBack or arrayConcat as a LOGICAL_ERROR. Please keep the producer fix from #108551 when reverting the strict fuzzer gate, for example by creating the column from result_type's scale whenever ResultDataType is DataTypeDateTime64.

*assert_cast<const DataTypeArray &>(*result_type).getNestedType()).getScale();

auto res = ColumnArray::create(DataTypeDateTime64(result_scale).createColumn());
auto res = ColumnArray::create(DataTypeDateTime64(start_time_scale).createColumn());

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.

TimeSlotsImpl rescales values to max({dt_scale, duration_scale, time_slot_scale}), but after this revert the returned type ignores Size scale and the data column is created with only start_time_scale. For timeSlots(toDateTime64(..., 1), toDecimal64(1, 1), toDecimal64(0.5, 4)), values are produced in scale 4 units but exposed as Array(DateTime64(1)), so timestamps are wrong and the result violates the documented "highest scale among all given arguments" contract. Please keep the timeSlots scale fix: include the third argument when deriving result scale and build the nested column with the declared DateTime64 scale from result_type.

@alexey-milovidov
alexey-milovidov merged commit 6adef4c into master Jun 30, 2026
16 of 18 checks passed
@alexey-milovidov
alexey-milovidov deleted the revert-108551-groeneai/fix-108517-writeslice-datetime64-array-push branch June 30, 2026 19:32
@alexey-milovidov alexey-milovidov self-assigned this Jun 30, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

@groeneai, now fix it properly.

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 30, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

@alexey-milovidov, plan and status.

Root cause of the revert: the strict columnMatchesType gate is correct, but it is a hard throw inside FunctionsStress.stress, so the test goes red the moment any of ~1200 functions returns a scale-divergent column. #108551 fixed two producers (changeDate, timeSlots); the gate then exposed more. Over the ~20h it was live on master the fuzzer flagged: reinterpret (57 hits) and YYYYMMDDhhmmssToDateTime64 (2 hits). A randomized fuzzer cannot prove the producer set is complete before merge, which is exactly why the gate broke master after passing local runs and the first CI.

Investigation results:

  • reinterpret is the real second producer (the same-physical-type passthrough returned the source scale). Already fixed in Fix reinterpret to Decimal/DateTime64 with a different scale #108878 (open).
  • YYYYMMDDhhmmssToDateTime64 is NOT a producer bug. With any clean precision argument (0..9) its declared scale equals the column scale. Both its hits had a reinterpret-divergent Decimal as the precision argument, i.e. the reinterpret bug surfacing through it as a consumer. Fix reinterpret to Decimal/DateTime64 with a different scale #108878 removes those too. So the gate also produces second-order false attributions.
  • changeDate and timeSlots producer fixes are real and correct (your revert's own review says keep them).

What I am opening now (fresh PR, off current master): re-land only the two proven producer source fixes plus a functional regression, no strict gate, so it cannot redden the stress test:

  • changeDate: build the DateTime64 result column from result_type's scale (the old is_same_v<InputDataType, DateTime64> guard was always false, so it used default_scale 3).
  • timeSlots: include the 3rd Size argument scale in the declared return type, and build the column at the declared scale.
  • Functional test 04338_... (parallel-safe): changeYear/Month/Day/Hour/Minute/Second and timeSlots over DateTime64(N != 3) through arrayPush/arrayConcat. Verified: it raises the writeSlice LOGICAL_ERROR on clean master (server abort in debug/sanitizer builds) and passes with the fix.

On the gate itself: it found two real bugs, so it has value, but as a hard throw it will keep reddening master whenever a new or missed producer mis-scales. If you want to keep it, I think it should record/normalize the divergent result instead of throwing, so the stress test stays a crash finder without gating master on producer-completeness. Your call; I can do that as a follow-up once #108878 and the producer fixes land. The production writeSlice LOGICAL_ERROR check stays unchanged (you ruled it correct).

alexey-milovidov added a commit to andremm/ClickHouse that referenced this pull request Jul 2, 2026
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]>
pull Bot pushed a commit to Haofei/ClickHouse that referenced this pull request Jul 9, 2026
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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…oeneai/fix-108517-writeslice-datetime64-array-push

Revert "Fix function property stress test scale-blind validity gate and changeDate result scale"
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog 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.

4 participants