Skip to content

Commit f7d48b9

Browse files
author
Dairyo Sekine
committed
support new grouping features
1 parent 3e88e07 commit f7d48b9

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

src/parser.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,13 @@ impl Parser {
16711671
let mut groupby = self.construct_node(NodeType::XXXByExprs)?;
16721672
self.next_token()?; // GROUP -> BY
16731673
groupby.push_node("by", self.construct_node(NodeType::Keyword)?);
1674+
if self.get_token(1)?.in_(&vec!["ROLLUP", "CUBE"]) {
1675+
self.next_token()?; // -> ROLLUP | CUBE
1676+
groupby.push_node_vec("how", self.parse_n_keywords(1)?);
1677+
} else if self.get_token(1)?.in_(&vec!["GROUPING"]) {
1678+
self.next_token()?; // -> GROUPING
1679+
groupby.push_node_vec("how", self.parse_n_keywords(2)?);
1680+
}
16741681
self.next_token()?; // BY -> expr
16751682
groupby.push_node_vec("exprs", self.parse_exprs(&vec![], false)?);
16761683
node.push_node("groupby", groupby);

src/parser/tests/tests_select.rs

+49-6
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,6 @@ groupby:
20622062
",
20632063
0,
20642064
)),
2065-
// NOTE ROLLUP is not a function but it is OK
20662065
Box::new(SuccessTestCase::new(
20672066
"\
20682067
SELECT x, SUM(y) FROM t GROUP BY ROLLUP(x)
@@ -2089,13 +2088,57 @@ groupby:
20892088
by:
20902089
self: BY (Keyword)
20912090
exprs:
2092-
- self: ( (CallingFunction)
2093-
args:
2094-
- self: x (Identifier)
2095-
func:
2096-
self: ROLLUP (Identifier)
2091+
- self: ( (GroupedExpr)
2092+
expr:
2093+
self: x (Identifier)
2094+
rparen:
2095+
self: ) (Symbol)
2096+
how:
2097+
- self: ROLLUP (Keyword)
2098+
",
2099+
0,
2100+
)),
2101+
// CUBE() may be not a function but it's OK
2102+
Box::new(SuccessTestCase::new(
2103+
"\
2104+
SELECT count(*) FROM t GROUP BY GROUPING SETS (a, CUBE(b))
2105+
",
2106+
"\
2107+
self: SELECT (SelectStatement)
2108+
exprs:
2109+
- self: ( (CallingFunction)
2110+
args:
2111+
- self: * (Asterisk)
2112+
func:
2113+
self: count (Identifier)
2114+
rparen:
2115+
self: ) (Symbol)
2116+
from:
2117+
self: FROM (KeywordWithExpr)
2118+
expr:
2119+
self: t (Identifier)
2120+
groupby:
2121+
self: GROUP (XXXByExprs)
2122+
by:
2123+
self: BY (Keyword)
2124+
exprs:
2125+
- self: ( (StructLiteral)
2126+
exprs:
2127+
- self: a (Identifier)
2128+
comma:
2129+
self: , (Symbol)
2130+
- self: ( (CallingFunction)
2131+
args:
2132+
- self: b (Identifier)
2133+
func:
2134+
self: CUBE (Identifier)
2135+
rparen:
2136+
self: ) (Symbol)
20972137
rparen:
20982138
self: ) (Symbol)
2139+
how:
2140+
- self: GROUPING (Keyword)
2141+
- self: SETS (Keyword)
20992142
",
21002143
0,
21012144
)),

0 commit comments

Comments
 (0)