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
9 changes: 4 additions & 5 deletions bigframes/testing/compiler_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

import bigframes.core
import bigframes.core.compile as compile
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 = compile.sqlglot

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

# Compared with BigQueryCachingExecutor, SQLCompilerExecutor skips
# caching the subtree.
return self.compiler.compile_sql(
compile.CompileRequest(array_value.node, sort_rows=ordered)
).sql
request = compile.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,12 @@
WITH `bfcte_0` AS (
SELECT
`float64_col`,
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
CORR(`int64_col`, `float64_col`) 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 `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
WITH `bfcte_0` AS (
SELECT
`float64_col`,
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COVAR_SAMP(`int64_col`, `float64_col`) 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 `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`bool_col`,
`bytes_col`,
`date_col`,
`datetime_col`,
`duration_col`,
`float64_col`,
`geography_col`,
`int64_col`,
`int64_too`,
`numeric_col`,
`rowindex`,
`rowindex_2`,
`string_col`,
`time_col`,
`timestamp_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
ROW_NUMBER() OVER () AS `bfcol_32`
FROM `bfcte_0`
)
SELECT
`bfcol_32` AS `row_number`
FROM `bfcte_1`
ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `row_number`
FROM (
SELECT
*
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `row_number`
FROM `bfcte_1`
ROW_NUMBER() OVER (ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC) - 1 AS `row_number`
FROM (
SELECT
`t0`.`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
WITH `bfcte_0` AS (
SELECT
`bool_col`,
`bytes_col`,
`date_col`,
`datetime_col`,
`duration_col`,
`float64_col`,
`geography_col`,
`int64_col`,
`int64_too`,
`numeric_col`,
`rowindex`,
`rowindex_2`,
`string_col`,
`time_col`,
`timestamp_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COUNT(1) AS `bfcol_32`
FROM `bfcte_0`
)
SELECT
`bfcol_32` AS `size`
FROM `bfcte_1`
*
FROM (
SELECT
COUNT(1) AS `size`
FROM (
SELECT
`t0`.`rowindex` AS `bfuid_col_1`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `int64_col`
FROM `bfcte_1`
*
FROM (
SELECT
ARRAY_AGG(
`t1`.`int64_col` IGNORE NULLS ORDER BY (`t1`.`int64_col` IS NULL) ASC, (`t1`.`int64_col`) ASC
) AS `int64_col`
FROM (
SELECT
`t0`.`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
WITH `bfcte_0` AS (
SELECT
`string_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*
FROM (
SELECT
COALESCE(
STRING_AGG(`string_col`, ','
ORDER BY
`string_col` IS NULL ASC,
`string_col` ASC),
string_agg(
`t1`.`string_col` ORDER BY (`t1`.`string_col` IS NULL) ASC, (`t1`.`string_col`) ASC,
','
),
''
) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `string_col`
FROM `bfcte_1`
) AS `string_col`
FROM (
SELECT
`t0`.`string_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
WITH `bfcte_0` AS (
SELECT
`bool_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
COALESCE(LOGICAL_AND(`bool_col`), TRUE) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `bool_col`
FROM `bfcte_1`
*
FROM (
SELECT
COALESCE(LOGICAL_AND(`t1`.`bool_col`), TRUE) AS `bool_col`
FROM (
SELECT
`t0`.`bool_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
WITH `bfcte_0` AS (
SELECT
`bool_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
CASE
WHEN `bool_col` IS NULL
THEN NULL
ELSE COALESCE(LOGICAL_AND(`bool_col`) OVER (), TRUE)
END AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `agg_bool`
FROM `bfcte_1`
CASE
WHEN `t1`.`bool_col` IS NULL
THEN NULL
WHEN TRUE
THEN COALESCE(LOGICAL_AND(`t1`.`bool_col`) OVER (), TRUE)
ELSE CAST(NULL AS BOOL)
END AS `agg_bool`
FROM (
SELECT
`t0`.`bool_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
WITH `bfcte_0` AS (
SELECT
`bool_col`,
`string_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
CASE
WHEN `bool_col` IS NULL
THEN NULL
ELSE COALESCE(LOGICAL_AND(`bool_col`) OVER (PARTITION BY `string_col`), TRUE)
END AS `bfcol_2`
FROM `bfcte_0`
)
SELECT
`bfcol_2` AS `agg_bool`
FROM `bfcte_1`
CASE
WHEN `t1`.`bool_col` IS NULL
THEN NULL
WHEN TRUE
THEN COALESCE(LOGICAL_AND(`t1`.`bool_col`) OVER (PARTITION BY `t1`.`string_col`), TRUE)
ELSE CAST(NULL AS BOOL)
END AS `agg_bool`
FROM (
SELECT
`t0`.`bool_col`,
`t0`.`string_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
ANY_VALUE(`int64_col`) AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `int64_col`
FROM `bfcte_1`
*
FROM (
SELECT
ANY_VALUE(`t1`.`int64_col`) AS `int64_col`
FROM (
SELECT
`t0`.`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
) AS `t2`
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
CASE WHEN `int64_col` IS NULL THEN NULL ELSE ANY_VALUE(`int64_col`) OVER () END AS `bfcol_1`
FROM `bfcte_0`
)
SELECT
`bfcol_1` AS `agg_int64`
FROM `bfcte_1`
CASE
WHEN `t1`.`int64_col` IS NULL
THEN NULL
WHEN TRUE
THEN ANY_VALUE(`t1`.`int64_col`) OVER ()
ELSE CAST(NULL AS INT64)
END AS `agg_int64`
FROM (
SELECT
`t0`.`int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
Loading
Loading