-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add returnsZeroOnEmptyInput to AggregationFunctionMetadata #17963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add returnsZeroOnEmptyInput to AggregationFunctionMetadata #17963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % but I would wait for @dain review too
COUNT, COUNT_IF, and APPROX_DISTINCT do have not standard behavior when no input was supplied to the function. They return the value 0, as opposed to standard NULL. Before this change, OptimizeMixedDistinctAggregations relied on matching string function name to handle this case, but this is brittle and may cause silent correctness issues if a new function with this characteristic is added.
f958e07
to
2195285
Compare
I rebased on the master and dropped the first commit with tests that landed there |
I’m not sure this is the right abstraction. There’s nothing standard about returning 0 on empty input. What would that property mean for a function that does not return a number but returns, say, an empty array or map on no input? |
Without changes to the |
I understand that, and it’s fine for the optimization to be targeted at functions that return 0 on no input. I’m not sure it should be a generic attribute for every aggregation, unless we can generalize it to aggregations that don’t return numbers. |
Generalization would overcomplicate things and be hard to test, so I wouldn't introduce it until needed.
? |
As @martint does not agree it's a good approach, I'm closing the PR |
Description
COUNT
,COUNT_IF
, andAPPROX_DISTINCT
do have not standardbehavior when no input was supplied to the function.
They return the value 0, as opposed to standard
NULL
.Before this change,
OptimizeMixedDistinctAggregations
relied onmatching string function name to handle this case, but
this is brittle and may cause silent correctness issues
if a new function with this characteristic is added.
Additional context and related issues
Release notes
( X) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: