fix: handle aggregate operations on empty selections (#2510) · google/bigframes@34fb5da · GitHub
Skip to content

Commit 34fb5da

Browse files
authored
fix: handle aggregate operations on empty selections (#2510)
SQL generator output fallbacks (SELECT 1 placeholder). Fixes #<452681068> 🦕
1 parent b589de9 commit 34fb5da

3 files changed

Lines changed: 37 additions & 3 deletions

File tree

tests/system/small/test_dataframe.py

Lines changed: 17 additions & 0 deletions

third_party/bigframes_vendored/ibis/backends/sql/compilers/base.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,9 +1394,17 @@ def _generate_groups(groups):
13941394
return map(sge.convert, range(1, len(groups) + 1))
13951395

13961396
def visit_Aggregate(self, op, *, parent, groups, metrics):
1397-
sel = sg.select(
1398-
*self._cleanup_names(groups), *self._cleanup_names(metrics), copy=False
1399-
).from_(parent, copy=False)
1397+
exprs = []
1398+
if groups:
1399+
exprs.extend(self._cleanup_names(groups))
1400+
if metrics:
1401+
exprs.extend(self._cleanup_names(metrics))
1402+
1403+
if not exprs:
1404+
# Empty aggregated projections are invalid in BigQuery
1405+
exprs = [sge.Literal.number(1)]
1406+
1407+
sel = sg.select(*exprs, copy=False).from_(parent, copy=False)
14001408

14011409
if groups:
14021410
sel = sel.group_by(*self._generate_groups(groups.values()), copy=False)

third_party/bigframes_vendored/ibis/backends/sql/compilers/bigquery/__init__.py

Lines changed: 9 additions & 0 deletions

0 commit comments

Comments
 (0)