Skip to content

Commit 72a8f3e

Browse files
authored
Merge #101: support GROUP BY ALL in BigQuery
support GROUP BY ALL in BigQuery
2 parents 3264604 + ca75e8d commit 72a8f3e

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sql-parser-cst",
33
"description": "Parses SQL into Concrete Syntax Tree (CST)",
44
"license": "GPL-2.0-or-later",
5-
"version": "0.31.1",
5+
"version": "0.32.0",
66
"main": "lib/main.js",
77
"types": "lib/main.d.ts",
88
"repository": {

src/cst/Select.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export type AllSelectNodes =
4444
| GroupByRollup
4545
| GroupByCube
4646
| GroupByGroupingSets
47+
| GroupByAll
4748
| HavingClause
4849
| WindowClause
4950
| QualifyClause
@@ -276,7 +277,12 @@ export interface GroupByClause extends BaseNode {
276277
withRollupKw?: [Keyword<"WITH">, Keyword<"ROLLUP">]; // MySQL, MariaDB
277278
}
278279

279-
type GroupingElement = Expr | GroupByRollup | GroupByCube | GroupByGroupingSets;
280+
type GroupingElement =
281+
| Expr
282+
| GroupByRollup
283+
| GroupByCube
284+
| GroupByGroupingSets
285+
| GroupByAll;
280286

281287
// BigQuery, PostgreSQL
282288
export interface GroupByRollup extends BaseNode {
@@ -292,6 +298,12 @@ export interface GroupByCube extends BaseNode {
292298
columns: ParenExpr<ListExpr<Expr>>;
293299
}
294300

301+
// BigQuery
302+
export interface GroupByAll extends BaseNode {
303+
type: "group_by_all";
304+
allKw: Keyword<"ALL">;
305+
}
306+
295307
// PostgreSQL
296308
export interface GroupByGroupingSets extends BaseNode {
297309
type: "group_by_grouping_sets";

src/parser.pegjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ grouping_element
913913
= group_by_rollup
914914
/ group_by_cube
915915
/ group_by_grouping_sets
916+
/ group_by_all &bigquery
916917
/ paren$empty_list
917918
/ expr
918919

@@ -943,6 +944,14 @@ group_by_grouping_sets
943944
});
944945
}
945946

947+
group_by_all
948+
= kw:ALL {
949+
return loc({
950+
type: "group_by_all",
951+
allKw: read(kw),
952+
});
953+
}
954+
946955
/**
947956
* SELECT .. HAVING
948957
* --------------------------------------------------------------------------------------

src/showNode/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const selectMap: FullTransformMap<string, AllSelectNodes> = {
104104
group_by_rollup: (node) => show([node.rollupKw, node.columns]),
105105
group_by_cube: (node) => show([node.cubeKw, node.columns]),
106106
group_by_grouping_sets: (node) => show([node.groupingSetsKw, node.columns]),
107+
group_by_all: (node) => show([node.allKw]),
107108
having_clause: (node) => show([node.havingKw, node.expr]),
108109
qualify_clause: (node) => show([node.qualifyKw, node.expr]),
109110
order_by_clause: (node) =>

test/select/group_by.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ describe("select GROUP BY", () => {
2020
});
2121
});
2222

23+
dialect(["bigquery"], () => {
24+
it("supports GROUP BY ALL", () => {
25+
testClauseWc("GROUP BY ALL");
26+
});
27+
});
28+
2329
dialect(["bigquery", "postgresql"], () => {
2430
it("supports GROUP BY ROLLUP()", () => {
2531
testClauseWc("GROUP BY ROLLUP ( id, name + age )");

0 commit comments

Comments
 (0)