Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bigframes/testing/compiler_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
import typing

import bigframes.core
import bigframes.core.compile.sqlglot as sqlglot
from bigframes.core.compile import configs
from bigframes.core.compile.ibis_compiler import ibis_compiler

import bigframes.session.executor


@dataclasses.dataclass
class SQLCompilerExecutor(bigframes.session.executor.Executor):
"""Executor for SQL compilation using sqlglot."""

compiler = sqlglot

def to_sql(
self,
array_value: bigframes.core.ArrayValue,
Expand All @@ -38,6 +38,6 @@ def to_sql(

# Compared with BigQueryCachingExecutor, SQLCompilerExecutor skips
# caching the subtree.
return self.compiler.SQLGlotCompiler().compile(
array_value.node, ordered=ordered
)
request = configs.CompileRequest(array_value.node, sort_rows=ordered)
compiled = ibis_compiler.compile_sql(request)
return compiled.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
WITH `bfcte_0` AS (
SELECT
`string_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COUNT(1) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `string_col_agg`
FROM `bfcte_1`
*
FROM (
SELECT
COUNT(1) AS `string_col_agg`
FROM (
SELECT
`t0`.`string_col`
FROM (
SELECT
`string_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-08-26T20:49:28.159676')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COALESCE(SUM(`bfcol_0`), 0) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `int64_col_agg`
FROM `bfcte_1`
*
FROM (
SELECT
COALESCE(SUM(`t1`.`int64_col`), 0) AS `int64_col_agg`
FROM (
SELECT
`t0`.`int64_col`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-08-26T20:49:28.159676')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,54 +1,15 @@
WITH `bfcte_0` AS (
SELECT
`bool_col` AS `bfcol_0`,
`int64_col` AS `bfcol_1`,
`rowindex` AS `bfcol_2`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_2` AS `bfcol_6`,
`bfcol_1` AS `bfcol_7`,
`bfcol_0` AS `bfcol_8`,
`bfcol_1` + `bfcol_1` AS `bfcol_9`
FROM `bfcte_0`
), `bfcte_2` AS (
SELECT
*,
`bfcol_6` AS `bfcol_14`,
`bfcol_7` AS `bfcol_15`,
`bfcol_8` AS `bfcol_16`,
`bfcol_9` AS `bfcol_17`,
`bfcol_7` + 1 AS `bfcol_18`
FROM `bfcte_1`
), `bfcte_3` AS (
SELECT
*,
`bfcol_14` AS `bfcol_24`,
`bfcol_15` AS `bfcol_25`,
`bfcol_16` AS `bfcol_26`,
`bfcol_17` AS `bfcol_27`,
`bfcol_18` AS `bfcol_28`,
`bfcol_15` + CAST(`bfcol_16` AS INT64) AS `bfcol_29`
FROM `bfcte_2`
), `bfcte_4` AS (
SELECT
*,
`bfcol_24` AS `bfcol_36`,
`bfcol_25` AS `bfcol_37`,
`bfcol_26` AS `bfcol_38`,
`bfcol_27` AS `bfcol_39`,
`bfcol_28` AS `bfcol_40`,
`bfcol_29` AS `bfcol_41`,
CAST(`bfcol_26` AS INT64) + `bfcol_25` AS `bfcol_42`
FROM `bfcte_3`
)
SELECT
`bfcol_36` AS `rowindex`,
`bfcol_37` AS `int64_col`,
`bfcol_38` AS `bool_col`,
`bfcol_39` AS `int_add_int`,
`bfcol_40` AS `int_add_1`,
`bfcol_41` AS `int_add_bool`,
`bfcol_42` AS `bool_add_int`
FROM `bfcte_4`
`t0`.`rowindex`,
`t0`.`int64_col`,
`t0`.`bool_col`,
`t0`.`int64_col` + `t0`.`int64_col` AS `int_add_int`,
`t0`.`int64_col` + 1 AS `int_add_1`,
`t0`.`int64_col` + CAST(`t0`.`bool_col` AS INT64) AS `int_add_bool`,
CAST(`t0`.`bool_col` AS INT64) + `t0`.`int64_col` AS `bool_add_int`
FROM (
SELECT
`bool_col`,
`int64_col`,
`rowindex`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-08-26T20:49:28.159676')
) AS `t0`
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`string_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
CONCAT(`bfcol_0`, 'a') AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `string_col`
FROM `bfcte_1`
CONCAT(`t0`.`string_col`, 'a') AS `string_col`
FROM (
SELECT
`string_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-08-26T20:49:28.159676')
) AS `t0`
Original file line number Diff line number Diff line change
@@ -1,60 +1,16 @@
WITH `bfcte_0` AS (
SELECT
`date_col` AS `bfcol_0`,
`rowindex` AS `bfcol_1`,
`timestamp_col` AS `bfcol_2`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1` AS `bfcol_6`,
`bfcol_2` AS `bfcol_7`,
`bfcol_0` AS `bfcol_8`,
TIMESTAMP_ADD(CAST(`bfcol_0` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `bfcol_9`
FROM `bfcte_0`
), `bfcte_2` AS (
SELECT
*,
`bfcol_6` AS `bfcol_14`,
`bfcol_7` AS `bfcol_15`,
`bfcol_8` AS `bfcol_16`,
`bfcol_9` AS `bfcol_17`,
TIMESTAMP_ADD(`bfcol_7`, INTERVAL 86400000000 MICROSECOND) AS `bfcol_18`
FROM `bfcte_1`
), `bfcte_3` AS (
SELECT
*,
`bfcol_14` AS `bfcol_24`,
`bfcol_15` AS `bfcol_25`,
`bfcol_16` AS `bfcol_26`,
`bfcol_17` AS `bfcol_27`,
`bfcol_18` AS `bfcol_28`,
TIMESTAMP_ADD(CAST(`bfcol_16` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `bfcol_29`
FROM `bfcte_2`
), `bfcte_4` AS (
SELECT
*,
`bfcol_24` AS `bfcol_36`,
`bfcol_25` AS `bfcol_37`,
`bfcol_26` AS `bfcol_38`,
`bfcol_27` AS `bfcol_39`,
`bfcol_28` AS `bfcol_40`,
`bfcol_29` AS `bfcol_41`,
TIMESTAMP_ADD(`bfcol_25`, INTERVAL 86400000000 MICROSECOND) AS `bfcol_42`
FROM `bfcte_3`
), `bfcte_5` AS (
SELECT
*,
172800000000 AS `bfcol_50`
FROM `bfcte_4`
)
SELECT
`bfcol_36` AS `rowindex`,
`bfcol_37` AS `timestamp_col`,
`bfcol_38` AS `date_col`,
`bfcol_39` AS `date_add_timedelta`,
`bfcol_40` AS `timestamp_add_timedelta`,
`bfcol_41` AS `timedelta_add_date`,
`bfcol_42` AS `timedelta_add_timestamp`,
`bfcol_50` AS `timedelta_add_timedelta`
FROM `bfcte_5`
`t0`.`rowindex`,
`t0`.`timestamp_col`,
`t0`.`date_col`,
TIMESTAMP_ADD(CAST(`t0`.`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `date_add_timedelta`,
TIMESTAMP_ADD(`t0`.`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timestamp_add_timedelta`,
TIMESTAMP_ADD(CAST(`t0`.`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_date`,
TIMESTAMP_ADD(`t0`.`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_timestamp`,
172800000000 AS `timedelta_add_timedelta`
FROM (
SELECT
`date_col`,
`rowindex`,
`timestamp_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-08-26T20:49:28.159676')
) AS `t0`
Loading
Loading