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,9 +38,9 @@ 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

def execute(
self,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`,
`float64_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
CORR(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
FROM `bfcte_0`
)
SELECT
`bfcol_2` AS `corr_col`
FROM `bfcte_1`
*
FROM (
SELECT
CORR(`t1`.`int64_col`, `t1`.`float64_col`) AS `corr_col`
FROM (
SELECT
`t0`.`int64_col`,
`t0`.`float64_col`
FROM (
SELECT
`int64_col`,
`float64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`,
`float64_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COVAR_SAMP(`bfcol_0`, `bfcol_1`) AS `bfcol_2`
FROM `bfcte_0`
)
SELECT
`bfcol_2` AS `cov_col`
FROM `bfcte_1`
*
FROM (
SELECT
COVAR_SAMP(`t1`.`int64_col`, `t1`.`float64_col`) AS `cov_col`
FROM (
SELECT
`t0`.`int64_col`,
`t0`.`float64_col`
FROM (
SELECT
`int64_col`,
`float64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`bool_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
ROW_NUMBER() OVER () AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `row_number`
FROM `bfcte_1`
ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `row_number`
FROM (
SELECT
`bool_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
ROW_NUMBER() OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `row_number`
FROM `bfcte_1`
ROW_NUMBER() OVER (ORDER BY `t0`.`int64_col` IS NULL ASC, `t0`.`int64_col` ASC) - 1 AS `row_number`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COUNT(1) AS `bfcol_2`
FROM `bfcte_0`
)
SELECT
`bfcol_2` AS `size`
FROM `bfcte_1`
*
FROM (
SELECT
COUNT(1) AS `size`
FROM (
SELECT
`t0`.`rowindex` AS `bfuid_col_1`
FROM (
SELECT
`rowindex`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
APPROX_QUANTILES(`bfcol_0`, 4)[OFFSET(1)] AS `bfcol_1`,
APPROX_QUANTILES(`bfcol_0`, 4)[OFFSET(2)] AS `bfcol_2`,
APPROX_QUANTILES(`bfcol_0`, 4)[OFFSET(3)] AS `bfcol_3`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `q1`,
`bfcol_2` AS `q2`,
`bfcol_3` AS `q3`
FROM `bfcte_1`
*
FROM (
SELECT
approx_quantiles(`t1`.`int64_col`, 4)[safe_offset(1)] AS `q1`,
approx_quantiles(`t1`.`int64_col`, 4)[safe_offset(2)] AS `q2`,
approx_quantiles(`t1`.`int64_col`, 4)[safe_offset(3)] AS `q3`
FROM (
SELECT
`t0`.`int64_col`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) 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
APPROX_TOP_COUNT(`bfcol_0`, 10) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `int64_col`
FROM `bfcte_1`
*
FROM (
SELECT
approx_top_count(`t1`.`int64_col`, 10) AS `int64_col`
FROM (
SELECT
`t0`.`int64_col`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) 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
COUNT(`bfcol_0`) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `int64_col`
FROM `bfcte_1`
*
FROM (
SELECT
COUNT(`t1`.`int64_col`) AS `int64_col`
FROM (
SELECT
`t0`.`int64_col`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
DENSE_RANK() OVER (ORDER BY `bfcol_0` IS NULL ASC NULLS LAST, `bfcol_0` ASC NULLS LAST) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `agg_int64`
FROM `bfcte_1`
(
dense_rank() OVER (ORDER BY `t0`.`int64_col` IS NULL ASC, `t0`.`int64_col` ASC) - 1
) + 1 AS `agg_int64`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
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
MAX(`bfcol_0`) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `int64_col`
FROM `bfcte_1`
*
FROM (
SELECT
MAX(`t1`.`int64_col`) AS `int64_col`
FROM (
SELECT
`t0`.`int64_col`
FROM (
SELECT
`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
WITH `bfcte_0` AS (
SELECT
`bool_col` AS `bfcol_0`,
`int64_col` AS `bfcol_1`,
`duration_col` AS `bfcol_2`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1` AS `bfcol_6`,
`bfcol_0` AS `bfcol_7`,
`bfcol_2` AS `bfcol_8`
FROM `bfcte_0`
), `bfcte_2` AS (
SELECT
AVG(`bfcol_6`) AS `bfcol_12`,
AVG(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`,
CAST(FLOOR(AVG(`bfcol_8`)) AS INT64) AS `bfcol_14`,
CAST(FLOOR(AVG(`bfcol_6`)) AS INT64) AS `bfcol_15`
FROM `bfcte_1`
)
SELECT
`bfcol_12` AS `int64_col`,
`bfcol_13` AS `bool_col`,
`bfcol_14` AS `duration_col`,
`bfcol_15` AS `int64_col_w_floor`
FROM `bfcte_2`
*
FROM (
SELECT
AVG(`t1`.`bfuid_col_4`) AS `int64_col`,
AVG(CAST(`t1`.`bfuid_col_5` AS INT64)) AS `bool_col`,
CAST(FLOOR(AVG(`t1`.`bfuid_col_6`)) AS INT64) AS `duration_col`,
CAST(FLOOR(AVG(`t1`.`bfuid_col_4`)) AS INT64) AS `int64_col_w_floor`
FROM (
SELECT
`t0`.`int64_col` AS `bfuid_col_4`,
`t0`.`bool_col` AS `bfuid_col_5`,
CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `bfuid_col_6`
FROM (
SELECT
`bool_col`,
`int64_col`,
`duration_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF DATETIME('2025-09-30T20:19:48.854671')
) AS `t0`
) AS `t1`
) AS `t2`
Loading
Loading