Uh oh!
There was an error while loading. Please reload this page.
Support Avg distinct for decimal and float type - #15414
Closed
qazxcdswe123 wants to merge 7 commits into
Closed
Conversation
| let sum_scalar = self.sum_accumulator.evaluate()?; | ||
| match sum_scalar { | ||
| ScalarValue::Decimal128(Some(sum), _, _) => { |
ContributorAuthor
There was a problem hiding this comment.
Even though I prefer a generic solution like
I couldn't find a way to convert ScalarValue to Primitive.
And I also think this solution is acceptable
| )?; | ||
| // `distinct_count` returns `u64`, but `avg` expects `i256` | ||
| // first convert `u64` to `i128`, then convert `i128` to `i256` to avoid overflow | ||
| let distinct_cnt: i128 = self.sum_accumulator.distinct_count() as i128; |
ContributorAuthor
There was a problem hiding this comment.
this is awkward but can prevent overflow
| group1 NULL Int32 | ||
| statement ok | ||
| create table t_decimal (c decimal(10, 4)) as values (100.00), (125.00), (175.00), (200.00), (200.00), (300.00), (null), (null); |
ContributorAuthor
There was a problem hiding this comment.
This tests are not reliable as single_distinct_to_groupby is still there
qazxcdswe123force-pushed
the
avg-distinct-all
branch
from
March 25, 2025 13:54
33762e0 to
2ee004dCompareOmega359
commented
Mar 25, 2025
Contributor
FYI, the sqlite tests have a number of avg(distinct) queries that will need to be updated. See the README for details. |
alamb
marked this pull request as draft
March 25, 2025 20:30
Omega359
commented
May 23, 2025
Contributor
@qazxcdswe123 - Is there a reason why you closed this issue rather than update the tests? |
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 freeto 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?
float64type #15413avg(distinct)support #2408Rationale for this change
float64type #15413, SHOULD MERGE THAT FIRSTDistinctSumAccumulatorto calculate decimalWhat changes are included in this PR?
float64type #15413 andDecimalDistinctAvgAccumulatorimplematation usingDistinctSumAccumulatorsingle_distinct_to_groupbyrule have not been rm, sqllogictest is not accurate so I added tests indecimal.rsAre these changes tested?
Yes, sqllogictest and rust tests
Are there any user-facing changes?
No