Repository navigation
Resubmit: Preserve parameter types in timeseries aggregate functions - #103428
Conversation
…types in timeseries aggregate functions
fe9cf62 to
737f05d
Compare
|
Workflow [PR], commit [a57841f] Summary: ❌
AI ReviewSummaryThis PR restores parameter-type preservation for timeseries aggregate functions and adds coverage around the resulting type-mismatch behavior. The main remaining issue is that the new invariant check in Findings
ClickHouse Rules
Final VerdictStatus: Minimum required actions:
|
| /// recorded in the column metadata; or fail on parallel replicas under serialize_query_plan=1 because the replica's | ||
| /// decodeDataType() would reconstruct a type different from the one the coordinator sent in the plan.) | ||
| chassert(function && function->getParameters() == parameters, | ||
| "function->getParameters() must equal the parameters passed to the factory"); |
There was a problem hiding this comment.
I added a comment and assertion here to document the invariant.
There was a problem hiding this comment.
Pull request overview
Restores the invariant that IAggregateFunction::getParameters() must return exactly the parameters used to create the aggregate function (no normalization), primarily to keep DataTypeAggregateFunction stable across serialization/deserialization (e.g., parallel replicas + serialize_query_plan=1) and stored table metadata.
Changes:
- Pass through original parameter
Arrayinto time series aggregate function implementations (instead of normalizing stored parameters toDecimal64). - Add
chassert-based invariants inAggregateFunctionFactoryto detect any aggregate function/combinator that mutates parameters. - Add/update stateless tests and tweak existing tests to avoid flakiness from randomized parallel replicas.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesBase.h |
Stores the original parameters_ in the base IAggregateFunction state for timeseries aggregates. |
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesHelpers.cpp |
Threads the original parameters through constructors for all relevant timeseries functions. |
src/AggregateFunctions/TimeSeries/AggregateFunctionTimeseriesLinearRegression.h |
Updates ctor to accept the original parameters_ (but introduces a ctor ambiguity risk). |
src/AggregateFunctions/AggregateFunctionFactory.cpp |
Adds assertions to enforce parameter preservation for creators and combinators. |
src/AggregateFunctions/IAggregateFunction.h |
Documents that getParameters() returns constructor parameters “as is”. |
tests/queries/0_stateless/04109_timeseries_aggregate_function_parameter_type_mismatch.sql |
New regression test proving mismatched parameter types cause CANNOT_CONVERT_TYPE. |
tests/queries/0_stateless/04109_timeseries_aggregate_function_parameter_type_mismatch.reference |
Expected output for the new test. |
tests/queries/0_stateless/03254_timeseries_to_grid_aggregate_function_sparse.sql |
Disables randomized parallel replicas at test start for determinism. |
tests/queries/0_stateless/03254_timeseries_instant_value_aggregate_functions.sql |
Similar test determinism tweaks + settings adjustments. |
tests/queries/0_stateless/03254_timeseries_instant_value_aggregate_functions.reference |
Updates expected type-name outputs reflecting preserved parameter types. |
| [toDateTime64('2024-01-01 00:00:10', 3, 'UTC'), | ||
| toDateTime64('2024-01-01 00:00:20', 3, 'UTC')]::Array(DateTime64(3, 'UTC')), | ||
| [1.0, 2.0]::Array(Float64) | ||
| ); -- { serverError CANNOT_CONVERT_TYPE } |
There was a problem hiding this comment.
I also added a test from report #102319 to document that this CANNOT_CONVERT_TYPE exception is an expected behavior and not a bug.
737f05d to
288461d
Compare
|
@alexey-milovidov — investigated the Verdict: not caused by this PR — pre-existing test-infrastructure race in the stuck-thread teardown path. Root causeLooking at the job log:
The flow:
For a normally-stopping worker this can't happen — the run loop ends with The chassert masks the actual failure ( This is not the timeseries-aggregate-types changeThe PR touches
Cross-PR data:
Proposed fix (separate PR, follow-up)The fix belongs in
The cleanest minimal patch is to skip the unsafe cleanup once String failure_details = reportResults(total_stats, stuck_threads);
writeSignalIDtoSignalPipe(SignalListener::StopThread);
signal_listener_thread.join();
HandledSignals::instance().reset();
if (stuck_threads > 0)
{
// Stuck workers are still inside SQL evaluation; we cannot run their destructors
// from this thread without (a) ~ThreadStatus tripping the cross-thread chassert
// in RUsageCounters::incrementProfileEvents, (b) ~thread() calling std::terminate,
// (c) UB from concurrent access to FunctionsStressTestThread members.
// Detach the OS threads and intentionally leak the vector — the process is about
// to fail the test anyway.
for (auto & t : threads)
if (t.thread.joinable())
t.thread.detach();
static std::vector<FunctionsStressTestThread> leaked;
leaked = std::move(threads);
}
ASSERT_TRUE(failure_details.empty()) << failure_details;I'll send this as a separate PR shortly. This PR should be unblocked by a CI rerun once the fix lands (or if you want to merge first, the failure is unrelated and is hiding the watchdog's actual Reproducing the underlying stuck-thread case is non-deterministic — |
|
@groeneai, thanks! Please send a PR. |
|
@alexey-milovidov — already filed: #103982 (May 4, before this thread). Fix: wraps
This avoids the CI on #103982: all 35+ relevant checks pass (asan/tsan/msan/ubsan unit tests, AST fuzzer, BuzzHouse, builds). Only red is the chronic "Docs check / Generate system tables documentation" flaky which fails in 30+ unrelated PRs (separate task). Could you take a look when you have a moment? |
|
Now we have to update the branch here. We can't merge with red checks. |
…arameter-types-in-timeseries-agg-functions
|
PR / Finish Workflow (pull_request) failed with |
…eries-agg-functions
LLVM Coverage Report
Changed lines: 100.00% (39/39) | lost baseline coverage: 4 line(s) · Uncovered code |
|
@groeneai Investigate CI failures |
|
@vitlibar — investigated all CI failures on 1. AST fuzzer (amd_debug, targeted, old_compatibility) —
|
| PR | failures | sample tests |
|---|---|---|
| 101218 | 5 | 03142_untuple_crash, 04003_grace_hash_join_with_totals, … |
| 104475 | 4 | 04093_text_index_separate_analysis, 01660_join_or_inner, … |
| 100177 | 4 | 02481_analyzer_optimize_aggregation_arithmetics, … |
| 104474 | 4 | 03170_float_schema_inference_small_block, … |
| 96978 | 4 | 02788_current_schemas_function, 02050_clickhouse_client_local_exception, … |
| 103428 | 3 | 02169_map_functions, 01109_sc0rp10_string_hash_map_zero_bytes, 02515_analyzer_null_for_empty |
| … 18 more PRs … |
Reported tests are whatever happened to be running when the macOS server crashed — they're random, not predictive. None of your 3 tests touch aggregate functions / Array combinator / TimeSeries. Today (2026-05-11), 30+ more unrelated PRs hit the same pattern. Pure environment noise.
3. Finish Workflow / Post Hooks (2026-05-09 20:22, 2026-05-07 ×3) + Docker server image / clickhouse-server:head-alpine-arm64 (2026-05-07) — Infrastructure
Workflow finalization steps + Alpine ARM64 docker build pipeline. Not test failures, not caused by your diff.
Recommendation
- Rebase on master to pick up Reject collection literals as data-type arguments (STID 1941-1bfa) #104520; that alone should drop the AST fuzzer hit.
- Re-run Fast test (arm_darwin) — the macOS instability is widespread enough that a re-run very likely passes on a different random subset.
- No code changes required from your side on this PR's failures.
For context — STID 4870 family (the bug this PR fixes) continues to recur on master almost daily (most recent: STID 4870-4f07 on Stress test (experimental, serverfuzz, azure, amd_msan), sha 12b7a618d1ea7a5f29b58d846fb979490904c2f5, 2026-05-09). PR is mergeable, blocked only on review.
Session: cron:clickhouse-ci-task-worker:20260511-121500
|
So the only real CI failure was Logical error: 'Inconsistent AST formatting: the original AST: (STID: 1941-1bfa) and it has been already fixed |
9f7bd11
|
@vitlibar @alexey-milovidov — status update on the STID 4870 family after this fix was reverted by #104672 on 2026-05-12 12:49 UTC. Public master regressed immediately after the revert
Sub-STIDs hitting master post-revert: The re-land in #104812 is stalled only by chronic flakes#104812 is a clean re-land (identical diff). Its CI on
Question / offerIf #104812 is being held back specifically over Happy to (a) investigate the private flake if you can share the failure signature/log, or (b) take a swing at the remaining chronic STID 1941-1bfa subvariants (PR #104991 addresses one — the NOT-tuple CODEC variant — but there are JOIN and aggregation-list variants still surfacing). Session: |
…, mannWhitneyUTest These aggregate functions accept parameters but constructed their base with an empty parameter array, so getParameters() returned []. The -Array combinator does not transform parameters and asserts wrapper.parameters == nested params, so e.g. groupArrayMovingSumArray(42)([1,2,3]) aborted with a LOGICAL_ERROR. Pass the parameters to the base constructor (the fix the ClickHouse#104812 TODO asked for). Parameters are plain UInt64/String literals, so this does not reintroduce the type-equality issue that reverted ClickHouse#103428. 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):
Resubmit #101083: Preserve parameter types in timeseries aggregate functions
(it was reverted in #102358)
We need to restore the initial invariant: For any aggregation function
IAggregateFunction::getParameters()should return exactly the parameters used to create the aggregation function. Aggregation functions are not allowed to change or normalize these parameters.Otherwise it would become a different
DataTypeAggregateFunction(seeDataTypeAggregateFunction::strictEquals),and could fail to reattach a table because
decodeDataType()would reconstruct a type different from the onerecorded in the column metadata; or fail on parallel replicas under serialize_query_plan=1 because the replica's
decodeDataType()would reconstruct a type different from the one the coordinator sent in the plan. And we actually saw a bunch of such issues already (#101407, #102345, #103079)It's difficult to fix all these issues and it's better to just restore the invariant. By the way, for non-timeseries aggregate functions parameter types are always preserved, and for example
quantile(toFloat32(0.5))isn't silently converted toquantile(0.5)or vice versa.Version info
26.5.1.518