Skip to content

Commit 6c0bbab

Browse files
committed
address comments
1 parent 02fd8fe commit 6c0bbab

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

bigframes/core/compile/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,28 @@
1313
# limitations under the License.
1414
from __future__ import annotations
1515

16+
from typing import Any
17+
18+
from bigframes import options
1619
from bigframes.core.compile.api import test_only_ibis_inferred_schema
1720
from bigframes.core.compile.configs import CompileRequest, CompileResult
1821

22+
23+
def compiler() -> Any:
24+
"""Returns the appropriate compiler module based on session options."""
25+
if options.experiments.sql_compiler == "experimental":
26+
import bigframes.core.compile.sqlglot.compiler as sqlglot_compiler
27+
28+
return sqlglot_compiler
29+
else:
30+
import bigframes.core.compile.ibis_compiler.ibis_compiler as ibis_compiler
31+
32+
return ibis_compiler
33+
34+
1935
__all__ = [
2036
"test_only_ibis_inferred_schema",
2137
"CompileRequest",
2238
"CompileResult",
39+
"compiler",
2340
]

bigframes/session/bq_caching_executor.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import bigframes.constants
3232
import bigframes.core
3333
from bigframes.core import bq_data, compile, local_data, rewrite
34-
import bigframes.core.compile.ibis_compiler.ibis_compiler as ibis_compiler
35-
import bigframes.core.compile.sqlglot.compiler as sqlglot_compiler
3634
import bigframes.core.compile.sqlglot.sqlglot_ir as sqlglot_ir
3735
import bigframes.core.events
3836
import bigframes.core.guid
@@ -177,12 +175,9 @@ def to_sql(
177175
else array_value.node
178176
)
179177
node = self._substitute_large_local_sources(node)
180-
compiler = (
181-
sqlglot_compiler
182-
if options.experiments.sql_compiler == "experimental"
183-
else ibis_compiler
178+
compiled = compile.compiler().compile_sql(
179+
compile.CompileRequest(node, sort_rows=ordered)
184180
)
185-
compiled = compiler.compile_sql(compile.CompileRequest(node, sort_rows=ordered))
186181
return compiled.sql
187182

188183
def execute(
@@ -298,12 +293,9 @@ def _export_gbq(
298293
# validate destination table
299294
existing_table = self._maybe_find_existing_table(spec)
300295

301-
compiler = (
302-
sqlglot_compiler
303-
if options.experiments.sql_compiler == "experimental"
304-
else ibis_compiler
296+
compiled = compile.compiler().compile_sql(
297+
compile.CompileRequest(plan, sort_rows=False)
305298
)
306-
compiled = compiler.compile_sql(compile.CompileRequest(plan, sort_rows=False))
307299
sql = compiled.sql
308300

309301
if (existing_table is not None) and _if_schema_match(
@@ -654,12 +646,7 @@ def _execute_plan_gbq(
654646
]
655647
cluster_cols = cluster_cols[:_MAX_CLUSTER_COLUMNS]
656648

657-
compiler = (
658-
sqlglot_compiler
659-
if options.experiments.sql_compiler == "experimental"
660-
else ibis_compiler
661-
)
662-
compiled = compiler.compile_sql(
649+
compiled = compile.compiler().compile_sql(
663650
compile.CompileRequest(
664651
plan,
665652
sort_rows=ordered,

0 commit comments

Comments
 (0)