Skip to content

Commit 32acaea

Browse files
committed
Fix rendering of nested label expressions
1 parent 2e84599 commit 32acaea

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

pybigquery/sqlalchemy_bigquery.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,17 @@ def visit_column(self, column, add_to_result_map=None,
183183
self.preparer.quote(tablename) + \
184184
"." + name
185185

186-
def visit_label(self, *args, **kwargs):
187-
# Use labels in GROUP BY clause
188-
if len(kwargs) == 0 or len(kwargs) == 1:
186+
def visit_label(self, *args, within_group_by=False, **kwargs):
187+
# Use labels in GROUP BY clause.
188+
#
189+
# Flag set in the group_by_clause method. Works around missing equivalent to
190+
# supports_simple_order_by_label for group by.
191+
if within_group_by:
189192
kwargs['render_label_as_label'] = args[0]
190-
result = super(BigQueryCompiler, self).visit_label(*args, **kwargs)
191-
return result
193+
return super(BigQueryCompiler, self).visit_label(*args, **kwargs)
194+
195+
def group_by_clause(self, select, **kw):
196+
return super(BigQueryCompiler, self).group_by_clause(select, **kw, within_group_by=True)
192197

193198

194199
class BigQueryTypeCompiler(GenericTypeCompiler):

0 commit comments

Comments
 (0)