Skip to content

Commit

Permalink
support group by all. fix #312
Browse files Browse the repository at this point in the history
  • Loading branch information
kitta65 committed Feb 29, 2024
1 parent 9d6c505 commit 281f381
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1685,15 +1685,20 @@ impl Parser {
let mut groupby = self.construct_node(NodeType::GroupByExprs)?;
self.next_token()?; // GROUP -> BY
groupby.push_node("by", self.construct_node(NodeType::Keyword)?);
if self.get_token(1)?.in_(&vec!["ROLLUP", "CUBE"]) {
self.next_token()?; // -> ROLLUP | CUBE
self.next_token()?; // -> ROLLUP | CUBE | GROUPING | ALL | exprs
if self.get_token(0)?.in_(&vec!["ROLLUP", "CUBE"]) {
groupby.push_node_vec("how", self.parse_n_keywords(1)?);
} else if self.get_token(1)?.in_(&vec!["GROUPING"]) {
self.next_token()?; // -> GROUPING
self.next_token()?; // BY -> expr
groupby.push_node_vec("exprs", self.parse_exprs(&vec![], false)?);
} else if self.get_token(0)?.in_(&vec!["GROUPING"]) {
groupby.push_node_vec("how", self.parse_n_keywords(2)?);
self.next_token()?; // BY -> expr
groupby.push_node_vec("exprs", self.parse_exprs(&vec![], false)?);
} else if self.get_token(0)?.in_(&vec!["ALL"]) {
groupby.push_node_vec("how", self.parse_n_keywords(1)?);
} else {
groupby.push_node_vec("exprs", self.parse_exprs(&vec![], false)?);
}
self.next_token()?; // BY -> expr
groupby.push_node_vec("exprs", self.parse_exprs(&vec![], false)?);
node.push_node("groupby", groupby);
}
// HAVING
Expand Down
19 changes: 19 additions & 0 deletions src/parser/tests/tests_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,25 @@ groupby:
how:
- self: GROUPING (Keyword)
- self: SETS (Keyword)
",
0,
)),
Box::new(SuccessTestCase::new(
"SELECT colname FROM tablename GROUP BY ALL",
"\
self: SELECT (SelectStatement)
exprs:
- self: colname (Identifier)
from:
self: FROM (KeywordWithExpr)
expr:
self: tablename (Identifier)
groupby:
self: GROUP (GroupByExprs)
by:
self: BY (Keyword)
how:
- self: ALL (Keyword)
",
0,
)),
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ export type GroupByExprs = BaseNode & {
children: {
by: NodeChild;
how?: NodeVecChild;
exprs: { NodeVec: Expr[] & UnknownNode[] };
exprs?: { NodeVec: Expr[] & UnknownNode[] };
};
};
Expand Down

0 comments on commit 281f381

Please sign in to comment.