Repository navigation
Conversation
`AggregateFunctionArray` is an adapter combinator: `agg(x) -> aggArray(x)`. It
does not transform parameters, so its `parameters` should always be identical to
the nested function's. For the vast majority of aggregate functions this is
trivially true, because the factory hands the same parameter array to both the
nested function and the combinator wrapper.
The `timeSeries*ToGrid` aggregate function family (`AggregateFunctionTimeseriesBase`)
is the exception: it deliberately normalizes its four timestamp parameters to
`DecimalField<Decimal64>` so that states serialized with different timestamp
scales remain merge-compatible. With user-typed literals (e.g. `UInt64_60`) the
wrapper's parameters would not match the nested function's normalized parameters
(`Decimal64_'60'`), and the wrapper's equality check fired:
Logical error: 'AggregateFunctionArray: parameters mismatch between Array
wrapper 'timeSeriesDeltaToGridArray' and nested function 'timeSeriesDeltaToGrid'.
Wrapper has 4 parameter(s): [UInt64_..., ...], nested function has 4
parameter(s): [Decimal64_'...', ...]'
In CI debug / sanitizer builds (`abort_on_logical_error: true`) this surfaced as
a server abort, and the AST fuzzer hit it daily across many master and PR runs
(STID 4870-4f07 / 4f21 family, issue ClickHouse#104459, ~149 occurrences over 30 days).
A previous attempt to resolve this by dropping the normalization on the
`timeSeries*ToGrid` side (ClickHouse#103428) was reverted in ClickHouse#104672 because it broke
backward compatibility with already-serialized timeseries state columns whose
metadata records `Decimal64`-normalized parameters. That path is therefore not
viable.
The wrapper-level fix in this PR does not touch the timeseries normalization.
`AggregateFunctionArray` now forwards `nested_->getParameters()` to its
`IAggregateFunctionHelper` base, which is a no-op for every aggregate function
that does not normalize its own parameters, and produces consistent metadata
for the timeseries family. The downstream equality check becomes always-true
and is removed. The wrapper's runtime behaviour (`add` / `merge` / `serialize`
/ `insertResultInto`) is entirely delegated to the nested function and is
unaffected.
Verified locally on the debug build:
- the issue's reproducer (`timeSeriesDeltaToGridArray(...)`, every 4-arg
variant, and the 5-arg `timeSeriesPredictLinearToGridArray`) used to abort
the server; with the patch they return the expected grid arrays.
- `INSERT-State` / `Merge` / `DETACH+ATTACH` round-trip through an
`AggregateFunction(timeSeriesLastToGridArray(60, 180, 10, 20), ...)` column
preserves the data on disk and after re-attach.
- existing Array-combinator tests (`01441_array_combinator`,
`01570_aggregator_combinator_simple_state`, `00915_simple_aggregate_function`,
`01129_state_array_unique`) all pass — the change is a no-op for them.
- new regression test `04235_timeseries_array_combinator_params_104459` passes
50 / 50 with `--test-runs 50` under full randomization.
Reproducer:
SET allow_experimental_time_series_aggregate_functions = 1;
WITH CAST('[(1600000000, 10), (1600000010, 20), (1600000020, 30)]',
'Array(Tuple(UInt32, Float64))') AS data
SELECT timeSeriesDeltaToGridArray(1600000010, 1600000320, 10, 300)(data.1, data.2);
CI report (AST fuzzer, amd_debug, targeted) on PR ClickHouse#104299:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=4c8770c47ae00af15728dff17dddd34f921076bd&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Fixes ClickHouse#104459
### Changelog category (leave one):
- Bug Fix (user-visible misbehavior in an official stable release)
### Changelog entry (a [user-readable short description](https://github.com/ClickHouse/ClickHouse/blob/master/docs/changelog_entry_guidelines.md) of the changes that goes into CHANGELOG.md):
Fix `Logical error: AggregateFunctionArray: parameters mismatch` when the `Array`
combinator is applied to a `timeSeries*ToGrid` aggregate function (e.g.
`timeSeriesDeltaToGridArray`, `timeSeriesPredictLinearToGridArray`,
`timeSeriesRateToGridArray`). The `timeSeries*ToGrid` family normalizes its
timestamp parameters to `Decimal64` internally, which did not match the
user-supplied parameters stored on the `Array` wrapper. The wrapper now
inherits the nested function's parameters so the two always agree. This is a
no-op for every other aggregate function.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
Pre-PR validation gate (self-check)Session: cron:clickhouse-ci-task-worker:20260513-001500 a) Deterministic repro? Yes. b) Root cause explained? The c) Fix matches root cause? Yes. d) Test intent preserved? / New tests added? No existing test relaxed or removed. Added e) Demonstrated in both directions? Yes.
f) Fix is general, not a narrow patch? Yes.
|
|
cc @alexey-milovidov @vitlibar @Avogar — could you review this? It fixes the chronic |
|
Workflow [PR], commit [9286f24] Summary: ❌
AI ReviewSummaryThis PR fixes Final Verdict
|
LLVM Coverage Report
Changed lines: 80.00% (4/5) · Uncovered code |
|
Closed, the issue will be fixed in #104812 |
AggregateFunctionArrayis an adapter combinator:agg(x) -> aggArray(x). It does not transform parameters, so itsparametersshould always be identical to the nested function's. For the vast majority of aggregate functions this is trivially true.The
timeSeries*ToGridaggregate function family (AggregateFunctionTimeseriesBase) is the exception: it deliberately normalizes its four timestamp parameters toDecimalField<Decimal64>so that states serialized with different timestamp scales remain merge-compatible. With user-typed literals (e.g.UInt64_60) the wrapper's parameters did not match the nested function's normalized parameters (Decimal64_'60'), and the wrapper's equality check fired:In CI debug / sanitizer builds (
abort_on_logical_error: true) this surfaces as a server abort. The AST fuzzer hit it daily on master across many PRs (STID 4870-4f07 / 4f21 family, ~149 occurrences over 30 days).A previous attempt to resolve this by dropping the normalization on the
timeSeries*ToGridside (#103428) was reverted in #104672 because it broke backward compatibility with already-serialized timeseries state columns whose metadata recordsDecimal64-normalized parameters. That path is not viable.This PR fixes the issue on the wrapper side without touching the timeseries normalization.
AggregateFunctionArraynow forwardsnested_->getParameters()to itsIAggregateFunctionHelperbase, which is a no-op for every aggregate function that does not normalize its own parameters, and produces consistent metadata for the timeseries family. The downstream equality check becomes always-true and is removed. The wrapper's runtime behaviour (add/merge/serialize/insertResultInto) is entirely delegated to the nested function and is unaffected.Verified locally on the debug build:
timeSeriesDeltaToGridArray(...), every 4-arg variant, and the 5-argtimeSeriesPredictLinearToGridArray) used to abort the server; with the patch they return the expected grid arrays.INSERT-State/Merge/DETACH+ATTACHround-trip through anAggregateFunction(timeSeriesLastToGridArray(60, 180, 10, 20), ...)column preserves the data on disk and after re-attach.01441_array_combinator,01570_aggregator_combinator_simple_state,00915_simple_aggregate_function,01129_state_array_unique) all pass — the change is a no-op for them.04235_timeseries_array_combinator_params_104459passes 50 / 50 with--test-runs 50under full randomization.Reproducer:
CI report (AST fuzzer, amd_debug, targeted) on PR #104299, requested by @alexey-milovidov:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=104299&sha=4c8770c47ae00af15728dff17dddd34f921076bd&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Fixes #104459.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: AggregateFunctionArray: parameters mismatchwhen theArraycombinator is applied to atimeSeries*ToGridaggregate function (e.g.timeSeriesDeltaToGridArray,timeSeriesPredictLinearToGridArray,timeSeriesRateToGridArray). ThetimeSeries*ToGridfamily normalizes its timestamp parameters toDecimal64internally, which did not match the user-supplied parameters stored on theArraywrapper. The wrapper now inherits the nested function's parameters so the two always agree. This is a no-op for every other aggregate function.Documentation entry for user-facing changes