Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.

Commit ee4e279

Browse files
committed
fix: inject SELECT 1 fallback for empty agg projections
1 parent 43353e2 commit ee4e279

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

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
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,15 @@ def visit_TimestampFromUNIX(self, op, *, arg, unit):
540540

541541
def visit_Cast(self, op, *, arg, to):
542542
from_ = op.arg.dtype
543+
if to.is_null():
544+
return sge.Null()
545+
if arg is NULL or (
546+
isinstance(arg, sge.Cast)
547+
and getattr(arg, "to", None) is not None
548+
and str(arg.to).upper() == "NULL"
549+
):
550+
if to.is_struct() or to.is_array():
551+
return sge.Cast(this=NULL, to=self.type_mapper.from_ibis(to))
543552
if from_.is_timestamp() and to.is_integer():
544553
return self.f.unix_micros(arg)
545554
elif from_.is_integer() and to.is_timestamp():

0 commit comments

Comments
 (0)