Skip to content

Commit 5154814

Browse files
committed
added test case
1 parent bd38a5e commit 5154814

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

sqlalchemy_bigquery/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,12 @@ def visit_label(self, *args, within_group_by=False, **kwargs):
343343
for keyword in ("GROUPING SETS", "ROLLUP", "CUBE")
344344
):
345345
kwargs["render_label_as_label"] = args[0]
346+
346347
return super(BigQueryCompiler, self).visit_label(*args, **kwargs)
347348

348349
def group_by_clause(self, select, **kw):
349350
return super(BigQueryCompiler, self).group_by_clause(
350-
select,
351-
**kw,
352-
within_group_by=True,
351+
select, **kw, within_group_by=True
353352
)
354353

355354
############################################################################

tests/unit/test_compiler.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
sqlalchemy_before_2_0,
2727
)
2828
from sqlalchemy.sql.functions import rollup, cube, grouping_sets
29+
from sqlalchemy import func
2930

3031

3132
def test_constraints_are_ignored(faux_conn, metadata):
@@ -343,3 +344,24 @@ def test_cube(faux_conn, metadata):
343344
)
344345
found_sql = q.compile(faux_conn).string
345346
assert found_sql == expected_sql
347+
348+
349+
def test_multiple_grouping_sets(faux_conn, metadata):
350+
table = setup_table(
351+
faux_conn,
352+
"table1",
353+
metadata,
354+
sqlalchemy.Column("foo", sqlalchemy.Integer),
355+
sqlalchemy.Column("bar", sqlalchemy.ARRAY(sqlalchemy.Integer)),
356+
)
357+
358+
q = sqlalchemy.select(table.c.foo, table.c.bar).group_by(
359+
grouping_sets(table.c.foo, table.c.bar), grouping_sets(table.c.foo)
360+
)
361+
362+
expected_sql = (
363+
"SELECT `table1`.`foo`, `table1`.`bar` \n"
364+
"FROM `table1` GROUP BY GROUPING SETS(`table1`.`foo`, `table1`.`bar`), GROUPING SETS(`table1`.`foo`)"
365+
)
366+
found_sql = q.compile(faux_conn).string
367+
assert found_sql == expected_sql

0 commit comments

Comments
 (0)