-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[bugfix] Fix SUM arithmetic rewrite under null handling #17338
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
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #17338 +/- ##
============================================
- Coverage 63.28% 63.24% -0.04%
Complexity 1474 1474
============================================
Files 3135 3139 +4
Lines 186477 187184 +707
Branches 28495 28652 +157
============================================
+ Hits 118006 118390 +384
- Misses 59357 59635 +278
- Partials 9114 9159 +45
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
6a097a9 to
8686ef3
Compare
Jackie-Jiang
left a comment
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.
Can we always rewrite it to count(column)? When null handling is not enabled, IIRC this will be processed as count(*)
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.
Pull request overview
This PR fixes a bug in the AggregationOptimizer where SUM aggregation rewrites were using count(1) instead of count(column), causing incorrect results when null handling is enabled. The fix ensures that when null handling is enabled, the optimizer correctly uses count(column) to preserve semantics for nullable columns.
Key Changes:
- Modified
AggregationOptimizerto usecount(column)instead ofcount(1)in SUM rewrites - Updated all helper methods to pass column expressions to count operations
- Added comprehensive test coverage for null handling scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
AggregationOptimizer.java |
Changed SUM rewrite logic to use count(column) instead of count(1), removed createCountOneExpression() method |
AggregationOptimizerTest.java |
Added test setup/teardown, new null handling tests, and updated all verification helpers to check for count(column) |
pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/AggregationOptimizerTest.java
Outdated
Show resolved
Hide resolved
pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/AggregationOptimizerTest.java
Outdated
Show resolved
Hide resolved
pinot-common/src/test/java/org/apache/pinot/sql/parsers/rewriter/AggregationOptimizerTest.java
Outdated
Show resolved
Hide resolved
done |
Jackie-Jiang
left a comment
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.
Please check if Calcite has rule with similar optimization. We need to ensure the rewrite is semantically identical
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.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| PinotQuery pinotQuery = new PinotQuery(); | ||
| pinotQuery.setSelectList(new ArrayList<>(Collections.singletonList(expression))); | ||
| return pinotQuery; | ||
| assertEquals(multiplicationFunction.getOperator().toLowerCase(), "times"); |
Copilot
AI
Dec 10, 2025
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.
The test is checking for a lowercase version of the operator name, but other tests in this file use exact string matching without case normalization. This introduces inconsistency. Consider using the exact operator name as returned by the parser or normalizing all operator comparisons consistently throughout the test class.
| assertEquals(multiplicationFunction.getOperator().toLowerCase(), "times"); | |
| assertEquals(multiplicationFunction.getOperator(), "times"); |
Summary