Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 1e62fd3

Browse files
fix cte emitter
1 parent accf797 commit 1e62fd3

File tree

51 files changed

+1182
-38
lines changed

Some content is hidden

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

51 files changed

+1182
-38
lines changed

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,11 @@ def _as_select(self) -> sge.Select:
510510
if isinstance(self.expr, sge.Select):
511511
return self.expr
512512
else: # table
513-
return sge.Select().from_(self.expr)
513+
return (
514+
sge.Select()
515+
.select(sge.Column(this=sge.Star(), table=self.expr))
516+
.from_(self.expr)
517+
)
514518

515519
def _as_subquery(self) -> sge.Subquery:
516520
return self._as_select().subquery()

bigframes/core/rewrite/as_sql.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ def _extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode:
237237
return sql_nodes.SqlWithCtesNode(
238238
root.top_down(lambda x: mapping.get(x, x)),
239239
cte_names,
240-
tuple(cte.top_down(lambda x: mapping.get(x, x)) for cte in topological_ctes),
240+
tuple(
241+
cte.child.top_down(lambda x: mapping.get(x, x)) for cte in topological_ctes # type: ignore
242+
),
241243
)
242244

243245

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_2` AS `corr_col`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6+
).*
27
FROM (
38
SELECT
49
`bfcol_2` AS `corr_col`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_2` AS `cov_col`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6+
).*
27
FROM (
38
SELECT
49
`bfcol_2` AS `cov_col`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_32` AS `size`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6+
).*
27
FROM (
38
SELECT
49
`bfcol_32` AS `size`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_1` AS `int64_col`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6+
).*
27
FROM (
38
SELECT
49
`bfcol_1` AS `int64_col`

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_1` AS `string_col`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6+
).*
27
FROM (
38
SELECT
49
`bfcol_1` AS `string_col`

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_2` AS `bool_col`,
5+
`bfcol_3` AS `int64_col`
6+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
7+
).*
28
FROM (
39
SELECT
410
`bfcol_2` AS `bool_col`,

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_2` AS `bool_col`,
5+
`bfcol_3` AS `int64_col`
6+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
7+
).*
28
FROM (
39
SELECT
410
`bfcol_2` AS `bool_col`,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
SELECT
2+
(
3+
SELECT
4+
`bfcol_1` AS `int64_col`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6+
).*
27
FROM (
38
SELECT
49
`bfcol_1` AS `int64_col`

0 commit comments

Comments
 (0)