Skip to content

Commit e2a30f1

Browse files
committed
refactor: add table aliases to prevent ambiguity in SQLGlotIR
1 parent 36261f5 commit e2a30f1

File tree

285 files changed

+305
-302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+305
-302
lines changed

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,20 @@ def from_table(
134134
"""
135135
version = (
136136
sge.Version(
137-
this="TIMESTAMP",
138-
expression=sge.Literal(this=system_time.isoformat(), is_string=True),
137+
this=sge.Identifier(this="SYSTEM_TIME", quoted=False),
138+
expression=sge.Literal.string(system_time.isoformat()),
139139
kind="AS OF",
140140
)
141141
if system_time
142142
else None
143143
)
144+
table_alias = next(uid_gen.get_uid_stream("bft_"))
144145
table_expr = sge.Table(
145146
this=sg.to_identifier(table_id, quoted=cls.quoted),
146147
db=sg.to_identifier(dataset_id, quoted=cls.quoted),
147148
catalog=sg.to_identifier(project_id, quoted=cls.quoted),
148149
version=version,
150+
alias=sge.Identifier(this=table_alias, quoted=cls.quoted),
149151
)
150152
if sql_predicate:
151153
select_expr = sge.Select().select(sge.Star()).from_(table_expr)

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
22
SELECT
33
`int64_col`,
44
`float64_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
66
), `bfcte_1` AS (
77
SELECT
88
CORR(`int64_col`, `float64_col`) AS `bfcol_2`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
22
SELECT
33
`int64_col`,
44
`float64_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
66
), `bfcte_1` AS (
77
SELECT
88
COVAR_SAMP(`int64_col`, `float64_col`) AS `bfcol_2`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
22
ROW_NUMBER() OVER () - 1 AS `row_number`
3-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
22
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `row_number`
3-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
*
4-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
55
), `bfcte_1` AS (
66
SELECT
77
COUNT(1) AS `bfcol_32`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
`int64_col`
4-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
55
), `bfcte_1` AS (
66
SELECT
77
ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
`string_col`
4-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
55
), `bfcte_1` AS (
66
SELECT
77
COALESCE(

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
22
SELECT
33
`bool_col`,
44
`int64_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
66
), `bfcte_1` AS (
77
SELECT
88
COALESCE(LOGICAL_AND(`bool_col`), TRUE) AS `bfcol_2`,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
22
COALESCE(LOGICAL_AND(`bool_col`) OVER (), TRUE) AS `agg_bool`
3-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

0 commit comments

Comments
 (0)