fix: Address avg return type overflow for decimals - #24371
Merged
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24371 +/- ##
==========================================
- Coverage 81.51% 81.51% -0.01%
==========================================
Files 1123 1123
Lines 405139 405235 +96
Branches 405139 405235 +96
==========================================
+ Hits 330242 330308 +66
- Misses 55568 55578 +10
- Partials 19329 19349 +20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
AdamGS
force-pushed
the
adamg/fix-24369
branch
from
August 24, 2026 17:55
04170e6 to
cecda08
Compare
AdamGS
marked this pull request as ready for review
August 24, 2026 18:51
kosiew
approved these changes
Aug 27, 2026
| 32768.5 Decimal32(9, 4) 32768.5 | ||
| 32768.5 Decimal64(13, 4) 32768.5 | ||
|
|
||
| # TPC-DS `store_returns.sr_return_amt` is Decimal32(7, 2). Its average needs |
Contributor
There was a problem hiding this comment.
Could we add a small GROUP BY SQLLogicTest using Decimal32(7, 2) and assert that the result type is Decimal64(11, 6)? The unit tests already exercise the grouped state conversion, but an end-to-end grouped query would also verify that the planner selects the groups accumulator and that it produces the widened Arrow output type.
Signed-off-by: Adam Gutglick <adamgsal@gmail.com>
AdamGS
force-pushed
the
adamg/fix-24369
branch
from
August 29, 2026 08:11
cecda08 to
5550865
Compare
Contributor
Author
|
@kosiew thank you for the quick review! |
Contributor
|
🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
avg(decimal)might lose precision and cause an overflow over return type #24369Rationale for this change
AVG(Decimal(p, s))derives a result with precision and scale increased by four. For example, AVG(Decimal32(9, 0)) returned Decimal32(9, 4), although the rescaled average can require 13 digits.This caused valid averages near the input precision limit to fail with an overflow even though Decimal64(13, 4) can represent the result.
What changes are included in this PR?
Are these changes tested?
Regression tests and adjusted SLT-based tests.
Are there any user-facing changes?
Yes. The Arrow result type of AVG(decimal) may now be wider when the derived precision does not fit the input variant.