Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support GROUP BY ALL in BigQuery #101

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sql-parser-cst",
"description": "Parses SQL into Concrete Syntax Tree (CST)",
"license": "GPL-2.0-or-later",
"version": "0.31.1",
"version": "0.32.0",
"main": "lib/main.js",
"types": "lib/main.d.ts",
"repository": {
Expand Down
14 changes: 13 additions & 1 deletion src/cst/Select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export type AllSelectNodes =
| GroupByRollup
| GroupByCube
| GroupByGroupingSets
| GroupByAll
| HavingClause
| WindowClause
| QualifyClause
Expand Down Expand Up @@ -276,7 +277,12 @@ export interface GroupByClause extends BaseNode {
withRollupKw?: [Keyword<"WITH">, Keyword<"ROLLUP">]; // MySQL, MariaDB
}

type GroupingElement = Expr | GroupByRollup | GroupByCube | GroupByGroupingSets;
type GroupingElement =
| Expr
| GroupByRollup
| GroupByCube
| GroupByGroupingSets
| GroupByAll;

// BigQuery, PostgreSQL
export interface GroupByRollup extends BaseNode {
Expand All @@ -292,6 +298,12 @@ export interface GroupByCube extends BaseNode {
columns: ParenExpr<ListExpr<Expr>>;
}

// BigQuery
export interface GroupByAll extends BaseNode {
type: "group_by_all";
allKw: Keyword<"ALL">;
}

// PostgreSQL
export interface GroupByGroupingSets extends BaseNode {
type: "group_by_grouping_sets";
Expand Down
9 changes: 9 additions & 0 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ grouping_element
= group_by_rollup
/ group_by_cube
/ group_by_grouping_sets
/ group_by_all &bigquery
/ paren$empty_list
/ expr

Expand Down Expand Up @@ -943,6 +944,14 @@ group_by_grouping_sets
});
}

group_by_all
= kw:ALL {
return loc({
type: "group_by_all",
allKw: read(kw),
});
}

/**
* SELECT .. HAVING
* --------------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/showNode/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const selectMap: FullTransformMap<string, AllSelectNodes> = {
group_by_rollup: (node) => show([node.rollupKw, node.columns]),
group_by_cube: (node) => show([node.cubeKw, node.columns]),
group_by_grouping_sets: (node) => show([node.groupingSetsKw, node.columns]),
group_by_all: (node) => show([node.allKw]),
having_clause: (node) => show([node.havingKw, node.expr]),
qualify_clause: (node) => show([node.qualifyKw, node.expr]),
order_by_clause: (node) =>
Expand Down
6 changes: 6 additions & 0 deletions test/select/group_by.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ describe("select GROUP BY", () => {
});
});

dialect(["bigquery"], () => {
it("supports GROUP BY ALL", () => {
testClauseWc("GROUP BY ALL");
});
});

dialect(["bigquery", "postgresql"], () => {
it("supports GROUP BY ROLLUP()", () => {
testClauseWc("GROUP BY ROLLUP ( id, name + age )");
Expand Down
Loading