Skip to content

[CALCITE-7863] AggregateReduceFunctionsOnGroupKeysRule fails for constant aggregates on empty input - #5336

Draft
xiedeyantu wants to merge 5 commits into
apache:mainfrom
xiedeyantu:CALCITE-7863
Draft

xiedeyantu wants to merge 5 commits into
apache:mainfrom
xiedeyantu:CALCITE-7863

Conversation

@xiedeyantu

Copy link
Copy Markdown
Member

Jira Link

CALCITE-7863

Changes Proposed

See CALCITE-7863

if (!Aggregate.isSimple(aggregate)) {
return null;
}
// A global aggregate may return NULL on empty input even when its

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.

Aggregate functions don't always return NULL on empty input. For example COUNT returns 0.

Is there an interface on SqlFunction that reports the value an aggregate function returns on empty input?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The current rule only supports the MIN, MAX, AVG, and ANY_VALUE aggregate functions, so I don't think the current fix leaves any issues unresolved. Perhaps we could also support COUNT through a special rewrite, but I haven't come up with an efficient approach yet.
I'm not sure if this addresses your concerns. I've added some tests, and I'd appreciate it if you could take another look when you have time.

@xiedeyantu
xiedeyantu marked this pull request as draft October 19, 2026 09:48
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants