Skip to content

Commit 9dd172e

Browse files
authored
Merge branch 'main' into main_chelsealin_perf
2 parents 2daf779 + 0434f26 commit 9dd172e

File tree

14 files changed

+45
-66
lines changed

14 files changed

+45
-66
lines changed

bigframes/core/compile/sqlglot/compiler.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,17 @@ def compile_sql_select(node: sql_nodes.SqlSelectNode, child: ir.SQLGlotIR):
153153
for ordering in node.sorting
154154
)
155155

156-
projected_cols: tuple[tuple[str, sge.Expression], ...] = tuple(
157-
(
158-
cdef.id.sql,
159-
expression_compiler.expression_compiler.compile_expression(cdef.expression),
156+
projected_cols: tuple[tuple[str, sge.Expression], ...] = tuple()
157+
if not node.is_star_selection:
158+
projected_cols = tuple(
159+
(
160+
cdef.id.sql,
161+
expression_compiler.expression_compiler.compile_expression(
162+
cdef.expression
163+
),
164+
)
165+
for cdef in node.selections
160166
)
161-
for cdef in node.selections
162-
)
163167

164168
sge_predicates = tuple(
165169
expression_compiler.expression_compiler.compile_expression(expression)

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def from_table(
150150
if sql_predicate:
151151
select_expr = sge.Select().select(sge.Star()).from_(table_expr)
152152
select_expr = select_expr.where(
153-
sg.parse_one(sql_predicate, dialect="bigquery"), append=False
153+
sg.parse_one(sql_predicate, dialect=cls.dialect), append=False
154154
)
155155
return cls(expr=select_expr, uid_gen=uid_gen)
156156

@@ -172,16 +172,19 @@ def select(
172172
if len(sorting) > 0:
173173
new_expr = new_expr.order_by(*sorting)
174174

175-
to_select = [
176-
sge.Alias(
177-
this=expr,
178-
alias=sge.to_identifier(id, quoted=self.quoted),
179-
)
180-
if expr.alias_or_name != id
181-
else expr
182-
for id, expr in selections
183-
]
184-
new_expr = new_expr.select(*to_select, append=False)
175+
if len(selections) > 0:
176+
to_select = [
177+
sge.Alias(
178+
this=expr,
179+
alias=sge.to_identifier(id, quoted=self.quoted),
180+
)
181+
if expr.alias_or_name != id
182+
else expr
183+
for id, expr in selections
184+
]
185+
new_expr = new_expr.select(*to_select, append=False)
186+
else:
187+
new_expr = new_expr.select(sge.Star(), append=False)
185188

186189
if len(predicates) > 0:
187190
condition = _and(predicates)

bigframes/core/rewrite/select_pullup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,12 @@ def pull_up_source_ids(node: nodes.ReadTableNode) -> nodes.BigFrameNode:
5454
if all(id.sql == source_id for id, source_id in node.scan_list.items):
5555
return node
5656
else:
57-
source_ids = sorted(
58-
set(scan_item.source_id for scan_item in node.scan_list.items)
59-
)
6057
new_scan_list = nodes.ScanList.from_items(
6158
[
62-
nodes.ScanItem(identifiers.ColumnId(source_id), source_id)
63-
for source_id in source_ids
59+
nodes.ScanItem(
60+
identifiers.ColumnId(scan_item.source_id), scan_item.source_id
61+
)
62+
for scan_item in node.scan_list.items
6463
]
6564
)
6665
new_source = dataclasses.replace(node, scan_list=new_scan_list)

bigframes/core/sql_nodes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def consumed_ids(self):
142142
def _node_expressions(self):
143143
raise NotImplementedError()
144144

145+
@property
146+
def is_star_selection(self) -> bool:
147+
return tuple(self.ids) == tuple(self.child.ids)
148+
145149
@functools.cache
146150
def get_id_mapping(self) -> dict[identifiers.ColumnId, ex.Expression]:
147151
return {cdef.id: cdef.expression for cdef in self.selections}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`float64_col`,
4-
`int64_col`
3+
`int64_col`,
4+
`float64_col`
55
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
66
), `bfcte_1` AS (
77
SELECT

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`float64_col`,
4-
`int64_col`
3+
`int64_col`,
4+
`float64_col`
55
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
66
), `bfcte_1` AS (
77
SELECT

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`bool_col`,
4-
`bytes_col`,
5-
`date_col`,
6-
`datetime_col`,
7-
`duration_col`,
8-
`float64_col`,
9-
`geography_col`,
10-
`int64_col`,
11-
`int64_too`,
12-
`numeric_col`,
13-
`rowindex`,
14-
`rowindex_2`,
15-
`string_col`,
16-
`time_col`,
17-
`timestamp_col`
3+
*
184
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
195
), `bfcte_1` AS (
206
SELECT

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
`bool_col`,
4-
`duration_col`,
54
`int64_col`,
5+
`duration_col`,
66
`int64_col` AS `bfcol_6`,
77
`bool_col` AS `bfcol_7`,
88
`duration_col` AS `bfcol_8`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
`bool_col`,
4-
`duration_col`,
54
`int64_col`,
5+
`duration_col`,
66
`int64_col` AS `bfcol_6`,
77
`bool_col` AS `bfcol_7`,
88
`duration_col` AS `bfcol_8`

tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/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
3-
`int_list_col`,
43
`rowindex`,
4+
`int_list_col`,
55
`string_list_col`
66
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types`
77
), `bfcte_1` AS (

0 commit comments

Comments
 (0)