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

Commit f5a2276

Browse files
committed
select star if possible when compiling readtable
1 parent 56c2879 commit f5a2276

File tree

11 files changed

+31
-97
lines changed
  • bigframes/core
  • tests/unit/core/compile/sqlglot
    • aggregations/snapshots/test_nullary_compiler
    • expressions/snapshots/test_generic_ops/test_row_key
    • snapshots/test_compile_readtable
      • test_compile_readtable_w_json_types
      • test_compile_readtable_w_nested_structs_types
      • test_compile_readtable_w_repeated_types
      • test_compile_readtable_w_system_time
      • test_compile_readtable

11 files changed

+31
-97
lines changed

bigframes/core/compile/sqlglot/compiler.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,14 @@ def compile_readlocal(node: nodes.ReadLocalNode, child: ir.SQLGlotIR) -> ir.SQLG
176176
@_compile_node.register
177177
def compile_readtable(node: nodes.ReadTableNode, child: ir.SQLGlotIR):
178178
table = node.source.table
179+
is_star_selection = node.is_star_selection
179180
return ir.SQLGlotIR.from_table(
180181
table.project_id,
181182
table.dataset_id,
182183
table.table_id,
183184
col_names=[col.source_id for col in node.scan_list.items],
184185
alias_names=[col.id.sql for col in node.scan_list.items],
186+
is_star_selection=is_star_selection,
185187
uid_gen=child.uid_gen,
186188
sql_predicate=node.source.sql_predicate,
187189
system_time=node.source.at_time,

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def from_table(
118118
table_id: str,
119119
col_names: typing.Sequence[str],
120120
alias_names: typing.Sequence[str],
121+
is_star_selection: bool,
121122
uid_gen: guid.SequentialUIDGenerator,
122123
sql_predicate: typing.Optional[str] = None,
123124
system_time: typing.Optional[datetime.datetime] = None,
@@ -134,15 +135,7 @@ def from_table(
134135
sql_predicate (typing.Optional[str]): An optional SQL predicate for filtering.
135136
system_time (typing.Optional[str]): An optional system time for time-travel queries.
136137
"""
137-
selections = [
138-
sge.Alias(
139-
this=sge.to_identifier(col_name, quoted=cls.quoted),
140-
alias=sge.to_identifier(alias_name, quoted=cls.quoted),
141-
)
142-
if col_name != alias_name
143-
else sge.to_identifier(col_name, quoted=cls.quoted)
144-
for col_name, alias_name in zip(col_names, alias_names)
145-
]
138+
146139
version = (
147140
sge.Version(
148141
this="TIMESTAMP",
@@ -158,7 +151,19 @@ def from_table(
158151
catalog=sg.to_identifier(project_id, quoted=cls.quoted),
159152
version=version,
160153
)
161-
select_expr = sge.Select().select(*selections).from_(table_expr)
154+
if is_star_selection:
155+
select_expr = sge.Select().select(sge.Star()).from_(table_expr)
156+
else:
157+
selections = [
158+
sge.Alias(
159+
this=sge.to_identifier(col_name, quoted=cls.quoted),
160+
alias=sge.to_identifier(alias_name, quoted=cls.quoted),
161+
)
162+
if col_name != alias_name
163+
else sge.to_identifier(col_name, quoted=cls.quoted)
164+
for col_name, alias_name in zip(col_names, alias_names)
165+
]
166+
select_expr = sge.Select().select(*selections).from_(table_expr)
162167
if sql_predicate:
163168
select_expr = select_expr.where(
164169
sg.parse_one(sql_predicate, dialect="bigquery"), append=False

bigframes/core/nodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,12 @@ def order_ambiguous(self) -> bool:
819819
def explicitly_ordered(self) -> bool:
820820
return self.source.ordering is not None
821821

822+
@property
823+
def is_star_selection(self) -> bool:
824+
physical_names = tuple(item.name for item in self.source.table.physical_schema)
825+
scan_names = tuple(item.source_id for item in self.scan_list.items)
826+
return physical_names == scan_names
827+
822828
@functools.cached_property
823829
def variables_introduced(self) -> int:
824830
return len(self.scan_list.items) + 1

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number/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-
`geography_col`,
8-
`int64_col`,
9-
`int64_too`,
10-
`numeric_col`,
11-
`float64_col`,
12-
`rowindex`,
13-
`rowindex_2`,
14-
`string_col`,
15-
`time_col`,
16-
`timestamp_col`,
17-
`duration_col`
3+
*
184
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
195
), `bfcte_1` AS (
206
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-
`geography_col`,
8-
`int64_col`,
9-
`int64_too`,
10-
`numeric_col`,
11-
`float64_col`,
12-
`rowindex`,
13-
`rowindex_2`,
14-
`string_col`,
15-
`time_col`,
16-
`timestamp_col`,
17-
`duration_col`
3+
*
184
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
195
), `bfcte_1` AS (
206
SELECT

tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_row_key/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-
`geography_col`,
8-
`int64_col`,
9-
`int64_too`,
10-
`numeric_col`,
11-
`float64_col`,
12-
`rowindex`,
13-
`rowindex_2`,
14-
`string_col`,
15-
`time_col`,
16-
`timestamp_col`,
17-
`duration_col`
3+
*
184
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
195
), `bfcte_1` AS (
206
SELECT

tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable/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-
`geography_col`,
8-
`int64_col`,
9-
`int64_too`,
10-
`numeric_col`,
11-
`float64_col`,
12-
`rowindex`,
13-
`rowindex_2`,
14-
`string_col`,
15-
`time_col`,
16-
`timestamp_col`,
17-
`duration_col`
3+
*
184
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
195
)
206
SELECT

tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_json_types/out.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex`,
4-
`json_col`
3+
*
54
FROM `bigframes-dev`.`sqlglot_test`.`json_types`
65
)
76
SELECT

tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_nested_structs_types/out.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`id`,
4-
`people`
3+
*
54
FROM `bigframes-dev`.`sqlglot_test`.`nested_structs_types`
65
)
76
SELECT

tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_repeated_types/out.sql

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
WITH `bfcte_0` AS (
22
SELECT
3-
`rowindex`,
4-
`int_list_col`,
5-
`bool_list_col`,
6-
`float_list_col`,
7-
`date_list_col`,
8-
`date_time_list_col`,
9-
`numeric_list_col`,
10-
`string_list_col`
3+
*
114
FROM `bigframes-dev`.`sqlglot_test`.`repeated_types`
125
)
136
SELECT

0 commit comments

Comments
 (0)