Skip to content

fix: Add overflow check to evaluate of sum decimal accumulator #1922

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

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

Conversation

leung-ming
Copy link
Contributor

@leung-ming leung-ming commented Jun 22, 2025

Which issue does this PR close?

Rationale for this change

sum may overflow in merge_batch

What changes are included in this PR?

add overflow check to evaluate

How are these changes tested?

org.apache.comet.exec.CometAggregateSuite

@codecov-commenter
Copy link

codecov-commenter commented Jun 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 58.83%. Comparing base (f09f8af) to head (c7e9053).
Report is 286 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1922      +/-   ##
============================================
+ Coverage     56.12%   58.83%   +2.70%     
- Complexity      976     1141     +165     
============================================
  Files           119      130      +11     
  Lines         11743    12853    +1110     
  Branches       2251     2393     +142     
============================================
+ Hits           6591     7562     +971     
- Misses         4012     4073      +61     
- Partials       1140     1218      +78     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andygrove
Copy link
Member

The CI test failure is unrelated to changes in this PR and is now fixed in main branch

@@ -375,11 +375,17 @@ impl GroupsAccumulator for SumDecimalGroupsAccumulator {
// are null, in this case we'll return null
// 2. if `is_empty` is false, but `null_state` is true, it means there's an overflow. In
// non-ANSI mode Spark returns null.
let result = emit_to.take_needed(&mut self.sum);
result.iter().enumerate().for_each(|(i, &v)| {
Copy link
Contributor

Choose a reason for hiding this comment

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

In what case does this become necessary? decimal overflow is checked in update_batch (via update_single).

Copy link
Contributor Author

@leung-ming leung-ming Jun 25, 2025

Choose a reason for hiding this comment

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

Partial aggregate.
Use the test as example:
When 42 and 9*9 are parted.

part_1.update(42) // ok, 42
part_2.update(9*9) // ok, 9*9
// gather exchange
final.merge(part_1); final.merge(part_2) // overflow without setting nulls
final.evaluate() // overflowed value returned, spark throw

BTW, when 42 and 9*9 are not parted, sum will work, but avg will fail, I am not yet put it to test though.

avg.update(42) // ok, 42
avg.update(9*9) // new_sum overflow, sum is still 42, count is 2 and null bit is set
avg.evaluate() // the evaluate of avg without checking the null bit, yielding 21

There maybe other issues in avg, to be fixed later with #1893

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Thank you for the explanation!

@leung-ming leung-ming changed the title fix: Add overflow check for SumDecimalGroupsAccumulator::evaluate fix: Add overflow check to evaluate of sum decimal accumulator Jun 25, 2025
Copy link
Contributor

@parthchandra parthchandra left a comment

Choose a reason for hiding this comment

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

lgtm. pending ci

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.

4 participants