Skip to content

Commit 19b7b3a

Browse files
authored
[improvement](nereids)Support GROUP BY ... WITH ROLLUP syntax (#51948)
### What problem does this PR solve? Support GROUP BY ... WITH ROLLUP syntax mysql> SELECT year, month, SUM(amount) AS total_amount FROM sales GROUP BY year, month WITH ROLLUP order by year desc, month desc; +------+-------+--------------+ | year | month | total_amount | +------+-------+--------------+ | 2024 | 1 | 3400.00 | | 2024 | NULL | 3400.00 | | 2023 | 2 | 4000.00 | | 2023 | 1 | 3000.00 | | 2023 | NULL | 7000.00 | | NULL | NULL | 10400.00 | +------+-------+--------------+ 6 rows in set (0.02 sec)
1 parent f03dc40 commit 19b7b3a

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ groupingElement
12011201
: ROLLUP LEFT_PAREN (expression (COMMA expression)*)? RIGHT_PAREN
12021202
| CUBE LEFT_PAREN (expression (COMMA expression)*)? RIGHT_PAREN
12031203
| GROUPING SETS LEFT_PAREN groupingSet (COMMA groupingSet)* RIGHT_PAREN
1204-
| expression (COMMA expression)*
1204+
| expression (COMMA expression)* (WITH ROLLUP)?
12051205
;
12061206

12071207
groupingSet

regression-test/data/nereids_syntax_p0/grouping_sets.out

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,35 @@
132132
13 0
133133
7 0
134134

135+
-- !select_with_rollup1 --
136+
\N \N 36
137+
2 \N 6
138+
2 0 \N
139+
2 1 6
140+
3 \N 12
141+
3 2 12
142+
4 \N 18
143+
4 0 \N
144+
4 3 18
145+
146+
-- !select_with_rollup2 --
147+
\N 1
148+
2 0
149+
3 0
150+
4 0
151+
152+
-- !select_with_rollup3 --
153+
3 0
154+
8 0
155+
9 0
156+
20 1
157+
158+
-- !select_with_rollup4 --
159+
\N 1
160+
2 0
161+
3 0
162+
4 0
163+
135164
-- !select --
136165
\N \N 36
137166
\N 0 \N

regression-test/suites/nereids_syntax_p0/grouping_sets.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ suite("test_nereids_grouping_sets") {
110110
order_qt_select "select sum(k2+1), grouping_id(k1+1) from groupingSetsTable group by grouping sets((k1+1)) having (k1+1) > 1;";
111111
order_qt_select "select sum(k2+1), grouping_id(k1+1) from groupingSetsTable group by grouping sets((k1+1), (k1)) having (k1+1) > 1;";
112112

113+
// with rollup
114+
qt_select_with_rollup1 """
115+
select (k1 + 1) k1_, k2, sum(k3) from groupingSetsTable group by
116+
k1_, k2 with rollup order by k1_, k2
117+
"""
118+
qt_select_with_rollup2 "select k1+1, grouping(k1+1) from groupingSetsTable group by (k1+1) with rollup order by k1+1;";
119+
qt_select_with_rollup3 "select sum(k2), grouping(k1+1) from groupingSetsTable group by k1+1 with rollup order by sum(k2)"
120+
qt_select_with_rollup4 "select k1+1, grouping_id(k1) from groupingSetsTable group by k1 with rollup order by k1+1;"
121+
113122
// old grouping sets
114123
qt_select """
115124
SELECT k1, k2, SUM(k3) FROM groupingSetsTable

0 commit comments

Comments
 (0)