Skip to content

Fix assertion failure in AggregateFunctionArray with parametric Nothing functions - #100679

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
nerve-bot:fix-aggregate-nothing-params
Mar 29, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
nerve-bot:fix-aggregate-nothing-params

Conversation

@nerve-bot

@nerve-bot nerve-bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix server crash (assertion failure) when using parametric aggregate functions with Array combinator and NULL arguments, such as quantileIfArrayArray(0.5)([[NULL]], [[1]]).

What this PR does

Fixes #100584 — assertion parameters == nested_func->getParameters() failure in AggregateFunctionArray constructor, triggered by the AST fuzzer.

Root cause: AggregateFunctionNothingImpl constructor explicitly discarded all parameters by passing Array() to the base class (line 52 in AggregateFunctionNothing.h). When the Null combinator resolved a parametric function like quantile(0.5) with only-NULL arguments, it created AggregateFunctionNothingNull with the original parameters [0.5] — but those parameters were silently dropped by the constructor.

When an outer combinator (like Array) then wrapped this Nothing function, it passed the original parameters to its own wrapper, but nested_func->getParameters() returned empty — triggering the assertion.

Fix:

  1. AggregateFunctionNothing.h: Preserve parameters through the constructor instead of discarding them. The Nothing functions don't use parameters functionally, but preserving them maintains consistency for combinator chains.
  2. AggregateFunctionFactory.cpp: Pass the original parameters (instead of Array()) when wrapping Nothing functions with combinators, matching the normal code path.

Reproducer (crashes on debug builds without fix):

SELECT quantileIfArrayArray(0.5)([[NULL]], [[1]]);  -- Server crash
SELECT quantileIfArray(0.5)([NULL], [1]);            -- Server crash
SELECT medianIfArrayArray(0.5)([[NULL]], [[1]]);     -- Server crash

🤖 Generated with Claude Code

Version info

  • Merged into: 26.4.1.382

…ng functions

AggregateFunctionNothingImpl constructor was discarding all parameters
by explicitly passing Array() to the base class. When the Null combinator
created a NothingNull function with parameters (e.g. quantile(0.5) resolved
with Nullable(Nothing) arguments), these parameters were lost. Outer
combinator wrappers like Array then received the original parameters but
nested_func->getParameters() returned empty, causing the assertion
`parameters == nested_func->getParameters()` to fail.

The fix preserves parameters through AggregateFunctionNothingImpl
(they are stored but not functionally used) and passes them consistently
in the factory's combinator wrapper path.

Closes ClickHouse#100584

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@nikitamikhaylov nikitamikhaylov added the can be tested Allows running workflows for external contributors label Mar 25, 2026
@clickhouse-gh

clickhouse-gh Bot commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ec89372]

Summary: ✅


AI Review

Summary

This PR fixes an assertion exception in aggregate combinator chains involving parametric functions over all-NULL inputs by preserving parameters in AggregateFunctionNothingImpl and forwarding those parameters through combinator wrapping. The fix is targeted, consistent with the root cause, and backed by a focused stateless regression test. I did not find correctness, safety, or performance issues in the proposed changes.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 25, 2026
…ation

Update 03318_ubsan_resample_arguments_count to expect ILLEGAL_TYPE_OF_ARGUMENT
instead of NUMBER_OF_ARGUMENTS_DOESNT_MATCH. The old error was an artifact of
AggregateFunctionNothing dropping parameters — now that parameters are preserved,
the Resample combinator validates successfully and the real error (Merge suffix
receiving Nullable(Nothing) instead of AggregateFunction) is reported.

Add type-name check to regression test to demonstrate the fix on release builds
(assertions only fire in debug mode, so bugfix validation needs this).
@clickhouse-gh

clickhouse-gh Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.10% +0.00%
Functions 24.60% 24.50% -0.10%
Branches 76.70% 76.60% -0.10%

PR changed lines: PR changed-lines coverage: 100.00% (12/12, 0 noise lines excluded)
Diff coverage report
Uncovered code

@groeneai

Copy link
Copy Markdown
Collaborator

cc @rschu1ze @alexey-milovidov — could you review this? It fixes an assertion failure in AggregateFunctionArray when used with parametric Nothing functions.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the fix is correct. Thank you!

@alexey-milovidov alexey-milovidov self-assigned this Mar 29, 2026
@alexey-milovidov
alexey-milovidov merged commit 86d453b into ClickHouse:master Mar 29, 2026
149 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Assertion `parameters == nested_func->getParameters()' failed (STID: 4870-4e45)

5 participants