From 6a1107ecf7f5bd37bfbcdd45e50db1a12ee2e728 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Thu, 12 Feb 2026 01:12:07 +0000 Subject: [PATCH 01/15] refactor: Add cte factoring to new compiler --- bigframes/core/compile/sqlglot/compiler.py | 50 ++++++++ bigframes/core/compile/sqlglot/sqlglot_ir.py | 114 +++++-------------- bigframes/core/nodes.py | 67 +++++++++++ bigframes/core/rewrite/__init__.py | 2 + bigframes/core/rewrite/ctes.py | 43 +++++++ bigframes/core/rewrite/pruning.py | 57 +++++++++- bigframes/session/bq_caching_executor.py | 9 ++ 7 files changed, 257 insertions(+), 85 deletions(-) create mode 100644 bigframes/core/rewrite/ctes.py diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index 786c5a1ed1f..105277836da 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -48,6 +48,8 @@ def compile_sql(request: configs.CompileRequest) -> configs.CompileResult: output_cols=output_names, limit=request.peek_count, ) + # Extract CTEs early, as later rewriters could otherwise make common subtrees diverge + result_node = typing.cast(nodes.ResultNode, rewrite.extract_ctes(result_node)) if request.sort_rows: # Can only pullup slice if we are doing ORDER BY in outermost SELECT # Need to do this before replacing unsupported ops, as that will rewrite slice ops @@ -103,11 +105,21 @@ def _compile_result_node(root: nodes.ResultNode) -> str: root = _remap_variables(root, uid_gen) root = typing.cast(nodes.ResultNode, rewrite.defer_selection(root)) + # TODO: Extract out CTEs to a with_ctes node? + cte_nodes = _get_ctes(root) + # Have to bind schema as the final step before compilation. # Probably, should defer even further root = typing.cast(nodes.ResultNode, schema_binding.bind_schema_to_tree(root)) sqlglot_ir = compile_node(rewrite.as_sql_nodes(root), uid_gen) + sqlglot_ir = sqlglot_ir.with_ctes( + tuple( + (compile_node(cte_node, uid_gen)._as_select(), cte_node.name) + for cte_node in cte_nodes + ) + ) + return sqlglot_ir.sql @@ -247,6 +259,31 @@ def compile_isin_join( ) +@_compile_node.register +def compile_cte_node(node: nodes.CteRefNode, _) + table = node.name + return ir.SQLGlotIR.from_table( + table.project_id, + table.dataset_id, + table.table_id, + uid_gen=child.uid_gen, + sql_predicate=node.source.sql_predicate, + system_time=node.source.at_time, + ) + +@_compile_node.register +def compile_cte_node(node: nodes.CteNode, _) + table = node.source.table + return ir.SQLGlotIR.from_table( + table.project_id, + table.dataset_id, + table.table_id, + uid_gen=child.uid_gen, + sql_predicate=node.source.sql_predicate, + system_time=node.source.at_time, + ) + + @_compile_node.register def compile_concat(node: nodes.ConcatNode, *children: ir.SQLGlotIR) -> ir.SQLGlotIR: assert len(children) >= 1 @@ -312,3 +349,16 @@ def _replace_unsupported_ops(node: nodes.BigFrameNode): node = nodes.bottom_up(node, rewrite.rewrite_slice) node = nodes.bottom_up(node, rewrite.rewrite_range_rolling) return node + + +def _get_ctes(root: nodes.ResultNode) -> typing.Sequence[nodes.CteNode]: + """ + Get ctes from plan in topological order. + """ + + def merge_list(node, cte_list): + if isinstance(node, nodes.CteNode): + return (*cte_list, node) + return cte_list + + return root.reduce_up(merge_list) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index d0bd32697c4..8732e97349d 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -165,7 +165,7 @@ def select( ) -> SQLGlotIR: # TODO: Explicitly insert CTEs into plan if isinstance(self.expr, sge.Select): - new_expr, _ = self._select_to_cte() + new_expr, _ = self._as_from_item() else: new_expr = sge.Select().from_(self.expr) @@ -222,21 +222,8 @@ def from_union( assert ( len(list(selects)) >= 2 ), f"At least two select expressions must be provided, but got {selects}." - - existing_ctes: list[sge.CTE] = [] - union_selects: list[sge.Select] = [] - for select in selects: - assert isinstance( - select, sge.Select - ), f"All provided expressions must be of type sge.Select, but got {type(select)}" - - select_expr = select.copy() - select_expr, select_ctes = _pop_query_ctes(select_expr) - existing_ctes = _merge_ctes(existing_ctes, select_ctes) - union_selects.append(select_expr) - - union_expr: sge.Query = union_selects[0].subquery() - for select in union_selects[1:]: + union_expr: sge.Query = selects[0].subquery() + for select in selects[1:]: union_expr = sge.Union( this=union_expr, expression=select.subquery(), @@ -254,7 +241,6 @@ def from_union( final_select_expr = ( sge.Select().select(*selections).from_(union_expr.subquery()) ) - final_select_expr = _set_query_ctes(final_select_expr, existing_ctes) return cls(expr=final_select_expr, uid_gen=uid_gen) def join( @@ -266,12 +252,8 @@ def join( joins_nulls: bool = True, ) -> SQLGlotIR: """Joins the current query with another SQLGlotIR instance.""" - left_select, left_cte_name = self._select_to_cte() - right_select, right_cte_name = right._select_to_cte() - - left_select, left_ctes = _pop_query_ctes(left_select) - right_select, right_ctes = _pop_query_ctes(right_select) - merged_ctes = _merge_ctes(left_ctes, right_ctes) + left_from = self._as_from_item() + right_from = right._as_from_item() join_on = _and( tuple( @@ -283,10 +265,9 @@ def join( new_expr = ( sge.Select() .select(sge.Star()) - .from_(sge.Table(this=left_cte_name)) - .join(sge.Table(this=right_cte_name), on=join_on, join_type=join_type_str) + .from_(left_from) + .join(right_from, on=join_on, join_type=join_type_str) ) - new_expr = _set_query_ctes(new_expr, merged_ctes) return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) @@ -298,16 +279,12 @@ def isin_join( joins_nulls: bool = True, ) -> SQLGlotIR: """Joins the current query with another SQLGlotIR instance.""" - left_select, left_cte_name = self._select_to_cte() + left_from = self._as_from_item() # Prefer subquery over CTE for the IN clause's right side to improve SQL readability. right_select = right._as_select() - left_select, left_ctes = _pop_query_ctes(left_select) - right_select, right_ctes = _pop_query_ctes(right_select) - merged_ctes = _merge_ctes(left_ctes, right_ctes) - left_condition = typed_expr.TypedExpr( - sge.Column(this=conditions[0].expr, table=left_cte_name), + sge.Column(this=conditions[0].expr, table=left_from), conditions[0].dtype, ) @@ -341,10 +318,9 @@ def isin_join( new_expr = ( sge.Select() - .select(sge.Column(this=sge.Star(), table=left_cte_name), new_column) - .from_(sge.Table(this=left_cte_name)) + .select(sge.Column(this=sge.Star(), table=left_from), new_column) + .from_(left_from) ) - new_expr = _set_query_ctes(new_expr, merged_ctes) return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) @@ -368,7 +344,7 @@ def sample(self, fraction: float) -> SQLGlotIR: expression=_literal(fraction, dtypes.FLOAT_DTYPE), ) - new_expr = self._select_to_cte()[0].where(condition, append=False) + new_expr = self._as_select().where(condition, append=False) return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) def aggregate( @@ -392,7 +368,7 @@ def aggregate( for id, expr in aggregations ] - new_expr, _ = self._select_to_cte() + new_expr = self._as_select() new_expr = new_expr.group_by(*by_cols).select( *[*by_cols, *aggregations_expr], append=False ) @@ -407,12 +383,26 @@ def aggregate( new_expr = new_expr.where(condition, append=False) return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + def with_ctes( + self, + ctes: tuple[tuple[str, sge.Select], ...], + ) -> SQLGlotIR: + sge_ctes = [ + sge.CTE( + this=cte, + alias=cte_name, + ) + for cte_name, cte in ctes + ] + select_expr = _set_query_ctes(self._as_select(), sge_ctes) + return SQLGlotIR(expr=select_expr, uid_gen=self.uid_gen) + def insert( self, destination: bigquery.TableReference, ) -> str: """Generates an INSERT INTO SQL statement from the current SELECT clause.""" - return sge.insert(self._as_from_item(), _table(destination)).sql( + return sge.insert(self._as_select(), _table(destination)).sql( dialect=self.dialect, pretty=self.pretty ) @@ -436,7 +426,7 @@ def replace( merge_str = sge.Merge( this=_table(destination), - using=self._as_from_item(), + using=self._as_select(), on=_literal(False, dtypes.BOOL_DTYPE), ).sql(dialect=self.dialect, pretty=self.pretty) return f"{merge_str}\n{whens_str}" @@ -459,7 +449,7 @@ def _explode_single_column( ) selection = sge.Star(replace=[unnested_column_alias.as_(column)]) - new_expr, _ = self._select_to_cte() + new_expr = self._as_select() # Use LEFT JOIN to preserve rows when unnesting empty arrays. new_expr = new_expr.select(selection, append=False).join( unnest_expr, join_type="LEFT" @@ -510,7 +500,7 @@ def _explode_multiple_columns( for column in columns ] ) - new_expr, _ = self._select_to_cte() + new_expr = self._as_select() # Use LEFT JOIN to preserve rows when unnesting empty arrays. new_expr = new_expr.select(selection, append=False).join( unnest_expr, join_type="LEFT" @@ -532,25 +522,6 @@ def _as_select(self) -> sge.Select: def _as_subquery(self) -> sge.Subquery: return self._as_select().subquery() - def _select_to_cte(self) -> tuple[sge.Select, sge.Identifier]: - """Transforms a given sge.Select query by pushing its main SELECT statement - into a new CTE and then generates a 'SELECT * FROM new_cte_name' - for the new query.""" - cte_name = sge.to_identifier( - next(self.uid_gen.get_uid_stream("bfcte_")), quoted=self.quoted - ) - select_expr = self._as_select().copy() - select_expr, existing_ctes = _pop_query_ctes(select_expr) - new_cte = sge.CTE( - this=select_expr, - alias=cte_name, - ) - new_select_expr = ( - sge.Select().select(sge.Star()).from_(sge.Table(this=cte_name)) - ) - new_select_expr = _set_query_ctes(new_select_expr, [*existing_ctes, new_cte]) - return new_select_expr, cte_name - def _is_null_literal(expr: sge.Expression) -> bool: """Checks if the given expression is a NULL literal.""" @@ -743,26 +714,3 @@ def _set_query_ctes( else: raise ValueError("The expression does not support CTEs.") return new_expr - - -def _merge_ctes(ctes1: list[sge.CTE], ctes2: list[sge.CTE]) -> list[sge.CTE]: - """Merges two lists of CTEs, de-duplicating by alias name.""" - seen = {cte.alias: cte for cte in ctes1} - for cte in ctes2: - if cte.alias not in seen: - seen[cte.alias] = cte - return list(seen.values()) - - -def _pop_query_ctes( - expr: sge.Select, -) -> tuple[sge.Select, list[sge.CTE]]: - """Pops the CTEs of a given sge.Select expression.""" - if "with" in expr.arg_types.keys(): - expr_ctes = expr.args.pop("with", []) - return expr, expr_ctes - elif "with_" in expr.arg_types.keys(): - expr_ctes = expr.args.pop("with_", []) - return expr, expr_ctes - else: - raise ValueError("The expression does not support CTEs.") diff --git a/bigframes/core/nodes.py b/bigframes/core/nodes.py index ddccb39ef98..a187be7caeb 100644 --- a/bigframes/core/nodes.py +++ b/bigframes/core/nodes.py @@ -1715,6 +1715,73 @@ def _node_expressions(self): return tuple(ref for ref, _ in self.output_cols) +@dataclasses.dataclass(frozen=True, eq=False) +class CteRefNode(UnaryNode): + cols: tuple[ex.DerefOp, ...] + + @property + def fields(self) -> Sequence[Field]: + # Fields property here is for output schema, not to be consumed by a parent node. + input_fields_by_id = {field.id: field for field in self.child.fields} + return tuple(input_fields_by_id[ref.id] for ref in self.cols) + + @property + def variables_introduced(self) -> int: + # This operation only renames variables, doesn't actually create new ones + return 0 + + @property + def row_count(self) -> Optional[int]: + return self.child.row_count + + @property + def node_defined_ids(self) -> Tuple[identifiers.ColumnId, ...]: + return () + + def remap_vars( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> CteRefNode: + return self + + def remap_refs( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> CteRefNode: + new_cols = tuple(id.remap_column_refs(mappings) for id in self.cols) + return dataclasses.replace(self, cols=new_cols) + + +@dataclasses.dataclass(frozen=True, eq=False) +class CteNode(UnaryNode): + name: str + + @property + def fields(self) -> Sequence[Field]: + return self.child.fields + + @property + def variables_introduced(self) -> int: + # This operation only renames variables, doesn't actually create new ones + return 0 + + @property + def row_count(self) -> Optional[int]: + return self.child.row_count + + @property + def node_defined_ids(self) -> Tuple[identifiers.ColumnId, ...]: + return () + + def remap_vars( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> CteNode: + return self + + def remap_refs( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> CteNode: + return self + + # Tree operators def top_down( root: BigFrameNode, diff --git a/bigframes/core/rewrite/__init__.py b/bigframes/core/rewrite/__init__.py index a120612aae5..5279418f5fb 100644 --- a/bigframes/core/rewrite/__init__.py +++ b/bigframes/core/rewrite/__init__.py @@ -13,6 +13,7 @@ # limitations under the License. from bigframes.core.rewrite.as_sql import as_sql_nodes +from bigframes.core.rewrite.ctes import extract_ctes from bigframes.core.rewrite.fold_row_count import fold_row_counts from bigframes.core.rewrite.identifiers import remap_variables from bigframes.core.rewrite.implicit_align import try_row_join @@ -34,6 +35,7 @@ __all__ = [ "as_sql_nodes", + "extract_ctes", "legacy_join_as_projection", "try_row_join", "rewrite_slice", diff --git a/bigframes/core/rewrite/ctes.py b/bigframes/core/rewrite/ctes.py new file mode 100644 index 00000000000..debdb6832bd --- /dev/null +++ b/bigframes/core/rewrite/ctes.py @@ -0,0 +1,43 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from __future__ import annotations + +from collections import defaultdict + +from bigframes.core import expression, nodes + + +def extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: + # identify candidates + # candidates + node_parents: dict[nodes.BigFrameNode, int] = defaultdict(int) + for parent in root.unique_nodes(): + for child in parent.child_nodes: + node_parents[child] += 1 + + counter = 0 + # ok time to replace via extract + # we just mark in place, rather than pull out of the tree. + # if we did pull out of tree, we'd want to make sure to extract bottom-up + def insert_cte_markers(node: nodes.BigFrameNode) -> nodes.BigFrameNode: + nonlocal counter + if node_parents[node] > 1: + counter += 1 + return nodes.CteRefNode( + nodes.CteNode(node, name=f"cte_{counter})"), + cols=tuple(expression.DerefOp(id) for id in node.ids), + ) + return node + + return root.top_down(insert_cte_markers) diff --git a/bigframes/core/rewrite/pruning.py b/bigframes/core/rewrite/pruning.py index 7695ace3b33..730609ffe6b 100644 --- a/bigframes/core/rewrite/pruning.py +++ b/bigframes/core/rewrite/pruning.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import collections import dataclasses import functools import itertools @@ -22,7 +23,39 @@ def column_pruning( root: nodes.BigFrameNode, ) -> nodes.BigFrameNode: - return nodes.top_down(root, prune_columns) + # We wrap the entire process in a fixed-point iteration to ensure + # the global push-down through CTEs fully settles. + @to_fixed(max_iterations=100) + def prune_tree(current_root: nodes.BigFrameNode) -> nodes.BigFrameNode: + # Apply local top-down pruning rules (pushes selections to CteRefNodes) + pushed_root = nodes.top_down(current_root, prune_columns) + + # Gather the union of required columns globally across all CTE refs + cte_reqs: typing.DefaultDict[ + nodes.BigFrameNode, set[identifiers.ColumnId] + ] = collections.defaultdict(set) + + def gather_reqs(node: nodes.BigFrameNode) -> nodes.BigFrameNode: + if isinstance(node, nodes.CteRefNode): + # node.child is the referenced CTE definition (CteNode) + for col in node.cols: + cte_reqs[node.child].add(col.id) + return node + + nodes.top_down(pushed_root, gather_reqs) + + # Apply the unioned required columns to the CTE definitions + def apply_cte_reqs(node: nodes.BigFrameNode) -> nodes.BigFrameNode: + if isinstance(node, nodes.CteNode) and node in cte_reqs: + needed_ids = frozenset(cte_reqs[node]) + pruned_child = prune_node(node.child, needed_ids) + if pruned_child is not node.child: + return node.replace_child(pruned_child) + return node + + return nodes.top_down(pushed_root, apply_cte_reqs) + + return prune_tree(root) def to_fixed(max_iterations: int = 100): @@ -67,7 +100,8 @@ def prune_selection_child( # Important to check this first if list(selection.ids) == list(child.ids): - if (ref.ref.id == ref.id for ref in selection.input_output_pairs): + # Added all() here - a generator object is natively truthy + if all(ref.ref.id == ref.id for ref in selection.input_output_pairs): # selection is no-op so just remove it entirely return child @@ -75,6 +109,25 @@ def prune_selection_child( return selection.remap_refs( {id: ref.id for ref, id in child.input_output_pairs} ).replace_child(child.child) + + elif isinstance(child, nodes.CteRefNode): + # Push selection locally into the CTE Reference + needed_ids = selection.consumed_ids + new_cols = ( + tuple(col for col in child.cols if col.id in needed_ids) or child.cols[0:1] + ) + + if new_cols == child.cols: + return selection + return selection.replace_child(dataclasses.replace(child, cols=new_cols)) + + elif isinstance(child, nodes.CteNode): + # Pass-through selection to the CTE Definition just in case it's wrapped locally + pruned_child = prune_node(child.child, selection.consumed_ids) + if pruned_child is child.child: + return selection + return selection.replace_child(child.replace_child(pruned_child)) + elif isinstance(child, nodes.AdditiveNode): if not set(field.id for field in child.added_fields) & selection.consumed_ids: return selection.replace_child(child.additive_base) diff --git a/bigframes/session/bq_caching_executor.py b/bigframes/session/bq_caching_executor.py index 2f5ec035dc6..9eb6ccd897a 100644 --- a/bigframes/session/bq_caching_executor.py +++ b/bigframes/session/bq_caching_executor.py @@ -488,6 +488,15 @@ def prepare_plan( return plan + def simplify_plan( + self, plan: nodes.BigFrameNode, use_cache: bool = True + ) -> nodes.BigFrameNode: + if use_cache: + plan = self.replace_cached_subtrees(plan) + plan = rewrite.column_pruning(plan) + plan = plan.top_down(rewrite.fold_row_counts) + return plan + def _cache_with_cluster_cols( self, array_value: bigframes.core.ArrayValue, cluster_cols: Sequence[str] ): From 10a9798d6e51bb3e4904c015ed847e239ac065b5 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 00:12:52 +0000 Subject: [PATCH 02/15] separate logical cte nodes from concrete sql ones --- bigframes/core/compile/sqlglot/compiler.py | 22 ++-- bigframes/core/compile/sqlglot/sqlglot_ir.py | 4 +- bigframes/core/nodes.py | 40 +----- bigframes/core/rewrite/as_sql.py | 20 +++ bigframes/core/rewrite/ctes.py | 11 +- bigframes/core/rewrite/pruning.py | 53 +------- bigframes/core/sql_nodes.py | 128 ++++++++++++++++++- 7 files changed, 164 insertions(+), 114 deletions(-) diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index 79d2be1ba07..f2119015a3a 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -106,21 +106,11 @@ def _compile_result_node(root: nodes.ResultNode) -> str: root = _remap_variables(root, uid_gen) root = typing.cast(nodes.ResultNode, rewrite.defer_selection(root)) - # TODO: Extract out CTEs to a with_ctes node? - cte_nodes = _get_ctes(root) - # Have to bind schema as the final step before compilation. # Probably, should defer even further root = typing.cast(nodes.ResultNode, schema_binding.bind_schema_to_tree(root)) sqlglot_ir_obj = compile_node(rewrite.as_sql_nodes(root), uid_gen) - sqlglot_ir_obj = sqlglot_ir_obj.with_ctes( - tuple( - (compile_node(cte_node, uid_gen)._as_select(), cte_node.name) - for cte_node in cte_nodes - ) - ) - return sqlglot_ir_obj.sql @@ -269,16 +259,20 @@ def compile_isin_join( @_compile_node.register -def compile_cte_ref_node(node: nodes.CteRefNode, child: sqlglot_ir.SQLGlotIR): +def compile_cte_ref_node(node: sql_nodes.SqlCteRefNode, child: sqlglot_ir.SQLGlotIR): return sqlglot_ir.SQLGlotIR.from_cte_ref( - node.child.name, # type: ignore + node.cte_name, uid_gen=child.uid_gen, ) @_compile_node.register -def compile_cte_node(node: nodes.CteNode, child: sqlglot_ir.SQLGlotIR): - raise ValueError("CTE definitions should not be directly compiled") +def compile_with_ctes_node( + node: sql_nodes.SqlWithCtesNode, + child: sqlglot_ir.SQLGlotIR, + *ctes: sqlglot_ir.SQLGlotIR, +): + return child.with_ctes(tuple(zip(node.cte_names, ctes))) @_compile_node.register diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index bd61a30a5c4..859b3d742d7 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -386,11 +386,11 @@ def aggregate( def with_ctes( self, - ctes: tuple[tuple[str, sge.Select], ...], + ctes: tuple[tuple[str, SQLGlotIR], ...], ) -> SQLGlotIR: sge_ctes = [ sge.CTE( - this=cte, + this=cte._as_select(), alias=cte_name, ) for cte_name, cte in ctes diff --git a/bigframes/core/nodes.py b/bigframes/core/nodes.py index 0974175e660..6071eaeaea2 100644 --- a/bigframes/core/nodes.py +++ b/bigframes/core/nodes.py @@ -1713,44 +1713,11 @@ def _node_expressions(self): return tuple(ref for ref, _ in self.output_cols) -@dataclasses.dataclass(frozen=True, eq=False) -class CteRefNode(UnaryNode): - cols: tuple[ex.DerefOp, ...] - - @property - def fields(self) -> Sequence[Field]: - # Fields property here is for output schema, not to be consumed by a parent node. - input_fields_by_id = {field.id: field for field in self.child.fields} - return tuple(input_fields_by_id[ref.id] for ref in self.cols) - - @property - def variables_introduced(self) -> int: - # This operation only renames variables, doesn't actually create new ones - return 0 - - @property - def row_count(self) -> Optional[int]: - return self.child.row_count - - @property - def node_defined_ids(self) -> Tuple[identifiers.ColumnId, ...]: - return () - - def remap_vars( - self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] - ) -> CteRefNode: - return self - - def remap_refs( - self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] - ) -> CteRefNode: - new_cols = tuple(id.remap_column_refs(mappings) for id in self.cols) - return dataclasses.replace(self, cols=new_cols) - - @dataclasses.dataclass(frozen=True, eq=False) class CteNode(UnaryNode): - name: str + """ + Semantically a no-op, used to indicate shared subtrees and act as optimization boundary. + """ @property def fields(self) -> Sequence[Field]: @@ -1758,7 +1725,6 @@ def fields(self) -> Sequence[Field]: @property def variables_introduced(self) -> int: - # This operation only renames variables, doesn't actually create new ones return 0 @property diff --git a/bigframes/core/rewrite/as_sql.py b/bigframes/core/rewrite/as_sql.py index 32d677f75d7..a1ce1fcc5c5 100644 --- a/bigframes/core/rewrite/as_sql.py +++ b/bigframes/core/rewrite/as_sql.py @@ -222,6 +222,26 @@ def _as_sql_node(node: nodes.BigFrameNode) -> nodes.BigFrameNode: return node +def _extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: + topological_ctes = list( + filter(lambda n: isinstance(n, nodes.CteNode), root.iter_nodes_topo()) + ) + cte_names = tuple(f"cte_{i}" for i in range(len(topological_ctes))) + + mapping = { + cte_node: sql_nodes.SqlCteRefNode(cte_name, tuple(cte_node.fields)) + for cte_node, cte_name in zip(topological_ctes, cte_names) + } + + # Replace all CTEs with CTE references and wrap the new root in a WITH clause + return sql_nodes.SqlWithCtesNode( + root.top_down(lambda x: mapping.get(x, x)), + cte_names, + tuple(cte.top_down(lambda x: mapping.get(x, x)) for cte in topological_ctes), + ) + + def as_sql_nodes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: # TODO: Aggregations, Unions, Joins, raw data sources + root = _extract_ctes(root) return nodes.bottom_up(root, _as_sql_node) diff --git a/bigframes/core/rewrite/ctes.py b/bigframes/core/rewrite/ctes.py index debdb6832bd..12506ea834a 100644 --- a/bigframes/core/rewrite/ctes.py +++ b/bigframes/core/rewrite/ctes.py @@ -15,29 +15,24 @@ from collections import defaultdict -from bigframes.core import expression, nodes +from bigframes.core import nodes def extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: # identify candidates - # candidates node_parents: dict[nodes.BigFrameNode, int] = defaultdict(int) for parent in root.unique_nodes(): for child in parent.child_nodes: node_parents[child] += 1 counter = 0 - # ok time to replace via extract + # we just mark in place, rather than pull out of the tree. - # if we did pull out of tree, we'd want to make sure to extract bottom-up def insert_cte_markers(node: nodes.BigFrameNode) -> nodes.BigFrameNode: nonlocal counter if node_parents[node] > 1: counter += 1 - return nodes.CteRefNode( - nodes.CteNode(node, name=f"cte_{counter})"), - cols=tuple(expression.DerefOp(id) for id in node.ids), - ) + return nodes.CteNode(node) return node return root.top_down(insert_cte_markers) diff --git a/bigframes/core/rewrite/pruning.py b/bigframes/core/rewrite/pruning.py index 730609ffe6b..591ae857031 100644 --- a/bigframes/core/rewrite/pruning.py +++ b/bigframes/core/rewrite/pruning.py @@ -11,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import collections import dataclasses import functools import itertools @@ -23,39 +22,7 @@ def column_pruning( root: nodes.BigFrameNode, ) -> nodes.BigFrameNode: - # We wrap the entire process in a fixed-point iteration to ensure - # the global push-down through CTEs fully settles. - @to_fixed(max_iterations=100) - def prune_tree(current_root: nodes.BigFrameNode) -> nodes.BigFrameNode: - # Apply local top-down pruning rules (pushes selections to CteRefNodes) - pushed_root = nodes.top_down(current_root, prune_columns) - - # Gather the union of required columns globally across all CTE refs - cte_reqs: typing.DefaultDict[ - nodes.BigFrameNode, set[identifiers.ColumnId] - ] = collections.defaultdict(set) - - def gather_reqs(node: nodes.BigFrameNode) -> nodes.BigFrameNode: - if isinstance(node, nodes.CteRefNode): - # node.child is the referenced CTE definition (CteNode) - for col in node.cols: - cte_reqs[node.child].add(col.id) - return node - - nodes.top_down(pushed_root, gather_reqs) - - # Apply the unioned required columns to the CTE definitions - def apply_cte_reqs(node: nodes.BigFrameNode) -> nodes.BigFrameNode: - if isinstance(node, nodes.CteNode) and node in cte_reqs: - needed_ids = frozenset(cte_reqs[node]) - pruned_child = prune_node(node.child, needed_ids) - if pruned_child is not node.child: - return node.replace_child(pruned_child) - return node - - return nodes.top_down(pushed_root, apply_cte_reqs) - - return prune_tree(root) + return nodes.top_down(root, prune_columns) def to_fixed(max_iterations: int = 100): @@ -110,24 +77,6 @@ def prune_selection_child( {id: ref.id for ref, id in child.input_output_pairs} ).replace_child(child.child) - elif isinstance(child, nodes.CteRefNode): - # Push selection locally into the CTE Reference - needed_ids = selection.consumed_ids - new_cols = ( - tuple(col for col in child.cols if col.id in needed_ids) or child.cols[0:1] - ) - - if new_cols == child.cols: - return selection - return selection.replace_child(dataclasses.replace(child, cols=new_cols)) - - elif isinstance(child, nodes.CteNode): - # Pass-through selection to the CTE Definition just in case it's wrapped locally - pruned_child = prune_node(child.child, selection.consumed_ids) - if pruned_child is child.child: - return selection - return selection.replace_child(child.replace_child(pruned_child)) - elif isinstance(child, nodes.AdditiveNode): if not set(field.id for field in child.added_fields) & selection.consumed_ids: return selection.replace_child(child.additive_base) diff --git a/bigframes/core/sql_nodes.py b/bigframes/core/sql_nodes.py index 5d921de7aeb..45048dc2b15 100644 --- a/bigframes/core/sql_nodes.py +++ b/bigframes/core/sql_nodes.py @@ -16,13 +16,18 @@ import dataclasses import functools -from typing import Mapping, Optional, Sequence, Tuple +from typing import Callable, Mapping, Optional, Sequence, Tuple from bigframes.core import bq_data, identifiers, nodes import bigframes.core.expression as ex from bigframes.core.ordering import OrderingExpression import bigframes.dtypes +# SQL Nodes are generally terminal, so don't support rich transformation methods +# like remap_vars, remap_refs, etc. +# Still, fields should be defined on them, as typing info is still used for +# dispatching some operators in the emitter, and for validation. + # TODO: Join node, union node @dataclasses.dataclass(frozen=True) @@ -84,6 +89,127 @@ def remap_refs( raise NotImplementedError() # type: ignore +@dataclasses.dataclass(frozen=True) +class SqlWithCtesNode(nodes.BigFrameNode): + # def, name pairs + child: nodes.BigFrameNode + cte_names: tuple[str, ...] + cte_defs: tuple[nodes.BigFrameNode, ...] + + @property + def child_nodes(self) -> Sequence[nodes.BigFrameNode]: + return (self.child, *self.cte_defs) + + @property + def fields(self) -> Sequence[nodes.Field]: + return self.child.fields + + @property + def variables_introduced(self) -> int: + # This operation only renames variables, doesn't actually create new ones + return 0 + + @property + def defines_namespace(self) -> bool: + return True + + @property + def explicitly_ordered(self) -> bool: + return False + + @property + def order_ambiguous(self) -> bool: + return True + + @property + def row_count(self) -> Optional[int]: + return self.child.row_count + + @property + def node_defined_ids(self) -> Tuple[identifiers.ColumnId, ...]: + return tuple(self.ids) + + @property + def consumed_ids(self): + return () + + @property + def _node_expressions(self): + return () + + def remap_vars( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> SqlWithCtesNode: + raise NotImplementedError() + + def remap_refs( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> SqlWithCtesNode: + raise NotImplementedError() # type: ignore + + def transform_children( + self, transform: Callable[[nodes.BigFrameNode], nodes.BigFrameNode] + ) -> SqlWithCtesNode: + return SqlWithCtesNode( + transform(self.child), + self.cte_names, + tuple(transform(cte) for cte in self.cte_defs), + ) + + +@dataclasses.dataclass(frozen=True) +class SqlCteRefNode(nodes.LeafNode): + cte_name: str + cte_schema: tuple[nodes.Field, ...] + + @property + def fields(self) -> Sequence[nodes.Field]: + return self.cte_schema + + @property + def variables_introduced(self) -> int: + # This operation only renames variables, doesn't actually create new ones + return 0 + + @property + def defines_namespace(self) -> bool: + return True + + @property + def explicitly_ordered(self) -> bool: + return False + + @property + def order_ambiguous(self) -> bool: + return True + + @property + def row_count(self) -> Optional[int]: + raise NotImplementedError() + + @property + def node_defined_ids(self) -> Tuple[identifiers.ColumnId, ...]: + return tuple(self.ids) + + @property + def consumed_ids(self): + return () + + @property + def _node_expressions(self): + return () + + def remap_vars( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> SqlCteRefNode: + raise NotImplementedError() + + def remap_refs( + self, mappings: Mapping[identifiers.ColumnId, identifiers.ColumnId] + ) -> SqlCteRefNode: + raise NotImplementedError() # type: ignore + + @dataclasses.dataclass(frozen=True) class SqlSelectNode(nodes.UnaryNode): selections: tuple[nodes.ColumnDef, ...] = () From a5283f10faef3339a991fa479f5b46726e752cb8 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 00:15:56 +0000 Subject: [PATCH 03/15] move extract_ctes later in compiler --- bigframes/core/compile/sqlglot/compiler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index f2119015a3a..2ba1f333487 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -49,8 +49,6 @@ def compile_sql(request: configs.CompileRequest) -> configs.CompileResult: output_cols=output_names, limit=request.peek_count, ) - # Extract CTEs early, as later rewriters could otherwise make common subtrees diverge - result_node = typing.cast(nodes.ResultNode, rewrite.extract_ctes(result_node)) if request.sort_rows: # Can only pullup slice if we are doing ORDER BY in outermost SELECT # Need to do this before replacing unsupported ops, as that will rewrite slice ops @@ -64,6 +62,8 @@ def compile_sql(request: configs.CompileRequest) -> configs.CompileResult: if request.sort_rows: result_node = typing.cast(nodes.ResultNode, rewrite.column_pruning(result_node)) encoded_type_refs = data_type_logger.encode_type_refs(result_node) + # TODO: Extract CTEs earlier + result_node = typing.cast(nodes.ResultNode, rewrite.extract_ctes(result_node)) sql = _compile_result_node(result_node) return configs.CompileResult( sql, @@ -76,6 +76,8 @@ def compile_sql(request: configs.CompileRequest) -> configs.CompileResult: result_node = dataclasses.replace(result_node, order_by=None) result_node = typing.cast(nodes.ResultNode, rewrite.column_pruning(result_node)) encoded_type_refs = data_type_logger.encode_type_refs(result_node) + # TODO: Extract CTEs earlier + result_node = typing.cast(nodes.ResultNode, rewrite.extract_ctes(result_node)) sql = _compile_result_node(result_node) # Return the ordering iff no extra columns are needed to define the row order if ordering is not None: From 49ddfdfbddf1d0eeafd371ac2f667fbba78a0418 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 00:23:33 +0000 Subject: [PATCH 04/15] fix _as_from_item helper --- bigframes/core/compile/sqlglot/sqlglot_ir.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index 859b3d742d7..297147c8c30 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -167,7 +167,7 @@ def select( ) -> SQLGlotIR: # TODO: Explicitly insert CTEs into plan if isinstance(self.expr, sge.Select): - new_expr, _ = self._as_from_item() + new_expr = self._as_from_item() else: new_expr = sge.Select().from_(self.expr) From accf797d2bc43906a54cfbb29b77823363dcdea2 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 00:47:50 +0000 Subject: [PATCH 05/15] fix test issues and update snapshots --- bigframes/core/compile/sqlglot/sqlglot_ir.py | 10 +- bigframes/core/rewrite/as_sql.py | 2 +- .../test_binary_compiler/test_corr/out.sql | 15 +- .../test_binary_compiler/test_cov/out.sql | 15 +- .../test_nullary_compiler/test_size/out.sql | 14 +- .../test_array_agg/out.sql | 14 +- .../test_string_agg/out.sql | 20 +- .../test_unary_compiler/test_all/out.sql | 18 +- .../test_unary_compiler/test_any/out.sql | 18 +- .../test_any_value/out.sql | 14 +- .../test_approx_quartiles/out.sql | 20 +- .../test_approx_top_count/out.sql | 14 +- .../test_unary_compiler/test_count/out.sql | 14 +- .../test_unary_compiler/test_max/out.sql | 14 +- .../test_unary_compiler/test_mean/out.sql | 28 +-- .../test_unary_compiler/test_median/out.sql | 22 +- .../test_unary_compiler/test_min/out.sql | 14 +- .../test_unary_compiler/test_nunique/out.sql | 14 +- .../test_unary_compiler/test_pop_var/out.sql | 18 +- .../test_unary_compiler/test_product/out.sql | 18 +- .../test_unary_compiler/test_quantile/out.sql | 21 +- .../test_unary_compiler/test_std/out.sql | 28 +-- .../test_unary_compiler/test_sum/out.sql | 18 +- .../test_unary_compiler/test_var/out.sql | 18 +- .../test_compile_aggregate/out.sql | 18 +- .../test_compile_aggregate_wo_dropna/out.sql | 18 +- .../test_compile_concat/out.sql | 47 ++-- .../test_compile_concat_filter_sorted/out.sql | 62 +++-- .../test_compile_explode_dataframe/out.sql | 15 +- .../test_compile_explode_series/out.sql | 12 +- .../test_compile_fromrange/out.sql | 236 +++++++----------- .../test_st_regionstats/out.sql | 90 ++++--- .../out.sql | 18 +- .../test_compile_geo/test_st_simplify/out.sql | 8 +- .../test_compile_isin/out.sql | 46 +--- .../test_compile_isin_not_nullable/out.sql | 39 +-- .../test_compile_join/out.sql | 36 ++- .../test_compile_join_w_on/bool_col/out.sql | 38 +-- .../float64_col/out.sql | 38 +-- .../test_compile_join_w_on/int64_col/out.sql | 38 +-- .../numeric_col/out.sql | 38 +-- .../test_compile_join_w_on/string_col/out.sql | 36 +-- .../test_compile_join_w_on/time_col/out.sql | 36 +-- .../test_compile_random_sample/out.sql | 40 ++- .../test_compile_readlocal/out.sql | 38 ++- .../test_compile_readlocal_w_json_df/out.sql | 10 +- .../test_compile_readlocal_w_lists_df/out.sql | 22 +- .../out.sql | 20 +- .../out.sql | 10 +- .../out.sql | 8 +- .../out.sql | 48 ++-- 51 files changed, 587 insertions(+), 879 deletions(-) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index 297147c8c30..e0bfabbb656 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -154,7 +154,7 @@ def from_cte_ref( uid_gen: guid.SequentialUIDGenerator, ) -> SQLGlotIR: table_expr = sge.Table( - this=cte_ref, + this=sql.identifier(cte_ref), ) return cls(expr=table_expr, uid_gen=uid_gen) @@ -391,7 +391,7 @@ def with_ctes( sge_ctes = [ sge.CTE( this=cte._as_select(), - alias=cte_name, + alias=sql.identifier(cte_name), ) for cte_name, cte in ctes ] @@ -408,9 +408,9 @@ def resample( ) -> SQLGlotIR: generate_array = sge.func( "GENERATE_ARRAY", - start_expr._as_select(), - stop_expr._as_select(), - step_expr._as_select(), + start_expr, + stop_expr, + step_expr, ) unnested_column_alias = sql.identifier( diff --git a/bigframes/core/rewrite/as_sql.py b/bigframes/core/rewrite/as_sql.py index a1ce1fcc5c5..fe53155197d 100644 --- a/bigframes/core/rewrite/as_sql.py +++ b/bigframes/core/rewrite/as_sql.py @@ -226,7 +226,7 @@ def _extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: topological_ctes = list( filter(lambda n: isinstance(n, nodes.CteNode), root.iter_nodes_topo()) ) - cte_names = tuple(f"cte_{i}" for i in range(len(topological_ctes))) + cte_names = tuple(f"bfcte_{i}" for i in range(len(topological_ctes))) mapping = { cte_node: sql_nodes.SqlCteRefNode(cte_name, tuple(cte_node.fields)) diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql index fb930323dbd..4051bf239ed 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql @@ -1,13 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col`, - `float64_col` + `bfcol_2` AS `corr_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - CORR(`int64_col`, `float64_col`) AS `bfcol_2` - FROM `bfcte_0` -) -SELECT - `bfcol_2` AS `corr_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql index 92b8ea4d3ab..a645d7be37a 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql @@ -1,13 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col`, - `float64_col` + `bfcol_2` AS `cov_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COVAR_SAMP(`int64_col`, `float64_col`) AS `bfcol_2` - FROM `bfcte_0` -) -SELECT - `bfcol_2` AS `cov_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql index 4d67203ecc6..29f1861e3bd 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_32` AS `size` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COUNT(1) AS `bfcol_32` - FROM `bfcte_0` -) -SELECT - `bfcol_32` AS `size` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql index f929970a227..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql index 7e697719b36..091d53ae96d 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql @@ -1,18 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `string_col` + `bfcol_1` AS `string_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COALESCE( - STRING_AGG(`string_col`, ',' - ORDER BY - `string_col` IS NULL ASC, - `string_col` ASC), - '' - ) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `string_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql index dc1f6fb4f79..e29a986ab59 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql @@ -1,15 +1,7 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col` + `bfcol_2` AS `bool_col`, + `bfcol_3` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COALESCE(LOGICAL_AND(`bool_col`), TRUE) AS `bfcol_2`, - COALESCE(LOGICAL_AND(`int64_col` <> 0), TRUE) AS `bfcol_3` - FROM `bfcte_0` -) -SELECT - `bfcol_2` AS `bool_col`, - `bfcol_3` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql index 8ae589fb09f..e29a986ab59 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql @@ -1,15 +1,7 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col` + `bfcol_2` AS `bool_col`, + `bfcol_3` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COALESCE(LOGICAL_OR(`bool_col`), FALSE) AS `bfcol_2`, - COALESCE(LOGICAL_OR(`int64_col` <> 0), FALSE) AS `bfcol_3` - FROM `bfcte_0` -) -SELECT - `bfcol_2` AS `bool_col`, - `bfcol_3` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql index e8556018852..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - ANY_VALUE(`int64_col`) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql index e2a119499f2..dada28d2625 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql @@ -1,16 +1,8 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `q1`, + `bfcol_2` AS `q2`, + `bfcol_3` AS `q3` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - APPROX_QUANTILES(`int64_col`, 4)[OFFSET(1)] AS `bfcol_1`, - APPROX_QUANTILES(`int64_col`, 4)[OFFSET(2)] AS `bfcol_2`, - APPROX_QUANTILES(`int64_col`, 4)[OFFSET(3)] AS `bfcol_3` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `q1`, - `bfcol_2` AS `q2`, - `bfcol_3` AS `q3` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql index 1c391c6691f..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - APPROX_TOP_COUNT(`int64_col`, 10) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql index 61f073b7dc8..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COUNT(`int64_col`) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql index 7e01c2c7187..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - MAX(`int64_col`) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql index 94287fc432b..768e90ed59e 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql @@ -1,23 +1,9 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col`, - `duration_col`, - `int64_col` AS `bfcol_6`, - `bool_col` AS `bfcol_7`, - `duration_col` AS `bfcol_8` + `bfcol_12` AS `int64_col`, + `bfcol_13` AS `bool_col`, + `bfcol_14` AS `duration_col`, + `bfcol_15` AS `int64_col_w_floor` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - AVG(`bfcol_6`) AS `bfcol_12`, - AVG(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`, - CAST(FLOOR(AVG(`bfcol_8`)) AS INT64) AS `bfcol_14`, - CAST(FLOOR(AVG(`bfcol_6`)) AS INT64) AS `bfcol_15` - FROM `bfcte_0` -) -SELECT - `bfcol_12` AS `int64_col`, - `bfcol_13` AS `bool_col`, - `bfcol_14` AS `duration_col`, - `bfcol_15` AS `int64_col_w_floor` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql index 7d1215163f8..1fc1b3cb685 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql @@ -1,18 +1,8 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `date_col`, - `int64_col`, - `string_col` + `bfcol_3` AS `int64_col`, + `bfcol_4` AS `date_col`, + `bfcol_5` AS `string_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - APPROX_QUANTILES(`int64_col`, 2)[OFFSET(1)] AS `bfcol_3`, - APPROX_QUANTILES(`date_col`, 2)[OFFSET(1)] AS `bfcol_4`, - APPROX_QUANTILES(`string_col`, 2)[OFFSET(1)] AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_3` AS `int64_col`, - `bfcol_4` AS `date_col`, - `bfcol_5` AS `string_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql index 144c07d7010..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - MIN(`int64_col`) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql index e0cc1a2eac5..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql @@ -1,12 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COUNT(DISTINCT `int64_col`) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql index b855c791182..484c8e77cf1 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql @@ -1,15 +1,7 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col` + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - VAR_POP(`int64_col`) AS `bfcol_4`, - VAR_POP(CAST(`bool_col` AS INT64)) AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql index 33204f2ff56..f0c57c615df 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql @@ -1,16 +1,6 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `int64_col` + `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - CASE - WHEN LOGICAL_OR(`int64_col` = 0) - THEN 0 - ELSE POWER(2, SUM(IF(`int64_col` = 0, 0, LOG(ABS(`int64_col`), 2)))) * POWER(-1, MOD(SUM(CASE WHEN SIGN(`int64_col`) = -1 THEN 1 ELSE 0 END), 2)) - END AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `int64_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql index 656d01ea2e5..cff34e632ba 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql @@ -1,17 +1,8 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col` + `bfcol_4` AS `int64`, + `bfcol_5` AS `bool`, + `bfcol_6` AS `int64_w_floor` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - PERCENTILE_CONT(`int64_col`, 0.5) OVER () AS `bfcol_4`, - PERCENTILE_CONT(CAST(`bool_col` AS INT64), 0.5) OVER () AS `bfcol_5`, - CAST(FLOOR(PERCENTILE_CONT(`int64_col`, 0.5) OVER ()) AS INT64) AS `bfcol_6` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `int64`, - `bfcol_5` AS `bool`, - `bfcol_6` AS `int64_w_floor` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql index e3c3d7b5253..768e90ed59e 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql @@ -1,23 +1,9 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col`, - `duration_col`, - `int64_col` AS `bfcol_6`, - `bool_col` AS `bfcol_7`, - `duration_col` AS `bfcol_8` + `bfcol_12` AS `int64_col`, + `bfcol_13` AS `bool_col`, + `bfcol_14` AS `duration_col`, + `bfcol_15` AS `int64_col_w_floor` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - STDDEV(`bfcol_6`) AS `bfcol_12`, - STDDEV(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`, - CAST(FLOOR(STDDEV(`bfcol_8`)) AS INT64) AS `bfcol_14`, - CAST(FLOOR(STDDEV(`bfcol_6`)) AS INT64) AS `bfcol_15` - FROM `bfcte_0` -) -SELECT - `bfcol_12` AS `int64_col`, - `bfcol_13` AS `bool_col`, - `bfcol_14` AS `duration_col`, - `bfcol_15` AS `int64_col_w_floor` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql index c67eef9da34..484c8e77cf1 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql @@ -1,15 +1,7 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col` + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - COALESCE(SUM(`int64_col`), 0) AS `bfcol_4`, - COALESCE(SUM(CAST(`bool_col` AS INT64)), 0) AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql index b35d67c1ce1..484c8e77cf1 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql @@ -1,15 +1,7 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_col` + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - VARIANCE(`int64_col`) AS `bfcol_4`, - VARIANCE(CAST(`bool_col` AS INT64)) AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` -FROM `bfcte_1` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql index cfd9c7c87f0..03251698713 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql @@ -1,23 +1,13 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_too`, - `int64_too` AS `bfcol_2`, - `bool_col` AS `bfcol_3` + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `int64_too` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `bfcol_3`, - COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` - FROM `bfcte_0` WHERE NOT `bfcol_3` IS NULL GROUP BY `bfcol_3` ) -SELECT - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `int64_too` -FROM `bfcte_1` ORDER BY `bfcol_3` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql index e71099d82e6..df59432286b 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql @@ -1,21 +1,11 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - `bool_col`, - `int64_too`, - `int64_too` AS `bfcol_2`, - `bool_col` AS `bfcol_3` + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `int64_too` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `bfcol_3`, - COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` - FROM `bfcte_0` GROUP BY `bfcol_3` ) -SELECT - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `int64_too` -FROM `bfcte_1` ORDER BY `bfcol_3` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql index 3b0f9f0633d..40bb73bd1c6 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql @@ -1,41 +1,44 @@ WITH `bfcte_0` AS ( SELECT - `bfcol_9` AS `bfcol_30`, - `bfcol_10` AS `bfcol_31`, - `bfcol_11` AS `bfcol_32`, - `bfcol_12` AS `bfcol_33`, - `bfcol_13` AS `bfcol_34`, - `bfcol_14` AS `bfcol_35` + FROM `bfcte_0` +), `bfcte_1` AS ( + SELECT + FROM `bfcte_1` +), `bfcte_2` AS ( + SELECT + FROM `bfcte_2` +) +SELECT +FROM ( + SELECT + `bfcol_30` AS `rowindex`, + `bfcol_31` AS `rowindex_1`, + `bfcol_32` AS `int64_col`, + `bfcol_33` AS `string_col` FROM ( ( SELECT - `rowindex` AS `bfcol_9`, - `rowindex` AS `bfcol_10`, - `int64_col` AS `bfcol_11`, - `string_col` AS `bfcol_12`, + `bfcol_3` AS `bfcol_9`, + `bfcol_4` AS `bfcol_10`, + `bfcol_5` AS `bfcol_11`, + `bfcol_6` AS `bfcol_12`, 0 AS `bfcol_13`, ROW_NUMBER() OVER () - 1 AS `bfcol_14` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ) UNION ALL ( SELECT - `rowindex` AS `bfcol_24`, - `rowindex` AS `bfcol_25`, - `int64_col` AS `bfcol_26`, - `string_col` AS `bfcol_27`, + `bfcol_18` AS `bfcol_24`, + `bfcol_19` AS `bfcol_25`, + `bfcol_20` AS `bfcol_26`, + `bfcol_21` AS `bfcol_27`, 1 AS `bfcol_28`, ROW_NUMBER() OVER () - 1 AS `bfcol_29` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_2` ) ) ) -SELECT - `bfcol_30` AS `rowindex`, - `bfcol_31` AS `rowindex_1`, - `bfcol_32` AS `int64_col`, - `bfcol_33` AS `string_col` -FROM `bfcte_0` ORDER BY `bfcol_34` ASC NULLS LAST, `bfcol_35` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql index a18d6998d43..a4d1ed11434 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql @@ -1,55 +1,65 @@ WITH `bfcte_0` AS ( SELECT - `bfcol_6` AS `bfcol_42`, - `bfcol_7` AS `bfcol_43`, - `bfcol_8` AS `bfcol_44`, - `bfcol_9` AS `bfcol_45` + FROM `bfcte_0` +), `bfcte_1` AS ( + SELECT + FROM `bfcte_1` +), `bfcte_2` AS ( + SELECT + FROM `bfcte_2` +), `bfcte_3` AS ( + SELECT + FROM `bfcte_3` +), `bfcte_4` AS ( + SELECT + FROM `bfcte_4` +), `bfcte_5` AS ( + SELECT + FROM `bfcte_5` +) +SELECT +FROM ( + SELECT + `bfcol_42` AS `float64_col`, + `bfcol_43` AS `int64_col` FROM ( ( SELECT - `float64_col` AS `bfcol_6`, - `int64_col` AS `bfcol_7`, + `bfcol_2` AS `bfcol_6`, + `bfcol_3` AS `bfcol_7`, 0 AS `bfcol_8`, - ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `bfcol_9` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ROW_NUMBER() OVER (ORDER BY `bfcol_3` ASC NULLS LAST) - 1 AS `bfcol_9` + FROM `bfcte_1` ) UNION ALL ( SELECT - `float64_col` AS `bfcol_17`, - `int64_too` AS `bfcol_18`, + `bfcol_13` AS `bfcol_17`, + `bfcol_14` AS `bfcol_18`, 1 AS `bfcol_19`, ROW_NUMBER() OVER () - 1 AS `bfcol_20` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - `bool_col` + FROM `bfcte_3` ) UNION ALL ( SELECT - `float64_col` AS `bfcol_27`, - `int64_col` AS `bfcol_28`, + `bfcol_23` AS `bfcol_27`, + `bfcol_24` AS `bfcol_28`, 2 AS `bfcol_29`, - ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `bfcol_30` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ROW_NUMBER() OVER (ORDER BY `bfcol_24` ASC NULLS LAST) - 1 AS `bfcol_30` + FROM `bfcte_4` ) UNION ALL ( SELECT - `float64_col` AS `bfcol_38`, - `int64_too` AS `bfcol_39`, + `bfcol_34` AS `bfcol_38`, + `bfcol_35` AS `bfcol_39`, 3 AS `bfcol_40`, ROW_NUMBER() OVER () - 1 AS `bfcol_41` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - `bool_col` + FROM `bfcte_5` ) ) ) -SELECT - `bfcol_42` AS `float64_col`, - `bfcol_43` AS `int64_col` -FROM `bfcte_0` ORDER BY `bfcol_44` ASC NULLS LAST, `bfcol_45` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql index e2a80e201bb..ffcde677a7c 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql @@ -1,21 +1,12 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT `rowindex`, + `rowindex` AS `rowindex_1`, `int_list_col`, `string_list_col` FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - * - REPLACE (`int_list_col`[SAFE_OFFSET(`bfcol_13`)] AS `int_list_col`, `string_list_col`[SAFE_OFFSET(`bfcol_13`)] AS `string_list_col`) - FROM `bfcte_0` LEFT JOIN UNNEST(GENERATE_ARRAY(0, LEAST(ARRAY_LENGTH(`int_list_col`) - 1, ARRAY_LENGTH(`string_list_col`) - 1))) AS `bfcol_13` WITH OFFSET AS `bfcol_7` ) -SELECT - `rowindex`, - `rowindex` AS `rowindex_1`, - `int_list_col`, - `string_list_col` -FROM `bfcte_1` ORDER BY `bfcol_7` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql index 03ac4d0e03a..90749e98a3e 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql @@ -1,18 +1,10 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT `rowindex`, `int_list_col` FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - * - REPLACE (`bfcol_8` AS `int_list_col`) - FROM `bfcte_0` LEFT JOIN UNNEST(`int_list_col`) AS `bfcol_8` WITH OFFSET AS `bfcol_4` ) -SELECT - `rowindex`, - `int_list_col` -FROM `bfcte_1` ORDER BY `bfcol_4` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index 47455a292b8..310080142dc 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -1,165 +1,101 @@ -WITH `bfcte_6` AS ( +WITH `bfcte_0` AS ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) -), `bfcte_15` AS ( - SELECT - `bfcol_0` AS `bfcol_1` - FROM `bfcte_6` -), `bfcte_5` AS ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) -), `bfcte_10` AS ( - SELECT - MIN(`bfcol_2`) AS `bfcol_4` - FROM `bfcte_5` -), `bfcte_16` AS ( - SELECT - * - FROM `bfcte_10` -), `bfcte_19` AS ( - SELECT - * - FROM `bfcte_15` - CROSS JOIN `bfcte_16` -), `bfcte_21` AS ( - SELECT - `bfcol_1`, - `bfcol_4`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_1` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_4` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_5` - FROM `bfcte_19` -), `bfcte_23` AS ( - SELECT - MIN(`bfcol_5`) AS `bfcol_7` - FROM `bfcte_21` -), `bfcte_24` AS ( - SELECT - * - FROM `bfcte_23` -), `bfcte_4` AS ( + FROM `bfcte_0` +), `bfcte_1` AS ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) -), `bfcte_13` AS ( + FROM `bfcte_1` +), `bfcte_2` AS ( SELECT - `bfcol_8` AS `bfcol_9` - FROM `bfcte_4` + FROM `bfcte_2` ), `bfcte_3` AS ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) -), `bfcte_9` AS ( - SELECT - MIN(`bfcol_11`) AS `bfcol_37` FROM `bfcte_3` -), `bfcte_14` AS ( +), `bfcte_4` AS ( SELECT - * - FROM `bfcte_9` -), `bfcte_18` AS ( + FROM `bfcte_4` +), `bfcte_5` AS ( SELECT - * - FROM `bfcte_13` - CROSS JOIN `bfcte_14` -), `bfcte_20` AS ( + FROM `bfcte_5` +), `bfcte_6` AS ( SELECT - `bfcol_9`, - `bfcol_37`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_9` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_37` AS DATE) AS TIMESTAMP)), - 7000000 + FROM `bfcte_6` +) +SELECT +FROM ( + SELECT + CAST(TIMESTAMP_MICROS( + CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) + ) AS DATETIME) AS `bigframes_unnamed_index`, + `bfcol_55` AS `int64_col`, + `bfcol_56` AS `int64_too` + FROM ( + SELECT + * + FROM ( + SELECT + `bfcol_67` AS `bfcol_41` + FROM ( + SELECT + * + FROM ( + SELECT + `bfcol_1`, + `bfcol_4`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_1` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_4` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_5` + FROM `bfcte_1` + CROSS JOIN `bfcte_5` + ) ) - ) AS INT64) AS `bfcol_38` - FROM `bfcte_18` -), `bfcte_22` AS ( - SELECT - MAX(`bfcol_38`) AS `bfcol_40` - FROM `bfcte_20` -), `bfcte_25` AS ( - SELECT - * - FROM `bfcte_22` -), `bfcte_26` AS ( - SELECT - `bfcol_67` AS `bfcol_41` - FROM `bfcte_24` - CROSS JOIN `bfcte_25` - CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_7`, `bfcol_40`, 1)) AS `bfcol_67` -), `bfcte_2` AS ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) -), `bfcte_8` AS ( - SELECT - MIN(`bfcol_42`) AS `bfcol_44` - FROM `bfcte_2` -), `bfcte_27` AS ( - SELECT - * - FROM `bfcte_8` -), `bfcte_28` AS ( - SELECT - * - FROM `bfcte_26` - CROSS JOIN `bfcte_27` -), `bfcte_1` AS ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) -), `bfcte_11` AS ( - SELECT - `bfcol_45` AS `bfcol_48`, - `bfcol_46` AS `bfcol_49`, - `bfcol_47` AS `bfcol_50` - FROM `bfcte_1` -), `bfcte_0` AS ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) -), `bfcte_7` AS ( - SELECT - MIN(`bfcol_51`) AS `bfcol_53` - FROM `bfcte_0` -), `bfcte_12` AS ( - SELECT - * - FROM `bfcte_7` -), `bfcte_17` AS ( - SELECT - * - FROM `bfcte_11` - CROSS JOIN `bfcte_12` -), `bfcte_29` AS ( - SELECT - `bfcol_49` AS `bfcol_55`, - `bfcol_50` AS `bfcol_56`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_48` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_53` AS DATE) AS TIMESTAMP)), - 7000000 + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + `bfcol_9`, + `bfcol_37`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_9` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_37` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_38` + FROM `bfcte_4` + CROSS JOIN ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + ) + ) ) - ) AS INT64) AS `bfcol_57` - FROM `bfcte_17` -), `bfcte_30` AS ( - SELECT - * - FROM `bfcte_28` - LEFT JOIN `bfcte_29` + CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_7`, `bfcol_40`, 1)) AS `bfcol_67` + ) + CROSS JOIN `bfcte_3` + ) + LEFT JOIN ( + SELECT + `bfcol_49` AS `bfcol_55`, + `bfcol_50` AS `bfcol_56`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_48` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_53` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_57` + FROM ( + SELECT + `bfcol_45` AS `bfcol_48`, + `bfcol_46` AS `bfcol_49`, + `bfcol_47` AS `bfcol_50` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + ) + CROSS JOIN `bfcte_6` + ) ON `bfcol_41` = `bfcol_57` ) -SELECT - CAST(TIMESTAMP_MICROS( - CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) - ) AS DATETIME) AS `bigframes_unnamed_index`, - `bfcol_55` AS `int64_col`, - `bfcol_56` AS `int64_too` -FROM `bfcte_30` ORDER BY `bfcol_41` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql index 457436e98c4..3193c7cd0cc 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql @@ -1,51 +1,49 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`min`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`max`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`sum`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`count`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`mean`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`area` FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ) -SELECT - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`min`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`max`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`sum`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`count`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`mean`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`area` -FROM `bfcte_0` ORDER BY `bfcol_1` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql index 410909d80c5..19dd32b19df 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql @@ -1,15 +1,13 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`sum`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ) -SELECT - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`sum`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` -FROM `bfcte_0` ORDER BY `bfcol_1` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql index 1c146e1e1be..e0b1a6f834a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql @@ -1,10 +1,8 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ) -SELECT - ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` -FROM `bfcte_0` ORDER BY `bfcol_1` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index d80febf41ca..af50c5c8ee1 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -1,36 +1,12 @@ -WITH `bfcte_2` AS ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_0` AS ( - SELECT - `int64_too` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `int64_too` - FROM `bfcte_0` - GROUP BY - `int64_too` -), `bfcte_3` AS ( - SELECT - `bfcte_2`.*, - EXISTS( - SELECT - 1 - FROM ( - SELECT - `int64_too` AS `bfcol_4` - FROM `bfcte_1` - ) AS `bft_1` - WHERE - COALESCE(`bfcte_2`.`bfcol_3`, 0) = COALESCE(`bft_1`.`bfcol_4`, 0) - AND COALESCE(`bfcte_2`.`bfcol_3`, 1) = COALESCE(`bft_1`.`bfcol_4`, 1) - ) AS `bfcol_5` - FROM `bfcte_2` -) SELECT - `bfcol_2` AS `rowindex`, - `bfcol_5` AS `int64_col` -FROM `bfcte_3` \ No newline at end of file +FROM ( + SELECT + `bfcol_2` AS `rowindex`, + `bfcol_5` AS `int64_col` + FROM ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 2b2735b1637..935dddb587b 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -1,29 +1,12 @@ -WITH `bfcte_2` AS ( - SELECT - `rowindex` AS `bfcol_2`, - `rowindex_2` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_0` AS ( - SELECT - `rowindex_2` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `rowindex_2` - FROM `bfcte_0` - GROUP BY - `rowindex_2` -), `bfcte_3` AS ( - SELECT - `bfcte_2`.*, - `bfcte_2`.`bfcol_3` IN (( - SELECT - `rowindex_2` AS `bfcol_4` - FROM `bfcte_1` - )) AS `bfcol_5` - FROM `bfcte_2` -) SELECT - `bfcol_2` AS `rowindex`, - `bfcol_5` AS `rowindex_2` -FROM `bfcte_3` \ No newline at end of file +FROM ( + SELECT + `bfcol_2` AS `rowindex`, + `bfcol_5` AS `rowindex_2` + FROM ( + SELECT + `rowindex` AS `bfcol_2`, + `rowindex_2` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql index dfc40840271..695dc9a4197 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql @@ -1,22 +1,20 @@ -WITH `bfcte_0` AS ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `int64_col` AS `bfcol_6`, - `int64_too` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( +SELECT +FROM ( SELECT - * - FROM `bfcte_0` - LEFT JOIN `bfcte_1` + `bfcol_3` AS `int64_col`, + `bfcol_7` AS `int64_too` + FROM ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) + LEFT JOIN ( + SELECT + `int64_col` AS `bfcol_6`, + `int64_too` AS `bfcol_7` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ON COALESCE(`bfcol_2`, 0) = COALESCE(`bfcol_6`, 0) AND COALESCE(`bfcol_2`, 1) = COALESCE(`bfcol_6`, 1) -) -SELECT - `bfcol_3` AS `int64_col`, - `bfcol_7` AS `int64_too` -FROM `bfcte_2` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql index b3a2b456737..545223dfcac 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql @@ -1,23 +1,31 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_2`, - `bool_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_0` ), `bfcte_1` AS ( SELECT - `rowindex` AS `bfcol_6`, - `bool_col` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ), `bfcte_2` AS ( SELECT - * - FROM `bfcte_0` - INNER JOIN `bfcte_1` - ON COALESCE(CAST(`bfcol_3` AS STRING), '0') = COALESCE(CAST(`bfcol_7` AS STRING), '0') - AND COALESCE(CAST(`bfcol_3` AS STRING), '1') = COALESCE(CAST(`bfcol_7` AS STRING), '1') + FROM `bfcte_2` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `rowindex_y` -FROM `bfcte_2` \ No newline at end of file +FROM ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON COALESCE(CAST(`bfcol_3` AS STRING), '0') = COALESCE(CAST(`bfcol_7` AS STRING), '0') + AND COALESCE(CAST(`bfcol_3` AS STRING), '1') = COALESCE(CAST(`bfcol_7` AS STRING), '1') +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql index 4abc6aa4a75..ddc6bb7f98a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql @@ -1,23 +1,31 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_2`, - `float64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_0` ), `bfcte_1` AS ( SELECT - `rowindex` AS `bfcol_6`, - `float64_col` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ), `bfcte_2` AS ( SELECT - * - FROM `bfcte_0` - INNER JOIN `bfcte_1` - ON IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) = IF(IS_NAN(`bfcol_7`), 2, COALESCE(`bfcol_7`, 0)) - AND IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) = IF(IS_NAN(`bfcol_7`), 3, COALESCE(`bfcol_7`, 1)) + FROM `bfcte_2` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `float64_col`, - `bfcol_6` AS `rowindex_y` -FROM `bfcte_2` \ No newline at end of file +FROM ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `float64_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) = IF(IS_NAN(`bfcol_7`), 2, COALESCE(`bfcol_7`, 0)) + AND IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) = IF(IS_NAN(`bfcol_7`), 3, COALESCE(`bfcol_7`, 1)) +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql index b841ac1325c..dfc6f01fce9 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql @@ -1,23 +1,31 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_0` ), `bfcte_1` AS ( SELECT - `rowindex` AS `bfcol_6`, - `int64_col` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ), `bfcte_2` AS ( SELECT - * - FROM `bfcte_0` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_7`, 0) - AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_7`, 1) + FROM `bfcte_2` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `int64_col`, - `bfcol_6` AS `rowindex_y` -FROM `bfcte_2` \ No newline at end of file +FROM ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `int64_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_7`, 0) + AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_7`, 1) +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql index af2aaa69dc4..d914359c00f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql @@ -1,23 +1,31 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_2`, - `numeric_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_0` ), `bfcte_1` AS ( SELECT - `rowindex` AS `bfcol_6`, - `numeric_col` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ), `bfcte_2` AS ( SELECT - * - FROM `bfcte_0` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(0 AS NUMERIC)) - AND COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(1 AS NUMERIC)) + FROM `bfcte_2` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `numeric_col`, - `bfcol_6` AS `rowindex_y` -FROM `bfcte_2` \ No newline at end of file +FROM ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `numeric_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(0 AS NUMERIC)) + AND COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(1 AS NUMERIC)) +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql index dfde2efb868..eaa3a1db15a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql @@ -1,23 +1,29 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_0`, - `string_col` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_0` ), `bfcte_1` AS ( SELECT - `rowindex` AS `bfcol_4`, - `string_col` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ), `bfcte_2` AS ( SELECT - * - FROM `bfcte_0` - INNER JOIN `bfcte_1` - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') + FROM `bfcte_2` +), `bfcte_3` AS ( + SELECT + FROM `bfcte_3` ) SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `string_col`, - `bfcol_4` AS `rowindex_y` -FROM `bfcte_2` \ No newline at end of file +FROM ( + SELECT + `bfcol_0` AS `rowindex_x`, + `bfcol_1` AS `string_col`, + `bfcol_4` AS `rowindex_y` + FROM `bfcte_3` + INNER JOIN ( + SELECT + `bfcol_2` AS `bfcol_4`, + `bfcol_3` AS `bfcol_5` + FROM `bfcte_2` + ) + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql index 5a858124416..fd86768382d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql @@ -1,23 +1,29 @@ WITH `bfcte_0` AS ( SELECT - `rowindex` AS `bfcol_0`, - `time_col` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_0` ), `bfcte_1` AS ( SELECT - `rowindex` AS `bfcol_4`, - `time_col` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM `bfcte_1` ), `bfcte_2` AS ( SELECT - * - FROM `bfcte_0` - INNER JOIN `bfcte_1` - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') + FROM `bfcte_2` +), `bfcte_3` AS ( + SELECT + FROM `bfcte_3` ) SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `time_col`, - `bfcol_4` AS `rowindex_y` -FROM `bfcte_2` \ No newline at end of file +FROM ( + SELECT + `bfcol_0` AS `rowindex_x`, + `bfcol_1` AS `time_col`, + `bfcol_4` AS `rowindex_y` + FROM `bfcte_3` + INNER JOIN ( + SELECT + `bfcol_2` AS `bfcol_4`, + `bfcol_3` AS `bfcol_5` + FROM `bfcte_2` + ) + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql index 2f80d6ffbcc..96bcbcc0824 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql @@ -1,6 +1,21 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `bool_col`, + `bfcol_1` AS `bytes_col`, + `bfcol_2` AS `date_col`, + `bfcol_3` AS `datetime_col`, + `bfcol_4` AS `geography_col`, + `bfcol_5` AS `int64_col`, + `bfcol_6` AS `int64_too`, + `bfcol_7` AS `numeric_col`, + `bfcol_8` AS `float64_col`, + `bfcol_9` AS `rowindex`, + `bfcol_10` AS `rowindex_2`, + `bfcol_11` AS `string_col`, + `bfcol_12` AS `time_col`, + `bfcol_13` AS `timestamp_col`, + `bfcol_14` AS `duration_col` FROM UNNEST(ARRAY>[STRUCT( TRUE, CAST(b'Hello, World!' AS BYTES), @@ -155,29 +170,8 @@ WITH `bfcte_0` AS ( 432000000000, 8 )]) -), `bfcte_1` AS ( - SELECT - * - FROM `bfcte_0` WHERE RAND() < 0.1 ) -SELECT - `bfcol_0` AS `bool_col`, - `bfcol_1` AS `bytes_col`, - `bfcol_2` AS `date_col`, - `bfcol_3` AS `datetime_col`, - `bfcol_4` AS `geography_col`, - `bfcol_5` AS `int64_col`, - `bfcol_6` AS `int64_too`, - `bfcol_7` AS `numeric_col`, - `bfcol_8` AS `float64_col`, - `bfcol_9` AS `rowindex`, - `bfcol_10` AS `rowindex_2`, - `bfcol_11` AS `string_col`, - `bfcol_12` AS `time_col`, - `bfcol_13` AS `timestamp_col`, - `bfcol_14` AS `duration_col` -FROM `bfcte_1` ORDER BY `bfcol_15` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql index 2b080b0b7ce..0186fbb11be 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql @@ -1,6 +1,22 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `bool_col`, + `bfcol_2` AS `bytes_col`, + `bfcol_3` AS `date_col`, + `bfcol_4` AS `datetime_col`, + `bfcol_5` AS `geography_col`, + `bfcol_6` AS `int64_col`, + `bfcol_7` AS `int64_too`, + `bfcol_8` AS `numeric_col`, + `bfcol_9` AS `float64_col`, + `bfcol_10` AS `rowindex_1`, + `bfcol_11` AS `rowindex_2`, + `bfcol_12` AS `string_col`, + `bfcol_13` AS `time_col`, + `bfcol_14` AS `timestamp_col`, + `bfcol_15` AS `duration_col` FROM UNNEST(ARRAY>[STRUCT( 0, TRUE, @@ -165,23 +181,5 @@ WITH `bfcte_0` AS ( 8 )]) ) -SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `bool_col`, - `bfcol_2` AS `bytes_col`, - `bfcol_3` AS `date_col`, - `bfcol_4` AS `datetime_col`, - `bfcol_5` AS `geography_col`, - `bfcol_6` AS `int64_col`, - `bfcol_7` AS `int64_too`, - `bfcol_8` AS `numeric_col`, - `bfcol_9` AS `float64_col`, - `bfcol_10` AS `rowindex_1`, - `bfcol_11` AS `rowindex_2`, - `bfcol_12` AS `string_col`, - `bfcol_13` AS `time_col`, - `bfcol_14` AS `timestamp_col`, - `bfcol_15` AS `duration_col` -FROM `bfcte_0` ORDER BY `bfcol_16` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql index 4e21266b87b..f48e8ef940f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql @@ -1,11 +1,9 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `json_col` FROM UNNEST(ARRAY>[STRUCT(0, PARSE_JSON('null'), 0), STRUCT(1, PARSE_JSON('true'), 1), STRUCT(2, PARSE_JSON('100'), 2), STRUCT(3, PARSE_JSON('0.98'), 3), STRUCT(4, PARSE_JSON('"a string"'), 4), STRUCT(5, PARSE_JSON('[]'), 5), STRUCT(6, PARSE_JSON('[1,2,3]'), 6), STRUCT(7, PARSE_JSON('[{"a":1},{"a":2},{"a":null},{}]'), 7), STRUCT(8, PARSE_JSON('"100"'), 8), STRUCT(9, PARSE_JSON('{"date":"2024-07-16"}'), 9), STRUCT(10, PARSE_JSON('{"int_value":2,"null_filed":null}'), 10), STRUCT(11, PARSE_JSON('{"list_data":[10,20,30]}'), 11)]) ) -SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `json_col` -FROM `bfcte_0` ORDER BY `bfcol_2` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql index 923476aafd4..945b43ecb51 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql @@ -1,6 +1,14 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `int_list_col`, + `bfcol_2` AS `bool_list_col`, + `bfcol_3` AS `float_list_col`, + `bfcol_4` AS `date_list_col`, + `bfcol_5` AS `date_time_list_col`, + `bfcol_6` AS `numeric_list_col`, + `bfcol_7` AS `string_list_col` FROM UNNEST(ARRAY, `bfcol_2` ARRAY, `bfcol_3` ARRAY, `bfcol_4` ARRAY, `bfcol_5` ARRAY, `bfcol_6` ARRAY, `bfcol_7` ARRAY, `bfcol_8` INT64>>[STRUCT( 0, [1], @@ -33,15 +41,5 @@ WITH `bfcte_0` AS ( 2 )]) ) -SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `int_list_col`, - `bfcol_2` AS `bool_list_col`, - `bfcol_3` AS `float_list_col`, - `bfcol_4` AS `date_list_col`, - `bfcol_5` AS `date_time_list_col`, - `bfcol_6` AS `numeric_list_col`, - `bfcol_7` AS `string_list_col` -FROM `bfcte_0` ORDER BY `bfcol_8` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql index ba5e0c8f1cf..1435f4fb010 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql @@ -1,6 +1,13 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `col_none`, + `bfcol_1` AS `col_inf`, + `bfcol_2` AS `col_neginf`, + `bfcol_3` AS `col_nan`, + `bfcol_4` AS `col_struct_none`, + `bfcol_5` AS `col_struct_w_none`, + `bfcol_6` AS `col_list_none` FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( CAST(NULL AS FLOAT64), CAST('Infinity' AS FLOAT64), @@ -12,14 +19,5 @@ WITH `bfcte_0` AS ( 0 ), STRUCT(1.0, 1.0, 1.0, 1.0, STRUCT(1 AS `foo`), STRUCT(1 AS `foo`), [1, 2], 1), STRUCT(2.0, 2.0, 2.0, 2.0, STRUCT(2 AS `foo`), STRUCT(2 AS `foo`), [3, 4], 2)]) ) -SELECT - `bfcol_0` AS `col_none`, - `bfcol_1` AS `col_inf`, - `bfcol_2` AS `col_neginf`, - `bfcol_3` AS `col_nan`, - `bfcol_4` AS `col_struct_none`, - `bfcol_5` AS `col_struct_w_none`, - `bfcol_6` AS `col_list_none` -FROM `bfcte_0` ORDER BY `bfcol_7` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql index 7ded9cf5fff..ea263528e30 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql @@ -1,6 +1,8 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `id`, + `bfcol_1` AS `person` FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( 1, STRUCT( @@ -19,9 +21,5 @@ WITH `bfcte_0` AS ( 1 )]) ) -SELECT - `bfcol_0` AS `id`, - `bfcol_1` AS `person` -FROM `bfcte_0` ORDER BY `bfcol_2` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql index 512d3ca6bdd..9916e999af2 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql @@ -1,10 +1,8 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT * FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` WHERE `rowindex` > 0 AND `string_col` IN ('Hello, World!') -) -SELECT - * -FROM `bfcte_0` \ No newline at end of file +) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql index 887e7e9212d..6bbf0747bac 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql @@ -1,31 +1,29 @@ -WITH `bfcte_0` AS ( +SELECT +FROM ( SELECT - * + `bfcol_0` AS `ts_col`, + CASE + WHEN COALESCE( + SUM(CAST(( + `bfcol_1` + ) IS NOT NULL AS INT64)) OVER ( + ORDER BY UNIX_MICROS(`bfcol_0`) ASC + RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ), + 0 + ) < 1 + THEN NULL + WHEN TRUE + THEN COALESCE( + SUM(`bfcol_1`) OVER ( + ORDER BY UNIX_MICROS(`bfcol_0`) ASC + RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ), + 0 + ) + END AS `int_col` FROM UNNEST(ARRAY>[STRUCT(CAST('2025-01-01T00:00:00+00:00' AS TIMESTAMP), 0, 0), STRUCT(CAST('2025-01-01T00:00:01+00:00' AS TIMESTAMP), 1, 1), STRUCT(CAST('2025-01-01T00:00:02+00:00' AS TIMESTAMP), 2, 2), STRUCT(CAST('2025-01-01T00:00:03+00:00' AS TIMESTAMP), 3, 3), STRUCT(CAST('2025-01-01T00:00:04+00:00' AS TIMESTAMP), 0, 4), STRUCT(CAST('2025-01-01T00:00:05+00:00' AS TIMESTAMP), 1, 5), STRUCT(CAST('2025-01-01T00:00:06+00:00' AS TIMESTAMP), 2, 6), STRUCT(CAST('2025-01-01T00:00:07+00:00' AS TIMESTAMP), 3, 7), STRUCT(CAST('2025-01-01T00:00:08+00:00' AS TIMESTAMP), 0, 8), STRUCT(CAST('2025-01-01T00:00:09+00:00' AS TIMESTAMP), 1, 9), STRUCT(CAST('2025-01-01T00:00:10+00:00' AS TIMESTAMP), 2, 10), STRUCT(CAST('2025-01-01T00:00:11+00:00' AS TIMESTAMP), 3, 11), STRUCT(CAST('2025-01-01T00:00:12+00:00' AS TIMESTAMP), 0, 12), STRUCT(CAST('2025-01-01T00:00:13+00:00' AS TIMESTAMP), 1, 13), STRUCT(CAST('2025-01-01T00:00:14+00:00' AS TIMESTAMP), 2, 14), STRUCT(CAST('2025-01-01T00:00:15+00:00' AS TIMESTAMP), 3, 15), STRUCT(CAST('2025-01-01T00:00:16+00:00' AS TIMESTAMP), 0, 16), STRUCT(CAST('2025-01-01T00:00:17+00:00' AS TIMESTAMP), 1, 17), STRUCT(CAST('2025-01-01T00:00:18+00:00' AS TIMESTAMP), 2, 18), STRUCT(CAST('2025-01-01T00:00:19+00:00' AS TIMESTAMP), 3, 19)]) ) -SELECT - `bfcol_0` AS `ts_col`, - CASE - WHEN COALESCE( - SUM(CAST(( - `bfcol_1` - ) IS NOT NULL AS INT64)) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW - ), - 0 - ) < 1 - THEN NULL - WHEN TRUE - THEN COALESCE( - SUM(`bfcol_1`) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW - ), - 0 - ) - END AS `int_col` -FROM `bfcte_0` ORDER BY `bfcol_0` ASC NULLS LAST, `bfcol_2` ASC NULLS LAST \ No newline at end of file From 1e62fd3eaf5d0d481c56ba10c92ef692690c3c39 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 00:58:58 +0000 Subject: [PATCH 06/15] fix cte emitter --- bigframes/core/compile/sqlglot/sqlglot_ir.py | 6 +- bigframes/core/rewrite/as_sql.py | 4 +- .../test_binary_compiler/test_corr/out.sql | 5 + .../test_binary_compiler/test_cov/out.sql | 5 + .../test_nullary_compiler/test_size/out.sql | 5 + .../test_array_agg/out.sql | 5 + .../test_string_agg/out.sql | 5 + .../test_unary_compiler/test_all/out.sql | 6 + .../test_unary_compiler/test_any/out.sql | 6 + .../test_any_value/out.sql | 5 + .../test_approx_quartiles/out.sql | 7 + .../test_approx_top_count/out.sql | 5 + .../test_unary_compiler/test_count/out.sql | 5 + .../test_unary_compiler/test_max/out.sql | 5 + .../test_unary_compiler/test_mean/out.sql | 8 + .../test_unary_compiler/test_median/out.sql | 7 + .../test_unary_compiler/test_min/out.sql | 5 + .../test_unary_compiler/test_nunique/out.sql | 5 + .../test_unary_compiler/test_pop_var/out.sql | 6 + .../test_unary_compiler/test_product/out.sql | 5 + .../test_unary_compiler/test_quantile/out.sql | 7 + .../test_unary_compiler/test_std/out.sql | 8 + .../test_unary_compiler/test_sum/out.sql | 6 + .../test_unary_compiler/test_var/out.sql | 6 + .../test_compile_aggregate/out.sql | 12 ++ .../test_compile_aggregate_wo_dropna/out.sql | 10 + .../test_compile_concat/out.sql | 48 ++++- .../test_compile_concat_filter_sorted/out.sql | 71 ++++++- .../test_compile_explode_dataframe/out.sql | 11 ++ .../test_compile_explode_series/out.sql | 9 + .../test_compile_fromrange/out.sql | 139 ++++++++++++- .../test_st_regionstats/out.sql | 48 +++++ .../out.sql | 12 ++ .../test_compile_geo/test_st_simplify/out.sql | 7 + .../test_compile_isin/out.sql | 11 ++ .../test_compile_isin_not_nullable/out.sql | 11 ++ .../test_compile_join/out.sql | 19 ++ .../test_compile_join_w_on/bool_col/out.sql | 31 ++- .../float64_col/out.sql | 31 ++- .../test_compile_join_w_on/int64_col/out.sql | 31 ++- .../numeric_col/out.sql | 31 ++- .../test_compile_join_w_on/string_col/out.sql | 29 ++- .../test_compile_join_w_on/time_col/out.sql | 29 ++- .../test_compile_random_sample/out.sql | 176 +++++++++++++++++ .../test_compile_readlocal/out.sql | 184 ++++++++++++++++++ .../test_compile_readlocal_w_json_df/out.sql | 8 + .../test_compile_readlocal_w_lists_df/out.sql | 44 +++++ .../out.sql | 22 +++ .../out.sql | 24 +++ .../out.sql | 7 + .../out.sql | 28 +++ 51 files changed, 1182 insertions(+), 38 deletions(-) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index e0bfabbb656..11bf0fdbffe 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -510,7 +510,11 @@ def _as_select(self) -> sge.Select: if isinstance(self.expr, sge.Select): return self.expr else: # table - return sge.Select().from_(self.expr) + return ( + sge.Select() + .select(sge.Column(this=sge.Star(), table=self.expr)) + .from_(self.expr) + ) def _as_subquery(self) -> sge.Subquery: return self._as_select().subquery() diff --git a/bigframes/core/rewrite/as_sql.py b/bigframes/core/rewrite/as_sql.py index fe53155197d..19b924960e2 100644 --- a/bigframes/core/rewrite/as_sql.py +++ b/bigframes/core/rewrite/as_sql.py @@ -237,7 +237,9 @@ def _extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: return sql_nodes.SqlWithCtesNode( root.top_down(lambda x: mapping.get(x, x)), cte_names, - tuple(cte.top_down(lambda x: mapping.get(x, x)) for cte in topological_ctes), + tuple( + cte.child.top_down(lambda x: mapping.get(x, x)) for cte in topological_ctes # type: ignore + ), ) diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql index 4051bf239ed..f95c0533fc1 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_2` AS `corr_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_2` AS `corr_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql index a645d7be37a..ebd56c1b507 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_2` AS `cov_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_2` AS `cov_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql index 29f1861e3bd..99e70582f39 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_32` AS `size` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_32` AS `size` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql index 091d53ae96d..26e896ec5e8 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `string_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `string_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql index e29a986ab59..b7143e3315b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql @@ -1,4 +1,10 @@ SELECT + ( + SELECT + `bfcol_2` AS `bool_col`, + `bfcol_3` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_2` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql index e29a986ab59..b7143e3315b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql @@ -1,4 +1,10 @@ SELECT + ( + SELECT + `bfcol_2` AS `bool_col`, + `bfcol_3` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_2` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql index dada28d2625..726cc0c8a45 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql @@ -1,4 +1,11 @@ SELECT + ( + SELECT + `bfcol_1` AS `q1`, + `bfcol_2` AS `q2`, + `bfcol_3` AS `q3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `q1`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql index 768e90ed59e..20d4b375f92 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql @@ -1,4 +1,12 @@ SELECT + ( + SELECT + `bfcol_12` AS `int64_col`, + `bfcol_13` AS `bool_col`, + `bfcol_14` AS `duration_col`, + `bfcol_15` AS `int64_col_w_floor` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_12` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql index 1fc1b3cb685..9abc3db357e 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql @@ -1,4 +1,11 @@ SELECT + ( + SELECT + `bfcol_3` AS `int64_col`, + `bfcol_4` AS `date_col`, + `bfcol_5` AS `string_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_3` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql index 484c8e77cf1..b84907b4d28 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql @@ -1,4 +1,10 @@ SELECT + ( + SELECT + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_4` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql index f0c57c615df..946a0e5f74f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql @@ -1,4 +1,9 @@ SELECT + ( + SELECT + `bfcol_1` AS `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_1` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql index cff34e632ba..c7c0bb0c99d 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql @@ -1,4 +1,11 @@ SELECT + ( + SELECT + `bfcol_4` AS `int64`, + `bfcol_5` AS `bool`, + `bfcol_6` AS `int64_w_floor` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_4` AS `int64`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql index 768e90ed59e..20d4b375f92 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql @@ -1,4 +1,12 @@ SELECT + ( + SELECT + `bfcol_12` AS `int64_col`, + `bfcol_13` AS `bool_col`, + `bfcol_14` AS `duration_col`, + `bfcol_15` AS `int64_col_w_floor` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_12` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql index 484c8e77cf1..b84907b4d28 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql @@ -1,4 +1,10 @@ SELECT + ( + SELECT + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_4` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql index 484c8e77cf1..b84907b4d28 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql @@ -1,4 +1,10 @@ SELECT + ( + SELECT + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).* FROM ( SELECT `bfcol_4` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql index 03251698713..5c60bcda3b4 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql @@ -1,4 +1,16 @@ SELECT + ( + SELECT + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `int64_too` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + WHERE + NOT `bfcol_3` IS NULL + GROUP BY + `bfcol_3` + ) + ORDER BY + `bfcol_3` ASC NULLS LAST.* FROM ( SELECT `bfcol_3` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql index df59432286b..49fba1f3b50 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql @@ -1,4 +1,14 @@ SELECT + ( + SELECT + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `int64_too` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + GROUP BY + `bfcol_3` + ) + ORDER BY + `bfcol_3` ASC NULLS LAST.* FROM ( SELECT `bfcol_3` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql index 40bb73bd1c6..162b93d8254 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql @@ -1,14 +1,56 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `rowindex` AS `bfcol_18`, + `rowindex` AS `bfcol_19`, + `int64_col` AS `bfcol_20`, + `string_col` AS `bfcol_21` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `rowindex` AS `bfcol_3`, + `rowindex` AS `bfcol_4`, + `int64_col` AS `bfcol_5`, + `string_col` AS `bfcol_6` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ) SELECT + ( + SELECT + `bfcol_30` AS `rowindex`, + `bfcol_31` AS `rowindex_1`, + `bfcol_32` AS `int64_col`, + `bfcol_33` AS `string_col` + FROM ( + ( + SELECT + `bfcol_3` AS `bfcol_9`, + `bfcol_4` AS `bfcol_10`, + `bfcol_5` AS `bfcol_11`, + `bfcol_6` AS `bfcol_12`, + 0 AS `bfcol_13`, + ROW_NUMBER() OVER () - 1 AS `bfcol_14` + FROM `bfcte_1` + ) + UNION ALL + ( + SELECT + `bfcol_18` AS `bfcol_24`, + `bfcol_19` AS `bfcol_25`, + `bfcol_20` AS `bfcol_26`, + `bfcol_21` AS `bfcol_27`, + 1 AS `bfcol_28`, + ROW_NUMBER() OVER () - 1 AS `bfcol_29` + FROM `bfcte_2` + ) + ) + ) + ORDER BY + `bfcol_34` ASC NULLS LAST, + `bfcol_35` ASC NULLS LAST.* FROM ( SELECT `bfcol_30` AS `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql index a4d1ed11434..2e87ca242da 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql @@ -1,23 +1,82 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `float64_col` AS `bfcol_23`, + `int64_col` AS `bfcol_24` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `float64_col` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `float64_col` AS `bfcol_34`, + `int64_too` AS `bfcol_35` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + WHERE + `bool_col` ), `bfcte_3` AS ( SELECT - FROM `bfcte_3` + `float64_col` AS `bfcol_13`, + `int64_too` AS `bfcol_14` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + WHERE + `bool_col` ), `bfcte_4` AS ( SELECT - FROM `bfcte_4` + `bfcte_0`.* + FROM `bfcte_0` ), `bfcte_5` AS ( SELECT - FROM `bfcte_5` + `bfcte_2`.* + FROM `bfcte_2` ) SELECT + ( + SELECT + `bfcol_42` AS `float64_col`, + `bfcol_43` AS `int64_col` + FROM ( + ( + SELECT + `bfcol_2` AS `bfcol_6`, + `bfcol_3` AS `bfcol_7`, + 0 AS `bfcol_8`, + ROW_NUMBER() OVER (ORDER BY `bfcol_3` ASC NULLS LAST) - 1 AS `bfcol_9` + FROM `bfcte_1` + ) + UNION ALL + ( + SELECT + `bfcol_13` AS `bfcol_17`, + `bfcol_14` AS `bfcol_18`, + 1 AS `bfcol_19`, + ROW_NUMBER() OVER () - 1 AS `bfcol_20` + FROM `bfcte_3` + ) + UNION ALL + ( + SELECT + `bfcol_23` AS `bfcol_27`, + `bfcol_24` AS `bfcol_28`, + 2 AS `bfcol_29`, + ROW_NUMBER() OVER (ORDER BY `bfcol_24` ASC NULLS LAST) - 1 AS `bfcol_30` + FROM `bfcte_4` + ) + UNION ALL + ( + SELECT + `bfcol_34` AS `bfcol_38`, + `bfcol_35` AS `bfcol_39`, + 3 AS `bfcol_40`, + ROW_NUMBER() OVER () - 1 AS `bfcol_41` + FROM `bfcte_5` + ) + ) + ) + ORDER BY + `bfcol_44` ASC NULLS LAST, + `bfcol_45` ASC NULLS LAST.* FROM ( SELECT `bfcol_42` AS `float64_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql index ffcde677a7c..f52a24392c8 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql @@ -1,4 +1,15 @@ SELECT + ( + SELECT + `rowindex`, + `rowindex` AS `rowindex_1`, + `int_list_col`, + `string_list_col` + FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` + LEFT JOIN UNNEST(GENERATE_ARRAY(0, LEAST(ARRAY_LENGTH(`int_list_col`) - 1, ARRAY_LENGTH(`string_list_col`) - 1))) AS `bfcol_13` WITH OFFSET AS `bfcol_7` + ) + ORDER BY + `bfcol_7` ASC NULLS LAST.* FROM ( SELECT `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql index 90749e98a3e..172659d74a7 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql @@ -1,4 +1,13 @@ SELECT + ( + SELECT + `rowindex`, + `int_list_col` + FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` + LEFT JOIN UNNEST(`int_list_col`) AS `bfcol_8` WITH OFFSET AS `bfcol_4` + ) + ORDER BY + `bfcol_4` ASC NULLS LAST.* FROM ( SELECT `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index 310080142dc..cdc9d4779ed 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -1,26 +1,151 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + ( + SELECT + `bfcol_8` AS `bfcol_9` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ).* + FROM ( + SELECT + `bfcol_8` AS `bfcol_9` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ) ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + ( + SELECT + `bfcol_0` AS `bfcol_1` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ).* + FROM ( + SELECT + `bfcol_0` AS `bfcol_1` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ) ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ).* + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ) ), `bfcte_3` AS ( SELECT - FROM `bfcte_3` + ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ).* + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ) ), `bfcte_4` AS ( SELECT - FROM `bfcte_4` + `bfcte_0`.* + FROM `bfcte_0` ), `bfcte_5` AS ( SELECT - FROM `bfcte_5` + ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ).* + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + ) ), `bfcte_6` AS ( SELECT - FROM `bfcte_6` + `bfcte_2`.* + FROM `bfcte_2` ) SELECT + ( + SELECT + CAST(TIMESTAMP_MICROS( + CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) + ) AS DATETIME) AS `bigframes_unnamed_index`, + `bfcol_55` AS `int64_col`, + `bfcol_56` AS `int64_too` + FROM ( + SELECT + * + FROM ( + SELECT + `bfcol_67` AS `bfcol_41` + FROM ( + SELECT + * + FROM ( + SELECT + `bfcol_1`, + `bfcol_4`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_1` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_4` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_5` + FROM `bfcte_1` + CROSS JOIN `bfcte_5` + ) + ) + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + `bfcol_9`, + `bfcol_37`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_9` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_37` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_38` + FROM `bfcte_4` + CROSS JOIN ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + ) + ) + ) + CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_7`, `bfcol_40`, 1)) AS `bfcol_67` + ) + CROSS JOIN `bfcte_3` + ) + LEFT JOIN ( + SELECT + `bfcol_49` AS `bfcol_55`, + `bfcol_50` AS `bfcol_56`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_48` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_53` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_57` + FROM ( + SELECT + `bfcol_45` AS `bfcol_48`, + `bfcol_46` AS `bfcol_49`, + `bfcol_47` AS `bfcol_50` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + ) + CROSS JOIN `bfcte_6` + ) + ON `bfcol_41` = `bfcol_57` + ) + ORDER BY + `bfcol_41` ASC NULLS LAST.* FROM ( SELECT CAST(TIMESTAMP_MICROS( diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql index 3193c7cd0cc..5b024b16209 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql @@ -1,4 +1,52 @@ SELECT + ( + SELECT + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`min`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`max`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`sum`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`count`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`mean`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`area` + FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) + ) + ORDER BY + `bfcol_1` ASC NULLS LAST.* FROM ( SELECT ST_REGIONSTATS( diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql index 19dd32b19df..9e323884be7 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql @@ -1,4 +1,16 @@ SELECT + ( + SELECT + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`sum`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` + FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) + ) + ORDER BY + `bfcol_1` ASC NULLS LAST.* FROM ( SELECT ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql index e0b1a6f834a..49b27b8a8d1 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql @@ -1,4 +1,11 @@ SELECT + ( + SELECT + ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` + FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) + ) + ORDER BY + `bfcol_1` ASC NULLS LAST.* FROM ( SELECT ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index af50c5c8ee1..0a5e88bfddf 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -1,4 +1,15 @@ SELECT + ( + SELECT + `bfcol_2` AS `rowindex`, + `bfcol_5` AS `int64_col` + FROM ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) + ).* FROM ( SELECT `bfcol_2` AS `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 935dddb587b..58cff610c11 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -1,4 +1,15 @@ SELECT + ( + SELECT + `bfcol_2` AS `rowindex`, + `bfcol_5` AS `rowindex_2` + FROM ( + SELECT + `rowindex` AS `bfcol_2`, + `rowindex_2` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) + ).* FROM ( SELECT `bfcol_2` AS `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql index 695dc9a4197..5930c2e2071 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql @@ -1,4 +1,23 @@ SELECT + ( + SELECT + `bfcol_3` AS `int64_col`, + `bfcol_7` AS `int64_too` + FROM ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) + LEFT JOIN ( + SELECT + `int64_col` AS `bfcol_6`, + `int64_too` AS `bfcol_7` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) + ON COALESCE(`bfcol_2`, 0) = COALESCE(`bfcol_6`, 0) + AND COALESCE(`bfcol_2`, 1) = COALESCE(`bfcol_6`, 1) + ).* FROM ( SELECT `bfcol_3` AS `int64_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql index 545223dfcac..430e4eeb6d5 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql @@ -1,14 +1,39 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `bool_col` AS `bfcol_4`, + `rowindex` AS `bfcol_5` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `bool_col` AS `bfcol_0`, + `rowindex` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ) SELECT + ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON COALESCE(CAST(`bfcol_3` AS STRING), '0') = COALESCE(CAST(`bfcol_7` AS STRING), '0') + AND COALESCE(CAST(`bfcol_3` AS STRING), '1') = COALESCE(CAST(`bfcol_7` AS STRING), '1') + ).* FROM ( SELECT `bfcol_2` AS `rowindex_x`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql index ddc6bb7f98a..13471efdc2f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql @@ -1,14 +1,39 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `float64_col` AS `bfcol_4`, + `rowindex` AS `bfcol_5` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `float64_col` AS `bfcol_0`, + `rowindex` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ) SELECT + ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `float64_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) = IF(IS_NAN(`bfcol_7`), 2, COALESCE(`bfcol_7`, 0)) + AND IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) = IF(IS_NAN(`bfcol_7`), 3, COALESCE(`bfcol_7`, 1)) + ).* FROM ( SELECT `bfcol_2` AS `rowindex_x`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql index dfc6f01fce9..6cf4f2a2fd4 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql @@ -1,14 +1,39 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `int64_col` AS `bfcol_4`, + `rowindex` AS `bfcol_5` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `int64_col` AS `bfcol_0`, + `rowindex` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ) SELECT + ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `int64_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_7`, 0) + AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_7`, 1) + ).* FROM ( SELECT `bfcol_2` AS `rowindex_x`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql index d914359c00f..64638f88d6f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql @@ -1,14 +1,39 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `numeric_col` AS `bfcol_4`, + `rowindex` AS `bfcol_5` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `numeric_col` AS `bfcol_0`, + `rowindex` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ) SELECT + ( + SELECT + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `numeric_col`, + `bfcol_6` AS `rowindex_y` + FROM ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_1` + ) + INNER JOIN ( + SELECT + `bfcol_5` AS `bfcol_6`, + `bfcol_4` AS `bfcol_7` + FROM `bfcte_2` + ) + ON COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(0 AS NUMERIC)) + AND COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(1 AS NUMERIC)) + ).* FROM ( SELECT `bfcol_2` AS `rowindex_x`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql index eaa3a1db15a..35b498a881a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql @@ -1,17 +1,38 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `rowindex` AS `bfcol_2`, + `string_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `rowindex` AS `bfcol_0`, + `string_col` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ), `bfcte_3` AS ( SELECT - FROM `bfcte_3` + `bfcte_1`.* + FROM `bfcte_1` ) SELECT + ( + SELECT + `bfcol_0` AS `rowindex_x`, + `bfcol_1` AS `string_col`, + `bfcol_4` AS `rowindex_y` + FROM `bfcte_3` + INNER JOIN ( + SELECT + `bfcol_2` AS `bfcol_4`, + `bfcol_3` AS `bfcol_5` + FROM `bfcte_2` + ) + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') + ).* FROM ( SELECT `bfcol_0` AS `rowindex_x`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql index fd86768382d..ce9dae97553 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql @@ -1,17 +1,38 @@ WITH `bfcte_0` AS ( SELECT - FROM `bfcte_0` + `rowindex` AS `bfcol_2`, + `time_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - FROM `bfcte_1` + `rowindex` AS `bfcol_0`, + `time_col` AS `bfcol_1` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - FROM `bfcte_2` + `bfcte_0`.* + FROM `bfcte_0` ), `bfcte_3` AS ( SELECT - FROM `bfcte_3` + `bfcte_1`.* + FROM `bfcte_1` ) SELECT + ( + SELECT + `bfcol_0` AS `rowindex_x`, + `bfcol_1` AS `time_col`, + `bfcol_4` AS `rowindex_y` + FROM `bfcte_3` + INNER JOIN ( + SELECT + `bfcol_2` AS `bfcol_4`, + `bfcol_3` AS `bfcol_5` + FROM `bfcte_2` + ) + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') + ).* FROM ( SELECT `bfcol_0` AS `rowindex_x`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql index 96bcbcc0824..e3711bb6583 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql @@ -1,4 +1,180 @@ SELECT + ( + SELECT + `bfcol_0` AS `bool_col`, + `bfcol_1` AS `bytes_col`, + `bfcol_2` AS `date_col`, + `bfcol_3` AS `datetime_col`, + `bfcol_4` AS `geography_col`, + `bfcol_5` AS `int64_col`, + `bfcol_6` AS `int64_too`, + `bfcol_7` AS `numeric_col`, + `bfcol_8` AS `float64_col`, + `bfcol_9` AS `rowindex`, + `bfcol_10` AS `rowindex_2`, + `bfcol_11` AS `string_col`, + `bfcol_12` AS `time_col`, + `bfcol_13` AS `timestamp_col`, + `bfcol_14` AS `duration_col` + FROM UNNEST(ARRAY>[STRUCT( + TRUE, + CAST(b'Hello, World!' AS BYTES), + CAST('2021-07-21' AS DATE), + CAST('2021-07-21T11:39:45' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-122.0838511 37.3860517)'), + 123456789, + 0, + CAST(1.234567890 AS NUMERIC), + 1.25, + 0, + 0, + 'Hello, World!', + CAST('11:41:43.076160' AS TIME), + CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), + 4, + 0 + ), STRUCT( + FALSE, + CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), + CAST('1991-02-03' AS DATE), + CAST('1991-01-02T03:45:06' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-71.104 42.315)'), + -987654321, + 1, + CAST(1.234567890 AS NUMERIC), + 2.51, + 1, + 1, + 'こんにちは', + CAST('11:14:34.701606' AS TIME), + CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), + -1000000, + 1 + ), STRUCT( + TRUE, + CAST(b'\xc2\xa1Hola Mundo!' AS BYTES), + CAST('2023-03-01' AS DATE), + CAST('2023-03-01T10:55:13' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-0.124474760143016 51.5007826749545)'), + 314159, + 0, + CAST(101.101010100 AS NUMERIC), + 25000000000.0, + 2, + 2, + ' ¡Hola Mundo! ', + CAST('23:59:59.999999' AS TIME), + CAST('2023-03-01T10:55:13.250125+00:00' AS TIMESTAMP), + 0, + 2 + ), STRUCT( + CAST(NULL AS BOOLEAN), + CAST(NULL AS BYTES), + CAST(NULL AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + CAST(NULL AS INT64), + 1, + CAST(NULL AS NUMERIC), + CAST(NULL AS FLOAT64), + 3, + 3, + CAST(NULL AS STRING), + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + CAST(NULL AS INT64), + 3 + ), STRUCT( + FALSE, + CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), + CAST('2021-07-21' AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + -234892, + -2345, + CAST(NULL AS NUMERIC), + CAST(NULL AS FLOAT64), + 4, + 4, + 'Hello, World!', + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + 31540000000000, + 4 + ), STRUCT( + FALSE, + CAST(b'G\xc3\xbcten Tag' AS BYTES), + CAST('1980-03-14' AS DATE), + CAST('1980-03-14T15:16:17' AS DATETIME), + CAST(NULL AS GEOGRAPHY), + 55555, + 0, + CAST(5.555555000 AS NUMERIC), + 555.555, + 5, + 5, + 'Güten Tag!', + CAST('15:16:17.181921' AS TIME), + CAST('1980-03-14T15:16:17.181921+00:00' AS TIMESTAMP), + 4, + 5 + ), STRUCT( + TRUE, + CAST(b'Hello\tBigFrames!\x07' AS BYTES), + CAST('2023-05-23' AS DATE), + CAST('2023-05-23T11:37:01' AS DATETIME), + ST_GEOGFROMTEXT('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), + 101202303, + 2, + CAST(-10.090807000 AS NUMERIC), + -123.456, + 6, + 6, + 'capitalize, This ', + CAST('01:02:03.456789' AS TIME), + CAST('2023-05-23T11:42:55.000001+00:00' AS TIMESTAMP), + CAST(NULL AS INT64), + 6 + ), STRUCT( + TRUE, + CAST(NULL AS BYTES), + CAST('2038-01-20' AS DATE), + CAST('2038-01-19T03:14:08' AS DATETIME), + CAST(NULL AS GEOGRAPHY), + -214748367, + 2, + CAST(11111111.100000000 AS NUMERIC), + 42.42, + 7, + 7, + ' سلام', + CAST('12:00:00.000001' AS TIME), + CAST('2038-01-19T03:14:17.999999+00:00' AS TIMESTAMP), + 4, + 7 + ), STRUCT( + FALSE, + CAST(NULL AS BYTES), + CAST(NULL AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + 2, + 1, + CAST(NULL AS NUMERIC), + 6.87, + 8, + 8, + 'T', + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + 432000000000, + 8 + )]) + WHERE + RAND() < 0.1 + ) + ORDER BY + `bfcol_15` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql index 0186fbb11be..a0f9f08fcc8 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql @@ -1,4 +1,188 @@ SELECT + ( + SELECT + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `bool_col`, + `bfcol_2` AS `bytes_col`, + `bfcol_3` AS `date_col`, + `bfcol_4` AS `datetime_col`, + `bfcol_5` AS `geography_col`, + `bfcol_6` AS `int64_col`, + `bfcol_7` AS `int64_too`, + `bfcol_8` AS `numeric_col`, + `bfcol_9` AS `float64_col`, + `bfcol_10` AS `rowindex_1`, + `bfcol_11` AS `rowindex_2`, + `bfcol_12` AS `string_col`, + `bfcol_13` AS `time_col`, + `bfcol_14` AS `timestamp_col`, + `bfcol_15` AS `duration_col` + FROM UNNEST(ARRAY>[STRUCT( + 0, + TRUE, + CAST(b'Hello, World!' AS BYTES), + CAST('2021-07-21' AS DATE), + CAST('2021-07-21T11:39:45' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-122.0838511 37.3860517)'), + 123456789, + 0, + CAST(1.234567890 AS NUMERIC), + 1.25, + 0, + 0, + 'Hello, World!', + CAST('11:41:43.076160' AS TIME), + CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), + 4, + 0 + ), STRUCT( + 1, + FALSE, + CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), + CAST('1991-02-03' AS DATE), + CAST('1991-01-02T03:45:06' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-71.104 42.315)'), + -987654321, + 1, + CAST(1.234567890 AS NUMERIC), + 2.51, + 1, + 1, + 'こんにちは', + CAST('11:14:34.701606' AS TIME), + CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), + -1000000, + 1 + ), STRUCT( + 2, + TRUE, + CAST(b'\xc2\xa1Hola Mundo!' AS BYTES), + CAST('2023-03-01' AS DATE), + CAST('2023-03-01T10:55:13' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-0.124474760143016 51.5007826749545)'), + 314159, + 0, + CAST(101.101010100 AS NUMERIC), + 25000000000.0, + 2, + 2, + ' ¡Hola Mundo! ', + CAST('23:59:59.999999' AS TIME), + CAST('2023-03-01T10:55:13.250125+00:00' AS TIMESTAMP), + 0, + 2 + ), STRUCT( + 3, + CAST(NULL AS BOOLEAN), + CAST(NULL AS BYTES), + CAST(NULL AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + CAST(NULL AS INT64), + 1, + CAST(NULL AS NUMERIC), + CAST(NULL AS FLOAT64), + 3, + 3, + CAST(NULL AS STRING), + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + CAST(NULL AS INT64), + 3 + ), STRUCT( + 4, + FALSE, + CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), + CAST('2021-07-21' AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + -234892, + -2345, + CAST(NULL AS NUMERIC), + CAST(NULL AS FLOAT64), + 4, + 4, + 'Hello, World!', + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + 31540000000000, + 4 + ), STRUCT( + 5, + FALSE, + CAST(b'G\xc3\xbcten Tag' AS BYTES), + CAST('1980-03-14' AS DATE), + CAST('1980-03-14T15:16:17' AS DATETIME), + CAST(NULL AS GEOGRAPHY), + 55555, + 0, + CAST(5.555555000 AS NUMERIC), + 555.555, + 5, + 5, + 'Güten Tag!', + CAST('15:16:17.181921' AS TIME), + CAST('1980-03-14T15:16:17.181921+00:00' AS TIMESTAMP), + 4, + 5 + ), STRUCT( + 6, + TRUE, + CAST(b'Hello\tBigFrames!\x07' AS BYTES), + CAST('2023-05-23' AS DATE), + CAST('2023-05-23T11:37:01' AS DATETIME), + ST_GEOGFROMTEXT('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), + 101202303, + 2, + CAST(-10.090807000 AS NUMERIC), + -123.456, + 6, + 6, + 'capitalize, This ', + CAST('01:02:03.456789' AS TIME), + CAST('2023-05-23T11:42:55.000001+00:00' AS TIMESTAMP), + CAST(NULL AS INT64), + 6 + ), STRUCT( + 7, + TRUE, + CAST(NULL AS BYTES), + CAST('2038-01-20' AS DATE), + CAST('2038-01-19T03:14:08' AS DATETIME), + CAST(NULL AS GEOGRAPHY), + -214748367, + 2, + CAST(11111111.100000000 AS NUMERIC), + 42.42, + 7, + 7, + ' سلام', + CAST('12:00:00.000001' AS TIME), + CAST('2038-01-19T03:14:17.999999+00:00' AS TIMESTAMP), + 4, + 7 + ), STRUCT( + 8, + FALSE, + CAST(NULL AS BYTES), + CAST(NULL AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + 2, + 1, + CAST(NULL AS NUMERIC), + 6.87, + 8, + 8, + 'T', + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + 432000000000, + 8 + )]) + ) + ORDER BY + `bfcol_16` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql index f48e8ef940f..8ef1b34a183 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql @@ -1,4 +1,12 @@ SELECT + ( + SELECT + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `json_col` + FROM UNNEST(ARRAY>[STRUCT(0, PARSE_JSON('null'), 0), STRUCT(1, PARSE_JSON('true'), 1), STRUCT(2, PARSE_JSON('100'), 2), STRUCT(3, PARSE_JSON('0.98'), 3), STRUCT(4, PARSE_JSON('"a string"'), 4), STRUCT(5, PARSE_JSON('[]'), 5), STRUCT(6, PARSE_JSON('[1,2,3]'), 6), STRUCT(7, PARSE_JSON('[{"a":1},{"a":2},{"a":null},{}]'), 7), STRUCT(8, PARSE_JSON('"100"'), 8), STRUCT(9, PARSE_JSON('{"date":"2024-07-16"}'), 9), STRUCT(10, PARSE_JSON('{"int_value":2,"null_filed":null}'), 10), STRUCT(11, PARSE_JSON('{"list_data":[10,20,30]}'), 11)]) + ) + ORDER BY + `bfcol_2` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql index 945b43ecb51..b2e92918e44 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql @@ -1,4 +1,48 @@ SELECT + ( + SELECT + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `int_list_col`, + `bfcol_2` AS `bool_list_col`, + `bfcol_3` AS `float_list_col`, + `bfcol_4` AS `date_list_col`, + `bfcol_5` AS `date_time_list_col`, + `bfcol_6` AS `numeric_list_col`, + `bfcol_7` AS `string_list_col` + FROM UNNEST(ARRAY, `bfcol_2` ARRAY, `bfcol_3` ARRAY, `bfcol_4` ARRAY, `bfcol_5` ARRAY, `bfcol_6` ARRAY, `bfcol_7` ARRAY, `bfcol_8` INT64>>[STRUCT( + 0, + [1], + [TRUE], + [1.2, 2.3], + ['2021-07-21'], + ['2021-07-21 11:39:45'], + [1.2, 2.3, 3.4], + ['abc', 'de', 'f'], + 0 + ), STRUCT( + 1, + [1, 2], + [TRUE, FALSE], + [1.1], + ['2021-07-21', '1987-03-28'], + ['1999-03-14 17:22:00'], + [5.5, 2.3], + ['a', 'bc', 'de'], + 1 + ), STRUCT( + 2, + [1, 2, 3], + [TRUE], + [0.5, -1.9, 2.3], + ['2017-08-01', '2004-11-22'], + ['1979-06-03 03:20:45'], + [1.7000000000000002], + ['', 'a'], + 2 + )]) + ) + ORDER BY + `bfcol_8` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `rowindex`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql index 1435f4fb010..7acfe7b4534 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql @@ -1,4 +1,26 @@ SELECT + ( + SELECT + `bfcol_0` AS `col_none`, + `bfcol_1` AS `col_inf`, + `bfcol_2` AS `col_neginf`, + `bfcol_3` AS `col_nan`, + `bfcol_4` AS `col_struct_none`, + `bfcol_5` AS `col_struct_w_none`, + `bfcol_6` AS `col_list_none` + FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( + CAST(NULL AS FLOAT64), + CAST('Infinity' AS FLOAT64), + CAST('-Infinity' AS FLOAT64), + CAST(NULL AS FLOAT64), + CAST(NULL AS STRUCT), + STRUCT(CAST(NULL AS INT64) AS `foo`), + ARRAY[], + 0 + ), STRUCT(1.0, 1.0, 1.0, 1.0, STRUCT(1 AS `foo`), STRUCT(1 AS `foo`), [1, 2], 1), STRUCT(2.0, 2.0, 2.0, 2.0, STRUCT(2 AS `foo`), STRUCT(2 AS `foo`), [3, 4], 2)]) + ) + ORDER BY + `bfcol_7` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `col_none`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql index ea263528e30..10b3d9d7de8 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql @@ -1,4 +1,28 @@ SELECT + ( + SELECT + `bfcol_0` AS `id`, + `bfcol_1` AS `person` + FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( + 1, + STRUCT( + 'Alice' AS `name`, + 30 AS `age`, + STRUCT('New York' AS `city`, 'USA' AS `country`) AS `address` + ), + 0 + ), STRUCT( + 2, + STRUCT( + 'Bob' AS `name`, + 25 AS `age`, + STRUCT('London' AS `city`, 'UK' AS `country`) AS `address` + ), + 1 + )]) + ) + ORDER BY + `bfcol_2` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `id`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql index 9916e999af2..b620bf0aa5b 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql @@ -1,4 +1,11 @@ SELECT + ( + SELECT + * + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + WHERE + `rowindex` > 0 AND `string_col` IN ('Hello, World!') + ).* FROM ( SELECT * diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql index 6bbf0747bac..5337f13e755 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql @@ -1,4 +1,32 @@ SELECT + ( + SELECT + `bfcol_0` AS `ts_col`, + CASE + WHEN COALESCE( + SUM(CAST(( + `bfcol_1` + ) IS NOT NULL AS INT64)) OVER ( + ORDER BY UNIX_MICROS(`bfcol_0`) ASC + RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ), + 0 + ) < 1 + THEN NULL + WHEN TRUE + THEN COALESCE( + SUM(`bfcol_1`) OVER ( + ORDER BY UNIX_MICROS(`bfcol_0`) ASC + RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ), + 0 + ) + END AS `int_col` + FROM UNNEST(ARRAY>[STRUCT(CAST('2025-01-01T00:00:00+00:00' AS TIMESTAMP), 0, 0), STRUCT(CAST('2025-01-01T00:00:01+00:00' AS TIMESTAMP), 1, 1), STRUCT(CAST('2025-01-01T00:00:02+00:00' AS TIMESTAMP), 2, 2), STRUCT(CAST('2025-01-01T00:00:03+00:00' AS TIMESTAMP), 3, 3), STRUCT(CAST('2025-01-01T00:00:04+00:00' AS TIMESTAMP), 0, 4), STRUCT(CAST('2025-01-01T00:00:05+00:00' AS TIMESTAMP), 1, 5), STRUCT(CAST('2025-01-01T00:00:06+00:00' AS TIMESTAMP), 2, 6), STRUCT(CAST('2025-01-01T00:00:07+00:00' AS TIMESTAMP), 3, 7), STRUCT(CAST('2025-01-01T00:00:08+00:00' AS TIMESTAMP), 0, 8), STRUCT(CAST('2025-01-01T00:00:09+00:00' AS TIMESTAMP), 1, 9), STRUCT(CAST('2025-01-01T00:00:10+00:00' AS TIMESTAMP), 2, 10), STRUCT(CAST('2025-01-01T00:00:11+00:00' AS TIMESTAMP), 3, 11), STRUCT(CAST('2025-01-01T00:00:12+00:00' AS TIMESTAMP), 0, 12), STRUCT(CAST('2025-01-01T00:00:13+00:00' AS TIMESTAMP), 1, 13), STRUCT(CAST('2025-01-01T00:00:14+00:00' AS TIMESTAMP), 2, 14), STRUCT(CAST('2025-01-01T00:00:15+00:00' AS TIMESTAMP), 3, 15), STRUCT(CAST('2025-01-01T00:00:16+00:00' AS TIMESTAMP), 0, 16), STRUCT(CAST('2025-01-01T00:00:17+00:00' AS TIMESTAMP), 1, 17), STRUCT(CAST('2025-01-01T00:00:18+00:00' AS TIMESTAMP), 2, 18), STRUCT(CAST('2025-01-01T00:00:19+00:00' AS TIMESTAMP), 3, 19)]) + ) + ORDER BY + `bfcol_0` ASC NULLS LAST, + `bfcol_2` ASC NULLS LAST.* FROM ( SELECT `bfcol_0` AS `ts_col`, From e60f3edfa35e93d043ef40fe81dcaa5bb8b4ef95 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 01:39:16 +0000 Subject: [PATCH 07/15] dont create with expression without ctes --- bigframes/core/compile/sqlglot/compiler.py | 13 -- bigframes/core/compile/sqlglot/sqlglot_ir.py | 4 +- bigframes/core/rewrite/as_sql.py | 3 + bigframes/core/rewrite/ctes.py | 4 - .../test_binary_compiler/test_corr/out.sql | 8 +- .../test_binary_compiler/test_cov/out.sql | 8 +- .../test_nullary_compiler/test_size/out.sql | 8 +- .../test_array_agg/out.sql | 8 +- .../test_string_agg/out.sql | 8 +- .../test_unary_compiler/test_all/out.sql | 9 +- .../test_unary_compiler/test_any/out.sql | 9 +- .../test_any_value/out.sql | 8 +- .../test_approx_quartiles/out.sql | 10 +- .../test_approx_top_count/out.sql | 8 +- .../test_unary_compiler/test_count/out.sql | 8 +- .../test_unary_compiler/test_max/out.sql | 8 +- .../test_unary_compiler/test_mean/out.sql | 11 +- .../test_unary_compiler/test_median/out.sql | 10 +- .../test_unary_compiler/test_min/out.sql | 8 +- .../test_unary_compiler/test_nunique/out.sql | 8 +- .../test_unary_compiler/test_pop_var/out.sql | 9 +- .../test_unary_compiler/test_product/out.sql | 8 +- .../test_unary_compiler/test_quantile/out.sql | 10 +- .../test_unary_compiler/test_std/out.sql | 11 +- .../test_unary_compiler/test_sum/out.sql | 9 +- .../test_unary_compiler/test_var/out.sql | 9 +- .../test_compile_aggregate/out.sql | 15 +- .../test_compile_aggregate_wo_dropna/out.sql | 13 +- .../test_compile_explode_dataframe/out.sql | 14 +- .../test_compile_explode_series/out.sql | 12 +- .../test_st_regionstats/out.sql | 51 +---- .../out.sql | 15 +- .../test_compile_geo/test_st_simplify/out.sql | 10 +- .../test_compile_isin/out.sql | 14 +- .../test_compile_isin_not_nullable/out.sql | 14 +- .../test_compile_join/out.sql | 22 +-- .../test_compile_random_sample/out.sql | 179 +---------------- .../test_compile_readlocal/out.sql | 187 +----------------- .../test_compile_readlocal_w_json_df/out.sql | 11 +- .../test_compile_readlocal_w_lists_df/out.sql | 47 +---- .../out.sql | 25 +-- .../out.sql | 27 +-- .../out.sql | 10 +- .../out.sql | 31 +-- 44 files changed, 45 insertions(+), 869 deletions(-) diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index 2ba1f333487..e9c10493c03 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -366,16 +366,3 @@ def _replace_unsupported_ops(node: nodes.BigFrameNode): node = nodes.bottom_up(node, rewrite.rewrite_slice) node = nodes.bottom_up(node, rewrite.rewrite_range_rolling) return node - - -def _get_ctes(root: nodes.ResultNode) -> typing.Sequence[nodes.CteNode]: - """ - Get ctes from plan in topological order. - """ - - def merge_list(node, cte_list): - if isinstance(node, nodes.CteNode): - return (*cte_list, node) - return cte_list - - return root.reduce_up(merge_list) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index 11bf0fdbffe..7fff6760077 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -503,13 +503,13 @@ def _explode_multiple_columns( def _as_from_item(self) -> typing.Union[sge.Subquery, sge.Table]: if isinstance(self.expr, sge.Select): return self.expr.subquery() - else: # table + else: # table or cte return self.expr def _as_select(self) -> sge.Select: if isinstance(self.expr, sge.Select): return self.expr - else: # table + else: # table or cte return ( sge.Select() .select(sge.Column(this=sge.Star(), table=self.expr)) diff --git a/bigframes/core/rewrite/as_sql.py b/bigframes/core/rewrite/as_sql.py index 19b924960e2..fbd096590ef 100644 --- a/bigframes/core/rewrite/as_sql.py +++ b/bigframes/core/rewrite/as_sql.py @@ -228,6 +228,9 @@ def _extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: ) cte_names = tuple(f"bfcte_{i}" for i in range(len(topological_ctes))) + if len(topological_ctes) == 0: + return root + mapping = { cte_node: sql_nodes.SqlCteRefNode(cte_name, tuple(cte_node.fields)) for cte_node, cte_name in zip(topological_ctes, cte_names) diff --git a/bigframes/core/rewrite/ctes.py b/bigframes/core/rewrite/ctes.py index 12506ea834a..871dbc94479 100644 --- a/bigframes/core/rewrite/ctes.py +++ b/bigframes/core/rewrite/ctes.py @@ -25,13 +25,9 @@ def extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: for child in parent.child_nodes: node_parents[child] += 1 - counter = 0 - # we just mark in place, rather than pull out of the tree. def insert_cte_markers(node: nodes.BigFrameNode) -> nodes.BigFrameNode: - nonlocal counter if node_parents[node] > 1: - counter += 1 return nodes.CteNode(node) return node diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql index f95c0533fc1..ca82c1dccf9 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_2` AS `corr_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_2` AS `corr_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql index ebd56c1b507..9bc9cd33a67 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_2` AS `cov_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_2` AS `cov_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql index 99e70582f39..0e1026cecea 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_32` AS `size` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_32` AS `size` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql index 26e896ec5e8..e04bd89eba5 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `string_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `string_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql index b7143e3315b..336f82f64ac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql @@ -1,11 +1,4 @@ -SELECT - ( - SELECT - `bfcol_2` AS `bool_col`, - `bfcol_3` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_2` AS `bool_col`, `bfcol_3` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql index b7143e3315b..336f82f64ac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql @@ -1,11 +1,4 @@ -SELECT - ( - SELECT - `bfcol_2` AS `bool_col`, - `bfcol_3` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_2` AS `bool_col`, `bfcol_3` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql index 726cc0c8a45..5bb2459cdbd 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql @@ -1,12 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `q1`, - `bfcol_2` AS `q2`, - `bfcol_3` AS `q3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `q1`, `bfcol_2` AS `q2`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql index 20d4b375f92..2542c5ff217 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql @@ -1,13 +1,4 @@ -SELECT - ( - SELECT - `bfcol_12` AS `int64_col`, - `bfcol_13` AS `bool_col`, - `bfcol_14` AS `duration_col`, - `bfcol_15` AS `int64_col_w_floor` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_12` AS `int64_col`, `bfcol_13` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql index 9abc3db357e..c7c7580be34 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql @@ -1,12 +1,4 @@ -SELECT - ( - SELECT - `bfcol_3` AS `int64_col`, - `bfcol_4` AS `date_col`, - `bfcol_5` AS `string_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_3` AS `int64_col`, `bfcol_4` AS `date_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql index b84907b4d28..2e3b6c3f4b5 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql @@ -1,11 +1,4 @@ -SELECT - ( - SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_4` AS `int64_col`, `bfcol_5` AS `bool_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql index 946a0e5f74f..a5c55d0feac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql @@ -1,10 +1,4 @@ -SELECT - ( - SELECT - `bfcol_1` AS `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_1` AS `int64_col` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql index c7c0bb0c99d..aaf56156c33 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql @@ -1,12 +1,4 @@ -SELECT - ( - SELECT - `bfcol_4` AS `int64`, - `bfcol_5` AS `bool`, - `bfcol_6` AS `int64_w_floor` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_4` AS `int64`, `bfcol_5` AS `bool`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql index 20d4b375f92..2542c5ff217 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql @@ -1,13 +1,4 @@ -SELECT - ( - SELECT - `bfcol_12` AS `int64_col`, - `bfcol_13` AS `bool_col`, - `bfcol_14` AS `duration_col`, - `bfcol_15` AS `int64_col_w_floor` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_12` AS `int64_col`, `bfcol_13` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql index b84907b4d28..2e3b6c3f4b5 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql @@ -1,11 +1,4 @@ -SELECT - ( - SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_4` AS `int64_col`, `bfcol_5` AS `bool_col` diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql index b84907b4d28..2e3b6c3f4b5 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql @@ -1,11 +1,4 @@ -SELECT - ( - SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).* -FROM ( +( SELECT `bfcol_4` AS `int64_col`, `bfcol_5` AS `bool_col` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql index 5c60bcda3b4..47bd40594bc 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql @@ -1,17 +1,4 @@ -SELECT - ( - SELECT - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `int64_too` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - NOT `bfcol_3` IS NULL - GROUP BY - `bfcol_3` - ) - ORDER BY - `bfcol_3` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_3` AS `bool_col`, `bfcol_6` AS `int64_too` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql index 49fba1f3b50..d4d836354c1 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql @@ -1,15 +1,4 @@ -SELECT - ( - SELECT - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `int64_too` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - GROUP BY - `bfcol_3` - ) - ORDER BY - `bfcol_3` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_3` AS `bool_col`, `bfcol_6` AS `int64_too` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql index f52a24392c8..9ca4d846b64 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql @@ -1,16 +1,4 @@ -SELECT - ( - SELECT - `rowindex`, - `rowindex` AS `rowindex_1`, - `int_list_col`, - `string_list_col` - FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` - LEFT JOIN UNNEST(GENERATE_ARRAY(0, LEAST(ARRAY_LENGTH(`int_list_col`) - 1, ARRAY_LENGTH(`string_list_col`) - 1))) AS `bfcol_13` WITH OFFSET AS `bfcol_7` - ) - ORDER BY - `bfcol_7` ASC NULLS LAST.* -FROM ( +( SELECT `rowindex`, `rowindex` AS `rowindex_1`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql index 172659d74a7..6ab5539c530 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql @@ -1,14 +1,4 @@ -SELECT - ( - SELECT - `rowindex`, - `int_list_col` - FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` - LEFT JOIN UNNEST(`int_list_col`) AS `bfcol_8` WITH OFFSET AS `bfcol_4` - ) - ORDER BY - `bfcol_4` ASC NULLS LAST.* -FROM ( +( SELECT `rowindex`, `int_list_col` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql index 5b024b16209..2f67f9ccf9d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql @@ -1,53 +1,4 @@ -SELECT - ( - SELECT - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`min`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`max`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`sum`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`count`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`mean`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`area` - FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) - ) - ORDER BY - `bfcol_1` ASC NULLS LAST.* -FROM ( +( SELECT ST_REGIONSTATS( `bfcol_0`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql index 9e323884be7..d373bcb923d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql @@ -1,17 +1,4 @@ -SELECT - ( - SELECT - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`sum`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` - FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) - ) - ORDER BY - `bfcol_1` ASC NULLS LAST.* -FROM ( +( SELECT ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql index 49b27b8a8d1..4bbbfc5d9be 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql @@ -1,12 +1,4 @@ -SELECT - ( - SELECT - ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` - FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) - ) - ORDER BY - `bfcol_1` ASC NULLS LAST.* -FROM ( +( SELECT ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index 0a5e88bfddf..c19e7f3af59 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -1,16 +1,4 @@ -SELECT - ( - SELECT - `bfcol_2` AS `rowindex`, - `bfcol_5` AS `int64_col` - FROM ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ) - ).* -FROM ( +( SELECT `bfcol_2` AS `rowindex`, `bfcol_5` AS `int64_col` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 58cff610c11..58e786b2b6f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -1,16 +1,4 @@ -SELECT - ( - SELECT - `bfcol_2` AS `rowindex`, - `bfcol_5` AS `rowindex_2` - FROM ( - SELECT - `rowindex` AS `bfcol_2`, - `rowindex_2` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ) - ).* -FROM ( +( SELECT `bfcol_2` AS `rowindex`, `bfcol_5` AS `rowindex_2` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql index 5930c2e2071..fe5ed33b1c3 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql @@ -1,24 +1,4 @@ -SELECT - ( - SELECT - `bfcol_3` AS `int64_col`, - `bfcol_7` AS `int64_too` - FROM ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ) - LEFT JOIN ( - SELECT - `int64_col` AS `bfcol_6`, - `int64_too` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ) - ON COALESCE(`bfcol_2`, 0) = COALESCE(`bfcol_6`, 0) - AND COALESCE(`bfcol_2`, 1) = COALESCE(`bfcol_6`, 1) - ).* -FROM ( +( SELECT `bfcol_3` AS `int64_col`, `bfcol_7` AS `int64_too` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql index e3711bb6583..004775fe482 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql @@ -1,181 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `bool_col`, - `bfcol_1` AS `bytes_col`, - `bfcol_2` AS `date_col`, - `bfcol_3` AS `datetime_col`, - `bfcol_4` AS `geography_col`, - `bfcol_5` AS `int64_col`, - `bfcol_6` AS `int64_too`, - `bfcol_7` AS `numeric_col`, - `bfcol_8` AS `float64_col`, - `bfcol_9` AS `rowindex`, - `bfcol_10` AS `rowindex_2`, - `bfcol_11` AS `string_col`, - `bfcol_12` AS `time_col`, - `bfcol_13` AS `timestamp_col`, - `bfcol_14` AS `duration_col` - FROM UNNEST(ARRAY>[STRUCT( - TRUE, - CAST(b'Hello, World!' AS BYTES), - CAST('2021-07-21' AS DATE), - CAST('2021-07-21T11:39:45' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-122.0838511 37.3860517)'), - 123456789, - 0, - CAST(1.234567890 AS NUMERIC), - 1.25, - 0, - 0, - 'Hello, World!', - CAST('11:41:43.076160' AS TIME), - CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), - 4, - 0 - ), STRUCT( - FALSE, - CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), - CAST('1991-02-03' AS DATE), - CAST('1991-01-02T03:45:06' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-71.104 42.315)'), - -987654321, - 1, - CAST(1.234567890 AS NUMERIC), - 2.51, - 1, - 1, - 'こんにちは', - CAST('11:14:34.701606' AS TIME), - CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), - -1000000, - 1 - ), STRUCT( - TRUE, - CAST(b'\xc2\xa1Hola Mundo!' AS BYTES), - CAST('2023-03-01' AS DATE), - CAST('2023-03-01T10:55:13' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-0.124474760143016 51.5007826749545)'), - 314159, - 0, - CAST(101.101010100 AS NUMERIC), - 25000000000.0, - 2, - 2, - ' ¡Hola Mundo! ', - CAST('23:59:59.999999' AS TIME), - CAST('2023-03-01T10:55:13.250125+00:00' AS TIMESTAMP), - 0, - 2 - ), STRUCT( - CAST(NULL AS BOOLEAN), - CAST(NULL AS BYTES), - CAST(NULL AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - CAST(NULL AS INT64), - 1, - CAST(NULL AS NUMERIC), - CAST(NULL AS FLOAT64), - 3, - 3, - CAST(NULL AS STRING), - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - CAST(NULL AS INT64), - 3 - ), STRUCT( - FALSE, - CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), - CAST('2021-07-21' AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - -234892, - -2345, - CAST(NULL AS NUMERIC), - CAST(NULL AS FLOAT64), - 4, - 4, - 'Hello, World!', - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - 31540000000000, - 4 - ), STRUCT( - FALSE, - CAST(b'G\xc3\xbcten Tag' AS BYTES), - CAST('1980-03-14' AS DATE), - CAST('1980-03-14T15:16:17' AS DATETIME), - CAST(NULL AS GEOGRAPHY), - 55555, - 0, - CAST(5.555555000 AS NUMERIC), - 555.555, - 5, - 5, - 'Güten Tag!', - CAST('15:16:17.181921' AS TIME), - CAST('1980-03-14T15:16:17.181921+00:00' AS TIMESTAMP), - 4, - 5 - ), STRUCT( - TRUE, - CAST(b'Hello\tBigFrames!\x07' AS BYTES), - CAST('2023-05-23' AS DATE), - CAST('2023-05-23T11:37:01' AS DATETIME), - ST_GEOGFROMTEXT('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), - 101202303, - 2, - CAST(-10.090807000 AS NUMERIC), - -123.456, - 6, - 6, - 'capitalize, This ', - CAST('01:02:03.456789' AS TIME), - CAST('2023-05-23T11:42:55.000001+00:00' AS TIMESTAMP), - CAST(NULL AS INT64), - 6 - ), STRUCT( - TRUE, - CAST(NULL AS BYTES), - CAST('2038-01-20' AS DATE), - CAST('2038-01-19T03:14:08' AS DATETIME), - CAST(NULL AS GEOGRAPHY), - -214748367, - 2, - CAST(11111111.100000000 AS NUMERIC), - 42.42, - 7, - 7, - ' سلام', - CAST('12:00:00.000001' AS TIME), - CAST('2038-01-19T03:14:17.999999+00:00' AS TIMESTAMP), - 4, - 7 - ), STRUCT( - FALSE, - CAST(NULL AS BYTES), - CAST(NULL AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - 2, - 1, - CAST(NULL AS NUMERIC), - 6.87, - 8, - 8, - 'T', - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - 432000000000, - 8 - )]) - WHERE - RAND() < 0.1 - ) - ORDER BY - `bfcol_15` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `bool_col`, `bfcol_1` AS `bytes_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql index a0f9f08fcc8..4ed801603af 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql @@ -1,189 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `bool_col`, - `bfcol_2` AS `bytes_col`, - `bfcol_3` AS `date_col`, - `bfcol_4` AS `datetime_col`, - `bfcol_5` AS `geography_col`, - `bfcol_6` AS `int64_col`, - `bfcol_7` AS `int64_too`, - `bfcol_8` AS `numeric_col`, - `bfcol_9` AS `float64_col`, - `bfcol_10` AS `rowindex_1`, - `bfcol_11` AS `rowindex_2`, - `bfcol_12` AS `string_col`, - `bfcol_13` AS `time_col`, - `bfcol_14` AS `timestamp_col`, - `bfcol_15` AS `duration_col` - FROM UNNEST(ARRAY>[STRUCT( - 0, - TRUE, - CAST(b'Hello, World!' AS BYTES), - CAST('2021-07-21' AS DATE), - CAST('2021-07-21T11:39:45' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-122.0838511 37.3860517)'), - 123456789, - 0, - CAST(1.234567890 AS NUMERIC), - 1.25, - 0, - 0, - 'Hello, World!', - CAST('11:41:43.076160' AS TIME), - CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), - 4, - 0 - ), STRUCT( - 1, - FALSE, - CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), - CAST('1991-02-03' AS DATE), - CAST('1991-01-02T03:45:06' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-71.104 42.315)'), - -987654321, - 1, - CAST(1.234567890 AS NUMERIC), - 2.51, - 1, - 1, - 'こんにちは', - CAST('11:14:34.701606' AS TIME), - CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), - -1000000, - 1 - ), STRUCT( - 2, - TRUE, - CAST(b'\xc2\xa1Hola Mundo!' AS BYTES), - CAST('2023-03-01' AS DATE), - CAST('2023-03-01T10:55:13' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-0.124474760143016 51.5007826749545)'), - 314159, - 0, - CAST(101.101010100 AS NUMERIC), - 25000000000.0, - 2, - 2, - ' ¡Hola Mundo! ', - CAST('23:59:59.999999' AS TIME), - CAST('2023-03-01T10:55:13.250125+00:00' AS TIMESTAMP), - 0, - 2 - ), STRUCT( - 3, - CAST(NULL AS BOOLEAN), - CAST(NULL AS BYTES), - CAST(NULL AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - CAST(NULL AS INT64), - 1, - CAST(NULL AS NUMERIC), - CAST(NULL AS FLOAT64), - 3, - 3, - CAST(NULL AS STRING), - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - CAST(NULL AS INT64), - 3 - ), STRUCT( - 4, - FALSE, - CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), - CAST('2021-07-21' AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - -234892, - -2345, - CAST(NULL AS NUMERIC), - CAST(NULL AS FLOAT64), - 4, - 4, - 'Hello, World!', - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - 31540000000000, - 4 - ), STRUCT( - 5, - FALSE, - CAST(b'G\xc3\xbcten Tag' AS BYTES), - CAST('1980-03-14' AS DATE), - CAST('1980-03-14T15:16:17' AS DATETIME), - CAST(NULL AS GEOGRAPHY), - 55555, - 0, - CAST(5.555555000 AS NUMERIC), - 555.555, - 5, - 5, - 'Güten Tag!', - CAST('15:16:17.181921' AS TIME), - CAST('1980-03-14T15:16:17.181921+00:00' AS TIMESTAMP), - 4, - 5 - ), STRUCT( - 6, - TRUE, - CAST(b'Hello\tBigFrames!\x07' AS BYTES), - CAST('2023-05-23' AS DATE), - CAST('2023-05-23T11:37:01' AS DATETIME), - ST_GEOGFROMTEXT('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), - 101202303, - 2, - CAST(-10.090807000 AS NUMERIC), - -123.456, - 6, - 6, - 'capitalize, This ', - CAST('01:02:03.456789' AS TIME), - CAST('2023-05-23T11:42:55.000001+00:00' AS TIMESTAMP), - CAST(NULL AS INT64), - 6 - ), STRUCT( - 7, - TRUE, - CAST(NULL AS BYTES), - CAST('2038-01-20' AS DATE), - CAST('2038-01-19T03:14:08' AS DATETIME), - CAST(NULL AS GEOGRAPHY), - -214748367, - 2, - CAST(11111111.100000000 AS NUMERIC), - 42.42, - 7, - 7, - ' سلام', - CAST('12:00:00.000001' AS TIME), - CAST('2038-01-19T03:14:17.999999+00:00' AS TIMESTAMP), - 4, - 7 - ), STRUCT( - 8, - FALSE, - CAST(NULL AS BYTES), - CAST(NULL AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - 2, - 1, - CAST(NULL AS NUMERIC), - 6.87, - 8, - 8, - 'T', - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - 432000000000, - 8 - )]) - ) - ORDER BY - `bfcol_16` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `rowindex`, `bfcol_1` AS `bool_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql index 8ef1b34a183..f86f3e8c4bb 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql @@ -1,13 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `json_col` - FROM UNNEST(ARRAY>[STRUCT(0, PARSE_JSON('null'), 0), STRUCT(1, PARSE_JSON('true'), 1), STRUCT(2, PARSE_JSON('100'), 2), STRUCT(3, PARSE_JSON('0.98'), 3), STRUCT(4, PARSE_JSON('"a string"'), 4), STRUCT(5, PARSE_JSON('[]'), 5), STRUCT(6, PARSE_JSON('[1,2,3]'), 6), STRUCT(7, PARSE_JSON('[{"a":1},{"a":2},{"a":null},{}]'), 7), STRUCT(8, PARSE_JSON('"100"'), 8), STRUCT(9, PARSE_JSON('{"date":"2024-07-16"}'), 9), STRUCT(10, PARSE_JSON('{"int_value":2,"null_filed":null}'), 10), STRUCT(11, PARSE_JSON('{"list_data":[10,20,30]}'), 11)]) - ) - ORDER BY - `bfcol_2` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `rowindex`, `bfcol_1` AS `json_col` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql index b2e92918e44..85eacb8df67 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql @@ -1,49 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `int_list_col`, - `bfcol_2` AS `bool_list_col`, - `bfcol_3` AS `float_list_col`, - `bfcol_4` AS `date_list_col`, - `bfcol_5` AS `date_time_list_col`, - `bfcol_6` AS `numeric_list_col`, - `bfcol_7` AS `string_list_col` - FROM UNNEST(ARRAY, `bfcol_2` ARRAY, `bfcol_3` ARRAY, `bfcol_4` ARRAY, `bfcol_5` ARRAY, `bfcol_6` ARRAY, `bfcol_7` ARRAY, `bfcol_8` INT64>>[STRUCT( - 0, - [1], - [TRUE], - [1.2, 2.3], - ['2021-07-21'], - ['2021-07-21 11:39:45'], - [1.2, 2.3, 3.4], - ['abc', 'de', 'f'], - 0 - ), STRUCT( - 1, - [1, 2], - [TRUE, FALSE], - [1.1], - ['2021-07-21', '1987-03-28'], - ['1999-03-14 17:22:00'], - [5.5, 2.3], - ['a', 'bc', 'de'], - 1 - ), STRUCT( - 2, - [1, 2, 3], - [TRUE], - [0.5, -1.9, 2.3], - ['2017-08-01', '2004-11-22'], - ['1979-06-03 03:20:45'], - [1.7000000000000002], - ['', 'a'], - 2 - )]) - ) - ORDER BY - `bfcol_8` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `rowindex`, `bfcol_1` AS `int_list_col`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql index 7acfe7b4534..d56046177fb 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql @@ -1,27 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `col_none`, - `bfcol_1` AS `col_inf`, - `bfcol_2` AS `col_neginf`, - `bfcol_3` AS `col_nan`, - `bfcol_4` AS `col_struct_none`, - `bfcol_5` AS `col_struct_w_none`, - `bfcol_6` AS `col_list_none` - FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( - CAST(NULL AS FLOAT64), - CAST('Infinity' AS FLOAT64), - CAST('-Infinity' AS FLOAT64), - CAST(NULL AS FLOAT64), - CAST(NULL AS STRUCT), - STRUCT(CAST(NULL AS INT64) AS `foo`), - ARRAY[], - 0 - ), STRUCT(1.0, 1.0, 1.0, 1.0, STRUCT(1 AS `foo`), STRUCT(1 AS `foo`), [1, 2], 1), STRUCT(2.0, 2.0, 2.0, 2.0, STRUCT(2 AS `foo`), STRUCT(2 AS `foo`), [3, 4], 2)]) - ) - ORDER BY - `bfcol_7` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `col_none`, `bfcol_1` AS `col_inf`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql index 10b3d9d7de8..4e4a1225044 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql @@ -1,29 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `id`, - `bfcol_1` AS `person` - FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( - 1, - STRUCT( - 'Alice' AS `name`, - 30 AS `age`, - STRUCT('New York' AS `city`, 'USA' AS `country`) AS `address` - ), - 0 - ), STRUCT( - 2, - STRUCT( - 'Bob' AS `name`, - 25 AS `age`, - STRUCT('London' AS `city`, 'UK' AS `country`) AS `address` - ), - 1 - )]) - ) - ORDER BY - `bfcol_2` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `id`, `bfcol_1` AS `person` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql index b620bf0aa5b..558b20e71ca 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql @@ -1,12 +1,4 @@ -SELECT - ( - SELECT - * - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - `rowindex` > 0 AND `string_col` IN ('Hello, World!') - ).* -FROM ( +( SELECT * FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql index 5337f13e755..d372c230790 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql @@ -1,33 +1,4 @@ -SELECT - ( - SELECT - `bfcol_0` AS `ts_col`, - CASE - WHEN COALESCE( - SUM(CAST(( - `bfcol_1` - ) IS NOT NULL AS INT64)) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW - ), - 0 - ) < 1 - THEN NULL - WHEN TRUE - THEN COALESCE( - SUM(`bfcol_1`) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW - ), - 0 - ) - END AS `int_col` - FROM UNNEST(ARRAY>[STRUCT(CAST('2025-01-01T00:00:00+00:00' AS TIMESTAMP), 0, 0), STRUCT(CAST('2025-01-01T00:00:01+00:00' AS TIMESTAMP), 1, 1), STRUCT(CAST('2025-01-01T00:00:02+00:00' AS TIMESTAMP), 2, 2), STRUCT(CAST('2025-01-01T00:00:03+00:00' AS TIMESTAMP), 3, 3), STRUCT(CAST('2025-01-01T00:00:04+00:00' AS TIMESTAMP), 0, 4), STRUCT(CAST('2025-01-01T00:00:05+00:00' AS TIMESTAMP), 1, 5), STRUCT(CAST('2025-01-01T00:00:06+00:00' AS TIMESTAMP), 2, 6), STRUCT(CAST('2025-01-01T00:00:07+00:00' AS TIMESTAMP), 3, 7), STRUCT(CAST('2025-01-01T00:00:08+00:00' AS TIMESTAMP), 0, 8), STRUCT(CAST('2025-01-01T00:00:09+00:00' AS TIMESTAMP), 1, 9), STRUCT(CAST('2025-01-01T00:00:10+00:00' AS TIMESTAMP), 2, 10), STRUCT(CAST('2025-01-01T00:00:11+00:00' AS TIMESTAMP), 3, 11), STRUCT(CAST('2025-01-01T00:00:12+00:00' AS TIMESTAMP), 0, 12), STRUCT(CAST('2025-01-01T00:00:13+00:00' AS TIMESTAMP), 1, 13), STRUCT(CAST('2025-01-01T00:00:14+00:00' AS TIMESTAMP), 2, 14), STRUCT(CAST('2025-01-01T00:00:15+00:00' AS TIMESTAMP), 3, 15), STRUCT(CAST('2025-01-01T00:00:16+00:00' AS TIMESTAMP), 0, 16), STRUCT(CAST('2025-01-01T00:00:17+00:00' AS TIMESTAMP), 1, 17), STRUCT(CAST('2025-01-01T00:00:18+00:00' AS TIMESTAMP), 2, 18), STRUCT(CAST('2025-01-01T00:00:19+00:00' AS TIMESTAMP), 3, 19)]) - ) - ORDER BY - `bfcol_0` ASC NULLS LAST, - `bfcol_2` ASC NULLS LAST.* -FROM ( +( SELECT `bfcol_0` AS `ts_col`, CASE From ce9fbb9b1f465679eabbf51cf82bcf1c1e6376b7 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 01:48:52 +0000 Subject: [PATCH 08/15] amend selection compilation --- bigframes/core/compile/sqlglot/sqlglot_ir.py | 5 +- .../test_binary_compiler/test_corr/out.sql | 6 +- .../test_binary_compiler/test_cov/out.sql | 6 +- .../test_nullary_compiler/test_size/out.sql | 6 +- .../test_array_agg/out.sql | 6 +- .../test_string_agg/out.sql | 12 +- .../test_unary_compiler/test_all/out.sql | 9 +- .../test_unary_compiler/test_any/out.sql | 9 +- .../test_any_value/out.sql | 6 +- .../test_approx_quartiles/out.sql | 12 +- .../test_approx_top_count/out.sql | 6 +- .../test_unary_compiler/test_count/out.sql | 6 +- .../test_unary_compiler/test_max/out.sql | 6 +- .../test_unary_compiler/test_mean/out.sql | 15 +- .../test_unary_compiler/test_median/out.sql | 12 +- .../test_unary_compiler/test_min/out.sql | 6 +- .../test_unary_compiler/test_nunique/out.sql | 6 +- .../test_unary_compiler/test_pop_var/out.sql | 9 +- .../test_unary_compiler/test_product/out.sql | 10 +- .../test_unary_compiler/test_quantile/out.sql | 12 +- .../test_unary_compiler/test_std/out.sql | 15 +- .../test_unary_compiler/test_sum/out.sql | 9 +- .../test_unary_compiler/test_var/out.sql | 9 +- .../test_compile_aggregate/out.sql | 9 +- .../test_compile_aggregate_wo_dropna/out.sql | 9 +- .../test_compile_concat/out.sql | 47 +---- .../test_compile_concat_filter_sorted/out.sql | 53 +---- .../test_compile_explode_dataframe/out.sql | 13 +- .../test_compile_explode_series/out.sql | 9 +- .../test_compile_fromrange/out.sql | 187 +++++------------- .../test_st_regionstats/out.sql | 88 +++++---- .../out.sql | 16 +- .../test_compile_geo/test_st_simplify/out.sql | 6 +- .../test_compile_isin/out.sql | 47 ++++- .../test_compile_isin_not_nullable/out.sql | 31 ++- .../test_compile_join/out.sql | 8 +- .../test_compile_join_w_on/bool_col/out.sql | 27 +-- .../float64_col/out.sql | 27 +-- .../test_compile_join_w_on/int64_col/out.sql | 27 +-- .../numeric_col/out.sql | 27 +-- .../test_compile_join_w_on/string_col/out.sql | 22 +-- .../test_compile_join_w_on/time_col/out.sql | 22 +-- .../test_compile_random_sample/out.sql | 34 ++-- .../test_compile_readlocal/out.sql | 36 ++-- .../test_compile_readlocal_w_json_df/out.sql | 8 +- .../test_compile_readlocal_w_lists_df/out.sql | 20 +- .../out.sql | 18 +- .../out.sql | 8 +- .../out.sql | 4 +- .../out.sql | 46 ++--- 50 files changed, 477 insertions(+), 570 deletions(-) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index 7fff6760077..a1808d618c6 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -166,10 +166,7 @@ def select( limit: typing.Optional[int] = None, ) -> SQLGlotIR: # TODO: Explicitly insert CTEs into plan - if isinstance(self.expr, sge.Select): - new_expr = self._as_from_item() - else: - new_expr = sge.Select().from_(self.expr) + new_expr = sge.Select().from_(self._as_from_item()) if len(sorting) > 0: new_expr = new_expr.order_by(*sorting) diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql index ca82c1dccf9..96560c464a2 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_2` AS `corr_col` +FROM ( SELECT - `bfcol_2` AS `corr_col` + CORR(`int64_col`, `float64_col`) AS `bfcol_2` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql index 9bc9cd33a67..6708dbec801 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_2` AS `cov_col` +FROM ( SELECT - `bfcol_2` AS `cov_col` + COVAR_SAMP(`int64_col`, `float64_col`) AS `bfcol_2` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql index 0e1026cecea..05206c1bd71 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_32` AS `size` +FROM ( SELECT - `bfcol_32` AS `size` + COUNT(1) AS `bfcol_32` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql index a5c55d0feac..e03ad7c732d 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql index e04bd89eba5..7f075191f7d 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql @@ -1,5 +1,13 @@ -( +SELECT + `bfcol_1` AS `string_col` +FROM ( SELECT - `bfcol_1` AS `string_col` + COALESCE( + STRING_AGG(`string_col`, ',' + ORDER BY + `string_col` IS NULL ASC, + `string_col` ASC), + '' + ) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql index 336f82f64ac..bc4846bb44c 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql @@ -1,6 +1,9 @@ -( +SELECT + `bfcol_2` AS `bool_col`, + `bfcol_3` AS `int64_col` +FROM ( SELECT - `bfcol_2` AS `bool_col`, - `bfcol_3` AS `int64_col` + COALESCE(LOGICAL_AND(`bool_col`), TRUE) AS `bfcol_2`, + COALESCE(LOGICAL_AND(`int64_col` <> 0), TRUE) AS `bfcol_3` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql index 336f82f64ac..cb8e16e0070 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql @@ -1,6 +1,9 @@ -( +SELECT + `bfcol_2` AS `bool_col`, + `bfcol_3` AS `int64_col` +FROM ( SELECT - `bfcol_2` AS `bool_col`, - `bfcol_3` AS `int64_col` + COALESCE(LOGICAL_OR(`bool_col`), FALSE) AS `bfcol_2`, + COALESCE(LOGICAL_OR(`int64_col` <> 0), FALSE) AS `bfcol_3` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql index a5c55d0feac..1cae1a0b218 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + ANY_VALUE(`int64_col`) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql index 5bb2459cdbd..a69f8827707 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql @@ -1,7 +1,11 @@ -( +SELECT + `bfcol_1` AS `q1`, + `bfcol_2` AS `q2`, + `bfcol_3` AS `q3` +FROM ( SELECT - `bfcol_1` AS `q1`, - `bfcol_2` AS `q2`, - `bfcol_3` AS `q3` + APPROX_QUANTILES(`int64_col`, 4)[OFFSET(1)] AS `bfcol_1`, + APPROX_QUANTILES(`int64_col`, 4)[OFFSET(2)] AS `bfcol_2`, + APPROX_QUANTILES(`int64_col`, 4)[OFFSET(3)] AS `bfcol_3` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql index a5c55d0feac..bb5d143414e 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + APPROX_TOP_COUNT(`int64_col`, 10) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql index a5c55d0feac..698b2d407da 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + COUNT(`int64_col`) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql index a5c55d0feac..0a5a4a407cb 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + MAX(`int64_col`) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql index 2542c5ff217..48f2d72ef8c 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql @@ -1,8 +1,13 @@ -( +SELECT + `bfcol_12` AS `int64_col`, + `bfcol_13` AS `bool_col`, + `bfcol_14` AS `duration_col`, + `bfcol_15` AS `int64_col_w_floor` +FROM ( SELECT - `bfcol_12` AS `int64_col`, - `bfcol_13` AS `bool_col`, - `bfcol_14` AS `duration_col`, - `bfcol_15` AS `int64_col_w_floor` + AVG(`bfcol_6`) AS `bfcol_12`, + AVG(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`, + CAST(FLOOR(AVG(`bfcol_8`)) AS INT64) AS `bfcol_14`, + CAST(FLOOR(AVG(`bfcol_6`)) AS INT64) AS `bfcol_15` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql index c7c7580be34..b9cc5e338aa 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql @@ -1,7 +1,11 @@ -( +SELECT + `bfcol_3` AS `int64_col`, + `bfcol_4` AS `date_col`, + `bfcol_5` AS `string_col` +FROM ( SELECT - `bfcol_3` AS `int64_col`, - `bfcol_4` AS `date_col`, - `bfcol_5` AS `string_col` + APPROX_QUANTILES(`int64_col`, 2)[OFFSET(1)] AS `bfcol_3`, + APPROX_QUANTILES(`date_col`, 2)[OFFSET(1)] AS `bfcol_4`, + APPROX_QUANTILES(`string_col`, 2)[OFFSET(1)] AS `bfcol_5` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql index a5c55d0feac..c21c9c8b830 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + MIN(`int64_col`) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql index a5c55d0feac..559c53747ba 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql @@ -1,5 +1,7 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + COUNT(DISTINCT `int64_col`) AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql index 2e3b6c3f4b5..cad5f6f88ac 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql @@ -1,6 +1,9 @@ -( +SELECT + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` +FROM ( SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` + VAR_POP(`int64_col`) AS `bfcol_4`, + VAR_POP(CAST(`bool_col` AS INT64)) AS `bfcol_5` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql index a5c55d0feac..23422e814ab 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql @@ -1,5 +1,11 @@ -( +SELECT + `bfcol_1` AS `int64_col` +FROM ( SELECT - `bfcol_1` AS `int64_col` + CASE + WHEN LOGICAL_OR(`int64_col` = 0) + THEN 0 + ELSE POWER(2, SUM(IF(`int64_col` = 0, 0, LOG(ABS(`int64_col`), 2)))) * POWER(-1, MOD(SUM(CASE WHEN SIGN(`int64_col`) = -1 THEN 1 ELSE 0 END), 2)) + END AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql index aaf56156c33..03a8dc65717 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql @@ -1,7 +1,11 @@ -( +SELECT + `bfcol_4` AS `int64`, + `bfcol_5` AS `bool`, + `bfcol_6` AS `int64_w_floor` +FROM ( SELECT - `bfcol_4` AS `int64`, - `bfcol_5` AS `bool`, - `bfcol_6` AS `int64_w_floor` + PERCENTILE_CONT(`int64_col`, 0.5) OVER () AS `bfcol_4`, + PERCENTILE_CONT(CAST(`bool_col` AS INT64), 0.5) OVER () AS `bfcol_5`, + CAST(FLOOR(PERCENTILE_CONT(`int64_col`, 0.5) OVER ()) AS INT64) AS `bfcol_6` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql index 2542c5ff217..8e01e27de62 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql @@ -1,8 +1,13 @@ -( +SELECT + `bfcol_12` AS `int64_col`, + `bfcol_13` AS `bool_col`, + `bfcol_14` AS `duration_col`, + `bfcol_15` AS `int64_col_w_floor` +FROM ( SELECT - `bfcol_12` AS `int64_col`, - `bfcol_13` AS `bool_col`, - `bfcol_14` AS `duration_col`, - `bfcol_15` AS `int64_col_w_floor` + STDDEV(`bfcol_6`) AS `bfcol_12`, + STDDEV(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`, + CAST(FLOOR(STDDEV(`bfcol_8`)) AS INT64) AS `bfcol_14`, + CAST(FLOOR(STDDEV(`bfcol_6`)) AS INT64) AS `bfcol_15` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql index 2e3b6c3f4b5..49d018c5d32 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql @@ -1,6 +1,9 @@ -( +SELECT + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` +FROM ( SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` + COALESCE(SUM(`int64_col`), 0) AS `bfcol_4`, + COALESCE(SUM(CAST(`bool_col` AS INT64)), 0) AS `bfcol_5` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql index 2e3b6c3f4b5..39979fa8fee 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql @@ -1,6 +1,9 @@ -( +SELECT + `bfcol_4` AS `int64_col`, + `bfcol_5` AS `bool_col` +FROM ( SELECT - `bfcol_4` AS `int64_col`, - `bfcol_5` AS `bool_col` + VARIANCE(`int64_col`) AS `bfcol_4`, + VARIANCE(CAST(`bool_col` AS INT64)) AS `bfcol_5` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql index 47bd40594bc..7facf57d09d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql @@ -1,7 +1,10 @@ -( +SELECT + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `int64_too` +FROM ( SELECT - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `int64_too` + `bfcol_3`, + COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` WHERE NOT `bfcol_3` IS NULL diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql index d4d836354c1..6721247e3e5 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql @@ -1,7 +1,10 @@ -( +SELECT + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `int64_too` +FROM ( SELECT - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `int64_too` + `bfcol_3`, + COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` GROUP BY `bfcol_3` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql index 162b93d8254..2f81190a925 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql @@ -18,45 +18,18 @@ WITH `bfcte_0` AS ( FROM `bfcte_0` ) SELECT - ( - SELECT - `bfcol_30` AS `rowindex`, - `bfcol_31` AS `rowindex_1`, - `bfcol_32` AS `int64_col`, - `bfcol_33` AS `string_col` - FROM ( - ( - SELECT - `bfcol_3` AS `bfcol_9`, - `bfcol_4` AS `bfcol_10`, - `bfcol_5` AS `bfcol_11`, - `bfcol_6` AS `bfcol_12`, - 0 AS `bfcol_13`, - ROW_NUMBER() OVER () - 1 AS `bfcol_14` - FROM `bfcte_1` - ) - UNION ALL - ( - SELECT - `bfcol_18` AS `bfcol_24`, - `bfcol_19` AS `bfcol_25`, - `bfcol_20` AS `bfcol_26`, - `bfcol_21` AS `bfcol_27`, - 1 AS `bfcol_28`, - ROW_NUMBER() OVER () - 1 AS `bfcol_29` - FROM `bfcte_2` - ) - ) - ) - ORDER BY - `bfcol_34` ASC NULLS LAST, - `bfcol_35` ASC NULLS LAST.* + `bfcol_30` AS `rowindex`, + `bfcol_31` AS `rowindex_1`, + `bfcol_32` AS `int64_col`, + `bfcol_33` AS `string_col` FROM ( SELECT - `bfcol_30` AS `rowindex`, - `bfcol_31` AS `rowindex_1`, - `bfcol_32` AS `int64_col`, - `bfcol_33` AS `string_col` + `bfcol_9` AS `bfcol_30`, + `bfcol_10` AS `bfcol_31`, + `bfcol_11` AS `bfcol_32`, + `bfcol_12` AS `bfcol_33`, + `bfcol_13` AS `bfcol_34`, + `bfcol_14` AS `bfcol_35` FROM ( ( SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql index 2e87ca242da..eb9ce237415 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql @@ -32,55 +32,14 @@ WITH `bfcte_0` AS ( FROM `bfcte_2` ) SELECT - ( - SELECT - `bfcol_42` AS `float64_col`, - `bfcol_43` AS `int64_col` - FROM ( - ( - SELECT - `bfcol_2` AS `bfcol_6`, - `bfcol_3` AS `bfcol_7`, - 0 AS `bfcol_8`, - ROW_NUMBER() OVER (ORDER BY `bfcol_3` ASC NULLS LAST) - 1 AS `bfcol_9` - FROM `bfcte_1` - ) - UNION ALL - ( - SELECT - `bfcol_13` AS `bfcol_17`, - `bfcol_14` AS `bfcol_18`, - 1 AS `bfcol_19`, - ROW_NUMBER() OVER () - 1 AS `bfcol_20` - FROM `bfcte_3` - ) - UNION ALL - ( - SELECT - `bfcol_23` AS `bfcol_27`, - `bfcol_24` AS `bfcol_28`, - 2 AS `bfcol_29`, - ROW_NUMBER() OVER (ORDER BY `bfcol_24` ASC NULLS LAST) - 1 AS `bfcol_30` - FROM `bfcte_4` - ) - UNION ALL - ( - SELECT - `bfcol_34` AS `bfcol_38`, - `bfcol_35` AS `bfcol_39`, - 3 AS `bfcol_40`, - ROW_NUMBER() OVER () - 1 AS `bfcol_41` - FROM `bfcte_5` - ) - ) - ) - ORDER BY - `bfcol_44` ASC NULLS LAST, - `bfcol_45` ASC NULLS LAST.* + `bfcol_42` AS `float64_col`, + `bfcol_43` AS `int64_col` FROM ( SELECT - `bfcol_42` AS `float64_col`, - `bfcol_43` AS `int64_col` + `bfcol_6` AS `bfcol_42`, + `bfcol_7` AS `bfcol_43`, + `bfcol_8` AS `bfcol_44`, + `bfcol_9` AS `bfcol_45` FROM ( ( SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql index 9ca4d846b64..1ffebc9cd51 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql @@ -1,9 +1,12 @@ -( +SELECT + `rowindex`, + `rowindex` AS `rowindex_1`, + `int_list_col`, + `string_list_col` +FROM ( SELECT - `rowindex`, - `rowindex` AS `rowindex_1`, - `int_list_col`, - `string_list_col` + * + REPLACE (`int_list_col`[SAFE_OFFSET(`bfcol_13`)] AS `int_list_col`, `string_list_col`[SAFE_OFFSET(`bfcol_13`)] AS `string_list_col`) FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` LEFT JOIN UNNEST(GENERATE_ARRAY(0, LEAST(ARRAY_LENGTH(`int_list_col`) - 1, ARRAY_LENGTH(`string_list_col`) - 1))) AS `bfcol_13` WITH OFFSET AS `bfcol_7` ) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql index 6ab5539c530..57dfdb14355 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql @@ -1,7 +1,10 @@ -( +SELECT + `rowindex`, + `int_list_col` +FROM ( SELECT - `rowindex`, - `int_list_col` + * + REPLACE (`bfcol_8` AS `int_list_col`) FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` LEFT JOIN UNNEST(`int_list_col`) AS `bfcol_8` WITH OFFSET AS `bfcol_4` ) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index cdc9d4779ed..ea546d9ceaf 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -1,49 +1,33 @@ WITH `bfcte_0` AS ( SELECT - ( - SELECT - `bfcol_8` AS `bfcol_9` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ).* + `bfcol_8` AS `bfcol_9` FROM ( SELECT - `bfcol_8` AS `bfcol_9` + * FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ) ), `bfcte_1` AS ( SELECT - ( - SELECT - `bfcol_0` AS `bfcol_1` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ).* + `bfcol_0` AS `bfcol_1` FROM ( SELECT - `bfcol_0` AS `bfcol_1` + * FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ) ), `bfcte_2` AS ( SELECT - ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ).* + * FROM ( SELECT - * + MIN(`bfcol_51`) AS `bfcol_53` FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ) ), `bfcte_3` AS ( SELECT - ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ).* + * FROM ( SELECT - * + MIN(`bfcol_42`) AS `bfcol_44` FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ) ), `bfcte_4` AS ( @@ -52,14 +36,10 @@ WITH `bfcte_0` AS ( FROM `bfcte_0` ), `bfcte_5` AS ( SELECT - ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ).* + * FROM ( SELECT - * + MIN(`bfcol_2`) AS `bfcol_4` FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ) ), `bfcte_6` AS ( @@ -68,91 +48,14 @@ WITH `bfcte_0` AS ( FROM `bfcte_2` ) SELECT - ( - SELECT - CAST(TIMESTAMP_MICROS( - CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) - ) AS DATETIME) AS `bigframes_unnamed_index`, - `bfcol_55` AS `int64_col`, - `bfcol_56` AS `int64_too` - FROM ( - SELECT - * - FROM ( - SELECT - `bfcol_67` AS `bfcol_41` - FROM ( - SELECT - * - FROM ( - SELECT - `bfcol_1`, - `bfcol_4`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_1` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_4` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_5` - FROM `bfcte_1` - CROSS JOIN `bfcte_5` - ) - ) - CROSS JOIN ( - SELECT - * - FROM ( - SELECT - `bfcol_9`, - `bfcol_37`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_9` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_37` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_38` - FROM `bfcte_4` - CROSS JOIN ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) - ) - ) - ) - CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_7`, `bfcol_40`, 1)) AS `bfcol_67` - ) - CROSS JOIN `bfcte_3` - ) - LEFT JOIN ( - SELECT - `bfcol_49` AS `bfcol_55`, - `bfcol_50` AS `bfcol_56`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_48` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_53` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_57` - FROM ( - SELECT - `bfcol_45` AS `bfcol_48`, - `bfcol_46` AS `bfcol_49`, - `bfcol_47` AS `bfcol_50` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) - ) - CROSS JOIN `bfcte_6` - ) - ON `bfcol_41` = `bfcol_57` - ) - ORDER BY - `bfcol_41` ASC NULLS LAST.* + CAST(TIMESTAMP_MICROS( + CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) + ) AS DATETIME) AS `bigframes_unnamed_index`, + `bfcol_55` AS `int64_col`, + `bfcol_56` AS `int64_too` FROM ( SELECT - CAST(TIMESTAMP_MICROS( - CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) - ) AS DATETIME) AS `bigframes_unnamed_index`, - `bfcol_55` AS `int64_col`, - `bfcol_56` AS `int64_too` + * FROM ( SELECT * @@ -164,16 +67,13 @@ FROM ( * FROM ( SELECT - `bfcol_1`, - `bfcol_4`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_1` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_4` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_5` - FROM `bfcte_1` - CROSS JOIN `bfcte_5` + MIN(`bfcol_5`) AS `bfcol_7` + FROM ( + SELECT + * + FROM `bfcte_1` + CROSS JOIN `bfcte_5` + ) ) ) CROSS JOIN ( @@ -181,19 +81,20 @@ FROM ( * FROM ( SELECT - `bfcol_9`, - `bfcol_37`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_9` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_37` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_38` - FROM `bfcte_4` - CROSS JOIN ( + MAX(`bfcol_38`) AS `bfcol_40` + FROM ( SELECT * - FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + FROM `bfcte_4` + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + MIN(`bfcol_11`) AS `bfcol_37` + FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + ) + ) ) ) ) @@ -213,12 +114,20 @@ FROM ( ) AS INT64) AS `bfcol_57` FROM ( SELECT - `bfcol_45` AS `bfcol_48`, - `bfcol_46` AS `bfcol_49`, - `bfcol_47` AS `bfcol_50` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + * + FROM ( + SELECT + `bfcol_45` AS `bfcol_48`, + `bfcol_46` AS `bfcol_49`, + `bfcol_47` AS `bfcol_50` + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + ) + ) + CROSS JOIN `bfcte_6` ) - CROSS JOIN `bfcte_6` ) ON `bfcol_41` = `bfcol_57` ) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql index 2f67f9ccf9d..dc2a8fdcb36 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql @@ -1,47 +1,49 @@ -( +SELECT + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`min`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`max`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`sum`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`count`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`mean`, + ST_REGIONSTATS( + `bfcol_0`, + 'ee://some/raster/uri', + band => 'band1', + include => 'some equation', + options => JSON '{"scale": 100}' + ).`area` +FROM ( SELECT - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`min`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`max`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`sum`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`count`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`mean`, - ST_REGIONSTATS( - `bfcol_0`, - 'ee://some/raster/uri', - band => 'band1', - include => 'some equation', - options => JSON '{"scale": 100}' - ).`area` + * FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ) ORDER BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql index d373bcb923d..1210c7d217b 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql @@ -1,11 +1,13 @@ -( +SELECT + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`sum`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, + ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` +FROM ( SELECT - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`min`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`max`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`sum`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, - ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` + * FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ) ORDER BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql index 4bbbfc5d9be..2512293b9fa 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql @@ -1,6 +1,8 @@ -( +SELECT + ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` +FROM ( SELECT - ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` + * FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ) ORDER BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index c19e7f3af59..07dc81f1498 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -1,7 +1,48 @@ -( +SELECT + `bfcol_2` AS `rowindex`, + `bfcol_5` AS `int64_col` +FROM ( SELECT - `bfcol_2` AS `rowindex`, - `bfcol_5` AS `int64_col` + ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).*, + EXISTS( + SELECT + 1 + FROM ( + SELECT + `int64_too` AS `bfcol_4` + FROM ( + SELECT + `int64_too` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + GROUP BY + `int64_too` + ) + ) AS `bft_1` + WHERE + COALESCE( + ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).`bfcol_3`, + 0 + ) = COALESCE(`bft_1`.`bfcol_4`, 0) + AND COALESCE( + ( + SELECT + `rowindex` AS `bfcol_2`, + `int64_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).`bfcol_3`, + 1 + ) = COALESCE(`bft_1`.`bfcol_4`, 1) + ) AS `bfcol_5` FROM ( SELECT `rowindex` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 58e786b2b6f..5308e1570f0 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -1,7 +1,32 @@ -( +SELECT + `bfcol_2` AS `rowindex`, + `bfcol_5` AS `rowindex_2` +FROM ( SELECT - `bfcol_2` AS `rowindex`, - `bfcol_5` AS `rowindex_2` + ( + SELECT + `rowindex` AS `bfcol_2`, + `rowindex_2` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).*, + ( + SELECT + `rowindex` AS `bfcol_2`, + `rowindex_2` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ).`bfcol_3` IN ( + ( + SELECT + `rowindex_2` AS `bfcol_4` + FROM ( + SELECT + `rowindex_2` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + GROUP BY + `rowindex_2` + ) + ) + ) AS `bfcol_5` FROM ( SELECT `rowindex` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql index fe5ed33b1c3..29bcbf8b793 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql @@ -1,7 +1,9 @@ -( +SELECT + `bfcol_3` AS `int64_col`, + `bfcol_7` AS `int64_too` +FROM ( SELECT - `bfcol_3` AS `int64_col`, - `bfcol_7` AS `int64_too` + * FROM ( SELECT `rowindex` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql index 430e4eeb6d5..106113cff84 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql @@ -14,31 +14,12 @@ WITH `bfcte_0` AS ( FROM `bfcte_0` ) SELECT - ( - SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `rowindex_y` - FROM ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` - ) - INNER JOIN ( - SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` - ) - ON COALESCE(CAST(`bfcol_3` AS STRING), '0') = COALESCE(CAST(`bfcol_7` AS STRING), '0') - AND COALESCE(CAST(`bfcol_3` AS STRING), '1') = COALESCE(CAST(`bfcol_7` AS STRING), '1') - ).* + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `bool_col`, + `bfcol_6` AS `rowindex_y` FROM ( SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `rowindex_y` + * FROM ( SELECT `bfcol_1` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql index 13471efdc2f..5258844ef88 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql @@ -14,31 +14,12 @@ WITH `bfcte_0` AS ( FROM `bfcte_0` ) SELECT - ( - SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `float64_col`, - `bfcol_6` AS `rowindex_y` - FROM ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` - ) - INNER JOIN ( - SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` - ) - ON IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) = IF(IS_NAN(`bfcol_7`), 2, COALESCE(`bfcol_7`, 0)) - AND IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) = IF(IS_NAN(`bfcol_7`), 3, COALESCE(`bfcol_7`, 1)) - ).* + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `float64_col`, + `bfcol_6` AS `rowindex_y` FROM ( SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `float64_col`, - `bfcol_6` AS `rowindex_y` + * FROM ( SELECT `bfcol_1` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql index 6cf4f2a2fd4..72fb492f8c4 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql @@ -14,31 +14,12 @@ WITH `bfcte_0` AS ( FROM `bfcte_0` ) SELECT - ( - SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `int64_col`, - `bfcol_6` AS `rowindex_y` - FROM ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` - ) - INNER JOIN ( - SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` - ) - ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_7`, 0) - AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_7`, 1) - ).* + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `int64_col`, + `bfcol_6` AS `rowindex_y` FROM ( SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `int64_col`, - `bfcol_6` AS `rowindex_y` + * FROM ( SELECT `bfcol_1` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql index 64638f88d6f..59067a57e17 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql @@ -14,31 +14,12 @@ WITH `bfcte_0` AS ( FROM `bfcte_0` ) SELECT - ( - SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `numeric_col`, - `bfcol_6` AS `rowindex_y` - FROM ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` - ) - INNER JOIN ( - SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` - ) - ON COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(0 AS NUMERIC)) - AND COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(1 AS NUMERIC)) - ).* + `bfcol_2` AS `rowindex_x`, + `bfcol_3` AS `numeric_col`, + `bfcol_6` AS `rowindex_y` FROM ( SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `numeric_col`, - `bfcol_6` AS `rowindex_y` + * FROM ( SELECT `bfcol_1` AS `bfcol_2`, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql index 35b498a881a..b4e5e97369c 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql @@ -18,26 +18,12 @@ WITH `bfcte_0` AS ( FROM `bfcte_1` ) SELECT - ( - SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `string_col`, - `bfcol_4` AS `rowindex_y` - FROM `bfcte_3` - INNER JOIN ( - SELECT - `bfcol_2` AS `bfcol_4`, - `bfcol_3` AS `bfcol_5` - FROM `bfcte_2` - ) - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') - ).* + `bfcol_0` AS `rowindex_x`, + `bfcol_1` AS `string_col`, + `bfcol_4` AS `rowindex_y` FROM ( SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `string_col`, - `bfcol_4` AS `rowindex_y` + * FROM `bfcte_3` INNER JOIN ( SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql index ce9dae97553..74ecdcb1537 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql @@ -18,26 +18,12 @@ WITH `bfcte_0` AS ( FROM `bfcte_1` ) SELECT - ( - SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `time_col`, - `bfcol_4` AS `rowindex_y` - FROM `bfcte_3` - INNER JOIN ( - SELECT - `bfcol_2` AS `bfcol_4`, - `bfcol_3` AS `bfcol_5` - FROM `bfcte_2` - ) - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') - ).* + `bfcol_0` AS `rowindex_x`, + `bfcol_1` AS `time_col`, + `bfcol_4` AS `rowindex_y` FROM ( SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `time_col`, - `bfcol_4` AS `rowindex_y` + * FROM `bfcte_3` INNER JOIN ( SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql index 004775fe482..313ba305964 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_random_sample/test_compile_random_sample/out.sql @@ -1,20 +1,22 @@ -( +SELECT + `bfcol_0` AS `bool_col`, + `bfcol_1` AS `bytes_col`, + `bfcol_2` AS `date_col`, + `bfcol_3` AS `datetime_col`, + `bfcol_4` AS `geography_col`, + `bfcol_5` AS `int64_col`, + `bfcol_6` AS `int64_too`, + `bfcol_7` AS `numeric_col`, + `bfcol_8` AS `float64_col`, + `bfcol_9` AS `rowindex`, + `bfcol_10` AS `rowindex_2`, + `bfcol_11` AS `string_col`, + `bfcol_12` AS `time_col`, + `bfcol_13` AS `timestamp_col`, + `bfcol_14` AS `duration_col` +FROM ( SELECT - `bfcol_0` AS `bool_col`, - `bfcol_1` AS `bytes_col`, - `bfcol_2` AS `date_col`, - `bfcol_3` AS `datetime_col`, - `bfcol_4` AS `geography_col`, - `bfcol_5` AS `int64_col`, - `bfcol_6` AS `int64_too`, - `bfcol_7` AS `numeric_col`, - `bfcol_8` AS `float64_col`, - `bfcol_9` AS `rowindex`, - `bfcol_10` AS `rowindex_2`, - `bfcol_11` AS `string_col`, - `bfcol_12` AS `time_col`, - `bfcol_13` AS `timestamp_col`, - `bfcol_14` AS `duration_col` + * FROM UNNEST(ARRAY>[STRUCT( TRUE, CAST(b'Hello, World!' AS BYTES), diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql index 4ed801603af..0ef61502df4 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql @@ -1,21 +1,23 @@ -( +SELECT + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `bool_col`, + `bfcol_2` AS `bytes_col`, + `bfcol_3` AS `date_col`, + `bfcol_4` AS `datetime_col`, + `bfcol_5` AS `geography_col`, + `bfcol_6` AS `int64_col`, + `bfcol_7` AS `int64_too`, + `bfcol_8` AS `numeric_col`, + `bfcol_9` AS `float64_col`, + `bfcol_10` AS `rowindex_1`, + `bfcol_11` AS `rowindex_2`, + `bfcol_12` AS `string_col`, + `bfcol_13` AS `time_col`, + `bfcol_14` AS `timestamp_col`, + `bfcol_15` AS `duration_col` +FROM ( SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `bool_col`, - `bfcol_2` AS `bytes_col`, - `bfcol_3` AS `date_col`, - `bfcol_4` AS `datetime_col`, - `bfcol_5` AS `geography_col`, - `bfcol_6` AS `int64_col`, - `bfcol_7` AS `int64_too`, - `bfcol_8` AS `numeric_col`, - `bfcol_9` AS `float64_col`, - `bfcol_10` AS `rowindex_1`, - `bfcol_11` AS `rowindex_2`, - `bfcol_12` AS `string_col`, - `bfcol_13` AS `time_col`, - `bfcol_14` AS `timestamp_col`, - `bfcol_15` AS `duration_col` + * FROM UNNEST(ARRAY>[STRUCT( 0, TRUE, diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql index f86f3e8c4bb..029546f3d0f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql @@ -1,7 +1,9 @@ -( +SELECT + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `json_col` +FROM ( SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `json_col` + * FROM UNNEST(ARRAY>[STRUCT(0, PARSE_JSON('null'), 0), STRUCT(1, PARSE_JSON('true'), 1), STRUCT(2, PARSE_JSON('100'), 2), STRUCT(3, PARSE_JSON('0.98'), 3), STRUCT(4, PARSE_JSON('"a string"'), 4), STRUCT(5, PARSE_JSON('[]'), 5), STRUCT(6, PARSE_JSON('[1,2,3]'), 6), STRUCT(7, PARSE_JSON('[{"a":1},{"a":2},{"a":null},{}]'), 7), STRUCT(8, PARSE_JSON('"100"'), 8), STRUCT(9, PARSE_JSON('{"date":"2024-07-16"}'), 9), STRUCT(10, PARSE_JSON('{"int_value":2,"null_filed":null}'), 10), STRUCT(11, PARSE_JSON('{"list_data":[10,20,30]}'), 11)]) ) ORDER BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql index 85eacb8df67..161487c07a1 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql @@ -1,13 +1,15 @@ -( +SELECT + `bfcol_0` AS `rowindex`, + `bfcol_1` AS `int_list_col`, + `bfcol_2` AS `bool_list_col`, + `bfcol_3` AS `float_list_col`, + `bfcol_4` AS `date_list_col`, + `bfcol_5` AS `date_time_list_col`, + `bfcol_6` AS `numeric_list_col`, + `bfcol_7` AS `string_list_col` +FROM ( SELECT - `bfcol_0` AS `rowindex`, - `bfcol_1` AS `int_list_col`, - `bfcol_2` AS `bool_list_col`, - `bfcol_3` AS `float_list_col`, - `bfcol_4` AS `date_list_col`, - `bfcol_5` AS `date_time_list_col`, - `bfcol_6` AS `numeric_list_col`, - `bfcol_7` AS `string_list_col` + * FROM UNNEST(ARRAY, `bfcol_2` ARRAY, `bfcol_3` ARRAY, `bfcol_4` ARRAY, `bfcol_5` ARRAY, `bfcol_6` ARRAY, `bfcol_7` ARRAY, `bfcol_8` INT64>>[STRUCT( 0, [1], diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql index d56046177fb..223046f3a8e 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql @@ -1,12 +1,14 @@ -( +SELECT + `bfcol_0` AS `col_none`, + `bfcol_1` AS `col_inf`, + `bfcol_2` AS `col_neginf`, + `bfcol_3` AS `col_nan`, + `bfcol_4` AS `col_struct_none`, + `bfcol_5` AS `col_struct_w_none`, + `bfcol_6` AS `col_list_none` +FROM ( SELECT - `bfcol_0` AS `col_none`, - `bfcol_1` AS `col_inf`, - `bfcol_2` AS `col_neginf`, - `bfcol_3` AS `col_nan`, - `bfcol_4` AS `col_struct_none`, - `bfcol_5` AS `col_struct_w_none`, - `bfcol_6` AS `col_list_none` + * FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( CAST(NULL AS FLOAT64), CAST('Infinity' AS FLOAT64), diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql index 4e4a1225044..f008ece2ca7 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql @@ -1,7 +1,9 @@ -( +SELECT + `bfcol_0` AS `id`, + `bfcol_1` AS `person` +FROM ( SELECT - `bfcol_0` AS `id`, - `bfcol_1` AS `person` + * FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( 1, STRUCT( diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql index 558b20e71ca..571551ce99f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql @@ -1,4 +1,6 @@ -( +SELECT + * +FROM ( SELECT * FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql index d372c230790..90f18a0a93c 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql @@ -1,26 +1,28 @@ -( +SELECT + `bfcol_0` AS `ts_col`, + CASE + WHEN COALESCE( + SUM(CAST(( + `bfcol_1` + ) IS NOT NULL AS INT64)) OVER ( + ORDER BY UNIX_MICROS(`bfcol_0`) ASC + RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ), + 0 + ) < 1 + THEN NULL + WHEN TRUE + THEN COALESCE( + SUM(`bfcol_1`) OVER ( + ORDER BY UNIX_MICROS(`bfcol_0`) ASC + RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ), + 0 + ) + END AS `int_col` +FROM ( SELECT - `bfcol_0` AS `ts_col`, - CASE - WHEN COALESCE( - SUM(CAST(( - `bfcol_1` - ) IS NOT NULL AS INT64)) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW - ), - 0 - ) < 1 - THEN NULL - WHEN TRUE - THEN COALESCE( - SUM(`bfcol_1`) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW - ), - 0 - ) - END AS `int_col` + * FROM UNNEST(ARRAY>[STRUCT(CAST('2025-01-01T00:00:00+00:00' AS TIMESTAMP), 0, 0), STRUCT(CAST('2025-01-01T00:00:01+00:00' AS TIMESTAMP), 1, 1), STRUCT(CAST('2025-01-01T00:00:02+00:00' AS TIMESTAMP), 2, 2), STRUCT(CAST('2025-01-01T00:00:03+00:00' AS TIMESTAMP), 3, 3), STRUCT(CAST('2025-01-01T00:00:04+00:00' AS TIMESTAMP), 0, 4), STRUCT(CAST('2025-01-01T00:00:05+00:00' AS TIMESTAMP), 1, 5), STRUCT(CAST('2025-01-01T00:00:06+00:00' AS TIMESTAMP), 2, 6), STRUCT(CAST('2025-01-01T00:00:07+00:00' AS TIMESTAMP), 3, 7), STRUCT(CAST('2025-01-01T00:00:08+00:00' AS TIMESTAMP), 0, 8), STRUCT(CAST('2025-01-01T00:00:09+00:00' AS TIMESTAMP), 1, 9), STRUCT(CAST('2025-01-01T00:00:10+00:00' AS TIMESTAMP), 2, 10), STRUCT(CAST('2025-01-01T00:00:11+00:00' AS TIMESTAMP), 3, 11), STRUCT(CAST('2025-01-01T00:00:12+00:00' AS TIMESTAMP), 0, 12), STRUCT(CAST('2025-01-01T00:00:13+00:00' AS TIMESTAMP), 1, 13), STRUCT(CAST('2025-01-01T00:00:14+00:00' AS TIMESTAMP), 2, 14), STRUCT(CAST('2025-01-01T00:00:15+00:00' AS TIMESTAMP), 3, 15), STRUCT(CAST('2025-01-01T00:00:16+00:00' AS TIMESTAMP), 0, 16), STRUCT(CAST('2025-01-01T00:00:17+00:00' AS TIMESTAMP), 1, 17), STRUCT(CAST('2025-01-01T00:00:18+00:00' AS TIMESTAMP), 2, 18), STRUCT(CAST('2025-01-01T00:00:19+00:00' AS TIMESTAMP), 3, 19)]) ) ORDER BY From 74b247076fe6533a9396bf8f9ee44c8f69d119ff Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 02:16:08 +0000 Subject: [PATCH 09/15] fix as_select star logic --- bigframes/core/compile/sqlglot/sqlglot_ir.py | 6 +----- .../test_compile_concat/test_compile_concat/out.sql | 2 +- .../test_compile_concat_filter_sorted/out.sql | 4 ++-- .../test_compile_fromrange/test_compile_fromrange/out.sql | 4 ++-- .../test_compile_join_w_on/bool_col/out.sql | 2 +- .../test_compile_join_w_on/float64_col/out.sql | 2 +- .../test_compile_join_w_on/int64_col/out.sql | 2 +- .../test_compile_join_w_on/numeric_col/out.sql | 2 +- .../test_compile_join_w_on/string_col/out.sql | 4 ++-- .../test_compile_join_w_on/time_col/out.sql | 4 ++-- 10 files changed, 14 insertions(+), 18 deletions(-) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index a1808d618c6..ea237fa208c 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -507,11 +507,7 @@ def _as_select(self) -> sge.Select: if isinstance(self.expr, sge.Select): return self.expr else: # table or cte - return ( - sge.Select() - .select(sge.Column(this=sge.Star(), table=self.expr)) - .from_(self.expr) - ) + return sge.Select().select(sge.Star()).from_(self.expr) def _as_subquery(self) -> sge.Subquery: return self._as_select().subquery() diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql index 2f81190a925..52e13d87f27 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql @@ -14,7 +14,7 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql index eb9ce237415..95edf4184fe 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql @@ -24,11 +24,11 @@ WITH `bfcte_0` AS ( `bool_col` ), `bfcte_4` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ), `bfcte_5` AS ( SELECT - `bfcte_2`.* + * FROM `bfcte_2` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index ea546d9ceaf..553a5bf30ba 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -32,7 +32,7 @@ WITH `bfcte_0` AS ( ) ), `bfcte_4` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ), `bfcte_5` AS ( SELECT @@ -44,7 +44,7 @@ WITH `bfcte_0` AS ( ) ), `bfcte_6` AS ( SELECT - `bfcte_2`.* + * FROM `bfcte_2` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql index 106113cff84..c407c9f0139 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql @@ -10,7 +10,7 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql index 5258844ef88..f4085495bab 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql @@ -10,7 +10,7 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql index 72fb492f8c4..735c43cc98d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql @@ -10,7 +10,7 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql index 59067a57e17..bc3d2778935 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql @@ -10,7 +10,7 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql index b4e5e97369c..a86e8a08aeb 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql @@ -10,11 +10,11 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ), `bfcte_3` AS ( SELECT - `bfcte_1`.* + * FROM `bfcte_1` ) SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql index 74ecdcb1537..8eadbfcd549 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql @@ -10,11 +10,11 @@ WITH `bfcte_0` AS ( FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_2` AS ( SELECT - `bfcte_0`.* + * FROM `bfcte_0` ), `bfcte_3` AS ( SELECT - `bfcte_1`.* + * FROM `bfcte_1` ) SELECT From 069dd0911a0414190b6fac0547db2efe567794c4 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 21:37:25 +0000 Subject: [PATCH 10/15] fix isin join logic --- bigframes/core/compile/sqlglot/sqlglot_ir.py | 151 +++++++----------- .../test_compile_isin/out.sql | 36 +---- .../test_compile_isin_not_nullable/out.sql | 14 +- 3 files changed, 69 insertions(+), 132 deletions(-) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index ea237fa208c..841956d76bb 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -280,32 +280,39 @@ def isin_join( ) -> SQLGlotIR: """Joins the current query with another SQLGlotIR instance.""" left_from = self._as_from_item() - # Prefer subquery over CTE for the IN clause's right side to improve SQL readability. right_select = right._as_select() - left_condition = typed_expr.TypedExpr( - sge.Column(this=conditions[0].expr, table=left_from), - conditions[0].dtype, - ) - new_column: sge.Expression if joins_nulls: - right_table_name = sql.identifier(next(self.uid_gen.get_uid_stream("bft_"))) - right_condition = typed_expr.TypedExpr( - sge.Column(this=conditions[1].expr, table=right_table_name), - conditions[1].dtype, + part1_id = sql.identifier(next(self.uid_gen.get_uid_stream("bfpart1_"))) + part2_id = sql.identifier(next(self.uid_gen.get_uid_stream("bfpart2_"))) + left_expr1, left_expr2 = _value_to_non_null_identity(conditions[0]) + left_as_struct = sge.Struct( + expressions=[ + sge.PropertyEQ(this=part1_id, expression=left_expr1), + sge.PropertyEQ(this=part2_id, expression=left_expr2), + ] ) - new_column = sge.Exists( - this=sge.Select() - .select(sge.convert(1)) - .from_(sge.Alias(this=right_select.subquery(), alias=right_table_name)) - .where( - _join_condition(left_condition, right_condition, joins_nulls=True) - ) + right_expr1, right_expr2 = _value_to_non_null_identity(conditions[1]) + right_select = right_select.select( + *[ + sge.Struct( + expressions=[ + sge.PropertyEQ(this=part1_id, expression=right_expr1), + sge.PropertyEQ(this=part2_id, expression=right_expr2), + ] + ) + ], + append=False, + ) + + new_column = sge.In( + this=left_as_struct, + expressions=[right_select.subquery()], ) else: new_column = sge.In( - this=left_condition.expr, + this=conditions[0].expr, expressions=[right_select.subquery()], ) @@ -314,12 +321,7 @@ def isin_join( alias=sql.identifier(indicator_col), ) - new_expr = ( - sge.Select() - .select(sge.Column(this=sge.Star(), table=left_from), new_column) - .from_(left_from) - ) - + new_expr = sge.Select().select(sge.Star(), new_column).from_(left_from) return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) def explode( @@ -543,77 +545,48 @@ def _join_condition( joins_nulls: If True, generates complex logic to handle nulls/NaNs. Otherwise, uses a simple equality check where appropriate. """ - is_floating_types = ( - left.dtype == dtypes.FLOAT_DTYPE and right.dtype == dtypes.FLOAT_DTYPE - ) - if not is_floating_types and not joins_nulls: + if not joins_nulls: return sge.EQ(this=left.expr, expression=right.expr) - - is_numeric_types = dtypes.is_numeric( - left.dtype, include_bool=False - ) and dtypes.is_numeric(right.dtype, include_bool=False) - if is_numeric_types: - return _join_condition_for_numeric(left, right) - else: - return _join_condition_for_others(left, right) - - -def _join_condition_for_others( - left: typed_expr.TypedExpr, - right: typed_expr.TypedExpr, -) -> sge.And: - """Generates a join condition for non-numeric types to match pandas's - null-handling logic. - """ - left_str = sql.cast(left.expr, "STRING") - right_str = sql.cast(right.expr, "STRING") - left_0 = sge.func("COALESCE", left_str, sql.literal("0", dtypes.STRING_DTYPE)) - left_1 = sge.func("COALESCE", left_str, sql.literal("1", dtypes.STRING_DTYPE)) - right_0 = sge.func("COALESCE", right_str, sql.literal("0", dtypes.STRING_DTYPE)) - right_1 = sge.func("COALESCE", right_str, sql.literal("1", dtypes.STRING_DTYPE)) + left_expr1, left_expr2 = _value_to_non_null_identity(left) + right_expr1, right_expr2 = _value_to_non_null_identity(right) return sge.And( - this=sge.EQ(this=left_0, expression=right_0), - expression=sge.EQ(this=left_1, expression=right_1), + this=sge.EQ(this=left_expr1, expression=right_expr1), + expression=sge.EQ(this=left_expr2, expression=right_expr2), ) -def _join_condition_for_numeric( - left: typed_expr.TypedExpr, - right: typed_expr.TypedExpr, -) -> sge.And: - """Generates a join condition for non-numeric types to match pandas's - null-handling logic. Specifically for FLOAT types, Pandas treats NaN aren't - equal so need to coalesce as well with different constants. - """ - is_floating_types = ( - left.dtype == dtypes.FLOAT_DTYPE and right.dtype == dtypes.FLOAT_DTYPE - ) - left_0 = sge.func("COALESCE", left.expr, sql.literal(0, left.dtype)) - left_1 = sge.func("COALESCE", left.expr, sql.literal(1, left.dtype)) - right_0 = sge.func("COALESCE", right.expr, sql.literal(0, right.dtype)) - right_1 = sge.func("COALESCE", right.expr, sql.literal(1, right.dtype)) - if not is_floating_types: - return sge.And( - this=sge.EQ(this=left_0, expression=right_0), - expression=sge.EQ(this=left_1, expression=right_1), +def _value_to_non_null_identity( + value: typed_expr.TypedExpr, +) -> tuple[sge.Expression, sge.Expression]: + # normal_value -> (normal_value, normal_value) + # null_value -> (0, 1) + # nan_value -> (2, 3) + if dtypes.is_numeric(value.dtype, include_bool=False): + expr1 = sge.func("COALESCE", value.expr, sql.literal(0, value.dtype)) + expr2 = sge.func("COALESCE", value.expr, sql.literal(1, value.dtype)) + if value.dtype == dtypes.FLOAT_DTYPE: + expr1 = sge.If( + this=sge.IsNan(this=value.expr), + true=sql.literal(2, value.dtype), + false=expr1, + ) + expr2 = sge.If( + this=sge.IsNan(this=value.expr), + true=sql.literal(3, value.dtype), + false=expr2, + ) + else: # general case, convert to string and coalesce + expr1 = sge.func( + "COALESCE", + sql.cast(value.expr, "STRING"), + sql.literal("0", dtypes.STRING_DTYPE), ) - - left_2 = sge.If( - this=sge.IsNan(this=left.expr), true=sql.literal(2, left.dtype), false=left_0 - ) - left_3 = sge.If( - this=sge.IsNan(this=left.expr), true=sql.literal(3, left.dtype), false=left_1 - ) - right_2 = sge.If( - this=sge.IsNan(this=right.expr), true=sql.literal(2, right.dtype), false=right_0 - ) - right_3 = sge.If( - this=sge.IsNan(this=right.expr), true=sql.literal(3, right.dtype), false=right_1 - ) - return sge.And( - this=sge.EQ(this=left_2, expression=right_2), - expression=sge.EQ(this=left_3, expression=right_3), - ) + expr2 = sge.func( + "COALESCE", + sql.cast(value.expr, "STRING"), + sql.literal("1", dtypes.STRING_DTYPE), + ) + return expr1, expr2 def _set_query_ctes( diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index 07dc81f1498..c85fe44170a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -3,18 +3,11 @@ SELECT `bfcol_5` AS `int64_col` FROM ( SELECT - ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).*, - EXISTS( - SELECT - 1 - FROM ( + *, + STRUCT(COALESCE(`bfcol_3`, 0) AS `bfpart1_0`, COALESCE(`bfcol_3`, 1) AS `bfpart2_0`) IN ( + ( SELECT - `int64_too` AS `bfcol_4` + STRUCT(COALESCE(`bfcol_4`, 0) AS `bfpart1_0`, COALESCE(`bfcol_4`, 1) AS `bfpart2_0`) FROM ( SELECT `int64_too` @@ -22,26 +15,7 @@ FROM ( GROUP BY `int64_too` ) - ) AS `bft_1` - WHERE - COALESCE( - ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).`bfcol_3`, - 0 - ) = COALESCE(`bft_1`.`bfcol_4`, 0) - AND COALESCE( - ( - SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).`bfcol_3`, - 1 - ) = COALESCE(`bft_1`.`bfcol_4`, 1) + ) ) AS `bfcol_5` FROM ( SELECT diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 5308e1570f0..6adafb2b662 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -3,18 +3,8 @@ SELECT `bfcol_5` AS `rowindex_2` FROM ( SELECT - ( - SELECT - `rowindex` AS `bfcol_2`, - `rowindex_2` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).*, - ( - SELECT - `rowindex` AS `bfcol_2`, - `rowindex_2` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ).`bfcol_3` IN ( + *, + `bfcol_3` IN ( ( SELECT `rowindex_2` AS `bfcol_4` From 5f2ed0daabb806eca7b98d37fee12bbb24611f7c Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Fri, 6 Mar 2026 22:24:50 +0000 Subject: [PATCH 11/15] redo id remapper --- bigframes/core/rewrite/identifiers.py | 96 +++++++++++++++------------ 1 file changed, 54 insertions(+), 42 deletions(-) diff --git a/bigframes/core/rewrite/identifiers.py b/bigframes/core/rewrite/identifiers.py index 8efcbb4a0b9..65aa9338ec5 100644 --- a/bigframes/core/rewrite/identifiers.py +++ b/bigframes/core/rewrite/identifiers.py @@ -13,13 +13,42 @@ # limitations under the License. from __future__ import annotations -import dataclasses import typing from bigframes.core import identifiers, nodes -# TODO: May as well just outright remove selection nodes in this process. +def _create_mapping_operator( + id_def_remapping_by_node: dict[ + nodes.BigFrameNode, dict[identifiers.ColumnId, identifiers.ColumnId] + ], + id_ref_remapping_by_node: dict[ + nodes.BigFrameNode, dict[identifiers.ColumnId, identifiers.ColumnId] + ], +): + """ + Builds a remapping operator that uses predefined local remappings for ids. + + Args: + id_remapping_by_node: A mapping from nodes to their local remappings. + + Returns: + A remapping operator. + """ + + def _mapping_operator(node: nodes.BigFrameNode) -> nodes.BigFrameNode: + # Step 1: Get the local remapping for the current node. + local_def_remaps = id_def_remapping_by_node.get(node, {}) + local_ref_remaps = id_ref_remapping_by_node.get(node, {}) + + node = node.remap_vars(local_def_remaps) + node = node.remap_refs(local_ref_remaps) + + return node + + return _mapping_operator + + def remap_variables( root: nodes.BigFrameNode, id_generator: typing.Iterator[identifiers.ColumnId], @@ -42,46 +71,29 @@ def remap_variables( A tuple of the new root node and a mapping from old to new column IDs visible to the parent node. """ - # Step 1: Recursively remap children to get their new nodes and ID mappings. - new_child_nodes: list[nodes.BigFrameNode] = [] - new_child_mappings: list[dict[identifiers.ColumnId, identifiers.ColumnId]] = [] - for child in root.child_nodes: - new_child, child_mappings = remap_variables(child, id_generator=id_generator) - new_child_nodes.append(new_child) - new_child_mappings.append(child_mappings) - - # Step 2: Transform children to use their new nodes. - remapped_children: dict[nodes.BigFrameNode, nodes.BigFrameNode] = { - child: new_child for child, new_child in zip(root.child_nodes, new_child_nodes) - } - new_root = root.transform_children(lambda node: remapped_children[node]) - - # Step 3: Transform the current node using the mappings from its children. - if isinstance(new_root, nodes.InNode): - new_root = typing.cast(nodes.InNode, new_root) - new_root = dataclasses.replace( - new_root, - left_col=new_root.left_col.remap_column_refs( - new_child_mappings[0], allow_partial_bindings=True - ), - ) - else: - downstream_mappings: dict[identifiers.ColumnId, identifiers.ColumnId] = { - k: v for mapping in new_child_mappings for k, v in mapping.items() - } - new_root = new_root.remap_refs(downstream_mappings) - - # Step 4: Create new IDs for columns defined by the current node. - node_defined_mappings = { - old_id: next(id_generator) for old_id in root.node_defined_ids - } - new_root = new_root.remap_vars(node_defined_mappings) + # step 1: defined remappings for each individual unique node + # step 2: bottom up traversal to apply remappings - new_root._validate() + id_def_remaps: dict[ + nodes.BigFrameNode, dict[identifiers.ColumnId, identifiers.ColumnId] + ] = {} + id_ref_remaps: dict[ + nodes.BigFrameNode, dict[identifiers.ColumnId, identifiers.ColumnId] + ] = {} + for node in root.iter_nodes_topo(): # bottom_up + local_def_remaps = { + col_id: next(id_generator) for col_id in node.node_defined_ids + } + id_def_remaps[node] = local_def_remaps - # Step 5: Determine which mappings to propagate up to the parent. - propagated_mappings = { - old_id: new_id for old_id, new_id in zip(root.ids, new_root.ids) - } + local_ref_remaps = {} + for child in node.child_nodes: # inherit ref and def mappings from children + local_ref_remaps.update(id_def_remaps[child]) + if not child.defines_namespace: + local_ref_remaps.update(id_ref_remaps[child]) + id_ref_remaps[node] = local_ref_remaps - return new_root, propagated_mappings + return ( + root.top_down(_create_mapping_operator(id_def_remaps, id_ref_remaps)), + id_def_remaps[root], + ) From 75e02ccef9a14dcb602e5c3e7faa361d56653865 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Sat, 7 Mar 2026 00:06:55 +0000 Subject: [PATCH 12/15] fix id issues preventing cte factoring --- bigframes/core/bigframe_node.py | 18 +-- bigframes/core/compile/sqlglot/compiler.py | 1 + bigframes/core/rewrite/ctes.py | 15 ++- bigframes/core/rewrite/identifiers.py | 32 +++-- .../test_compile_concat/out.sql | 63 ++++------ .../test_compile_concat_filter_sorted/out.sql | 84 +++++-------- .../test_compile_fromrange/out.sql | 116 +++++------------- .../test_compile_isin/out.sql | 10 +- .../test_compile_isin_not_nullable/out.sql | 10 +- .../test_compile_join/out.sql | 16 +-- .../test_compile_join_w_on/bool_col/out.sql | 31 ++--- .../float64_col/out.sql | 31 ++--- .../test_compile_join_w_on/int64_col/out.sql | 31 ++--- .../numeric_col/out.sql | 31 ++--- .../test_compile_join_w_on/string_col/out.sql | 27 ++-- .../test_compile_join_w_on/time_col/out.sql | 27 ++-- 16 files changed, 207 insertions(+), 336 deletions(-) diff --git a/bigframes/core/bigframe_node.py b/bigframes/core/bigframe_node.py index 7e40248a009..e14b48a7ec2 100644 --- a/bigframes/core/bigframe_node.py +++ b/bigframes/core/bigframe_node.py @@ -330,22 +330,12 @@ def top_down( """ Perform a top-down transformation of the BigFrameNode tree. """ - to_process = [self] - results: Dict[BigFrameNode, BigFrameNode] = {} - while to_process: - item = to_process.pop() - if item not in results.keys(): - item_result = transform(item) - results[item] = item_result - to_process.extend(item_result.child_nodes) + @functools.cache + def recursive_transform(node: BigFrameNode) -> BigFrameNode: + return transform(node).transform_children(recursive_transform) - to_process = [self] - # for each processed item, replace its children - for item in reversed(list(results.keys())): - results[item] = results[item].transform_children(lambda x: results[x]) - - return results[self] + return recursive_transform(self) def bottom_up( self: BigFrameNode, diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index e9c10493c03..646b5122ffc 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -98,6 +98,7 @@ def _remap_variables( result_node, _ = rewrite.remap_variables( node, map(identifiers.ColumnId, uid_gen.get_uid_stream("bfcol_")) ) + result_node.validate_tree() return typing.cast(nodes.ResultNode, result_node) diff --git a/bigframes/core/rewrite/ctes.py b/bigframes/core/rewrite/ctes.py index 871dbc94479..a5afd19bb35 100644 --- a/bigframes/core/rewrite/ctes.py +++ b/bigframes/core/rewrite/ctes.py @@ -25,10 +25,17 @@ def extract_ctes(root: nodes.BigFrameNode) -> nodes.BigFrameNode: for child in parent.child_nodes: node_parents[child] += 1 - # we just mark in place, rather than pull out of the tree. + # everywhere a multi-parent node is referenced, wrap it in a CTE node def insert_cte_markers(node: nodes.BigFrameNode) -> nodes.BigFrameNode: - if node_parents[node] > 1: - return nodes.CteNode(node) - return node + def _add_cte_if_needed(child: nodes.BigFrameNode) -> nodes.BigFrameNode: + if node_parents[child] > 1: + return nodes.CteNode(child) + return child + + if isinstance(node, nodes.CteNode): + # don't re-wrap CTE nodes + return node + + return node.transform_children(_add_cte_if_needed) return root.top_down(insert_cte_markers) diff --git a/bigframes/core/rewrite/identifiers.py b/bigframes/core/rewrite/identifiers.py index 65aa9338ec5..0b36e861528 100644 --- a/bigframes/core/rewrite/identifiers.py +++ b/bigframes/core/rewrite/identifiers.py @@ -38,13 +38,13 @@ def _create_mapping_operator( def _mapping_operator(node: nodes.BigFrameNode) -> nodes.BigFrameNode: # Step 1: Get the local remapping for the current node. - local_def_remaps = id_def_remapping_by_node.get(node, {}) - local_ref_remaps = id_ref_remapping_by_node.get(node, {}) + local_def_remaps = id_def_remapping_by_node[node] + local_ref_remaps = id_ref_remapping_by_node[node] - node = node.remap_vars(local_def_remaps) - node = node.remap_refs(local_ref_remaps) + result = node.remap_vars(local_def_remaps) + result = result.remap_refs(local_ref_remaps) - return node + return result return _mapping_operator @@ -80,19 +80,33 @@ def remap_variables( id_ref_remaps: dict[ nodes.BigFrameNode, dict[identifiers.ColumnId, identifiers.ColumnId] ] = {} - for node in root.iter_nodes_topo(): # bottom_up + for node in root.iter_nodes_topo(): # bottom up local_def_remaps = { col_id: next(id_generator) for col_id in node.node_defined_ids } id_def_remaps[node] = local_def_remaps local_ref_remaps = {} - for child in node.child_nodes: # inherit ref and def mappings from children + + # InNode is special case as ID scope inherited purely from left side + inheriting_nodes = ( + [node.child_nodes[0]] + if isinstance(node, nodes.InNode) + else node.child_nodes + ) + for child in inheriting_nodes: # inherit ref and def mappings from children + if not child.defines_namespace: # these nodes represent new id spaces + local_ref_remaps.update( + { + old_id: new_id + for old_id, new_id in id_ref_remaps[child].items() + if old_id in child.ids + } + ) local_ref_remaps.update(id_def_remaps[child]) - if not child.defines_namespace: - local_ref_remaps.update(id_ref_remaps[child]) id_ref_remaps[node] = local_ref_remaps + # have to do top down to preserve node identities return ( root.top_down(_create_mapping_operator(id_def_remaps, id_ref_remaps)), id_def_remaps[root], diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql index 52e13d87f27..5687ed918f1 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat/out.sql @@ -1,59 +1,48 @@ WITH `bfcte_0` AS ( - SELECT - `rowindex` AS `bfcol_18`, - `rowindex` AS `bfcol_19`, - `int64_col` AS `bfcol_20`, - `string_col` AS `bfcol_21` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `rowindex` AS `bfcol_3`, `rowindex` AS `bfcol_4`, `int64_col` AS `bfcol_5`, `string_col` AS `bfcol_6` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` ) SELECT - `bfcol_30` AS `rowindex`, - `bfcol_31` AS `rowindex_1`, - `bfcol_32` AS `int64_col`, - `bfcol_33` AS `string_col` + `bfcol_23` AS `rowindex`, + `bfcol_24` AS `rowindex_1`, + `bfcol_25` AS `int64_col`, + `bfcol_26` AS `string_col` FROM ( SELECT - `bfcol_9` AS `bfcol_30`, - `bfcol_10` AS `bfcol_31`, - `bfcol_11` AS `bfcol_32`, - `bfcol_12` AS `bfcol_33`, - `bfcol_13` AS `bfcol_34`, - `bfcol_14` AS `bfcol_35` + `bfcol_17` AS `bfcol_23`, + `bfcol_18` AS `bfcol_24`, + `bfcol_19` AS `bfcol_25`, + `bfcol_20` AS `bfcol_26`, + `bfcol_21` AS `bfcol_27`, + `bfcol_22` AS `bfcol_28` FROM ( ( SELECT - `bfcol_3` AS `bfcol_9`, - `bfcol_4` AS `bfcol_10`, - `bfcol_5` AS `bfcol_11`, - `bfcol_6` AS `bfcol_12`, - 0 AS `bfcol_13`, - ROW_NUMBER() OVER () - 1 AS `bfcol_14` - FROM `bfcte_1` + `bfcol_3` AS `bfcol_17`, + `bfcol_4` AS `bfcol_18`, + `bfcol_5` AS `bfcol_19`, + `bfcol_6` AS `bfcol_20`, + 0 AS `bfcol_21`, + ROW_NUMBER() OVER () - 1 AS `bfcol_22` + FROM `bfcte_0` ) UNION ALL ( SELECT - `bfcol_18` AS `bfcol_24`, - `bfcol_19` AS `bfcol_25`, - `bfcol_20` AS `bfcol_26`, - `bfcol_21` AS `bfcol_27`, - 1 AS `bfcol_28`, - ROW_NUMBER() OVER () - 1 AS `bfcol_29` - FROM `bfcte_2` + `bfcol_3` AS `bfcol_11`, + `bfcol_4` AS `bfcol_12`, + `bfcol_5` AS `bfcol_13`, + `bfcol_6` AS `bfcol_14`, + 1 AS `bfcol_15`, + ROW_NUMBER() OVER () - 1 AS `bfcol_16` + FROM `bfcte_0` ) ) ) ORDER BY - `bfcol_34` ASC NULLS LAST, - `bfcol_35` ASC NULLS LAST \ No newline at end of file + `bfcol_27` ASC NULLS LAST, + `bfcol_28` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql index 95edf4184fe..91ea792a7e3 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_concat/test_compile_concat_filter_sorted/out.sql @@ -1,83 +1,63 @@ WITH `bfcte_0` AS ( SELECT - `float64_col` AS `bfcol_23`, - `int64_col` AS `bfcol_24` + `float64_col` AS `bfcol_5`, + `int64_col` AS `bfcol_6` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ), `bfcte_1` AS ( SELECT - `float64_col` AS `bfcol_2`, - `int64_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - `float64_col` AS `bfcol_34`, - `int64_too` AS `bfcol_35` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - `bool_col` -), `bfcte_3` AS ( - SELECT - `float64_col` AS `bfcol_13`, - `int64_too` AS `bfcol_14` + `float64_col` AS `bfcol_7`, + `int64_too` AS `bfcol_8` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` WHERE `bool_col` -), `bfcte_4` AS ( - SELECT - * - FROM `bfcte_0` -), `bfcte_5` AS ( - SELECT - * - FROM `bfcte_2` ) SELECT - `bfcol_42` AS `float64_col`, - `bfcol_43` AS `int64_col` + `bfcol_33` AS `float64_col`, + `bfcol_34` AS `int64_col` FROM ( SELECT - `bfcol_6` AS `bfcol_42`, - `bfcol_7` AS `bfcol_43`, - `bfcol_8` AS `bfcol_44`, - `bfcol_9` AS `bfcol_45` + `bfcol_21` AS `bfcol_33`, + `bfcol_22` AS `bfcol_34`, + `bfcol_23` AS `bfcol_35`, + `bfcol_24` AS `bfcol_36` FROM ( ( SELECT - `bfcol_2` AS `bfcol_6`, - `bfcol_3` AS `bfcol_7`, - 0 AS `bfcol_8`, - ROW_NUMBER() OVER (ORDER BY `bfcol_3` ASC NULLS LAST) - 1 AS `bfcol_9` - FROM `bfcte_1` + `bfcol_5` AS `bfcol_21`, + `bfcol_6` AS `bfcol_22`, + 0 AS `bfcol_23`, + ROW_NUMBER() OVER (ORDER BY `bfcol_6` ASC NULLS LAST) - 1 AS `bfcol_24` + FROM `bfcte_0` ) UNION ALL ( SELECT - `bfcol_13` AS `bfcol_17`, - `bfcol_14` AS `bfcol_18`, - 1 AS `bfcol_19`, - ROW_NUMBER() OVER () - 1 AS `bfcol_20` - FROM `bfcte_3` + `bfcol_7` AS `bfcol_29`, + `bfcol_8` AS `bfcol_30`, + 1 AS `bfcol_31`, + ROW_NUMBER() OVER () - 1 AS `bfcol_32` + FROM `bfcte_1` ) UNION ALL ( SELECT - `bfcol_23` AS `bfcol_27`, - `bfcol_24` AS `bfcol_28`, - 2 AS `bfcol_29`, - ROW_NUMBER() OVER (ORDER BY `bfcol_24` ASC NULLS LAST) - 1 AS `bfcol_30` - FROM `bfcte_4` + `bfcol_5` AS `bfcol_17`, + `bfcol_6` AS `bfcol_18`, + 2 AS `bfcol_19`, + ROW_NUMBER() OVER (ORDER BY `bfcol_6` ASC NULLS LAST) - 1 AS `bfcol_20` + FROM `bfcte_0` ) UNION ALL ( SELECT - `bfcol_34` AS `bfcol_38`, - `bfcol_35` AS `bfcol_39`, - 3 AS `bfcol_40`, - ROW_NUMBER() OVER () - 1 AS `bfcol_41` - FROM `bfcte_5` + `bfcol_7` AS `bfcol_25`, + `bfcol_8` AS `bfcol_26`, + 3 AS `bfcol_27`, + ROW_NUMBER() OVER () - 1 AS `bfcol_28` + FROM `bfcte_1` ) ) ) ORDER BY - `bfcol_44` ASC NULLS LAST, - `bfcol_45` ASC NULLS LAST \ No newline at end of file + `bfcol_35` ASC NULLS LAST, + `bfcol_36` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index 553a5bf30ba..979a323826f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -1,58 +1,36 @@ WITH `bfcte_0` AS ( SELECT - `bfcol_8` AS `bfcol_9` - FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ) -), `bfcte_1` AS ( - SELECT - `bfcol_0` AS `bfcol_1` + `bfcol_0` AS `bfcol_4` FROM ( SELECT * FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ) -), `bfcte_2` AS ( - SELECT - * - FROM ( - SELECT - MIN(`bfcol_51`) AS `bfcol_53` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ) -), `bfcte_3` AS ( - SELECT - * - FROM ( - SELECT - MIN(`bfcol_42`) AS `bfcol_44` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ) -), `bfcte_4` AS ( +), `bfcte_1` AS ( SELECT - * + MIN(`bfcol_4`) AS `bfcol_8` FROM `bfcte_0` -), `bfcte_5` AS ( +), `bfcte_2` AS ( SELECT - * + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_4` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_8` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_14` FROM ( SELECT - MIN(`bfcol_2`) AS `bfcol_4` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) + * + FROM `bfcte_0` + CROSS JOIN `bfcte_1` ) -), `bfcte_6` AS ( - SELECT - * - FROM `bfcte_2` ) SELECT CAST(TIMESTAMP_MICROS( - CAST(CAST(`bfcol_41` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_44` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) + CAST(CAST(`bfcol_17` AS BIGNUMERIC) * 7000000 + CAST(UNIX_MICROS(CAST(CAST(`bfcol_8` AS DATE) AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) ) AS DATETIME) AS `bigframes_unnamed_index`, - `bfcol_55` AS `int64_col`, - `bfcol_56` AS `int64_too` + `bfcol_11` AS `int64_col`, + `bfcol_12` AS `int64_too` FROM ( SELECT * @@ -61,75 +39,49 @@ FROM ( * FROM ( SELECT - `bfcol_67` AS `bfcol_41` + `bfcol_27` AS `bfcol_17` FROM ( SELECT - * - FROM ( - SELECT - MIN(`bfcol_5`) AS `bfcol_7` - FROM ( - SELECT - * - FROM `bfcte_1` - CROSS JOIN `bfcte_5` - ) - ) + MIN(`bfcol_14`) AS `bfcol_16` + FROM `bfcte_2` ) CROSS JOIN ( SELECT - * - FROM ( - SELECT - MAX(`bfcol_38`) AS `bfcol_40` - FROM ( - SELECT - * - FROM `bfcte_4` - CROSS JOIN ( - SELECT - * - FROM ( - SELECT - MIN(`bfcol_11`) AS `bfcol_37` - FROM UNNEST(ARRAY>[STRUCT(0, CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(1, CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(2, CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(3, CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(4, CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(5, CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(6, CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(7, CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(8, CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(9, CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(10, CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(11, CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(12, CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(13, CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(14, CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(15, CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(16, CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(17, CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(18, CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(19, CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(20, CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(21, CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(22, CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(23, CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(24, CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(25, CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(26, CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(27, CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(28, CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(29, CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) - ) - ) - ) - ) + MAX(`bfcol_14`) AS `bfcol_15` + FROM `bfcte_2` ) - CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_7`, `bfcol_40`, 1)) AS `bfcol_67` + CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_16`, `bfcol_15`, 1)) AS `bfcol_27` ) - CROSS JOIN `bfcte_3` + CROSS JOIN `bfcte_1` ) LEFT JOIN ( SELECT - `bfcol_49` AS `bfcol_55`, - `bfcol_50` AS `bfcol_56`, + `bfcol_6` AS `bfcol_11`, + `bfcol_7` AS `bfcol_12`, CAST(FLOOR( IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_48` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_53` AS DATE) AS TIMESTAMP)), + UNIX_MICROS(CAST(`bfcol_5` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_8` AS DATE) AS TIMESTAMP)), 7000000 ) - ) AS INT64) AS `bfcol_57` + ) AS INT64) AS `bfcol_13` FROM ( SELECT * FROM ( SELECT - `bfcol_45` AS `bfcol_48`, - `bfcol_46` AS `bfcol_49`, - `bfcol_47` AS `bfcol_50` + `bfcol_1` AS `bfcol_5`, + `bfcol_2` AS `bfcol_6`, + `bfcol_3` AS `bfcol_7` FROM ( SELECT * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) ) ) - CROSS JOIN `bfcte_6` + CROSS JOIN `bfcte_1` ) ) - ON `bfcol_41` = `bfcol_57` + ON `bfcol_17` = `bfcol_13` ) ORDER BY - `bfcol_41` ASC NULLS LAST \ No newline at end of file + `bfcol_17` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index c85fe44170a..7f78d817f19 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -1,13 +1,13 @@ SELECT - `bfcol_2` AS `rowindex`, + `bfcol_3` AS `rowindex`, `bfcol_5` AS `int64_col` FROM ( SELECT *, - STRUCT(COALESCE(`bfcol_3`, 0) AS `bfpart1_0`, COALESCE(`bfcol_3`, 1) AS `bfpart2_0`) IN ( + STRUCT(COALESCE(`bfcol_4`, 0) AS `bfpart1_0`, COALESCE(`bfcol_4`, 1) AS `bfpart2_0`) IN ( ( SELECT - STRUCT(COALESCE(`bfcol_4`, 0) AS `bfpart1_0`, COALESCE(`bfcol_4`, 1) AS `bfpart2_0`) + STRUCT(COALESCE(`bfcol_0`, 0) AS `bfpart1_0`, COALESCE(`bfcol_0`, 1) AS `bfpart2_0`) FROM ( SELECT `int64_too` @@ -19,8 +19,8 @@ FROM ( ) AS `bfcol_5` FROM ( SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` + `rowindex` AS `bfcol_3`, + `int64_col` AS `bfcol_4` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 6adafb2b662..6829a712667 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -1,13 +1,13 @@ SELECT - `bfcol_2` AS `rowindex`, + `bfcol_3` AS `rowindex`, `bfcol_5` AS `rowindex_2` FROM ( SELECT *, - `bfcol_3` IN ( + `bfcol_4` IN ( ( SELECT - `rowindex_2` AS `bfcol_4` + `rowindex_2` AS `bfcol_0` FROM ( SELECT `rowindex_2` @@ -19,8 +19,8 @@ FROM ( ) AS `bfcol_5` FROM ( SELECT - `rowindex` AS `bfcol_2`, - `rowindex_2` AS `bfcol_3` + `rowindex` AS `bfcol_3`, + `rowindex_2` AS `bfcol_4` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql index 29bcbf8b793..dbc751213d1 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql @@ -1,21 +1,21 @@ SELECT - `bfcol_3` AS `int64_col`, - `bfcol_7` AS `int64_too` + `bfcol_7` AS `int64_col`, + `bfcol_5` AS `int64_too` FROM ( SELECT * FROM ( SELECT - `rowindex` AS `bfcol_2`, - `int64_col` AS `bfcol_3` + `rowindex` AS `bfcol_6`, + `int64_col` AS `bfcol_7` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) LEFT JOIN ( SELECT - `int64_col` AS `bfcol_6`, - `int64_too` AS `bfcol_7` + `int64_col` AS `bfcol_4`, + `int64_too` AS `bfcol_5` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` ) - ON COALESCE(`bfcol_2`, 0) = COALESCE(`bfcol_6`, 0) - AND COALESCE(`bfcol_2`, 1) = COALESCE(`bfcol_6`, 1) + ON COALESCE(`bfcol_6`, 0) = COALESCE(`bfcol_4`, 0) + AND COALESCE(`bfcol_6`, 1) = COALESCE(`bfcol_4`, 1) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql index c407c9f0139..a2f5aabe796 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql @@ -1,37 +1,28 @@ WITH `bfcte_0` AS ( - SELECT - `bool_col` AS `bfcol_4`, - `rowindex` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `bool_col` AS `bfcol_0`, `rowindex` AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `bool_col`, - `bfcol_6` AS `rowindex_y` + `bfcol_4` AS `rowindex_x`, + `bfcol_5` AS `bool_col`, + `bfcol_2` AS `rowindex_y` FROM ( SELECT * FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` ) INNER JOIN ( SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` ) - ON COALESCE(CAST(`bfcol_3` AS STRING), '0') = COALESCE(CAST(`bfcol_7` AS STRING), '0') - AND COALESCE(CAST(`bfcol_3` AS STRING), '1') = COALESCE(CAST(`bfcol_7` AS STRING), '1') + ON COALESCE(CAST(`bfcol_5` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') + AND COALESCE(CAST(`bfcol_5` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql index f4085495bab..1f1aac0b627 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql @@ -1,37 +1,28 @@ WITH `bfcte_0` AS ( - SELECT - `float64_col` AS `bfcol_4`, - `rowindex` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `float64_col` AS `bfcol_0`, `rowindex` AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `float64_col`, - `bfcol_6` AS `rowindex_y` + `bfcol_4` AS `rowindex_x`, + `bfcol_5` AS `float64_col`, + `bfcol_2` AS `rowindex_y` FROM ( SELECT * FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` ) INNER JOIN ( SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` ) - ON IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) = IF(IS_NAN(`bfcol_7`), 2, COALESCE(`bfcol_7`, 0)) - AND IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) = IF(IS_NAN(`bfcol_7`), 3, COALESCE(`bfcol_7`, 1)) + ON IF(IS_NAN(`bfcol_5`), 2, COALESCE(`bfcol_5`, 0)) = IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) + AND IF(IS_NAN(`bfcol_5`), 3, COALESCE(`bfcol_5`, 1)) = IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql index 735c43cc98d..c9381f53b3a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql @@ -1,37 +1,28 @@ WITH `bfcte_0` AS ( - SELECT - `int64_col` AS `bfcol_4`, - `rowindex` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `int64_col` AS `bfcol_0`, `rowindex` AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `int64_col`, - `bfcol_6` AS `rowindex_y` + `bfcol_4` AS `rowindex_x`, + `bfcol_5` AS `int64_col`, + `bfcol_2` AS `rowindex_y` FROM ( SELECT * FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` ) INNER JOIN ( SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` ) - ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_7`, 0) - AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_7`, 1) + ON COALESCE(`bfcol_5`, 0) = COALESCE(`bfcol_3`, 0) + AND COALESCE(`bfcol_5`, 1) = COALESCE(`bfcol_3`, 1) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql index bc3d2778935..29ad38feace 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql @@ -1,37 +1,28 @@ WITH `bfcte_0` AS ( - SELECT - `numeric_col` AS `bfcol_4`, - `rowindex` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `numeric_col` AS `bfcol_0`, `rowindex` AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` ) SELECT - `bfcol_2` AS `rowindex_x`, - `bfcol_3` AS `numeric_col`, - `bfcol_6` AS `rowindex_y` + `bfcol_4` AS `rowindex_x`, + `bfcol_5` AS `numeric_col`, + `bfcol_2` AS `rowindex_y` FROM ( SELECT * FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_1` + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` ) INNER JOIN ( SELECT - `bfcol_5` AS `bfcol_6`, - `bfcol_4` AS `bfcol_7` - FROM `bfcte_2` + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` ) - ON COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(0 AS NUMERIC)) - AND COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_7`, CAST(1 AS NUMERIC)) + ON COALESCE(`bfcol_5`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) + AND COALESCE(`bfcol_5`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql index a86e8a08aeb..44e384d90a7 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql @@ -1,36 +1,23 @@ WITH `bfcte_0` AS ( - SELECT - `rowindex` AS `bfcol_2`, - `string_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `rowindex` AS `bfcol_0`, `string_col` AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` -), `bfcte_3` AS ( - SELECT - * - FROM `bfcte_1` ) SELECT `bfcol_0` AS `rowindex_x`, `bfcol_1` AS `string_col`, - `bfcol_4` AS `rowindex_y` + `bfcol_2` AS `rowindex_y` FROM ( SELECT * - FROM `bfcte_3` + FROM `bfcte_0` INNER JOIN ( SELECT - `bfcol_2` AS `bfcol_4`, - `bfcol_3` AS `bfcol_5` - FROM `bfcte_2` + `bfcol_0` AS `bfcol_2`, + `bfcol_1` AS `bfcol_3` + FROM `bfcte_0` ) - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql index 8eadbfcd549..6a7fd06c35b 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql @@ -1,36 +1,23 @@ WITH `bfcte_0` AS ( - SELECT - `rowindex` AS `bfcol_2`, - `time_col` AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( SELECT `rowindex` AS `bfcol_0`, `time_col` AS `bfcol_1` FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - * - FROM `bfcte_0` -), `bfcte_3` AS ( - SELECT - * - FROM `bfcte_1` ) SELECT `bfcol_0` AS `rowindex_x`, `bfcol_1` AS `time_col`, - `bfcol_4` AS `rowindex_y` + `bfcol_2` AS `rowindex_y` FROM ( SELECT * - FROM `bfcte_3` + FROM `bfcte_0` INNER JOIN ( SELECT - `bfcol_2` AS `bfcol_4`, - `bfcol_3` AS `bfcol_5` - FROM `bfcte_2` + `bfcol_0` AS `bfcol_2`, + `bfcol_1` AS `bfcol_3` + FROM `bfcte_0` ) - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_5` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_5` AS STRING), '1') + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') ) \ No newline at end of file From 2d382c69c437ee1dee3efe4bb1cab3c26dd5ed20 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Sat, 7 Mar 2026 01:33:19 +0000 Subject: [PATCH 13/15] refactor ir internals to reduce select count --- bigframes/core/compile/sqlglot/compiler.py | 2 +- bigframes/core/compile/sqlglot/sqlglot_ir.py | 168 ++++++--- bigframes/core/rewrite/pruning.py | 1 - bigframes/session/bq_caching_executor.py | 9 - .../test_binary_compiler/test_corr/out.sql | 7 +- .../test_binary_compiler/test_cov/out.sql | 7 +- .../test_nullary_compiler/test_size/out.sql | 6 +- .../test_array_agg/out.sql | 6 +- .../test_string_agg/out.sql | 6 +- .../test_unary_compiler/test_all/out.sql | 7 +- .../test_unary_compiler/test_any/out.sql | 7 +- .../test_any_value/out.sql | 6 +- .../test_approx_quartiles/out.sql | 6 +- .../test_approx_top_count/out.sql | 6 +- .../test_unary_compiler/test_count/out.sql | 6 +- .../test_unary_compiler/test_max/out.sql | 6 +- .../test_unary_compiler/test_mean/out.sql | 11 +- .../test_unary_compiler/test_median/out.sql | 8 +- .../test_unary_compiler/test_min/out.sql | 6 +- .../test_unary_compiler/test_nunique/out.sql | 6 +- .../test_unary_compiler/test_pop_var/out.sql | 7 +- .../test_unary_compiler/test_product/out.sql | 6 +- .../test_unary_compiler/test_quantile/out.sql | 7 +- .../test_unary_compiler/test_std/out.sql | 11 +- .../test_unary_compiler/test_sum/out.sql | 7 +- .../test_unary_compiler/test_var/out.sql | 7 +- .../test_compile_aggregate/out.sql | 9 +- .../test_compile_aggregate_wo_dropna/out.sql | 9 +- .../test_compile_explode_dataframe/out.sql | 8 +- .../test_compile_explode_series/out.sql | 7 +- .../test_compile_fromrange/out.sql | 12 +- .../test_st_regionstats/out.sql | 6 +- .../out.sql | 6 +- .../test_compile_geo/test_st_simplify/out.sql | 6 +- .../test_compile_isin/out.sql | 16 +- .../test_compile_isin_not_nullable/out.sql | 6 +- .../test_compile_readlocal/out.sql | 330 +++++++++--------- .../test_compile_readlocal_w_json_df/out.sql | 6 +- .../test_compile_readlocal_w_lists_df/out.sql | 66 ++-- .../out.sql | 24 +- .../out.sql | 38 +- .../out.sql | 6 +- 42 files changed, 524 insertions(+), 363 deletions(-) diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index 646b5122ffc..0f84c4d09da 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -126,7 +126,7 @@ def compile_node( for current_node in list(node.iter_nodes_topo()): if current_node.child_nodes == (): # For leaf node, generates a dumpy child to pass the UID generator. - child_results = tuple([sqlglot_ir.SQLGlotIR(uid_gen=uid_gen)]) + child_results = tuple([sqlglot_ir.SQLGlotIR.empty(uid_gen=uid_gen)]) else: # Child nodes should have been compiled in the reverse topological order. child_results = tuple( diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index 841956d76bb..5b107b54ae5 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -14,6 +14,7 @@ from __future__ import annotations +import abc import dataclasses import datetime import functools @@ -38,20 +39,107 @@ to_wkt = dumps +class SelectableFragment(abc.ABC): + """ + Represent a grammar fragment that can be converted to a SELECT or FROM item. + """ + + def as_select_all(self) -> sge.Select: + ... + + def select(self, *items: sge.Expression) -> sge.Select: + ... + + def as_from_item(self) -> sge.FromItem: + ... + + +class SelectFragment(SelectableFragment): + def __init__(self, select_expr: sge.Select): + self.select_expr = select_expr + + def as_select_all(self) -> sge.Select: + return self.select_expr + + def select(self, *items: sge.Expression) -> sge.Select: + return sge.Select().select(*items).from_(self.select_expr.subquery()) + + def as_from_item(self) -> sge.FromItem: + return self.select_expr.subquery() + + +class TableFragment(SelectableFragment): + def __init__(self, table: sge.Table | sge.Unnest): + self.table = table + + def as_select_all(self) -> sge.Select: + return sge.Select().select(sge.Star()).from_(self.table) + + def select(self, *items: sge.Expression) -> sge.Select: + return sge.Select().select(*items).from_(self.table) + + def as_from_item(self) -> sge.FromItem: + return self.table + + +class DeferredSelectFragment(SelectableFragment): + def __init__(self, select_supplier: typing.Callable[[sge.Select], sge.Select]): + self.select_supplier = select_supplier + + def as_select_all(self) -> sge.Select: + return self.select_supplier(sge.Select().select(sge.Star())) + + def select(self, *items: sge.Expression) -> sge.Select: + return self.select_supplier(sge.Select().select(*items)) + + def as_from_item(self) -> sge.FromItem: + return self.select_supplier(sge.Select().select(sge.Star())).subquery() + + @dataclasses.dataclass(frozen=True) class SQLGlotIR: """Helper class to build SQLGlot Query and generate SQL string.""" - expr: typing.Union[sge.Select, sge.Table] = sg.select() + expr: SelectableFragment """The SQLGlot expression representing the query.""" uid_gen: guid.SequentialUIDGenerator = guid.SequentialUIDGenerator() """Generator for unique identifiers.""" + def __post_init__(self): + assert isinstance(self.expr, SelectableFragment) + @property def sql(self) -> str: """Generate SQL string from the given expression.""" - return sql.to_sql(self.expr) + return sql.to_sql(self.expr.as_select_all()) + + @classmethod + def empty( + cls, uid_gen: guid.SequentialUIDGenerator = guid.SequentialUIDGenerator() + ) -> SQLGlotIR: + return cls(expr=SelectFragment(sge.select()), uid_gen=uid_gen) + + @classmethod + def from_expr( + cls, + expr: sge.Expression, + uid_gen: guid.SequentialUIDGenerator = guid.SequentialUIDGenerator(), + ) -> SQLGlotIR: + if isinstance(expr, sge.Select): + return cls(expr=SelectFragment(expr), uid_gen=uid_gen) + elif isinstance(expr, (sge.Table, sge.Unnest)): + return cls(expr=TableFragment(expr), uid_gen=uid_gen) + else: + raise ValueError(f"Unsupported expression type: {type(expr)}") + + @classmethod + def from_func( + cls, + select_handler: typing.Callable[[sge.Select], sge.Select], + uid_gen: guid.SequentialUIDGenerator = guid.SequentialUIDGenerator(), + ): + return cls(expr=DeferredSelectFragment(select_handler), uid_gen=uid_gen) @classmethod def from_pyarrow( @@ -97,7 +185,7 @@ def from_pyarrow( ), ], ) - return cls(expr=sg.select(sge.Star()).from_(expr), uid_gen=uid_gen) + return cls.from_expr(expr=expr, uid_gen=uid_gen) @classmethod def from_table( @@ -143,9 +231,9 @@ def from_table( select_expr = select_expr.where( sg.parse_one(sql_predicate, dialect=sql.base.DIALECT), append=False ) - return cls(expr=select_expr, uid_gen=uid_gen) + return cls.from_expr(expr=select_expr, uid_gen=uid_gen) - return cls(expr=table_expr, uid_gen=uid_gen) + return cls.from_expr(expr=table_expr, uid_gen=uid_gen) @classmethod def from_cte_ref( @@ -156,7 +244,7 @@ def from_cte_ref( table_expr = sge.Table( this=sql.identifier(cte_ref), ) - return cls(expr=table_expr, uid_gen=uid_gen) + return cls.from_expr(expr=table_expr, uid_gen=uid_gen) def select( self, @@ -191,7 +279,7 @@ def select( if limit is not None: new_expr = new_expr.limit(limit) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) @classmethod def from_unparsed_query( @@ -209,7 +297,7 @@ def from_unparsed_query( ) select_expr = sge.Select().select(sge.Star()).from_(sge.Table(this=cte_name)) select_expr = _set_query_ctes(select_expr, [cte]) - return cls(expr=select_expr, uid_gen=uid_gen) + return cls.from_expr(expr=select_expr, uid_gen=uid_gen) @classmethod def from_union( @@ -241,7 +329,7 @@ def from_union( final_select_expr = ( sge.Select().select(*selections).from_(union_expr.subquery()) ) - return cls(expr=final_select_expr, uid_gen=uid_gen) + return cls.from_expr(expr=final_select_expr, uid_gen=uid_gen) def join( self, @@ -262,15 +350,13 @@ def join( ) join_type_str = join_type if join_type != "outer" else "full outer" - new_expr = ( - sge.Select() - .select(sge.Star()) - .from_(left_from) - .join(right_from, on=join_on, join_type=join_type_str) + return SQLGlotIR.from_func( + lambda select: select.from_(left_from).join( + right_from, on=join_on, join_type=join_type_str + ), + uid_gen=self.uid_gen, ) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) - def isin_join( self, right: SQLGlotIR, @@ -280,7 +366,6 @@ def isin_join( ) -> SQLGlotIR: """Joins the current query with another SQLGlotIR instance.""" left_from = self._as_from_item() - right_select = right._as_select() new_column: sge.Expression if joins_nulls: @@ -294,7 +379,7 @@ def isin_join( ] ) right_expr1, right_expr2 = _value_to_non_null_identity(conditions[1]) - right_select = right_select.select( + right_select = right.expr.select( *[ sge.Struct( expressions=[ @@ -303,7 +388,6 @@ def isin_join( ] ) ], - append=False, ) new_column = sge.In( @@ -313,7 +397,7 @@ def isin_join( else: new_column = sge.In( this=conditions[0].expr, - expressions=[right_select.subquery()], + expressions=[right._as_subquery()], ) new_column = sge.Alias( @@ -322,7 +406,7 @@ def isin_join( ) new_expr = sge.Select().select(sge.Star(), new_column).from_(left_from) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) def explode( self, @@ -344,8 +428,8 @@ def sample(self, fraction: float) -> SQLGlotIR: expression=sql.literal(fraction, dtypes.FLOAT_DTYPE), ) - new_expr = self._as_select().where(condition, append=False) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + new_expr = self.expr.as_select_all().where(condition, append=False) + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) def aggregate( self, @@ -368,10 +452,7 @@ def aggregate( for id, expr in aggregations ] - new_expr = self._as_select() - new_expr = new_expr.group_by(*by_cols).select( - *[*by_cols, *aggregations_expr], append=False - ) + new_expr = self.expr.select(*[*by_cols, *aggregations_expr]).group_by(*by_cols) condition = _and( tuple( @@ -381,7 +462,7 @@ def aggregate( ) if condition is not None: new_expr = new_expr.where(condition, append=False) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) def with_ctes( self, @@ -395,7 +476,7 @@ def with_ctes( for cte_name, cte in ctes ] select_expr = _set_query_ctes(self._as_select(), sge_ctes) - return SQLGlotIR(expr=select_expr, uid_gen=self.uid_gen) + return SQLGlotIR.from_expr(expr=select_expr, uid_gen=self.uid_gen) def resample( self, @@ -431,7 +512,7 @@ def resample( .join(unnest_expr, join_type="cross") ) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) def _explode_single_column( self, column_name: str, offsets_col: typing.Optional[str] @@ -449,12 +530,9 @@ def _explode_single_column( ) selection = sge.Star(replace=[unnested_column_alias.as_(column)]) - new_expr = self._as_select() # Use LEFT JOIN to preserve rows when unnesting empty arrays. - new_expr = new_expr.select(selection, append=False).join( - unnest_expr, join_type="LEFT" - ) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + new_expr = self.expr.select(selection).join(unnest_expr, join_type="LEFT") + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) def _explode_multiple_columns( self, @@ -492,26 +570,18 @@ def _explode_multiple_columns( for column in columns ] ) - new_expr = self._as_select() # Use LEFT JOIN to preserve rows when unnesting empty arrays. - new_expr = new_expr.select(selection, append=False).join( - unnest_expr, join_type="LEFT" - ) - return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen) + new_expr = self.expr.select(selection).join(unnest_expr, join_type="LEFT") + return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) - def _as_from_item(self) -> typing.Union[sge.Subquery, sge.Table]: - if isinstance(self.expr, sge.Select): - return self.expr.subquery() - else: # table or cte - return self.expr + def _as_from_item(self) -> typing.Union[sge.Subquery, sge.Table, sge.Unnest]: + return self.expr.as_from_item() def _as_select(self) -> sge.Select: - if isinstance(self.expr, sge.Select): - return self.expr - else: # table or cte - return sge.Select().select(sge.Star()).from_(self.expr) + return self.expr.as_select_all() def _as_subquery(self) -> sge.Subquery: + # Sometimes explicitly need a subquery, e.g. for IN expressions. return self._as_select().subquery() diff --git a/bigframes/core/rewrite/pruning.py b/bigframes/core/rewrite/pruning.py index 591ae857031..60400821c63 100644 --- a/bigframes/core/rewrite/pruning.py +++ b/bigframes/core/rewrite/pruning.py @@ -67,7 +67,6 @@ def prune_selection_child( # Important to check this first if list(selection.ids) == list(child.ids): - # Added all() here - a generator object is natively truthy if all(ref.ref.id == ref.id for ref in selection.input_output_pairs): # selection is no-op so just remove it entirely return child diff --git a/bigframes/session/bq_caching_executor.py b/bigframes/session/bq_caching_executor.py index ac162744871..cd1642f6deb 100644 --- a/bigframes/session/bq_caching_executor.py +++ b/bigframes/session/bq_caching_executor.py @@ -490,15 +490,6 @@ def prepare_plan( return plan - def simplify_plan( - self, plan: nodes.BigFrameNode, use_cache: bool = True - ) -> nodes.BigFrameNode: - if use_cache: - plan = self.replace_cached_subtrees(plan) - plan = rewrite.column_pruning(plan) - plan = plan.top_down(rewrite.fold_row_counts) - return plan - def _cache_with_cluster_cols( self, array_value: bigframes.core.ArrayValue, cluster_cols: Sequence[str] ): diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql index 96560c464a2..3e21a5ab676 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql @@ -3,5 +3,10 @@ SELECT FROM ( SELECT CORR(`int64_col`, `float64_col`) AS `bfcol_2` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col`, + `float64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql index 6708dbec801..569697d641b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql @@ -3,5 +3,10 @@ SELECT FROM ( SELECT COVAR_SAMP(`int64_col`, `float64_col`) AS `bfcol_2` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col`, + `float64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql index 05206c1bd71..a88aef5bf14 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT COUNT(1) AS `bfcol_32` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + * + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql index e03ad7c732d..f60fe13219a 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql index 7f075191f7d..e8dcc08432f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql @@ -9,5 +9,9 @@ FROM ( `string_col` ASC), '' ) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `string_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql index bc4846bb44c..68e005cc3e8 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all/out.sql @@ -5,5 +5,10 @@ FROM ( SELECT COALESCE(LOGICAL_AND(`bool_col`), TRUE) AS `bfcol_2`, COALESCE(LOGICAL_AND(`int64_col` <> 0), TRUE) AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql index cb8e16e0070..1ae688a5b62 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any/out.sql @@ -5,5 +5,10 @@ FROM ( SELECT COALESCE(LOGICAL_OR(`bool_col`), FALSE) AS `bfcol_2`, COALESCE(LOGICAL_OR(`int64_col` <> 0), FALSE) AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql index 1cae1a0b218..e8437c0bae2 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT ANY_VALUE(`int64_col`) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql index a69f8827707..b7a4afb7b6e 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_quartiles/out.sql @@ -7,5 +7,9 @@ FROM ( APPROX_QUANTILES(`int64_col`, 4)[OFFSET(1)] AS `bfcol_1`, APPROX_QUANTILES(`int64_col`, 4)[OFFSET(2)] AS `bfcol_2`, APPROX_QUANTILES(`int64_col`, 4)[OFFSET(3)] AS `bfcol_3` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql index bb5d143414e..61ad7ec76fe 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_approx_top_count/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT APPROX_TOP_COUNT(`int64_col`, 10) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql index 698b2d407da..8585da3e0a6 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT COUNT(`int64_col`) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql index 0a5a4a407cb..2a0896524ba 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT MAX(`int64_col`) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql index 48f2d72ef8c..ca8b6fc31cb 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/out.sql @@ -9,5 +9,14 @@ FROM ( AVG(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`, CAST(FLOOR(AVG(`bfcol_8`)) AS INT64) AS `bfcol_14`, CAST(FLOOR(AVG(`bfcol_6`)) AS INT64) AS `bfcol_15` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col`, + `duration_col`, + `int64_col` AS `bfcol_6`, + `bool_col` AS `bfcol_7`, + `duration_col` AS `bfcol_8` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql index b9cc5e338aa..f154ff257dd 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_median/out.sql @@ -7,5 +7,11 @@ FROM ( APPROX_QUANTILES(`int64_col`, 2)[OFFSET(1)] AS `bfcol_3`, APPROX_QUANTILES(`date_col`, 2)[OFFSET(1)] AS `bfcol_4`, APPROX_QUANTILES(`string_col`, 2)[OFFSET(1)] AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `date_col`, + `int64_col`, + `string_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql index c21c9c8b830..80956dfa836 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT MIN(`int64_col`) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql index 559c53747ba..fc5caa43bc7 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_nunique/out.sql @@ -3,5 +3,9 @@ SELECT FROM ( SELECT COUNT(DISTINCT `int64_col`) AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql index cad5f6f88ac..00280204d96 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/out.sql @@ -5,5 +5,10 @@ FROM ( SELECT VAR_POP(`int64_col`) AS `bfcol_4`, VAR_POP(CAST(`bool_col` AS INT64)) AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql index 23422e814ab..63ffa48a345 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/out.sql @@ -7,5 +7,9 @@ FROM ( THEN 0 ELSE POWER(2, SUM(IF(`int64_col` = 0, 0, LOG(ABS(`int64_col`), 2)))) * POWER(-1, MOD(SUM(CASE WHEN SIGN(`int64_col`) = -1 THEN 1 ELSE 0 END), 2)) END AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql index 03a8dc65717..e6a28bdf9a0 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_quantile/out.sql @@ -7,5 +7,10 @@ FROM ( PERCENTILE_CONT(`int64_col`, 0.5) OVER () AS `bfcol_4`, PERCENTILE_CONT(CAST(`bool_col` AS INT64), 0.5) OVER () AS `bfcol_5`, CAST(FLOOR(PERCENTILE_CONT(`int64_col`, 0.5) OVER ()) AS INT64) AS `bfcol_6` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql index 8e01e27de62..095962a950a 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/out.sql @@ -9,5 +9,14 @@ FROM ( STDDEV(CAST(`bfcol_7` AS INT64)) AS `bfcol_13`, CAST(FLOOR(STDDEV(`bfcol_8`)) AS INT64) AS `bfcol_14`, CAST(FLOOR(STDDEV(`bfcol_6`)) AS INT64) AS `bfcol_15` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col`, + `duration_col`, + `int64_col` AS `bfcol_6`, + `bool_col` AS `bfcol_7`, + `duration_col` AS `bfcol_8` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql index 49d018c5d32..efb9581b92a 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/out.sql @@ -5,5 +5,10 @@ FROM ( SELECT COALESCE(SUM(`int64_col`), 0) AS `bfcol_4`, COALESCE(SUM(CAST(`bool_col` AS INT64)), 0) AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql index 39979fa8fee..fc72650d21c 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/out.sql @@ -5,5 +5,10 @@ FROM ( SELECT VARIANCE(`int64_col`) AS `bfcol_4`, VARIANCE(CAST(`bool_col` AS INT64)) AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_col` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) ) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql index 7facf57d09d..becaa33c010 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate/out.sql @@ -5,7 +5,14 @@ FROM ( SELECT `bfcol_3`, COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_too`, + `int64_too` AS `bfcol_2`, + `bool_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) WHERE NOT `bfcol_3` IS NULL GROUP BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql index 6721247e3e5..4934cc5a0ba 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_aggregate/test_compile_aggregate_wo_dropna/out.sql @@ -5,7 +5,14 @@ FROM ( SELECT `bfcol_3`, COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `bool_col`, + `int64_too`, + `int64_too` AS `bfcol_2`, + `bool_col` AS `bfcol_3` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) GROUP BY `bfcol_3` ) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql index 1ffebc9cd51..e31ab3dd5e3 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_dataframe/out.sql @@ -7,7 +7,13 @@ FROM ( SELECT * REPLACE (`int_list_col`[SAFE_OFFSET(`bfcol_13`)] AS `int_list_col`, `string_list_col`[SAFE_OFFSET(`bfcol_13`)] AS `string_list_col`) - FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` + FROM ( + SELECT + `rowindex`, + `int_list_col`, + `string_list_col` + FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` + ) LEFT JOIN UNNEST(GENERATE_ARRAY(0, LEAST(ARRAY_LENGTH(`int_list_col`) - 1, ARRAY_LENGTH(`string_list_col`) - 1))) AS `bfcol_13` WITH OFFSET AS `bfcol_7` ) ORDER BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql index 57dfdb14355..38bfac508cf 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_explode/test_compile_explode_series/out.sql @@ -5,7 +5,12 @@ FROM ( SELECT * REPLACE (`bfcol_8` AS `int_list_col`) - FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` + FROM ( + SELECT + `rowindex`, + `int_list_col` + FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` + ) LEFT JOIN UNNEST(`int_list_col`) AS `bfcol_8` WITH OFFSET AS `bfcol_4` ) ORDER BY diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index 979a323826f..0dedff7823d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -1,11 +1,7 @@ WITH `bfcte_0` AS ( SELECT `bfcol_0` AS `bfcol_4` - FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) - ) + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME)), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME))]) ), `bfcte_1` AS ( SELECT MIN(`bfcol_4`) AS `bfcol_8` @@ -72,11 +68,7 @@ FROM ( `bfcol_1` AS `bfcol_5`, `bfcol_2` AS `bfcol_6`, `bfcol_3` AS `bfcol_7` - FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) - ) + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) ) CROSS JOIN `bfcte_1` ) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql index dc2a8fdcb36..d1d30dc85fe 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats/out.sql @@ -41,10 +41,6 @@ SELECT include => 'some equation', options => JSON '{"scale": 100}' ).`area` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) -) +FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ORDER BY `bfcol_1` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql index 1210c7d217b..7a4c65d6ecb 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_regionstats_without_optional_args/out.sql @@ -5,10 +5,6 @@ SELECT ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`count`, ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`mean`, ST_REGIONSTATS(`bfcol_0`, 'ee://some/raster/uri').`area` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) -) +FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ORDER BY `bfcol_1` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql index 2512293b9fa..42dacf0fd2f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_geo/test_st_simplify/out.sql @@ -1,9 +1,5 @@ SELECT ST_SIMPLIFY(`bfcol_0`, 123.125) AS `0` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) -) +FROM UNNEST(ARRAY>[STRUCT('POINT(1 1)', 0)]) ORDER BY `bfcol_1` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql index 7f78d817f19..dda52bbbd9b 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin/out.sql @@ -10,10 +10,18 @@ FROM ( STRUCT(COALESCE(`bfcol_0`, 0) AS `bfpart1_0`, COALESCE(`bfcol_0`, 1) AS `bfpart2_0`) FROM ( SELECT - `int64_too` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - GROUP BY - `int64_too` + `int64_too` AS `bfcol_0` + FROM ( + SELECT + `int64_too` + FROM ( + SELECT + `int64_too` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) + GROUP BY + `int64_too` + ) ) ) ) AS `bfcol_5` diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql index 6829a712667..45b619cd87f 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_isin/test_compile_isin_not_nullable/out.sql @@ -11,7 +11,11 @@ FROM ( FROM ( SELECT `rowindex_2` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + FROM ( + SELECT + `rowindex_2` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + ) GROUP BY `rowindex_2` ) diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql index 0ef61502df4..77ccc0e0ca4 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal/out.sql @@ -15,172 +15,168 @@ SELECT `bfcol_13` AS `time_col`, `bfcol_14` AS `timestamp_col`, `bfcol_15` AS `duration_col` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT( - 0, - TRUE, - CAST(b'Hello, World!' AS BYTES), - CAST('2021-07-21' AS DATE), - CAST('2021-07-21T11:39:45' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-122.0838511 37.3860517)'), - 123456789, - 0, - CAST(1.234567890 AS NUMERIC), - 1.25, - 0, - 0, - 'Hello, World!', - CAST('11:41:43.076160' AS TIME), - CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), - 4, - 0 - ), STRUCT( - 1, - FALSE, - CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), - CAST('1991-02-03' AS DATE), - CAST('1991-01-02T03:45:06' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-71.104 42.315)'), - -987654321, - 1, - CAST(1.234567890 AS NUMERIC), - 2.51, - 1, - 1, - 'こんにちは', - CAST('11:14:34.701606' AS TIME), - CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), - -1000000, - 1 - ), STRUCT( - 2, - TRUE, - CAST(b'\xc2\xa1Hola Mundo!' AS BYTES), - CAST('2023-03-01' AS DATE), - CAST('2023-03-01T10:55:13' AS DATETIME), - ST_GEOGFROMTEXT('POINT(-0.124474760143016 51.5007826749545)'), - 314159, - 0, - CAST(101.101010100 AS NUMERIC), - 25000000000.0, - 2, - 2, - ' ¡Hola Mundo! ', - CAST('23:59:59.999999' AS TIME), - CAST('2023-03-01T10:55:13.250125+00:00' AS TIMESTAMP), - 0, - 2 - ), STRUCT( - 3, - CAST(NULL AS BOOLEAN), - CAST(NULL AS BYTES), - CAST(NULL AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - CAST(NULL AS INT64), - 1, - CAST(NULL AS NUMERIC), - CAST(NULL AS FLOAT64), - 3, - 3, - CAST(NULL AS STRING), - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - CAST(NULL AS INT64), - 3 - ), STRUCT( - 4, - FALSE, - CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), - CAST('2021-07-21' AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - -234892, - -2345, - CAST(NULL AS NUMERIC), - CAST(NULL AS FLOAT64), - 4, - 4, - 'Hello, World!', - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - 31540000000000, - 4 - ), STRUCT( - 5, - FALSE, - CAST(b'G\xc3\xbcten Tag' AS BYTES), - CAST('1980-03-14' AS DATE), - CAST('1980-03-14T15:16:17' AS DATETIME), - CAST(NULL AS GEOGRAPHY), - 55555, - 0, - CAST(5.555555000 AS NUMERIC), - 555.555, - 5, - 5, - 'Güten Tag!', - CAST('15:16:17.181921' AS TIME), - CAST('1980-03-14T15:16:17.181921+00:00' AS TIMESTAMP), - 4, - 5 - ), STRUCT( - 6, - TRUE, - CAST(b'Hello\tBigFrames!\x07' AS BYTES), - CAST('2023-05-23' AS DATE), - CAST('2023-05-23T11:37:01' AS DATETIME), - ST_GEOGFROMTEXT('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), - 101202303, - 2, - CAST(-10.090807000 AS NUMERIC), - -123.456, - 6, - 6, - 'capitalize, This ', - CAST('01:02:03.456789' AS TIME), - CAST('2023-05-23T11:42:55.000001+00:00' AS TIMESTAMP), - CAST(NULL AS INT64), - 6 - ), STRUCT( - 7, - TRUE, - CAST(NULL AS BYTES), - CAST('2038-01-20' AS DATE), - CAST('2038-01-19T03:14:08' AS DATETIME), - CAST(NULL AS GEOGRAPHY), - -214748367, - 2, - CAST(11111111.100000000 AS NUMERIC), - 42.42, - 7, - 7, - ' سلام', - CAST('12:00:00.000001' AS TIME), - CAST('2038-01-19T03:14:17.999999+00:00' AS TIMESTAMP), - 4, - 7 - ), STRUCT( - 8, - FALSE, - CAST(NULL AS BYTES), - CAST(NULL AS DATE), - CAST(NULL AS DATETIME), - CAST(NULL AS GEOGRAPHY), - 2, - 1, - CAST(NULL AS NUMERIC), - 6.87, - 8, - 8, - 'T', - CAST(NULL AS TIME), - CAST(NULL AS TIMESTAMP), - 432000000000, - 8 - )]) -) +FROM UNNEST(ARRAY>[STRUCT( + 0, + TRUE, + CAST(b'Hello, World!' AS BYTES), + CAST('2021-07-21' AS DATE), + CAST('2021-07-21T11:39:45' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-122.0838511 37.3860517)'), + 123456789, + 0, + CAST(1.234567890 AS NUMERIC), + 1.25, + 0, + 0, + 'Hello, World!', + CAST('11:41:43.076160' AS TIME), + CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), + 4, + 0 +), STRUCT( + 1, + FALSE, + CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), + CAST('1991-02-03' AS DATE), + CAST('1991-01-02T03:45:06' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-71.104 42.315)'), + -987654321, + 1, + CAST(1.234567890 AS NUMERIC), + 2.51, + 1, + 1, + 'こんにちは', + CAST('11:14:34.701606' AS TIME), + CAST('2021-07-21T17:43:43.945289+00:00' AS TIMESTAMP), + -1000000, + 1 +), STRUCT( + 2, + TRUE, + CAST(b'\xc2\xa1Hola Mundo!' AS BYTES), + CAST('2023-03-01' AS DATE), + CAST('2023-03-01T10:55:13' AS DATETIME), + ST_GEOGFROMTEXT('POINT(-0.124474760143016 51.5007826749545)'), + 314159, + 0, + CAST(101.101010100 AS NUMERIC), + 25000000000.0, + 2, + 2, + ' ¡Hola Mundo! ', + CAST('23:59:59.999999' AS TIME), + CAST('2023-03-01T10:55:13.250125+00:00' AS TIMESTAMP), + 0, + 2 +), STRUCT( + 3, + CAST(NULL AS BOOLEAN), + CAST(NULL AS BYTES), + CAST(NULL AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + CAST(NULL AS INT64), + 1, + CAST(NULL AS NUMERIC), + CAST(NULL AS FLOAT64), + 3, + 3, + CAST(NULL AS STRING), + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + CAST(NULL AS INT64), + 3 +), STRUCT( + 4, + FALSE, + CAST(b'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf' AS BYTES), + CAST('2021-07-21' AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + -234892, + -2345, + CAST(NULL AS NUMERIC), + CAST(NULL AS FLOAT64), + 4, + 4, + 'Hello, World!', + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + 31540000000000, + 4 +), STRUCT( + 5, + FALSE, + CAST(b'G\xc3\xbcten Tag' AS BYTES), + CAST('1980-03-14' AS DATE), + CAST('1980-03-14T15:16:17' AS DATETIME), + CAST(NULL AS GEOGRAPHY), + 55555, + 0, + CAST(5.555555000 AS NUMERIC), + 555.555, + 5, + 5, + 'Güten Tag!', + CAST('15:16:17.181921' AS TIME), + CAST('1980-03-14T15:16:17.181921+00:00' AS TIMESTAMP), + 4, + 5 +), STRUCT( + 6, + TRUE, + CAST(b'Hello\tBigFrames!\x07' AS BYTES), + CAST('2023-05-23' AS DATE), + CAST('2023-05-23T11:37:01' AS DATETIME), + ST_GEOGFROMTEXT('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), + 101202303, + 2, + CAST(-10.090807000 AS NUMERIC), + -123.456, + 6, + 6, + 'capitalize, This ', + CAST('01:02:03.456789' AS TIME), + CAST('2023-05-23T11:42:55.000001+00:00' AS TIMESTAMP), + CAST(NULL AS INT64), + 6 +), STRUCT( + 7, + TRUE, + CAST(NULL AS BYTES), + CAST('2038-01-20' AS DATE), + CAST('2038-01-19T03:14:08' AS DATETIME), + CAST(NULL AS GEOGRAPHY), + -214748367, + 2, + CAST(11111111.100000000 AS NUMERIC), + 42.42, + 7, + 7, + ' سلام', + CAST('12:00:00.000001' AS TIME), + CAST('2038-01-19T03:14:17.999999+00:00' AS TIMESTAMP), + 4, + 7 +), STRUCT( + 8, + FALSE, + CAST(NULL AS BYTES), + CAST(NULL AS DATE), + CAST(NULL AS DATETIME), + CAST(NULL AS GEOGRAPHY), + 2, + 1, + CAST(NULL AS NUMERIC), + 6.87, + 8, + 8, + 'T', + CAST(NULL AS TIME), + CAST(NULL AS TIMESTAMP), + 432000000000, + 8 +)]) ORDER BY `bfcol_16` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql index 029546f3d0f..239399a3395 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_json_df/out.sql @@ -1,10 +1,6 @@ SELECT `bfcol_0` AS `rowindex`, `bfcol_1` AS `json_col` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(0, PARSE_JSON('null'), 0), STRUCT(1, PARSE_JSON('true'), 1), STRUCT(2, PARSE_JSON('100'), 2), STRUCT(3, PARSE_JSON('0.98'), 3), STRUCT(4, PARSE_JSON('"a string"'), 4), STRUCT(5, PARSE_JSON('[]'), 5), STRUCT(6, PARSE_JSON('[1,2,3]'), 6), STRUCT(7, PARSE_JSON('[{"a":1},{"a":2},{"a":null},{}]'), 7), STRUCT(8, PARSE_JSON('"100"'), 8), STRUCT(9, PARSE_JSON('{"date":"2024-07-16"}'), 9), STRUCT(10, PARSE_JSON('{"int_value":2,"null_filed":null}'), 10), STRUCT(11, PARSE_JSON('{"list_data":[10,20,30]}'), 11)]) -) +FROM UNNEST(ARRAY>[STRUCT(0, PARSE_JSON('null'), 0), STRUCT(1, PARSE_JSON('true'), 1), STRUCT(2, PARSE_JSON('100'), 2), STRUCT(3, PARSE_JSON('0.98'), 3), STRUCT(4, PARSE_JSON('"a string"'), 4), STRUCT(5, PARSE_JSON('[]'), 5), STRUCT(6, PARSE_JSON('[1,2,3]'), 6), STRUCT(7, PARSE_JSON('[{"a":1},{"a":2},{"a":null},{}]'), 7), STRUCT(8, PARSE_JSON('"100"'), 8), STRUCT(9, PARSE_JSON('{"date":"2024-07-16"}'), 9), STRUCT(10, PARSE_JSON('{"int_value":2,"null_filed":null}'), 10), STRUCT(11, PARSE_JSON('{"list_data":[10,20,30]}'), 11)]) ORDER BY `bfcol_2` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql index 161487c07a1..c183d81383a 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_lists_df/out.sql @@ -7,40 +7,36 @@ SELECT `bfcol_5` AS `date_time_list_col`, `bfcol_6` AS `numeric_list_col`, `bfcol_7` AS `string_list_col` -FROM ( - SELECT - * - FROM UNNEST(ARRAY, `bfcol_2` ARRAY, `bfcol_3` ARRAY, `bfcol_4` ARRAY, `bfcol_5` ARRAY, `bfcol_6` ARRAY, `bfcol_7` ARRAY, `bfcol_8` INT64>>[STRUCT( - 0, - [1], - [TRUE], - [1.2, 2.3], - ['2021-07-21'], - ['2021-07-21 11:39:45'], - [1.2, 2.3, 3.4], - ['abc', 'de', 'f'], - 0 - ), STRUCT( - 1, - [1, 2], - [TRUE, FALSE], - [1.1], - ['2021-07-21', '1987-03-28'], - ['1999-03-14 17:22:00'], - [5.5, 2.3], - ['a', 'bc', 'de'], - 1 - ), STRUCT( - 2, - [1, 2, 3], - [TRUE], - [0.5, -1.9, 2.3], - ['2017-08-01', '2004-11-22'], - ['1979-06-03 03:20:45'], - [1.7000000000000002], - ['', 'a'], - 2 - )]) -) +FROM UNNEST(ARRAY, `bfcol_2` ARRAY, `bfcol_3` ARRAY, `bfcol_4` ARRAY, `bfcol_5` ARRAY, `bfcol_6` ARRAY, `bfcol_7` ARRAY, `bfcol_8` INT64>>[STRUCT( + 0, + [1], + [TRUE], + [1.2, 2.3], + ['2021-07-21'], + ['2021-07-21 11:39:45'], + [1.2, 2.3, 3.4], + ['abc', 'de', 'f'], + 0 +), STRUCT( + 1, + [1, 2], + [TRUE, FALSE], + [1.1], + ['2021-07-21', '1987-03-28'], + ['1999-03-14 17:22:00'], + [5.5, 2.3], + ['a', 'bc', 'de'], + 1 +), STRUCT( + 2, + [1, 2, 3], + [TRUE], + [0.5, -1.9, 2.3], + ['2017-08-01', '2004-11-22'], + ['1979-06-03 03:20:45'], + [1.7000000000000002], + ['', 'a'], + 2 +)]) ORDER BY `bfcol_8` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql index 223046f3a8e..d9abf158c80 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_special_values/out.sql @@ -6,19 +6,15 @@ SELECT `bfcol_4` AS `col_struct_none`, `bfcol_5` AS `col_struct_w_none`, `bfcol_6` AS `col_list_none` -FROM ( - SELECT - * - FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( - CAST(NULL AS FLOAT64), - CAST('Infinity' AS FLOAT64), - CAST('-Infinity' AS FLOAT64), - CAST(NULL AS FLOAT64), - CAST(NULL AS STRUCT), - STRUCT(CAST(NULL AS INT64) AS `foo`), - ARRAY[], - 0 - ), STRUCT(1.0, 1.0, 1.0, 1.0, STRUCT(1 AS `foo`), STRUCT(1 AS `foo`), [1, 2], 1), STRUCT(2.0, 2.0, 2.0, 2.0, STRUCT(2 AS `foo`), STRUCT(2 AS `foo`), [3, 4], 2)]) -) +FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( + CAST(NULL AS FLOAT64), + CAST('Infinity' AS FLOAT64), + CAST('-Infinity' AS FLOAT64), + CAST(NULL AS FLOAT64), + CAST(NULL AS STRUCT), + STRUCT(CAST(NULL AS INT64) AS `foo`), + ARRAY[], + 0 +), STRUCT(1.0, 1.0, 1.0, 1.0, STRUCT(1 AS `foo`), STRUCT(1 AS `foo`), [1, 2], 1), STRUCT(2.0, 2.0, 2.0, 2.0, STRUCT(2 AS `foo`), STRUCT(2 AS `foo`), [3, 4], 2)]) ORDER BY `bfcol_7` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql index f008ece2ca7..75b8d52d714 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readlocal/test_compile_readlocal_w_structs_df/out.sql @@ -1,26 +1,22 @@ SELECT `bfcol_0` AS `id`, `bfcol_1` AS `person` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( - 1, - STRUCT( - 'Alice' AS `name`, - 30 AS `age`, - STRUCT('New York' AS `city`, 'USA' AS `country`) AS `address` - ), - 0 - ), STRUCT( - 2, - STRUCT( - 'Bob' AS `name`, - 25 AS `age`, - STRUCT('London' AS `city`, 'UK' AS `country`) AS `address` - ), - 1 - )]) -) +FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( + 1, + STRUCT( + 'Alice' AS `name`, + 30 AS `age`, + STRUCT('New York' AS `city`, 'USA' AS `country`) AS `address` + ), + 0 +), STRUCT( + 2, + STRUCT( + 'Bob' AS `name`, + 25 AS `age`, + STRUCT('London' AS `city`, 'UK' AS `country`) AS `address` + ), + 1 +)]) ORDER BY `bfcol_2` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql index 90f18a0a93c..ecb39603f3c 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_range_rolling/out.sql @@ -20,11 +20,7 @@ SELECT 0 ) END AS `int_col` -FROM ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT(CAST('2025-01-01T00:00:00+00:00' AS TIMESTAMP), 0, 0), STRUCT(CAST('2025-01-01T00:00:01+00:00' AS TIMESTAMP), 1, 1), STRUCT(CAST('2025-01-01T00:00:02+00:00' AS TIMESTAMP), 2, 2), STRUCT(CAST('2025-01-01T00:00:03+00:00' AS TIMESTAMP), 3, 3), STRUCT(CAST('2025-01-01T00:00:04+00:00' AS TIMESTAMP), 0, 4), STRUCT(CAST('2025-01-01T00:00:05+00:00' AS TIMESTAMP), 1, 5), STRUCT(CAST('2025-01-01T00:00:06+00:00' AS TIMESTAMP), 2, 6), STRUCT(CAST('2025-01-01T00:00:07+00:00' AS TIMESTAMP), 3, 7), STRUCT(CAST('2025-01-01T00:00:08+00:00' AS TIMESTAMP), 0, 8), STRUCT(CAST('2025-01-01T00:00:09+00:00' AS TIMESTAMP), 1, 9), STRUCT(CAST('2025-01-01T00:00:10+00:00' AS TIMESTAMP), 2, 10), STRUCT(CAST('2025-01-01T00:00:11+00:00' AS TIMESTAMP), 3, 11), STRUCT(CAST('2025-01-01T00:00:12+00:00' AS TIMESTAMP), 0, 12), STRUCT(CAST('2025-01-01T00:00:13+00:00' AS TIMESTAMP), 1, 13), STRUCT(CAST('2025-01-01T00:00:14+00:00' AS TIMESTAMP), 2, 14), STRUCT(CAST('2025-01-01T00:00:15+00:00' AS TIMESTAMP), 3, 15), STRUCT(CAST('2025-01-01T00:00:16+00:00' AS TIMESTAMP), 0, 16), STRUCT(CAST('2025-01-01T00:00:17+00:00' AS TIMESTAMP), 1, 17), STRUCT(CAST('2025-01-01T00:00:18+00:00' AS TIMESTAMP), 2, 18), STRUCT(CAST('2025-01-01T00:00:19+00:00' AS TIMESTAMP), 3, 19)]) -) +FROM UNNEST(ARRAY>[STRUCT(CAST('2025-01-01T00:00:00+00:00' AS TIMESTAMP), 0, 0), STRUCT(CAST('2025-01-01T00:00:01+00:00' AS TIMESTAMP), 1, 1), STRUCT(CAST('2025-01-01T00:00:02+00:00' AS TIMESTAMP), 2, 2), STRUCT(CAST('2025-01-01T00:00:03+00:00' AS TIMESTAMP), 3, 3), STRUCT(CAST('2025-01-01T00:00:04+00:00' AS TIMESTAMP), 0, 4), STRUCT(CAST('2025-01-01T00:00:05+00:00' AS TIMESTAMP), 1, 5), STRUCT(CAST('2025-01-01T00:00:06+00:00' AS TIMESTAMP), 2, 6), STRUCT(CAST('2025-01-01T00:00:07+00:00' AS TIMESTAMP), 3, 7), STRUCT(CAST('2025-01-01T00:00:08+00:00' AS TIMESTAMP), 0, 8), STRUCT(CAST('2025-01-01T00:00:09+00:00' AS TIMESTAMP), 1, 9), STRUCT(CAST('2025-01-01T00:00:10+00:00' AS TIMESTAMP), 2, 10), STRUCT(CAST('2025-01-01T00:00:11+00:00' AS TIMESTAMP), 3, 11), STRUCT(CAST('2025-01-01T00:00:12+00:00' AS TIMESTAMP), 0, 12), STRUCT(CAST('2025-01-01T00:00:13+00:00' AS TIMESTAMP), 1, 13), STRUCT(CAST('2025-01-01T00:00:14+00:00' AS TIMESTAMP), 2, 14), STRUCT(CAST('2025-01-01T00:00:15+00:00' AS TIMESTAMP), 3, 15), STRUCT(CAST('2025-01-01T00:00:16+00:00' AS TIMESTAMP), 0, 16), STRUCT(CAST('2025-01-01T00:00:17+00:00' AS TIMESTAMP), 1, 17), STRUCT(CAST('2025-01-01T00:00:18+00:00' AS TIMESTAMP), 2, 18), STRUCT(CAST('2025-01-01T00:00:19+00:00' AS TIMESTAMP), 3, 19)]) ORDER BY `bfcol_0` ASC NULLS LAST, `bfcol_2` ASC NULLS LAST \ No newline at end of file From 5717cfcf08747ca74e72268ef0ed0aff50f0d921 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Sat, 7 Mar 2026 01:50:06 +0000 Subject: [PATCH 14/15] avoid more select stars --- bigframes/core/compile/sqlglot/compiler.py | 2 +- bigframes/core/compile/sqlglot/sqlglot_ir.py | 34 ++++----- .../test_compile_fromrange/out.sql | 72 ++++++++----------- .../test_compile_join/out.sql | 28 ++++---- .../test_compile_join_w_on/bool_col/out.sql | 28 ++++---- .../float64_col/out.sql | 28 ++++---- .../test_compile_join_w_on/int64_col/out.sql | 28 ++++---- .../numeric_col/out.sql | 28 ++++---- .../test_compile_join_w_on/string_col/out.sql | 18 ++--- .../test_compile_join_w_on/time_col/out.sql | 18 ++--- .../out.sql | 10 +-- 11 files changed, 121 insertions(+), 173 deletions(-) diff --git a/bigframes/core/compile/sqlglot/compiler.py b/bigframes/core/compile/sqlglot/compiler.py index 0f84c4d09da..2f549b943a2 100644 --- a/bigframes/core/compile/sqlglot/compiler.py +++ b/bigframes/core/compile/sqlglot/compiler.py @@ -293,7 +293,7 @@ def compile_concat( ] return sqlglot_ir.SQLGlotIR.from_union( - [child._as_select() for child in children], + [child.expr.as_select_all() for child in children], output_aliases=output_aliases, uid_gen=uid_gen, ) diff --git a/bigframes/core/compile/sqlglot/sqlglot_ir.py b/bigframes/core/compile/sqlglot/sqlglot_ir.py index 5b107b54ae5..c815dbfd417 100644 --- a/bigframes/core/compile/sqlglot/sqlglot_ir.py +++ b/bigframes/core/compile/sqlglot/sqlglot_ir.py @@ -254,11 +254,6 @@ def select( limit: typing.Optional[int] = None, ) -> SQLGlotIR: # TODO: Explicitly insert CTEs into plan - new_expr = sge.Select().from_(self._as_from_item()) - - if len(sorting) > 0: - new_expr = new_expr.order_by(*sorting) - if len(selections) > 0: to_select = [ sge.Alias( @@ -269,9 +264,12 @@ def select( else expr for id, expr in selections ] - new_expr = new_expr.select(*to_select, append=False) + new_expr = self.expr.select(*to_select) else: - new_expr = new_expr.select(sge.Star(), append=False) + new_expr = self.expr.as_select_all() + + if len(sorting) > 0: + new_expr = new_expr.order_by(*sorting) if len(predicates) > 0: condition = _and(predicates) @@ -340,8 +338,8 @@ def join( joins_nulls: bool = True, ) -> SQLGlotIR: """Joins the current query with another SQLGlotIR instance.""" - left_from = self._as_from_item() - right_from = right._as_from_item() + left_from = self.expr.as_from_item() + right_from = right.expr.as_from_item() join_on = _and( tuple( @@ -365,7 +363,7 @@ def isin_join( joins_nulls: bool = True, ) -> SQLGlotIR: """Joins the current query with another SQLGlotIR instance.""" - left_from = self._as_from_item() + left_from = self.expr.as_from_item() new_column: sge.Expression if joins_nulls: @@ -470,12 +468,12 @@ def with_ctes( ) -> SQLGlotIR: sge_ctes = [ sge.CTE( - this=cte._as_select(), + this=cte.expr.as_select_all(), alias=sql.identifier(cte_name), ) for cte_name, cte in ctes ] - select_expr = _set_query_ctes(self._as_select(), sge_ctes) + select_expr = _set_query_ctes(self.expr.as_select_all(), sge_ctes) return SQLGlotIR.from_expr(expr=select_expr, uid_gen=self.uid_gen) def resample( @@ -507,8 +505,8 @@ def resample( new_expr = ( sge.Select() .select(unnested_column_alias.as_(final_col_id)) - .from_(self._as_from_item()) - .join(right._as_from_item(), join_type="cross") + .from_(self.expr.as_from_item()) + .join(right.expr.as_from_item(), join_type="cross") .join(unnest_expr, join_type="cross") ) @@ -574,15 +572,9 @@ def _explode_multiple_columns( new_expr = self.expr.select(selection).join(unnest_expr, join_type="LEFT") return SQLGlotIR.from_expr(expr=new_expr, uid_gen=self.uid_gen) - def _as_from_item(self) -> typing.Union[sge.Subquery, sge.Table, sge.Unnest]: - return self.expr.as_from_item() - - def _as_select(self) -> sge.Select: - return self.expr.as_select_all() - def _as_subquery(self) -> sge.Subquery: # Sometimes explicitly need a subquery, e.g. for IN expressions. - return self._as_select().subquery() + return self.expr.as_select_all().subquery() def _and(conditions: tuple[sge.Expression, ...]) -> typing.Optional[sge.Expression]: diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql index 0dedff7823d..437bfefa177 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_fromrange/test_compile_fromrange/out.sql @@ -14,12 +14,8 @@ WITH `bfcte_0` AS ( 7000000 ) ) AS INT64) AS `bfcol_14` - FROM ( - SELECT - * - FROM `bfcte_0` - CROSS JOIN `bfcte_1` - ) + FROM `bfcte_0` + CROSS JOIN `bfcte_1` ) SELECT CAST(TIMESTAMP_MICROS( @@ -32,48 +28,40 @@ FROM ( * FROM ( SELECT - * + `bfcol_27` AS `bfcol_17` FROM ( SELECT - `bfcol_27` AS `bfcol_17` - FROM ( - SELECT - MIN(`bfcol_14`) AS `bfcol_16` - FROM `bfcte_2` - ) - CROSS JOIN ( - SELECT - MAX(`bfcol_14`) AS `bfcol_15` - FROM `bfcte_2` - ) - CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_16`, `bfcol_15`, 1)) AS `bfcol_27` + MIN(`bfcol_14`) AS `bfcol_16` + FROM `bfcte_2` ) - CROSS JOIN `bfcte_1` - ) - LEFT JOIN ( - SELECT - `bfcol_6` AS `bfcol_11`, - `bfcol_7` AS `bfcol_12`, - CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`bfcol_5` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_8` AS DATE) AS TIMESTAMP)), - 7000000 - ) - ) AS INT64) AS `bfcol_13` - FROM ( + CROSS JOIN ( SELECT - * - FROM ( - SELECT - `bfcol_1` AS `bfcol_5`, - `bfcol_2` AS `bfcol_6`, - `bfcol_3` AS `bfcol_7` - FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) - ) - CROSS JOIN `bfcte_1` + MAX(`bfcol_14`) AS `bfcol_15` + FROM `bfcte_2` ) + CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_16`, `bfcol_15`, 1)) AS `bfcol_27` + ) + CROSS JOIN `bfcte_1` +) +LEFT JOIN ( + SELECT + `bfcol_6` AS `bfcol_11`, + `bfcol_7` AS `bfcol_12`, + CAST(FLOOR( + IEEE_DIVIDE( + UNIX_MICROS(CAST(`bfcol_5` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`bfcol_8` AS DATE) AS TIMESTAMP)), + 7000000 + ) + ) AS INT64) AS `bfcol_13` + FROM ( + SELECT + `bfcol_1` AS `bfcol_5`, + `bfcol_2` AS `bfcol_6`, + `bfcol_3` AS `bfcol_7` + FROM UNNEST(ARRAY>[STRUCT(CAST('2021-01-01T13:00:00' AS DATETIME), 0, 10), STRUCT(CAST('2021-01-01T13:00:01' AS DATETIME), 1, 11), STRUCT(CAST('2021-01-01T13:00:02' AS DATETIME), 2, 12), STRUCT(CAST('2021-01-01T13:00:03' AS DATETIME), 3, 13), STRUCT(CAST('2021-01-01T13:00:04' AS DATETIME), 4, 14), STRUCT(CAST('2021-01-01T13:00:05' AS DATETIME), 5, 15), STRUCT(CAST('2021-01-01T13:00:06' AS DATETIME), 6, 16), STRUCT(CAST('2021-01-01T13:00:07' AS DATETIME), 7, 17), STRUCT(CAST('2021-01-01T13:00:08' AS DATETIME), 8, 18), STRUCT(CAST('2021-01-01T13:00:09' AS DATETIME), 9, 19), STRUCT(CAST('2021-01-01T13:00:10' AS DATETIME), 10, 20), STRUCT(CAST('2021-01-01T13:00:11' AS DATETIME), 11, 21), STRUCT(CAST('2021-01-01T13:00:12' AS DATETIME), 12, 22), STRUCT(CAST('2021-01-01T13:00:13' AS DATETIME), 13, 23), STRUCT(CAST('2021-01-01T13:00:14' AS DATETIME), 14, 24), STRUCT(CAST('2021-01-01T13:00:15' AS DATETIME), 15, 25), STRUCT(CAST('2021-01-01T13:00:16' AS DATETIME), 16, 26), STRUCT(CAST('2021-01-01T13:00:17' AS DATETIME), 17, 27), STRUCT(CAST('2021-01-01T13:00:18' AS DATETIME), 18, 28), STRUCT(CAST('2021-01-01T13:00:19' AS DATETIME), 19, 29), STRUCT(CAST('2021-01-01T13:00:20' AS DATETIME), 20, 30), STRUCT(CAST('2021-01-01T13:00:21' AS DATETIME), 21, 31), STRUCT(CAST('2021-01-01T13:00:22' AS DATETIME), 22, 32), STRUCT(CAST('2021-01-01T13:00:23' AS DATETIME), 23, 33), STRUCT(CAST('2021-01-01T13:00:24' AS DATETIME), 24, 34), STRUCT(CAST('2021-01-01T13:00:25' AS DATETIME), 25, 35), STRUCT(CAST('2021-01-01T13:00:26' AS DATETIME), 26, 36), STRUCT(CAST('2021-01-01T13:00:27' AS DATETIME), 27, 37), STRUCT(CAST('2021-01-01T13:00:28' AS DATETIME), 28, 38), STRUCT(CAST('2021-01-01T13:00:29' AS DATETIME), 29, 39)]) ) - ON `bfcol_17` = `bfcol_13` + CROSS JOIN `bfcte_1` ) + ON `bfcol_17` = `bfcol_13` ORDER BY `bfcol_17` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql index dbc751213d1..389399e0208 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join/out.sql @@ -3,19 +3,15 @@ SELECT `bfcol_5` AS `int64_too` FROM ( SELECT - * - FROM ( - SELECT - `rowindex` AS `bfcol_6`, - `int64_col` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ) - LEFT JOIN ( - SELECT - `int64_col` AS `bfcol_4`, - `int64_too` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - ) - ON COALESCE(`bfcol_6`, 0) = COALESCE(`bfcol_4`, 0) - AND COALESCE(`bfcol_6`, 1) = COALESCE(`bfcol_4`, 1) -) \ No newline at end of file + `rowindex` AS `bfcol_6`, + `int64_col` AS `bfcol_7` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` +) +LEFT JOIN ( + SELECT + `int64_col` AS `bfcol_4`, + `int64_too` AS `bfcol_5` + FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` +) + ON COALESCE(`bfcol_6`, 0) = COALESCE(`bfcol_4`, 0) + AND COALESCE(`bfcol_6`, 1) = COALESCE(`bfcol_4`, 1) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql index a2f5aabe796..e8540dc7c29 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/bool_col/out.sql @@ -10,19 +10,15 @@ SELECT `bfcol_2` AS `rowindex_y` FROM ( SELECT - * - FROM ( - SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` - ) - INNER JOIN ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` - ) - ON COALESCE(CAST(`bfcol_5` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') - AND COALESCE(CAST(`bfcol_5` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') -) \ No newline at end of file + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` +) +INNER JOIN ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` +) + ON COALESCE(CAST(`bfcol_5` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') + AND COALESCE(CAST(`bfcol_5` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql index 1f1aac0b627..6a882cf1ee4 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/float64_col/out.sql @@ -10,19 +10,15 @@ SELECT `bfcol_2` AS `rowindex_y` FROM ( SELECT - * - FROM ( - SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` - ) - INNER JOIN ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` - ) - ON IF(IS_NAN(`bfcol_5`), 2, COALESCE(`bfcol_5`, 0)) = IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) - AND IF(IS_NAN(`bfcol_5`), 3, COALESCE(`bfcol_5`, 1)) = IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) -) \ No newline at end of file + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` +) +INNER JOIN ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` +) + ON IF(IS_NAN(`bfcol_5`), 2, COALESCE(`bfcol_5`, 0)) = IF(IS_NAN(`bfcol_3`), 2, COALESCE(`bfcol_3`, 0)) + AND IF(IS_NAN(`bfcol_5`), 3, COALESCE(`bfcol_5`, 1)) = IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1)) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql index c9381f53b3a..7b69d046faf 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/int64_col/out.sql @@ -10,19 +10,15 @@ SELECT `bfcol_2` AS `rowindex_y` FROM ( SELECT - * - FROM ( - SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` - ) - INNER JOIN ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` - ) - ON COALESCE(`bfcol_5`, 0) = COALESCE(`bfcol_3`, 0) - AND COALESCE(`bfcol_5`, 1) = COALESCE(`bfcol_3`, 1) -) \ No newline at end of file + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` +) +INNER JOIN ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` +) + ON COALESCE(`bfcol_5`, 0) = COALESCE(`bfcol_3`, 0) + AND COALESCE(`bfcol_5`, 1) = COALESCE(`bfcol_3`, 1) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql index 29ad38feace..c2f3c480314 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/numeric_col/out.sql @@ -10,19 +10,15 @@ SELECT `bfcol_2` AS `rowindex_y` FROM ( SELECT - * - FROM ( - SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` - ) - INNER JOIN ( - SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` - ) - ON COALESCE(`bfcol_5`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) - AND COALESCE(`bfcol_5`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) -) \ No newline at end of file + `bfcol_1` AS `bfcol_4`, + `bfcol_0` AS `bfcol_5` + FROM `bfcte_0` +) +INNER JOIN ( + SELECT + `bfcol_1` AS `bfcol_2`, + `bfcol_0` AS `bfcol_3` + FROM `bfcte_0` +) + ON COALESCE(`bfcol_5`, CAST(0 AS NUMERIC)) = COALESCE(`bfcol_3`, CAST(0 AS NUMERIC)) + AND COALESCE(`bfcol_5`, CAST(1 AS NUMERIC)) = COALESCE(`bfcol_3`, CAST(1 AS NUMERIC)) \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql index 44e384d90a7..bcc533e7c97 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/string_col/out.sql @@ -8,16 +8,12 @@ SELECT `bfcol_0` AS `rowindex_x`, `bfcol_1` AS `string_col`, `bfcol_2` AS `rowindex_y` -FROM ( +FROM `bfcte_0` +INNER JOIN ( SELECT - * + `bfcol_0` AS `bfcol_2`, + `bfcol_1` AS `bfcol_3` FROM `bfcte_0` - INNER JOIN ( - SELECT - `bfcol_0` AS `bfcol_2`, - `bfcol_1` AS `bfcol_3` - FROM `bfcte_0` - ) - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') -) \ No newline at end of file +) + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql index 6a7fd06c35b..d0f72da6ead 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_join/test_compile_join_w_on/time_col/out.sql @@ -8,16 +8,12 @@ SELECT `bfcol_0` AS `rowindex_x`, `bfcol_1` AS `time_col`, `bfcol_2` AS `rowindex_y` -FROM ( +FROM `bfcte_0` +INNER JOIN ( SELECT - * + `bfcol_0` AS `bfcol_2`, + `bfcol_1` AS `bfcol_3` FROM `bfcte_0` - INNER JOIN ( - SELECT - `bfcol_0` AS `bfcol_2`, - `bfcol_1` AS `bfcol_3` - FROM `bfcte_0` - ) - ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') - AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') -) \ No newline at end of file +) + ON COALESCE(CAST(`bfcol_1` AS STRING), '0') = COALESCE(CAST(`bfcol_3` AS STRING), '0') + AND COALESCE(CAST(`bfcol_1` AS STRING), '1') = COALESCE(CAST(`bfcol_3` AS STRING), '1') \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql index 571551ce99f..2b71ef917d9 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_columns_filters/out.sql @@ -1,9 +1,5 @@ SELECT * -FROM ( - SELECT - * - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - `rowindex` > 0 AND `string_col` IN ('Hello, World!') -) \ No newline at end of file +FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` +WHERE + `rowindex` > 0 AND `string_col` IN ('Hello, World!') \ No newline at end of file From b7d360ab91f680b06c10fb796bc1fa46f6817432 Mon Sep 17 00:00:00 2001 From: Trevor Bergeron Date: Sat, 7 Mar 2026 01:57:43 +0000 Subject: [PATCH 15/15] fix identifier tests --- bigframes/core/rewrite/identifiers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bigframes/core/rewrite/identifiers.py b/bigframes/core/rewrite/identifiers.py index 0b36e861528..fbedb4fa1ed 100644 --- a/bigframes/core/rewrite/identifiers.py +++ b/bigframes/core/rewrite/identifiers.py @@ -109,5 +109,9 @@ def remap_variables( # have to do top down to preserve node identities return ( root.top_down(_create_mapping_operator(id_def_remaps, id_ref_remaps)), - id_def_remaps[root], + # Only used by unit tests + { + old_id: (id_def_remaps[root] | id_ref_remaps[root])[old_id] + for old_id in root.ids + }, )