Skip to content

Make the list of aggregation functions dropping their parameters explicit - #106245

Draft
vitlibar wants to merge 1 commit into
ClickHouse:masterfrom
vitlibar:explicit-list-of-agg-functions-dropping-params
Draft

vitlibar wants to merge 1 commit into
ClickHouse:masterfrom
vitlibar:explicit-list-of-agg-functions-dropping-params

Conversation

@vitlibar

@vitlibar vitlibar commented Jun 1, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Make the list of aggregation functions dropping their parameters explicit

Follow-up to #104812 (comment)

@clickhouse-gh

clickhouse-gh Bot commented Jun 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [cfd95ad]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Logical error: Coordination mode mismatch for stream A: got B, expected C (STID: 6117-726a) FAIL cidb
AST fuzzer (amd_debug, targeted, old_compatibility) ERROR

AI Review

Summary

This PR replaces the broad empty-parameter tolerance in AggregateFunctionFactory with an explicit list of aggregate functions that currently drop parameters. The direct-function check is now tighter, but the new combinator check rejects a valid Map combinator path when the nested function is one of those parameter-dropping aggregates.

Findings

⚠️ Majors

  • [src/AggregateFunctions/AggregateFunctionFactory.cpp:288] The combined-function invariant now requires every combinator wrapper to preserve the outer parameters, but AggregateFunctionMap initializes its own parameters from nested->getParameters. For groupArrayMovingSumMap(3)(m), groupArrayMovingSum is allowed by the new list to return empty getParameters, so AggregateFunctionMap also returns empty parameters while the outer factory input is [3]. This makes the new chassert fire in debug/ASan builds for a valid aggregate-combinator expression.
    Suggested fix: pass the outer params into AggregateFunctionMap and initialize its base with those parameters, or otherwise make the combined-function check handle this explicit drop-list path without weakening the invariant for unrelated combinators.
Tests
  • ⚠️ Please add focused coverage for a parameterized drop-list aggregate through a combinator, for example groupArrayMovingSumMap(3) or groupArrayMovingAvgMap(3), so debug/ASan builds exercise the factory invariant.
Final Verdict

Status: ⚠️ Request changes

Minimum required action: preserve or explicitly allow the outer parameters for Map wrapped parameter-dropping aggregates before keeping the strict combined-function assertion.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jun 1, 2026

Copilot AI left a comment

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.

Pull request overview

Replaces a permissive function->getParameters().empty() tolerance in the aggregate function factory's invariant check with an explicit allow-list of known aggregation functions that drop their parameters, making the workaround visible and easier to remove later. Also fixes a minor typo in a comment.

Changes:

  • Introduces a dropsParameters() helper containing an explicit set of four aggregate function names known to drop parameters.
  • Updates two chassert invariant checks in AggregateFunctionFactory::getImpl to use the allow-list instead of accepting any empty-parameter result.
  • Fixes a typo ("even of" → "even if") in FieldVisitorToCastedLiteral.cpp.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/AggregateFunctions/AggregateFunctionFactory.cpp Adds explicit allow-list of parameter-dropping aggregates and tightens invariant checks.
src/Common/FieldVisitorToCastedLiteral.cpp Fixes a typo in a code comment.

@vitlibar
vitlibar force-pushed the explicit-list-of-agg-functions-dropping-params branch 2 times, most recently from 6a1c85f to 21f8d3f Compare June 1, 2026 17:00
@vitlibar
vitlibar force-pushed the explicit-list-of-agg-functions-dropping-params branch from 21f8d3f to 8b889fd Compare June 1, 2026 17:34
@vitlibar
vitlibar force-pushed the explicit-list-of-agg-functions-dropping-params branch from 8b889fd to cfd95ad Compare June 1, 2026 23:35
/// Same invariant as above.
chassert(combined_function && (combined_function->getParameters().empty() || combined_function->getParameters() == parameters),
"function->getParameters() must equal the parameters passed to the factory");
chassert(combined_function && combined_function->getParameters() == parameters,

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.

The new combinator assertion is too strong for Map wrapped aggregates that are on the drop list. For example, groupArrayMovingSumMap(3)(m) goes through the Map combinator with outer parameters == [3]; the nested groupArrayMovingSum is allowed above to return empty getParameters, and AggregateFunctionMap initializes its own parameters from nested->getParameters, so combined_function->getParameters is empty here and this chassert fires in debug/ASan builds for a valid aggregate. Please preserve the outer params in AggregateFunctionMap (or otherwise special-case this explicit drop-list path) before making the combined-function check strict.

@clickhouse-gh

clickhouse-gh Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.40% 84.40% +0.00%
Functions 92.40% 92.40% +0.00%
Branches 77.00% 77.00% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 13/14 (92.86%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@clickhouse-gh

clickhouse-gh Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Dear @vitlibar, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@abashkeev abashkeev added the comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). label Sep 4, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Dear @vitlibar, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-aggregate-functions Aggregate function implementations (sum, avg, count, quantile, combinators, etc.). pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants