-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
base: main
Are you sure you want to change the base?
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
@@ -6686,3 +6688,35 @@ SELECT a, median(b), arrow_typeof(median(b)) FROM group_median_all_nulls GROUP B | |||
---- | |||
group0 NULL Int32 | |||
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. |
Which issue does this PR close?
float64
type #15413avg(distinct)
support #2408Rationale for this change
float64
type #15413, SHOULD MERGE THAT FIRSTDistinctSumAccumulator
to calculate decimalWhat changes are included in this PR?
float64
type #15413 andDecimalDistinctAvgAccumulator
implematation usingDistinctSumAccumulator
single_distinct_to_groupby
rule have not been rm, sqllogictest is not accurate so I added tests indecimal.rs
Are these changes tested?
Yes, sqllogictest and rust tests
Are there any user-facing changes?
No