Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions be/src/exprs/aggregate/aggregate_function_avg.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ struct AggregateFunctionAvgData {
// null is handled in AggregationNode::_get_without_key_result
return static_cast<ResultT>(sum);
}
// to keep the same result with row vesion; see AggregateFunctions::decimalv2_avg_get_value
// DecimalV2 has fixed internal scale=9; its arithmetic operators already
// handle scale correctly, so no external multiplier is needed.
if constexpr (T == TYPE_DECIMALV2 && IsDecimalV2<ResultT>) {
DecimalV2Value decimal_val_count(count, 0);
DecimalV2Value decimal_val_sum(sum * multiplier);
DecimalV2Value cal_ret = decimal_val_sum / decimal_val_count;
DecimalV2Value cal_ret = sum / decimal_val_count;
return cal_ret;
} else {
if constexpr (T == TYPE_DECIMAL256) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@
-- !decimalv2_sum2 --
1000000000000000000.000000000

-- !decimalv2_avg_scale0_groupby --
-1.000000000
-1000000000.000000000
-1111111111.000000000
-1234567890.000000000
-9999999999.000000000
0E-9
1.000000000
1000000000.000000000
1111111111.000000000
1234567890.000000000
9999999999.000000000

-- !decimalv2_avg_scale0_all --
0E-9

Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,36 @@ suite("test_decimalv2_agg", "nonConcurrent") {
"""
qt_decimalv2_sum2 " select sum(k1) from test_decimalv2_agg; "

// test avg on decimalv2(10,0) with group by - scale 0 regression
sql """
drop table if exists test_decimalv2_avg_scale0;
"""
sql """
create table test_decimalv2_avg_scale0 (
id int,
data decimalv2(10,0) not null
) distributed by hash(id) buckets 1
properties("replication_num"="1");
"""
sql """
insert into test_decimalv2_avg_scale0 values
(0, 1234567890),
(1, 9999999999),
(2, 1000000000),
(3, 1111111111),
(4, -1234567890),
(5, -9999999999),
(6, -1000000000),
(7, -1111111111),
(8, 1),
(9, 0),
(10, -1);
"""
order_qt_decimalv2_avg_scale0_groupby """
select avg(data) from test_decimalv2_avg_scale0 group by data;
"""
qt_decimalv2_avg_scale0_all """
select avg(data) from test_decimalv2_avg_scale0;
"""

}
Loading