Skip to content

Commit 9741f50

Browse files
fix(bigframes): Fix bugs compiling ambiguous ids and in subqueries
1 parent 705e23d commit 9741f50

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

packages/bigframes/bigframes/core/compile/compiled.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ def isin_join(
381381
new_column = (
382382
(left_table[conditions[0]])
383383
.isin((right_table[conditions[1]]))
384+
.fillna(False)
384385
.name(indicator_col)
385386
)
386387

packages/bigframes/bigframes/session/_io/bigquery/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,19 +516,19 @@ def to_query(
516516
) -> str:
517517
"""Compile query_or_table with conditions(filters, wildcards) to query."""
518518
if is_query(query_or_table):
519-
sub_query = f"({query_or_table})"
519+
from_item = f"({query_or_table})"
520520
else:
521521
# Table ID can have 1, 2, 3, or 4 parts. Quoting all parts to be safe.
522522
# See: https://cloud.google.com/bigquery/docs/reference/standard-sql/lexical#identifiers
523523
parts = query_or_table.split(".")
524-
sub_query = ".".join(f"`{part}`" for part in parts)
524+
from_item = ".".join(f"`{part}`" for part in parts)
525525

526526
# TODO(b/338111344): Generate an index based on DefaultIndexKind if we
527527
# don't have index columns specified.
528528
if columns:
529529
# We only reduce the selection if columns is set, but we always
530530
# want to make sure index_cols is also included.
531-
select_clause = "SELECT " + ", ".join(f"`{column}`" for column in columns)
531+
select_clause = "SELECT " + ", ".join(f"`_bf_source`.`{column}`" for column in columns)
532532
else:
533533
select_clause = "SELECT *"
534534

@@ -545,7 +545,7 @@ def to_query(
545545

546546
return (
547547
f"{select_clause} "
548-
f"FROM {sub_query}"
548+
f"FROM {from_item} AS _bf_source"
549549
f"{time_travel_clause}{where_clause}{limit_clause}"
550550
)
551551

packages/bigframes/bigframes/session/polars_executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def _is_node_polars_executable(node: nodes.BigFrameNode):
122122
return False
123123
for expr in node._node_expressions:
124124
if isinstance(expr, agg_expressions.Aggregation):
125-
if not type(expr.op) in _COMPATIBLE_AGG_OPS:
125+
if type(expr.op) not in _COMPATIBLE_AGG_OPS:
126126
return False
127127
if isinstance(expr, expression.Expression):
128128
if not set(map(type, _get_expr_ops(expr))).issubset(_COMPATIBLE_SCALAR_OPS):

packages/bigframes/third_party/bigframes_vendored/sqlglot/parser.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4469,6 +4469,14 @@ def _parse_table(
44694469
if schema:
44704470
return self._parse_schema(this=this)
44714471

4472+
# see: https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#from_clause
4473+
# from_item, then alias, then time travel, then sample.
4474+
alias = self._parse_table_alias(
4475+
alias_tokens=alias_tokens or self.TABLE_ALIAS_TOKENS
4476+
)
4477+
if alias:
4478+
this.set("alias", alias)
4479+
44724480
version = self._parse_version()
44734481

44744482
if version:
@@ -4477,11 +4485,6 @@ def _parse_table(
44774485
if self.dialect.ALIAS_POST_TABLESAMPLE:
44784486
this.set("sample", self._parse_table_sample())
44794487

4480-
alias = self._parse_table_alias(
4481-
alias_tokens=alias_tokens or self.TABLE_ALIAS_TOKENS
4482-
)
4483-
if alias:
4484-
this.set("alias", alias)
44854488

44864489
if self._match(TokenType.INDEXED_BY):
44874490
this.set("indexed", self._parse_table_parts())

0 commit comments

Comments
 (0)