Skip to content

Commit e60f3ed

Browse files
dont create with expression without ctes
1 parent 1e62fd3 commit e60f3ed

File tree

44 files changed

+45
-869
lines changed

Some content is hidden

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

44 files changed

+45
-869
lines changed

bigframes/core/compile/sqlglot/compiler.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,16 +366,3 @@ def _replace_unsupported_ops(node: nodes.BigFrameNode):
366366
node = nodes.bottom_up(node, rewrite.rewrite_slice)
367367
node = nodes.bottom_up(node, rewrite.rewrite_range_rolling)
368368
return node
369-
370-
371-
def _get_ctes(root: nodes.ResultNode) -> typing.Sequence[nodes.CteNode]:
372-
"""
373-
Get ctes from plan in topological order.
374-
"""
375-
376-
def merge_list(node, cte_list):
377-
if isinstance(node, nodes.CteNode):
378-
return (*cte_list, node)
379-
return cte_list
380-
381-
return root.reduce_up(merge_list)

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,13 @@ def _explode_multiple_columns(
503503
def _as_from_item(self) -> typing.Union[sge.Subquery, sge.Table]:
504504
if isinstance(self.expr, sge.Select):
505505
return self.expr.subquery()
506-
else: # table
506+
else: # table or cte
507507
return self.expr
508508

509509
def _as_select(self) -> sge.Select:
510510
if isinstance(self.expr, sge.Select):
511511
return self.expr
512-
else: # table
512+
else: # table or cte
513513
return (
514514
sge.Select()
515515
.select(sge.Column(this=sge.Star(), table=self.expr))

bigframes/core/rewrite/as_sql.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ def _extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode:
228228
)
229229
cte_names = tuple(f"bfcte_{i}" for i in range(len(topological_ctes)))
230230

231+
if len(topological_ctes) == 0:
232+
return root
233+
231234
mapping = {
232235
cte_node: sql_nodes.SqlCteRefNode(cte_name, tuple(cte_node.fields))
233236
for cte_node, cte_name in zip(topological_ctes, cte_names)

bigframes/core/rewrite/ctes.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ def extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode:
2525
for child in parent.child_nodes:
2626
node_parents[child] += 1
2727

28-
counter = 0
29-
3028
# we just mark in place, rather than pull out of the tree.
3129
def insert_cte_markers(node: nodes.BigFrameNode) -> nodes.BigFrameNode:
32-
nonlocal counter
3330
if node_parents[node] > 1:
34-
counter += 1
3531
return nodes.CteNode(node)
3632
return node
3733

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
SELECT
2-
(
3-
SELECT
4-
`bfcol_2` AS `corr_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6-
).*
7-
FROM (
1+
(
82
SELECT
93
`bfcol_2` AS `corr_col`
104
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
SELECT
2-
(
3-
SELECT
4-
`bfcol_2` AS `cov_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6-
).*
7-
FROM (
1+
(
82
SELECT
93
`bfcol_2` AS `cov_col`
104
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
SELECT
2-
(
3-
SELECT
4-
`bfcol_32` AS `size`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6-
).*
7-
FROM (
1+
(
82
SELECT
93
`bfcol_32` AS `size`
104
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
SELECT
2-
(
3-
SELECT
4-
`bfcol_1` AS `int64_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6-
).*
7-
FROM (
1+
(
82
SELECT
93
`bfcol_1` AS `int64_col`
104
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
SELECT
2-
(
3-
SELECT
4-
`bfcol_1` AS `string_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
6-
).*
7-
FROM (
1+
(
82
SELECT
93
`bfcol_1` AS `string_col`
104
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
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-
).*
8-
FROM (
1+
(
92
SELECT
103
`bfcol_2` AS `bool_col`,
114
`bfcol_3` AS `int64_col`

0 commit comments

Comments
 (0)