Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

DHRUV6029
Copy link

@DHRUV6029 DHRUV6029 commented Nov 30, 2024

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

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

@DHRUV6029 DHRUV6029 requested a review from a team as a code owner November 30, 2024 06:00
Copy link

linux-foundation-easycla bot commented Nov 30, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

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.

1 participant