-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Support Avg distinct for decimal and float type
#15414
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
| let sum_scalar = self.sum_accumulator.evaluate()?; | ||
|
|
||
| match sum_scalar { | ||
| ScalarValue::Decimal128(Some(sum), _, _) => { |
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.
Even though I prefer a generic solution like
| struct DecimalAvgAccumulator<T: DecimalType + ArrowNumericType + Debug> { |
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; |
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.
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); |
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.
This tests are not reliable as single_distinct_to_groupby is still there
33762e0 to
2ee004d
Compare
|
FYI, the sqlite tests have a number of avg(distinct) queries that will need to be updated. See the README for details. |
|
@qazxcdswe123 - Is there a reason why you closed this issue rather than update the tests? |
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