|
19 | 19 | import typing |
20 | 20 | from typing import Dict, List, Tuple |
21 | 21 |
|
| 22 | +from bigframes_vendored.ibis.backends.sql.compilers import bigquery as bq_compiler |
| 23 | +import bigframes_vendored.sqlglot as sg |
22 | 24 | import geopandas as gpd # type: ignore |
23 | 25 | import numpy as np |
24 | 26 | import pandas as pd |
@@ -6298,18 +6300,13 @@ def test_agg_with_dict_containing_non_existing_col_raise_key_error(scalars_dfs): |
6298 | 6300 | bf_df.agg(agg_funcs) |
6299 | 6301 |
|
6300 | 6302 |
|
6301 | | -def test_empty_agg_projection_succeeds(): |
6302 | | - # Tests that the compiler generates a SELECT 1 fallback for empty aggregations, |
6303 | | - # protecting against BigQuery syntax errors when both groups and metrics are empty. |
6304 | | - import importlib |
| 6303 | +def test_empty_aggregation_generates_constant_fallback(): |
| 6304 | + # Given a BigQuery compiler and a parent table |
| 6305 | + compiler = bq_compiler.BigQueryCompiler() |
| 6306 | + parent_table = sg.table("parent_table") |
6305 | 6307 |
|
6306 | | - bq = importlib.import_module( |
6307 | | - "third_party.bigframes_vendored.ibis.backends.sql.compilers.bigquery" |
6308 | | - ) |
6309 | | - sg = importlib.import_module("third_party.bigframes_vendored.sqlglot") |
| 6308 | + # When visiting an Aggregate operation with empty groups and metrics |
| 6309 | + res = compiler.visit_Aggregate("op", parent=parent_table, groups=[], metrics=[]) |
6310 | 6310 |
|
6311 | | - compiler = bq.BigQueryCompiler() |
6312 | | - res = compiler.visit_Aggregate( |
6313 | | - "op", parent=sg.table("parent_table"), groups=[], metrics=[] |
6314 | | - ) |
| 6311 | + # Then it should generate a SELECT 1 fallback to avoid BigQuery syntax errors |
6315 | 6312 | assert "SELECT 1" in res.sql() |
0 commit comments