@@ -1427,7 +1427,7 @@ NULL Null
14271427statement ok
14281428create table t(c decimal(10, 4)) as values (0.0001), (0.0002), (0.0003), (0.0004), (0.0005), (0.0006);
14291429
1430- query LT
1430+ query RT
14311431select median(c), arrow_typeof(median(c)) from t;
14321432----
143314330.0003 Decimal128(10, 4)
@@ -1444,7 +1444,7 @@ drop table t;
14441444statement ok
14451445create table t(c decimal(10, 4)) as values (0.0001), (null), (0.0003), (0.0004), (0.0005);
14461446
1447- query LT
1447+ query RT
14481448select median(c), arrow_typeof(median(c)) from t;
14491449----
145014500.0003 Decimal128(10, 4)
@@ -1456,7 +1456,7 @@ drop table t;
14561456statement ok
14571457create table t(c decimal(10, 4)) as values (null), (null), (null);
14581458
1459- query LT
1459+ query RT
14601460select median(c), arrow_typeof(median(c)) from t;
14611461----
14621462NULL Decimal128(10, 4)
@@ -1540,7 +1540,7 @@ drop table t;
15401540statement ok
15411541create table t(c decimal(10, 4)) as values (0.0001), (0.0001), (0.0001), (0.0001), (0.0002), (0.0002), (0.0003), (0.0003);
15421542
1543- query L
1543+ query R
15441544select median(distinct c) from t;
15451545----
154615460.0002
@@ -1552,7 +1552,7 @@ drop table t;
15521552statement ok
15531553create table t(c decimal(10, 4)) as values (0.0001), (0.0001), (0.0001), (null), (null), (0.0002), (0.0003), (0.0003);
15541554
1555- query L
1555+ query R
15561556select median(distinct c) from t;
15571557----
155815580.0002
@@ -3291,7 +3291,7 @@ select avg(c1) from test
32913291statement ok
32923292create table t (c1 decimal(10, 0)) as values (1), (2), (3), (4), (5), (6);
32933293
3294- query LT
3294+ query RT
32953295select avg(c1), arrow_typeof(avg(c1)) from t;
32963296----
329732973.5 Decimal128(14, 4)
@@ -3303,7 +3303,7 @@ drop table t;
33033303statement ok
33043304create table t (c1 decimal(10, 0)) as values (1), (NULL), (3), (4), (5);
33053305
3306- query LT
3306+ query RT
33073307select avg(c1), arrow_typeof(avg(c1)) from t;
33083308----
330933093.25 Decimal128(14, 4)
@@ -3315,7 +3315,7 @@ drop table t;
33153315statement ok
33163316create table t (c1 decimal(10, 0)) as values (NULL), (NULL), (NULL), (NULL), (NULL), (NULL);
33173317
3318- query LT
3318+ query RT
33193319select avg(c1), arrow_typeof(avg(c1)) from t;
33203320----
33213321NULL Decimal128(14, 4)
@@ -4019,7 +4019,7 @@ drop table t;
40194019statement ok
40204020create table t (c decimal(35, 0)) as values (1), (2), (1), (3), (null), (null), (3), (-2);
40214021
4022- query LT
4022+ query RT
40234023select sum(distinct c), arrow_typeof(sum(distinct c)) from t;
40244024----
402540254 Decimal128(38, 0)
@@ -4983,7 +4983,7 @@ CREATE TABLE decimals (value DECIMAL(10, 2));
49834983statement ok
49844984INSERT INTO decimals VALUES (123.0001), (124.00);
49854985
4986- query LL
4986+ query RR
49874987SELECT MIN(value), MAX(value) FROM decimals;
49884988----
49894989123 124
@@ -4997,7 +4997,7 @@ CREATE TABLE decimals_batch (value DECIMAL(10, 0));
49974997statement ok
49984998INSERT INTO decimals_batch VALUES (1), (2), (3), (4), (5);
49994999
5000- query LL
5000+ query RR
50015001SELECT MIN(value), MAX(value) FROM decimals_batch;
50025002----
500350031 5
@@ -5008,7 +5008,7 @@ DROP TABLE decimals_batch;
50085008statement ok
50095009CREATE TABLE decimals_empty (value DECIMAL(10, 0));
50105010
5011- query LL
5011+ query RR
50125012SELECT MIN(value), MAX(value) FROM decimals_empty;
50135013----
50145014NULL NULL
@@ -5023,7 +5023,7 @@ CREATE TABLE decimals_all_nulls (value DECIMAL(10, 0));
50235023statement ok
50245024INSERT INTO decimals_all_nulls VALUES (NULL), (NULL), (NULL), (NULL), (NULL), (NULL);
50255025
5026- query LL
5026+ query RR
50275027SELECT MIN(value), MAX(value) FROM decimals_all_nulls;
50285028----
50295029NULL NULL
@@ -5038,7 +5038,7 @@ CREATE TABLE decimals_with_nulls (value DECIMAL(10, 0));
50385038statement ok
50395039INSERT INTO decimals_with_nulls VALUES (1), (NULL), (3), (4), (5);
50405040
5041- query LL
5041+ query RR
50425042SELECT MIN(value), MAX(value) FROM decimals_with_nulls;
50435043----
504450441 5
@@ -5052,7 +5052,7 @@ CREATE TABLE decimals_error (value DECIMAL(10, 2));
50525052statement ok
50535053INSERT INTO decimals_error VALUES (123.00), (arrow_cast(124.001, 'Decimal128(10, 3)'));
50545054
5055- query LL
5055+ query RR
50565056SELECT MIN(value), MAX(value) FROM decimals_error;
50575057----
50585058123 124
@@ -5066,7 +5066,7 @@ CREATE TABLE decimals_agg (value DECIMAL(10, 0));
50665066statement ok
50675067INSERT INTO decimals_agg VALUES (1), (2), (3), (4), (5);
50685068
5069- query LL
5069+ query RR
50705070SELECT MIN(value), MAX(value) FROM decimals_agg;
50715071----
507250721 5
@@ -6202,7 +6202,7 @@ select approx_median(a) from (select 1 as a where 1=0);
62026202NULL
62036203
62046204# aggregate_decimal_sum
6205- query LT
6205+ query RT
62066206select sum(c1), arrow_typeof(sum(c1)) from d_table;
62076207----
62086208100 Decimal128(20, 3)
@@ -6211,7 +6211,7 @@ select sum(c1), arrow_typeof(sum(c1)) from d_table;
62116211statement ok
62126212create table t (c decimal(35, 3)) as values (10), (null), (20);
62136213
6214- query LT
6214+ query RT
62156215select sum(c), arrow_typeof(sum(c)) from t;
62166216----
6217621730 Decimal128(38, 3)
@@ -6235,7 +6235,7 @@ drop table t;
62356235statement ok
62366236create table t (c1 decimal(10, 0), c2 int) as values (null, null), (null, null), (null, null);
62376237
6238- query LTIT
6238+ query RTIT
62396239select
62406240 sum(c1), arrow_typeof(sum(c1)),
62416241 sum(c2), arrow_typeof(sum(c2))
@@ -6282,20 +6282,20 @@ select sum(c), arrow_typeof(sum(c)) from t;
62826282statement ok
62836283drop table t;
62846284
6285- query TLT
6285+ query TRT
62866286select c2, sum(c1), arrow_typeof(sum(c1)) from d_table GROUP BY c2 ORDER BY c2;
62876287----
62886288A 1100.045 Decimal128(20, 3)
62896289B -1000.045 Decimal128(20, 3)
62906290
62916291
62926292# aggregate_decimal_avg
6293- query LT
6293+ query RT
62946294select avg(c1), arrow_typeof(avg(c1)) from d_table
62956295----
629662965 Decimal128(14, 7)
62976297
6298- query TLT
6298+ query TRT
62996299select c2, avg(c1), arrow_typeof(avg(c1)) from d_table GROUP BY c2 ORDER BY c2
63006300----
63016301A 110.0045 Decimal128(14, 7)
@@ -6468,15 +6468,15 @@ statement ok
64686468INSERT INTO test_decimal_table VALUES (1, 10.10, 100.1, NULL), (1, 20.20, 200.2, NULL), (2, 10.10, 700.1, NULL), (2, 20.20, 700.1, NULL), (3, 10.1, 100.1, NULL), (3, 10.1, NULL, NULL)
64696469
64706470# aggregate_decimal_with_group_by
6471- query IILLLLIILL rowsort
6471+ query IIRRRRIIRR rowsort
64726472select c1, count(c2), avg(c2), sum(c2), min(c2), max(c2), count(c3), count(c4), sum(c4), avg(c4) from test_decimal_table group by c1
64736473----
647464741 2 15.15 30.3 10.1 20.2 2 0 NULL NULL
647564752 2 15.15 30.3 10.1 20.2 2 0 NULL NULL
647664763 2 10.1 20.2 10.1 10.1 1 0 NULL NULL
64776477
64786478# aggregate_decimal_with_group_by_decimal
6479- query LILLLLIL rowsort
6479+ query RIRRRRIR rowsort
64806480select c3, count(c2), avg(c2), sum(c2), min(c2), max(c2), count(c4), sum(c4) from test_decimal_table group by c3
64816481----
64826482100.1 2 10.1 20.2 10.1 10.1 0 NULL
@@ -8519,14 +8519,14 @@ group0 NaN
85198519group1 NaN
85208520
85218521# group median decimal128 non-nullable
8522- query TL rowsort
8522+ query TR rowsort
85238523SELECT col_group, median(col_decimal128) FROM group_median_table_non_nullable GROUP BY col_group
85248524----
85258525group0 0.0002
85268526group1 0.0003
85278527
85288528# group median decimal256 non-nullable
8529- query TL rowsort
8529+ query TR rowsort
85308530SELECT col_group, median(col_decimal256) FROM group_median_table_non_nullable GROUP BY col_group
85318531----
85328532group0 0.0002
@@ -8610,14 +8610,14 @@ group0 NaN
86108610group1 NaN
86118611
86128612# group median decimal128 nullable
8613- query TL rowsort
8613+ query TR rowsort
86148614SELECT col_group, median(col_decimal128) FROM group_median_table_nullable GROUP BY col_group
86158615----
86168616group0 0.0002
86178617group1 0.0003
86188618
86198619# group median decimal256 nullable
8620- query TL rowsort
8620+ query TR rowsort
86218621SELECT col_group, median(col_decimal256) FROM group_median_table_nullable GROUP BY col_group
86228622----
86238623group0 0.0002
@@ -8646,7 +8646,7 @@ statement ok
86468646create table t_decimal (c decimal(10, 4)) as values (100.00), (125.00), (175.00), (200.00), (200.00), (300.00), (null), (null);
86478647
86488648# Test avg_distinct for Decimal128
8649- query LT
8649+ query RT
86508650select avg(distinct c), arrow_typeof(avg(distinct c)) from t_decimal;
86518651----
86528652180 Decimal128(14, 8)
@@ -8666,7 +8666,7 @@ create table t_decimal256 (c decimal(50, 2)) as values
86668666 (null),
86678667 (null);
86688668
8669- query LT
8669+ query RT
86708670select avg(distinct c), arrow_typeof(avg(distinct c)) from t_decimal256;
86718671----
86728672180 Decimal256(54, 6)
@@ -8810,7 +8810,7 @@ create table distinct_avg (a int, b double, c decimal(10, 4), d decimal(50, 2))
88108810;
88118811
88128812# Need two columns to ensure single_distinct_to_group_by rule doesn't kick in, so we know our actual avg(distinct) code is being tested
8813- query RTRTLTLTRRLL
8813+ query RTRTRTRTRRRR
88148814select
88158815 avg(distinct a),
88168816 arrow_typeof(avg(distinct a)),
@@ -8828,7 +8828,7 @@ from distinct_avg;
88288828----
882988293 Float64 37.4255 Float64 698.56005 Decimal128(14, 8) 15041.868333 Decimal256(54, 6) 4 56.52525 957.11074444 1272562.81625
88308830
8831- query RRLL rowsort
8831+ query RRRR rowsort
88328832select
88338833 avg(distinct a),
88348834 avg(distinct b),
@@ -8843,7 +8843,7 @@ group by b;
884388435 100.5 -49.5781 0.333333
884488445 44.112 -132.12 NULL
88458845
8846- query RRLL
8846+ query RRRR
88478847select
88488848 avg(distinct a),
88498849 avg(distinct b),
0 commit comments