Skip to content

Commit 4871331

Browse files
committed
Format GROUP BY ALL for BigQuery
1 parent ed4176f commit 4871331

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
],
3737
"dependencies": {
3838
"prettier": "^3.0.3",
39-
"sql-parser-cst": "^0.31.1"
39+
"sql-parser-cst": "^0.32.0"
4040
},
4141
"devDependencies": {
4242
"@types/jest": "^29.2.5",

src/syntax/select.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ export const selectMap: CstToDocMap<AllSelectNodes> = {
180180
group_by_cube: (print) => print(["cubeKw", "columns"]),
181181
group_by_grouping_sets: (print) =>
182182
print.spaced(["groupingSetsKw", "columns"]),
183+
group_by_all: (print) => print(["allKw"]),
183184

184185
// PARTITION BY clause
185186
partition_by_clause: (print) =>

test/select/select.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ describe("select", () => {
185185
`);
186186
});
187187

188+
it(`formats short query with GROUP BY ALL`, async () => {
189+
await testBigquery(dedent`
190+
SELECT * FROM tbl GROUP BY ALL
191+
`);
192+
});
193+
194+
it(`formats long query with GROUP BY ALL`, async () => {
195+
await testBigquery(dedent`
196+
SELECT *
197+
FROM my_table_name
198+
GROUP BY ALL
199+
HAVING my_table_name.col1 > 1
200+
LIMIT 5
201+
`);
202+
});
203+
204+
it(`capitalizes GROUP BY all`, async () => {
205+
expect(
206+
await pretty(`SELECT * FROM tbl GROUP BY all`, { dialect: "bigquery" }),
207+
).toBe(`SELECT * FROM tbl GROUP BY ALL`);
208+
});
209+
188210
it(`formats QUALIFY clause`, async () => {
189211
await testBigquery(`SELECT * FROM tbl QUALIFY x > 10`);
190212
});

0 commit comments

Comments
 (0)