-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Added Sum_IF() aggregate function #24174
base: master
Are you sure you want to change the base?
Conversation
In Contributor checklist I see that
is checked, but there is no documentation for this new function. Please add documentation for this new function, possibly in this file: https://github.com/prestodb/presto/blob/master/presto-docs/src/main/sphinx/functions/aggregate.rst. |
@steveburnett @elharo I have added the documentation for the function , can you please review it. |
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! (docs)
Pull branch, local doc build, looks good. Thanks!
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.
It looks like there is also a RealSumAggregation
function. Just to be complete, can we also add a version which supports the Real
type?
Description
Add new aggregate function sum_if(x, y) and sum_if(x, y, n) that returns the sum of values matching a condition. This provides a more concise way to write conditional sums without using CASE expressions.
Motivation and Context
Currently, to sum values conditionally, users need to write verbose CASE expressions like sum(CASE WHEN x THEN y END). The new sum_if function provides a cleaner, more readable alternative similar to the existing count_if function. This also aligns with common SQL developer requests for simplified conditional aggregations.
Issue/Feature Request #19060
Impact
Adds new SQL aggregate function sum_if
No breaking changes to existing functionality
Improves SQL readability for conditional sum operations
Test Plan
Added unit tests for basic functionality
Added tests for null handling
Added tests for default value parameter
Added tests for various data types
Added tests for edge cases (empty sets, all nulls)
Added integration tests with real data scenarios
Contributor checklist