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

Commit 34f76c7

Browse files
authored
refactor: remove the googlesql module (#2482)
Fixes internal issue 488047595🦕
1 parent 05d11b7 commit 34f76c7

File tree

20 files changed

+96
-831
lines changed

20 files changed

+96
-831
lines changed

bigframes/bigquery/_operations/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import google.cloud.bigquery
2222

23-
import bigframes.core.compile.sqlglot.sqlglot_ir as sqlglot_ir
23+
from bigframes.core.compile.sqlglot import sqlglot_ir
2424
import bigframes.dtypes
2525
import bigframes.operations
2626
import bigframes.series

bigframes/core/compile/compiled.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
import bigframes_vendored.ibis.expr.datatypes as ibis_dtypes
2424
import bigframes_vendored.ibis.expr.operations as ibis_ops
2525
import bigframes_vendored.ibis.expr.types as ibis_types
26+
import bigframes_vendored.sqlglot.expressions as sge
2627
from google.cloud import bigquery
2728
import pyarrow as pa
2829

2930
from bigframes.core import agg_expressions, rewrite
3031
import bigframes.core.agg_expressions as ex_types
31-
import bigframes.core.compile.googlesql
3232
import bigframes.core.compile.ibis_compiler.aggregate_compiler as agg_compiler
3333
import bigframes.core.compile.ibis_compiler.scalar_op_compiler as op_compilers
3434
import bigframes.core.compile.ibis_types
@@ -82,13 +82,21 @@ def to_sql(
8282
)
8383

8484
if order_by or limit or not is_noop_selection:
85-
sql = ibis_bigquery.Backend().compile(ibis_table)
86-
sql = (
87-
bigframes.core.compile.googlesql.Select()
88-
.from_(sql)
89-
.select(selection_strings)
90-
.sql()
91-
)
85+
# selections are (ref.id.sql, name) where ref.id.sql is escaped identifier
86+
to_select = [
87+
sge.Alias(
88+
this=sge.to_identifier(src, quoted=True),
89+
alias=sge.to_identifier(alias, quoted=True),
90+
)
91+
if src != alias
92+
else sge.to_identifier(src, quoted=True)
93+
for src, alias in selection_strings
94+
]
95+
# Use string formatting for FROM clause to avoid re-parsing potentially complex SQL (like ARRAY<STRUCT<...>>)
96+
# that sqlglot might not handle perfectly when parsing BigQuery dialect strings.
97+
select_sql = sge.Select().select(*to_select).sql(dialect="bigquery")
98+
ibis_sql = ibis_bigquery.Backend().compile(ibis_table)
99+
sql = f"{select_sql} FROM ({ibis_sql}) AS `t`"
92100

93101
# Single row frames may not have any ordering columns
94102
if len(order_by) > 0:
@@ -99,7 +107,7 @@ def to_sql(
99107
raise TypeError(f"Limit param: {limit} must be an int.")
100108
sql += f"\nLIMIT {limit}"
101109
else:
102-
sql = ibis_bigquery.Backend().compile(self._to_ibis_expr())
110+
sql = ibis_bigquery.Backend().compile(ibis_table)
103111
return typing.cast(str, sql)
104112

105113
@property

bigframes/core/compile/googlesql/__init__.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

bigframes/core/compile/googlesql/abc.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

bigframes/core/compile/googlesql/datatype.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

bigframes/core/compile/googlesql/expression.py

Lines changed: 0 additions & 124 deletions
This file was deleted.

bigframes/core/compile/googlesql/function.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)