Repository navigation
Conversation
…eSeries*ToGrid functions
The `timeSeries*ToGrid` aggregate function family normalizes its parameters
internally — 4 user-typed literals (start, end, step, window) are stored as
`Decimal64` fields scaled to match the timestamp column, and the 5-parameter
`timeSeriesPredictLinearToGrid` variant stores `predict_offset` as a member
instead of in the parameter array. This produces an intentional normalization
that lets states serialized with different timestamp scales merge together.
When the `Array` combinator wrapped such a function, its constructor fired
`LOGICAL_ERROR` ("parameters mismatch"): it was initializing its own parameter
array from the user-typed `params_` (`UInt64`, possibly 5 entries) but then
comparing against the nested function's normalized parameters (`Decimal64`,
always 4 entries). The assertion was originally a `chassert` that silently
compiled out in release; ClickHouse#102868 made it a real `LOGICAL_ERROR` to aid
diagnosis, which then surfaced as a master-level failure in serverfuzz /
`AST fuzzer` runs (STID 4870 family, ~10 hits across 60 days).
Fix the Array combinator by initializing its own parameter array from
`nested_->getParameters()` instead of the user-supplied `params_`. This makes
the wrapper transparent to whatever normalization the nested function performs:
`timeSeries*ToGridArray(...)` states now match the corresponding
`timeSeries*ToGrid(...)` states, preserving the scale-independent state
compatibility that `timeSeries*ToGrid` relies on.
For every other aggregate function the user-typed `params_` and
`nested_->getParameters()` are identical — no behavior change.
Reproducer (previously threw `LOGICAL_ERROR`, now succeeds):
```
SET allow_experimental_time_series_aggregate_functions = 1;
SELECT timeSeriesPredictLinearToGridArray(60, 180, 10, 20, -60)(ts, val) FROM ts;
SELECT timeSeriesDerivToGridArray(60, 180, 10, 20)(ts, val) FROM ts;
```
Regression test: `04102_timeseries_array_combinator_params`.
STID 4870 family: 4870-4f07, 4870-4f21, 4870-4d73, 5480-49e6.
Diagnostic PR that made the error visible: ClickHouse#102868.
Pre-PR validation gate (self-check)Session: cron:clickhouse-ci-task-worker:20260418-204500 a) Deterministic repro? Yes. b) Root cause explained? The c) Fix matches root cause? Yes. The d) Test intent preserved? / New tests added? No existing tests loosened. Added a new regression test e) Demonstrated in both directions? Yes. Manual test confirmed: the reproducer query throws f) Fix is general, not a narrow patch? Yes. The change applies to the I kept the scope minimal: only |
|
cc @alexey-milovidov @Algunenano @vitlibar — could you review this? It fixes |
|
Workflow [PR], commit [15a5f6b] Summary: ❌
AI ReviewSummaryThis PR fixes a real mismatch in Missing context
ClickHouse Rules
Final Verdict
|
LLVM Coverage Report
Changed lines: 80.00% (4/5) · Uncovered code |
|
Doesn't look good for now, needs investigation. |
|
The issue will be fixed in #103428, this PR is not needed. |
The
timeSeries*ToGridaggregate function family normalizes its four timestamp parameters internally toDecimal64(scaled to match the timestamp column) and, fortimeSeriesPredictLinearToGrid, storespredict_offsetas a member instead of in the parameter array. This normalization is intentional — it lets states serialized with different timestamp scales merge together.When the
Arraycombinator wrapped such a function, its constructor firedLOGICAL_ERROR(AggregateFunctionArray: parameters mismatch): it was initializing its own parameter array from the user-typedparams_(UInt64, sometimes 5 entries) but then comparing against the nested function's normalized parameters (Decimal64, always 4 entries). The assertion was originally achassertthat compiled out in release; #102868 promoted it to a realLOGICAL_ERRORfor diagnostics, which then surfaced as a master-level exception in serverfuzz /AST fuzzerstress runs (STID 4870 family, ~10 hits across 60 days; ~7 master, ~20 PR hits in the last 30 days).Fix the
Arraycombinator by initializing its own parameter array fromnested_->getParameters()instead of the user-suppliedparams_. TheArraywrapper is just an adapter over the nested function — its parameters should match the nested function's. Almost every aggregate function preservesparams_verbatim, sonested_->getParameters() == params_and there is no behaviour change. For thetimeSeries*ToGridfamily the two differ, and using the nested function's parameters makestimeSeries*ToGridArray(...)states byte-compatible with the unwrappedtimeSeries*ToGrid(...)states of the same scale.Reproducer (exception before, succeeds after):
Regression test:
04102_timeseries_array_combinator_params.Related:
AST fuzzer (amd_debug, targeted)on PRs that touchTimeSeries*(e.g. Improve TimeSeries table engine #99083), which reshape the fuzzer's exploration space.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: AggregateFunctionArray: parameters mismatchwhentimeSeries*ToGridaggregate functions are used with theArraycombinator (e.g.timeSeriesPredictLinearToGridArray,timeSeriesDerivToGridArray,timeSeriesRateToGridArray). TheArraywrapper was storing the user-typed parameters while the nested function stored normalizedDecimal64parameters, so their types and counts could differ. The wrapper now inherits the nested function's parameters, matching the behaviour of the unwrapped function.Documentation entry for user-facing changes