Skip to content

chore: compare SQLs generated by Ibis and sqlglot #1918

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
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
11 changes: 5 additions & 6 deletions bigframes/testing/compiler_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
import typing

import bigframes.core
import bigframes.core.compile.sqlglot as sqlglot
from bigframes.core.compile import configs
import bigframes.core.compile.compiler as 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 +37,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 = compiler.compile_sql(request)
return compiled.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`,
`rowindex` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1` AS `bfcol_4`,
`bfcol_0` + `bfcol_0` AS `bfcol_5`
FROM `bfcte_0`
)
SELECT
`bfcol_4` AS `rowindex`,
`bfcol_5` AS `int64_col`
FROM `bfcte_1`
`t0`.`rowindex`,
`t0`.`int64_col` + `t0`.`int64_col` AS `int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
WITH `bfcte_0` AS (
SELECT
`int64_col` AS `bfcol_0`,
`rowindex` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1` AS `bfcol_4`,
`bfcol_0` + 1 AS `bfcol_5`
FROM `bfcte_0`
)
SELECT
`bfcol_4` AS `rowindex`,
`bfcol_5` AS `int64_col`
FROM `bfcte_1`
`t0`.`rowindex`,
`t0`.`int64_col` + 1 AS `int64_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`string_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_0` AS `bfcol_4`,
CONCAT(`bfcol_1`, 'a') AS `bfcol_5`
FROM `bfcte_0`
)
SELECT
`bfcol_4` AS `rowindex`,
`bfcol_5` AS `string_col`
FROM `bfcte_1`
`t0`.`rowindex`,
CONCAT(`t0`.`string_col`, 'a') AS `string_col`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`json_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
), `bfcte_1` AS (
SELECT
*,
JSON_SET(`bfcol_1`, '$.a', 100) AS `bfcol_4`
FROM `bfcte_0`
), `bfcte_2` AS (
SELECT
*,
JSON_SET(`bfcol_4`, '$.b', 'hi') AS `bfcol_7`
FROM `bfcte_1`
)
SELECT
`bfcol_0` AS `rowindex`,
`bfcol_7` AS `json_col`
FROM `bfcte_2`
`t1`.`rowindex`,
json_set(json_set(`t1`.`json_col`, '$.a', 100), '$.b', 'hi') AS `json_col`
FROM (
SELECT
*
FROM `bigframes-dev.sqlglot_test.json_types` AS `t0`
) AS `t1`
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`string_list_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1`[SAFE_OFFSET(1)] AS `bfcol_4`
FROM `bfcte_0`
)
SELECT
`bfcol_0` AS `rowindex`,
`bfcol_4` AS `string_list_col`
FROM `bfcte_1`
`t0`.`rowindex`,
`t0`.`string_list_col`[safe_offset(1)] AS `string_list_col`
FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`string_list_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types`
), `bfcte_1` AS (
SELECT
*,
ARRAY(
SELECT
el
FROM UNNEST(`bfcol_1`) AS el WITH OFFSET AS slice_idx
WHERE
slice_idx >= 1
) AS `bfcol_4`
FROM `bfcte_0`
)
SELECT
`bfcol_0` AS `rowindex`,
`bfcol_4` AS `string_list_col`
FROM `bfcte_1`
`t0`.`rowindex`,
ARRAY(
SELECT
el
FROM UNNEST(`t0`.`string_list_col`) AS el WITH OFFSET AS bq_arr_slice
WHERE
bq_arr_slice >= IF(1 < 0, ARRAY_LENGTH(`t0`.`string_list_col`) + 1, 1)
) AS `string_list_col`
FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`string_list_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types`
), `bfcte_1` AS (
SELECT
*,
ARRAY(
SELECT
el
FROM UNNEST(`bfcol_1`) AS el WITH OFFSET AS slice_idx
WHERE
slice_idx >= 1 AND slice_idx < 5
) AS `bfcol_4`
FROM `bfcte_0`
)
SELECT
`bfcol_0` AS `rowindex`,
`bfcol_4` AS `string_list_col`
FROM `bfcte_1`
`t0`.`rowindex`,
ARRAY(
SELECT
el
FROM UNNEST(`t0`.`string_list_col`) AS el WITH OFFSET AS bq_arr_slice
WHERE
bq_arr_slice >= IF(1 < 0, ARRAY_LENGTH(`t0`.`string_list_col`) + 1, 1)
AND bq_arr_slice < IF(5 < 0, ARRAY_LENGTH(`t0`.`string_list_col`) + 5, 5)
) AS `string_list_col`
FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`string_list_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types`
), `bfcte_1` AS (
SELECT
*,
ARRAY_TO_STRING(`bfcol_1`, '.') AS `bfcol_4`
FROM `bfcte_0`
)
SELECT
`bfcol_0` AS `rowindex`,
`bfcol_4` AS `string_list_col`
FROM `bfcte_1`
`t0`.`rowindex`,
ARRAY_TO_STRING(`t0`.`string_list_col`, '.') AS `string_list_col`
FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0`
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
WITH `bfcte_0` AS (
SELECT
`rowindex` AS `bfcol_0`,
`string_col` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
JSON_VALUE(`bfcol_1`, '$') AS `bfcol_4`
FROM `bfcte_0`
)
SELECT
`bfcol_0` AS `rowindex`,
`bfcol_4` AS `string_col`
FROM `bfcte_1`
`t1`.`rowindex`,
json_value(`t1`.`string_col`, '$') AS `string_col`
FROM (
SELECT
`t0`.`rowindex`,
`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,27 +1,25 @@
WITH `bfcte_0` AS (
SELECT
`bool_col` AS `bfcol_0`,
`int64_too` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1` AS `bfcol_2`,
`bfcol_0` AS `bfcol_3`
FROM `bfcte_0`
), `bfcte_2` AS (
SELECT
`bool_col` AS `bool_col`,
`int64_too` AS `int64_too`
FROM
(SELECT
`t2`.`bfuid_col_34` AS `bool_col`,
`t2`.`bfuid_col_35` AS `int64_too`
FROM (
SELECT
`bfcol_3`,
COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6`
FROM `bfcte_1`
WHERE
NOT `bfcol_3` IS NULL
`t1`.`bfuid_col_34`,
COALESCE(SUM(`t1`.`bfuid_col_33`), 0) AS `bfuid_col_35`
FROM (
SELECT
`t0`.`int64_too` AS `bfuid_col_33`,
`t0`.`bool_col` AS `bfuid_col_34`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
GROUP BY
`bfcol_3`
)
SELECT
`bfcol_3` AS `bool_col`,
`bfcol_6` AS `int64_too`
FROM `bfcte_2`
ORDER BY
`bfcol_3` ASC NULLS LAST
1
) AS `t2`
WHERE
(
`t2`.`bfuid_col_34`
) IS NOT NULL)
ORDER BY `bool_col` ASC NULLS LAST
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
WITH `bfcte_0` AS (
SELECT
`bool_col` AS `bfcol_0`,
`int64_too` AS `bfcol_1`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
), `bfcte_1` AS (
SELECT
*,
`bfcol_1` AS `bfcol_2`,
`bfcol_0` AS `bfcol_3`
FROM `bfcte_0`
), `bfcte_2` AS (
SELECT
`bool_col` AS `bool_col`,
`int64_too` AS `int64_too`
FROM
(SELECT
`t2`.`bfuid_col_38` AS `bool_col`,
`t2`.`bfuid_col_39` AS `int64_too`
FROM (
SELECT
`bfcol_3`,
COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6`
FROM `bfcte_1`
`t1`.`bfuid_col_38`,
COALESCE(SUM(`t1`.`bfuid_col_37`), 0) AS `bfuid_col_39`
FROM (
SELECT
`t0`.`int64_too` AS `bfuid_col_37`,
`t0`.`bool_col` AS `bfuid_col_38`
FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`
) AS `t1`
GROUP BY
`bfcol_3`
)
SELECT
`bfcol_3` AS `bool_col`,
`bfcol_6` AS `int64_too`
FROM `bfcte_2`
ORDER BY
`bfcol_3` ASC NULLS LAST
1
) AS `t2`)
ORDER BY `bool_col` ASC NULLS LAST
Loading
Loading