Repository navigation
Preserve parameters in aggregate functions that dropped them, fixing the -Array combinator assert - #110143
Conversation
…, 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]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260712-043600 |
|
cc @vitlibar @rschu1ze — could you review this? It resolves the |
|
Workflow [PR], commit [2ac1a61] Summary: ✅
AI ReviewSummaryThis PR preserves aggregate-function parameters for the affected families so the Missing context / blind spots
Final Verdict✅ No blocking issues found in the current diff. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 141/158 (89.24%) · Uncovered code |
The window-size / test parameters of groupArrayMovingSum, groupArrayMovingAvg, kolmogorovSmirnovTest and mannWhitneyUTest only affect finalization, not the serialized state. Now that the parameters are preserved, the state type name carries them (e.g. AggregateFunction(groupArrayMovingSum(42), UInt64)), which made the new parameterized state incompatible for -Merge and aggregate CAST with legacy parameterless columns written before the change (state comparison goes through getNormalizedStateType -> DataTypeAggregateFunction::equals, which now saw a different parameter count). Override getNormalizedStateType() to normalize to an empty parameter list, the same approach quantile* uses for finalization-only parameters, so a legacy parameterless state and a new parameterized state share one representation. getParameters() still returns the parameters, so the -Array combinator invariant continues to hold. Extend the regression test to write a legacy parameterless state column and Merge it with the parameterized function. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Good catch, the compatibility concern is real and now fixed in 468fa74. The parameters here only affect finalization: State comparison for Verified against a build of the previous commit (parameter passing without normalization): |
intervalLengthSum takes no parameters, but its factory silently dropped any passed parameters. The -Array combinator then aborted on the wrapper-vs-nested parameter mismatch (STID 4870-4f21, found by the AST fuzzer while exercising the new 04368 test). Reject parameters with assertNoParameters instead. The 04368 legacy-compatibility check asserted the exact merged array of two concatenated states, whose order is not deterministic (and varies under parallel replicas). Assert order-independent invariants (element count and running total) instead. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed 303071f addressing two CI failures on the previous head:
Validated: 04368 passes 60/60 with randomized settings; |
The window-size parameter of groupArrayMovingSum/Avg accepts both Int64 and UInt64. After preserving parameters, the state type name printed the value without a type suffix, so groupArrayMovingSumState(42::Int64) serialized as AggregateFunction(groupArrayMovingSum(42), UInt64) and reparsed the parameter as UInt64, breaking lossless round-trip of the type name through metadata. Override shouldPrintParametersWithTypes() so a positive Int64 parameter stays 42::Int64 in the printed type name (same approach as AggregateFunctionTimeseriesBase). The -Array invariant is unaffected: it compares parameter Field values, not names. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed in 2916916. Chose option (b): Option (a) — normalizing the accepted integer to UInt64 in the ctor — would re-break the Verified:
Added the requested regression to 04368: KS/MWU are unaffected — their parameters are |
argMin, argMax and their aliases (argAndMin, argAndMax, min_by, max_by)
take no parameters but createAggregateFunctionArgMinMax silently ignored
the passed Array, building the base with empty params. The -Array
combinator then aborted on the wrapper-vs-nested parameter mismatch
(AggregateFunctionArray LOGICAL_ERROR, e.g. argMinArray('two-sided', 2)).
Reject parameters up front via assertNoParameters, matching the
intervalLengthSum fix.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed ec7cea0. The AST fuzzer hit the same To catch the whole family in one pass rather than per-fuzzer-finding, I runtime-probed all 236 aggregate functions with Extended 04368 to cover the argMin/argMax family (both the clean rejection and the still-working parameterless path). |
The compatibility block only proved the legacy-state upgrade path for groupArrayMovingSum. kolmogorovSmirnovTest and mannWhitneyUTest get the same getNormalizedStateType() normalization, so add one focused legacy-state case each: write an old parameterless AggregateFunction(kolmogorovSmirnovTest, ...) / AggregateFunction(mannWhitneyUTest, ...) column, then confirm it stays usable via parameterized ...Merge(...) and accepts aggregate-to-aggregate inserts of new parameterized states. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Extended
Both assert order-independent invariants of the finalized result ( |
The previous fix rejected parameters in intervalLengthSum and the
argMin/argMax family with assertNoParameters to kill the -Array combinator
abort. But before this PR those factories silently ignored parameters, so
persisted types like AggregateFunction(intervalLengthSum('two-sided', 1), ...)
and AggregateFunction(argMin('x', 1), ...) exist in the wild. Hard-rejecting
them made that metadata unreadable on upgrade (reparsed via
AggregateFunctionFactory::get).
Preserve the parameters on the function object instead, so getParameters()
matches the -Array wrapper, and override getNormalizedStateType() to normalize
them to Array{} in the state type. The parameters are non-semantic here and
never touch the serialized state, so a parameterized state and a legacy
parameterless column share one representation and stay Merge-/CAST-compatible.
Same approach already used for groupArrayMovingSum/Avg, kolmogorovSmirnovTest
and mannWhitneyUTest in this PR.
Extend 04368 with legacy-state compatibility cases for intervalLengthSum and
argMin/argMax.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Fixed in 8295853. Both
Verified locally: legacy parameterless |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 139/158 (87.97%) · Uncovered code |
CI finish ledger — 919af58Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task
The earlier partial fix #111528 (pin Session id: cron:our-pr-ci-monitor:20260729-103000 |
-Array combinator assert
…gSum-array-param-mismatch
The comment blocks above shouldPrintParametersWithTypes and getNormalizedStateType narrated how the parameters were dropped before and which spellings used to be accepted. That history belongs in the commit log, not at the call site, so each block now states only the property a reader needs there: the parameters do not reach the serialized state, therefore parameterized and parameterless states normalize to one representation and stay Merge-/CAST-compatible. No functional change.
Build profile diff (arm_release)Comparing Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionsArgMinArgMax… |
15.47 MiB | 16.21 MiB | +757.75 KiB (+4.78%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionGroupArrayMov… |
5.40 MiB | 5.62 MiB | +232.27 KiB (+4.20%) |
src/AggregateFunctions/CMakeFiles/clickhouse_aggregate_functions.dir/AggregateFunctionIntervalLengt… |
855.69 KiB | 888.62 KiB | +32.93 KiB (+3.85%) |
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
11 translation units recompiled, 52 s compile time in total, 11 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×1.05 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +5.3 s (+11%) in total before that adjustment.
|
@groeneai @alexey-milovidov — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
|
Answered in #118006 (comment): the bare |
`argMin`, `argMax` and `intervalLengthSum` accept parameters but never read them. ClickHouse#110143 started preserving them in `getParameters()` (the -Array combinator requires the wrapper's parameters to equal the nested function's), and this PR kept them out of the state type. The name that travels with a state serialized into a `Field` is built separately, in `ColumnAggregateFunction::getTypeString()`, straight from `getParameters()`, so it still spelled them out and disagreed with the state type: CREATE TABLE t (s AggregateFunction(argMin, UInt8, UInt8)) ENGINE = Memory; INSERT INTO t VALUES (arrayReduce('argMinState(map(1, 2))', [1, 2], [1, 2])); -- Code: 43, Cannot insert field with type AggregateFunction(argMin([(1, 2)]), UInt8, UInt8) -- into column with type AggregateFunction(argMin, UInt8, UInt8) SELECT dynamicType(x) FROM VALUES('x Dynamic', (arrayReduce('argMinState(map(1, 2))', [1, 2], [1, 2]))); -- Code: 36, Expected a literal or a CAST of a literal, got '[(1, 2)]' A `Map` parameter renders as `[(1, 2)]`, which the `AggregateFunction` type parser rejects, so every consumer that re-derives a type from that name fails: `ColumnAggregateFunction::insert`, `convertFieldToType`, and `FieldToDataType` when `Dynamic`/`Variant` discovers the variant type. State a single property instead of duplicating the parameter list: `areParametersPartOfState()` replaces the two per-function `getStateType()`/`getNormalizedStateType()` overrides and also decides what the column prints, so both carriers agree by construction. `getParameters()` keeps returning the real parameters, so the -Array invariant is untouched. Combinator-wrapped shapes (`argMinIfState`, `argMinArrayState`, ...) build their state type from the wrapper's own parameters, fail the same way on master, and are unchanged here; they are tracked in ClickHouse#118168. A name that still spells those parameters (declared metadata, a binary encoded type, an older server) denotes the same state, and `nameMatchesState` cannot recognise it because it starts by parsing the name, so `acceptsStateTypeName` compares that spelling verbatim as well.
|
@alexey-milovidov, should this PR go to the release branches, together with #118156? 26.3, 26.7 and 26.8 do not have it. Measured on official builds:
CREATE TABLE t ENGINE = MergeTree ORDER BY tuple() AS SELECT groupArrayMovingSumState(2)(number) AS s FROM numbers(5);
SELECT finalizeAggregation(s) FROM t; -- [0,1,3,5,7], after a restart [0,1,3,6,10]This PR alone brings #118006 along: Options: |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a
LOGICAL_ERROR(a server abort in debug and sanitizer builds) when the-Arraycombinator is applied with parameters toargMin,argMax,argAndMin,argAndMax,min_by,max_by,groupArrayMovingSum,groupArrayMovingAvg,kolmogorovSmirnovTest,mannWhitneyUTestorintervalLengthSum, for exampleargMaxArray(2)([1, 2, 3], [1, 2, 3]). These functions dropped the parameters they were given; they now preserve them, so a state type name also keeps them, e.g.AggregateFunction(groupArrayMovingSum(42), UInt64)instead of dropping the window size.Description
Found by the AST fuzzer. Example abort:
Reproducers, one per affected family:
Root cause: each of these functions built its
IAggregateFunctionDataHelperbase with an empty parameter array instead of the parameters it was passed, sogetParametersreturned[]. The-Arraycombinator does not transform parameters and asserts that the wrapper's parameters equal the nested function's; with the wrapper carrying[42]and the nested function returning[], the invariant fired.groupArrayMovingSum/groupArrayMovingAvgandkolmogorovSmirnovTest/mannWhitneyUTestare the set listed in the TODO added by #104812.intervalLengthSumand theargMin/argMaxfamily instead accepted parameters and silently ignored them, so hard-rejecting them would make existingAggregateFunction(argMin(...), ...)metadata unreadable on upgrade; for those the parameters are preserved and normalized away in the state type viagetNormalizedStateType, keeping legacy parameterless state columnsMerge- andCAST-compatible.No performance impact: the change only forwards an already-constructed parameter array to a base constructor, with no work added on any aggregation hot path.
Related: #104812
Workflow [PR]
Sync PR [sync-upstream/pr/110143]