Skip to content

Format GROUP BY ALL for BigQuery #41

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

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 @@ -36,7 +36,7 @@
],
"dependencies": {
"prettier": "^3.0.3",
"sql-parser-cst": "^0.31.1"
"sql-parser-cst": "^0.32.0"
},
"devDependencies": {
"@types/jest": "^29.2.5",
Expand Down
1 change: 1 addition & 0 deletions src/syntax/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const selectMap: CstToDocMap<AllSelectNodes> = {
group_by_cube: (print) => print(["cubeKw", "columns"]),
group_by_grouping_sets: (print) =>
print.spaced(["groupingSetsKw", "columns"]),
group_by_all: (print) => print(["allKw"]),

// PARTITION BY clause
partition_by_clause: (print) =>
Expand Down
22 changes: 22 additions & 0 deletions test/select/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,28 @@ describe("select", () => {
`);
});

it(`formats short query with GROUP BY ALL`, async () => {
await testBigquery(dedent`
SELECT * FROM tbl GROUP BY ALL
`);
});

it(`formats long query with GROUP BY ALL`, async () => {
await testBigquery(dedent`
SELECT *
FROM my_table_name
GROUP BY ALL
HAVING my_table_name.col1 > 1
LIMIT 5
`);
});

it(`capitalizes GROUP BY all`, async () => {
expect(
await pretty(`SELECT * FROM tbl GROUP BY all`, { dialect: "bigquery" }),
).toBe(`SELECT * FROM tbl GROUP BY ALL`);
});

it(`formats QUALIFY clause`, async () => {
await testBigquery(`SELECT * FROM tbl QUALIFY x > 10`);
});
Expand Down