From 281f381be7b9f0e1a8527933406b12678fb7d385 Mon Sep 17 00:00:00 2001 From: dr666m1 <26474260+kitta65@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:44:44 +0900 Subject: [PATCH] support group by all. fix #312 --- src/parser.rs | 17 +++++++++++------ src/parser/tests/tests_select.rs | 19 +++++++++++++++++++ src/types.rs | 2 +- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 01f7690..c4ec01b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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 diff --git a/src/parser/tests/tests_select.rs b/src/parser/tests/tests_select.rs index a78a4b0..5def164 100644 --- a/src/parser/tests/tests_select.rs +++ b/src/parser/tests/tests_select.rs @@ -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, )), diff --git a/src/types.rs b/src/types.rs index 7124e16..28bcb8d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -867,7 +867,7 @@ export type GroupByExprs = BaseNode & { children: { by: NodeChild; how?: NodeVecChild; - exprs: { NodeVec: Expr[] & UnknownNode[] }; + exprs?: { NodeVec: Expr[] & UnknownNode[] }; }; };