From 00f733408c2f58c56a47eb51ebae5f59b16c5af8 Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Tue, 22 Jul 2025 20:57:03 +0000 Subject: [PATCH 1/2] switch golden tests to ibis compiler --- bigframes/testing/compiler_session.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/bigframes/testing/compiler_session.py b/bigframes/testing/compiler_session.py index b248f37cfc8..f2992babc49 100644 --- a/bigframes/testing/compiler_session.py +++ b/bigframes/testing/compiler_session.py @@ -17,6 +17,7 @@ import bigframes.core import bigframes.core.compile as compile +from bigframes.core.compile.ibis_compiler import ibis_compiler import bigframes.session.executor @@ -24,8 +25,6 @@ class SQLCompilerExecutor(bigframes.session.executor.Executor): """Executor for SQL compilation using sqlglot.""" - compiler = compile.sqlglot - def to_sql( self, array_value: bigframes.core.ArrayValue, @@ -38,9 +37,9 @@ def to_sql( # Compared with BigQueryCachingExecutor, SQLCompilerExecutor skips # caching the subtree. - return self.compiler.compile_sql( - compile.CompileRequest(array_value.node, sort_rows=ordered) - ).sql + request = compile.CompileRequest(array_value.node, sort_rows=ordered) + compiled = ibis_compiler.compile_sql(request) + return compiled.sql def execute( self, From 59c3090ee8a042e916f70c2e75f11219a2e499aa Mon Sep 17 00:00:00 2001 From: Chelsea Lin Date: Thu, 26 Mar 2026 18:50:26 +0000 Subject: [PATCH 2/2] update snapshots --- .../test_binary_compiler/test_corr/out.sql | 23 +- .../test_binary_compiler/test_cov/out.sql | 23 +- .../test_row_number/out.sql | 8 +- .../test_row_number_with_window/out.sql | 8 +- .../test_nullary_compiler/test_size/out.sql | 21 +- .../test_array_agg/out.sql | 23 +- .../test_string_agg/out.sql | 29 +- .../test_unary_compiler/test_all/out.sql | 26 +- .../test_all_w_window/out.sql | 14 +- .../test_unary_compiler/test_any/out.sql | 26 +- .../test_any_value/out.sql | 21 +- .../test_any_value/window_out.sql | 11 +- .../test_any_value/window_partition_out.sql | 13 +- .../test_any_w_window/out.sql | 14 +- .../test_approx_quartiles/out.sql | 27 +- .../test_approx_top_count/out.sql | 21 +- .../test_unary_compiler/test_count/out.sql | 21 +- .../test_count/window_out.sql | 11 +- .../test_count/window_partition_out.sql | 13 +- .../test_unary_compiler/test_cut/int_bins.sql | 69 ++- .../test_cut/int_bins_labels.sql | 25 +- .../test_cut/interval_bins.sql | 15 +- .../test_cut/interval_bins_labels.sql | 15 +- .../test_diff_w_bool/out.sql | 8 +- .../test_diff_w_date/out.sql | 12 +- .../test_diff_w_datetime/out.sql | 10 +- .../test_diff_w_int/out.sql | 8 +- .../test_diff_w_timestamp/out.sql | 10 +- .../test_unary_compiler/test_first/out.sql | 10 +- .../test_first_non_null/out.sql | 10 +- .../test_unary_compiler/test_last/out.sql | 10 +- .../test_last_non_null/out.sql | 10 +- .../test_unary_compiler/test_max/out.sql | 21 +- .../test_max/window_out.sql | 11 +- .../test_max/window_partition_out.sql | 13 +- .../test_unary_compiler/test_mean/out.sql | 37 +- .../test_mean/window_out.sql | 11 +- .../test_mean/window_partition_out.sql | 13 +- .../test_unary_compiler/test_median/out.sql | 31 +- .../test_unary_compiler/test_min/out.sql | 21 +- .../test_min/window_out.sql | 11 +- .../test_min/window_partition_out.sql | 13 +- .../test_unary_compiler/test_nunique/out.sql | 21 +- .../test_unary_compiler/test_pop_var/out.sql | 26 +- .../test_pop_var/window_out.sql | 11 +- .../test_unary_compiler/test_product/out.sql | 32 +- .../test_product/window_partition_out.sql | 29 +- .../test_unary_compiler/test_qcut/out.sql | 127 +++-- .../test_unary_compiler/test_quantile/out.sql | 29 +- .../test_unary_compiler/test_rank/out.sql | 10 +- .../test_unary_compiler/test_shift/lag.sql | 8 +- .../test_unary_compiler/test_shift/lead.sql | 8 +- .../test_unary_compiler/test_shift/noop.sql | 4 +- .../test_unary_compiler/test_std/out.sql | 37 +- .../test_std/window_out.sql | 11 +- .../test_unary_compiler/test_sum/out.sql | 26 +- .../test_sum/window_out.sql | 14 +- .../test_sum/window_partition_out.sql | 16 +- .../test_unary_compiler/test_var/out.sql | 26 +- .../test_var/window_out.sql | 11 +- .../test_ai_ops/test_ai_classify/None/out.sql | 7 +- .../out.sql | 4 +- .../test_ai_ops/test_ai_generate/out.sql | 8 +- .../test_ai_ops/test_ai_generate_bool/out.sql | 8 +- .../out.sql | 8 +- .../out.sql | 8 +- .../test_ai_generate_double/out.sql | 8 +- .../out.sql | 8 +- .../out.sql | 8 +- .../test_ai_ops/test_ai_generate_int/out.sql | 8 +- .../out.sql | 8 +- .../out.sql | 8 +- .../out.sql | 8 +- .../test_ai_generate_with_model_param/out.sql | 8 +- .../out.sql | 8 +- .../test_ai_ops/test_ai_if/None/out.sql | 10 +- .../out.sql | 8 +- .../test_ai_ops/test_ai_score/None/out.sql | 10 +- .../out.sql | 8 +- .../test_array_ops/test_array_index/out.sql | 14 +- .../test_array_reduce_op/out.sql | 22 +- .../test_array_ops/test_array_slice/out.sql | 43 +- .../test_array_to_string/out.sql | 4 +- .../test_array_ops/test_to_array_op/out.sql | 14 +- .../test_obj_fetch_metadata/out.sql | 15 +- .../test_obj_get_access_url/out.sql | 15 +- .../out.sql | 8 +- .../test_blob_ops/test_obj_make_ref/out.sql | 11 +- .../test_obj_make_ref_json/out.sql | 8 +- .../test_bool_ops/test_and_op/out.sql | 16 +- .../test_bool_ops/test_or_op/out.sql | 16 +- .../test_bool_ops/test_xor_op/out.sql | 25 +- .../test_eq_null_match/out.sql | 4 +- .../test_eq_numeric/out.sql | 20 +- .../test_ge_numeric/out.sql | 18 +- .../test_gt_numeric/out.sql | 18 +- .../test_comparison_ops/test_is_in/out.sql | 36 +- .../test_le_numeric/out.sql | 18 +- .../test_lt_numeric/out.sql | 18 +- .../test_maximum_op/out.sql | 12 +- .../test_minimum_op/out.sql | 12 +- .../test_ne_numeric/out.sql | 20 +- .../test_add_timedelta/out.sql | 16 +- .../test_datetime_ops/test_date/out.sql | 4 +- .../test_datetime_to_integer_label/out.sql | 149 ++++-- .../test_datetime_ops/test_day/out.sql | 4 +- .../test_datetime_ops/test_dayofweek/out.sql | 8 +- .../test_datetime_ops/test_dayofyear/out.sql | 4 +- .../test_datetime_ops/test_floor_dt/out.sql | 26 +- .../test_datetime_ops/test_hour/out.sql | 4 +- .../out.sql | 8 +- .../out.sql | 115 ++-- .../out.sql | 139 +++-- .../out.sql | 12 +- .../out.sql | 18 +- .../test_datetime_ops/test_iso_day/out.sql | 4 +- .../test_datetime_ops/test_iso_week/out.sql | 4 +- .../test_datetime_ops/test_iso_year/out.sql | 4 +- .../test_datetime_ops/test_minute/out.sql | 4 +- .../test_datetime_ops/test_month/out.sql | 4 +- .../test_datetime_ops/test_normalize/out.sql | 4 +- .../test_datetime_ops/test_quarter/out.sql | 4 +- .../test_datetime_ops/test_second/out.sql | 4 +- .../test_datetime_ops/test_strftime/out.sql | 10 +- .../test_sub_timedelta/out.sql | 26 +- .../test_datetime_ops/test_time/out.sql | 4 +- .../test_to_datetime/out.sql | 12 +- .../test_to_timestamp/out.sql | 25 +- .../test_unix_micros/out.sql | 8 +- .../test_unix_millis/out.sql | 8 +- .../test_unix_seconds/out.sql | 4 +- .../test_datetime_ops/test_year/out.sql | 4 +- .../test_generic_ops/test_astype_bool/out.sql | 8 +- .../test_astype_float/out.sql | 6 +- .../test_astype_from_json/out.sql | 16 +- .../test_generic_ops/test_astype_int/out.sql | 18 +- .../test_generic_ops/test_astype_json/out.sql | 67 ++- .../test_astype_string/out.sql | 46 +- .../test_astype_time_like/out.sql | 10 +- .../test_binary_remote_function_op/out.sql | 15 +- .../test_case_when_op/out.sql | 33 +- .../test_generic_ops/test_clip/out.sql | 4 +- .../test_generic_ops/test_coalesce/out.sql | 6 +- .../test_generic_ops/test_fillna/out.sql | 4 +- .../test_generic_ops/test_hash/out.sql | 4 +- .../test_generic_ops/test_invert/out.sql | 12 +- .../test_generic_ops/test_isnull/out.sql | 6 +- .../test_generic_ops/test_map/out.sql | 8 +- .../test_nary_remote_function_op/out.sql | 17 +- .../test_generic_ops/test_notnull/out.sql | 4 +- .../test_remote_function_op/out.sql | 24 +- .../test_generic_ops/test_row_key/out.sql | 72 +-- .../test_sql_scalar_op/out.sql | 4 +- .../test_generic_ops/test_where/out.sql | 4 +- .../test_geo_ops/test_geo_area/out.sql | 4 +- .../test_geo_ops/test_geo_st_astext/out.sql | 4 +- .../test_geo_ops/test_geo_st_boundary/out.sql | 8 +- .../test_geo_ops/test_geo_st_buffer/out.sql | 8 +- .../test_geo_ops/test_geo_st_centroid/out.sql | 4 +- .../test_geo_st_convexhull/out.sql | 8 +- .../test_geo_st_difference/out.sql | 4 +- .../test_geo_ops/test_geo_st_distance/out.sql | 10 +- .../test_geo_st_geogfromtext/out.sql | 8 +- .../test_geo_st_geogpoint/out.sql | 4 +- .../test_geo_st_intersection/out.sql | 4 +- .../test_geo_ops/test_geo_st_isclosed/out.sql | 8 +- .../test_geo_ops/test_geo_st_length/out.sql | 8 +- .../snapshots/test_geo_ops/test_geo_x/out.sql | 4 +- .../snapshots/test_geo_ops/test_geo_y/out.sql | 4 +- .../test_json_ops/test_json_extract/out.sql | 8 +- .../test_json_extract_array/out.sql | 8 +- .../test_json_extract_string_array/out.sql | 8 +- .../test_json_ops/test_json_keys/out.sql | 10 +- .../test_json_ops/test_json_query/out.sql | 8 +- .../test_json_query_array/out.sql | 8 +- .../test_json_ops/test_json_set/out.sql | 8 +- .../test_json_ops/test_json_value/out.sql | 8 +- .../test_json_value_array/out.sql | 8 +- .../test_json_ops/test_parse_json/out.sql | 8 +- .../test_json_ops/test_to_json/out.sql | 8 +- .../test_json_ops/test_to_json_string/out.sql | 8 +- .../test_numeric_ops/test_abs/out.sql | 4 +- .../test_numeric_ops/test_add_numeric/out.sql | 18 +- .../test_numeric_ops/test_add_string/out.sql | 4 +- .../test_add_timedelta/out.sql | 16 +- .../test_numeric_ops/test_arccos/out.sql | 14 +- .../test_numeric_ops/test_arccosh/out.sql | 16 +- .../test_numeric_ops/test_arcsin/out.sql | 14 +- .../test_numeric_ops/test_arcsinh/out.sql | 8 +- .../test_numeric_ops/test_arctan/out.sql | 4 +- .../test_numeric_ops/test_arctan2/out.sql | 6 +- .../test_numeric_ops/test_arctanh/out.sql | 20 +- .../test_numeric_ops/test_ceil/out.sql | 8 +- .../test_numeric_ops/test_cos/out.sql | 4 +- .../test_numeric_ops/test_cosh/out.sql | 16 +- .../test_cosine_distance/out.sql | 11 +- .../test_numeric_ops/test_div_numeric/out.sql | 28 +- .../test_div_timedelta/out.sql | 20 +- .../test_euclidean_distance/out.sql | 11 +- .../test_numeric_ops/test_exp/out.sql | 14 +- .../test_numeric_ops/test_expm1/out.sql | 10 +- .../test_numeric_ops/test_floor/out.sql | 8 +- .../test_floordiv_numeric/out.sql | 62 +-- .../test_floordiv_timedelta/out.sql | 8 +- .../test_numeric_ops/test_isfinite/out.sql | 8 +- .../test_numeric_ops/test_ln/out.sql | 18 +- .../test_numeric_ops/test_log10/out.sql | 18 +- .../test_numeric_ops/test_log1p/out.sql | 26 +- .../test_manhattan_distance/out.sql | 11 +- .../test_numeric_ops/test_mod_numeric/out.sql | 325 ++++++----- .../test_numeric_ops/test_mul_numeric/out.sql | 18 +- .../test_mul_timedelta/out.sql | 34 +- .../test_numeric_ops/test_neg/out.sql | 4 +- .../test_numeric_ops/test_pos/out.sql | 4 +- .../test_numeric_ops/test_pow/out.sql | 429 +++++++++------ .../test_numeric_ops/test_round/out.sql | 20 +- .../test_numeric_ops/test_sin/out.sql | 4 +- .../test_numeric_ops/test_sinh/out.sql | 16 +- .../test_numeric_ops/test_sqrt/out.sql | 6 +- .../test_numeric_ops/test_sub_numeric/out.sql | 18 +- .../test_sub_timedelta/out.sql | 26 +- .../test_numeric_ops/test_tan/out.sql | 4 +- .../test_numeric_ops/test_tanh/out.sql | 17 +- .../test_unsafe_pow_op/out.sql | 31 +- .../test_string_ops/test_add_string/out.sql | 4 +- .../test_string_ops/test_capitalize/out.sql | 19 +- .../test_string_ops/test_endswith/out.sql | 6 +- .../test_string_ops/test_isalnum/out.sql | 4 +- .../test_string_ops/test_isalpha/out.sql | 4 +- .../test_string_ops/test_isdecimal/out.sql | 4 +- .../test_string_ops/test_isdigit/out.sql | 6 +- .../test_string_ops/test_islower/out.sql | 7 +- .../test_string_ops/test_isnumeric/out.sql | 4 +- .../test_string_ops/test_isspace/out.sql | 4 +- .../test_string_ops/test_isupper/out.sql | 7 +- .../test_string_ops/test_len/out.sql | 4 +- .../test_string_ops/test_len_w_array/out.sql | 4 +- .../test_string_ops/test_lower/out.sql | 4 +- .../test_string_ops/test_lstrip/out.sql | 8 +- .../test_regex_replace_str/out.sql | 4 +- .../test_string_ops/test_replace_str/out.sql | 4 +- .../test_string_ops/test_reverse/out.sql | 4 +- .../test_string_ops/test_rstrip/out.sql | 8 +- .../test_string_ops/test_startswith/out.sql | 6 +- .../test_string_ops/test_str_contains/out.sql | 4 +- .../test_str_contains_regex/out.sql | 4 +- .../test_string_ops/test_str_extract/out.sql | 18 +- .../test_string_ops/test_str_get/out.sql | 9 +- .../test_string_ops/test_str_pad/out.sql | 16 +- .../test_string_ops/test_str_repeat/out.sql | 4 +- .../test_string_ops/test_str_slice/out.sql | 110 +++- .../test_string_ops/test_strconcat/out.sql | 4 +- .../test_string_ops/test_string_split/out.sql | 4 +- .../test_string_ops/test_strip/out.sql | 8 +- .../test_string_ops/test_upper/out.sql | 4 +- .../test_string_ops/test_zfill/out.sql | 26 +- .../test_struct_ops/test_struct_field/out.sql | 6 +- .../test_struct_ops/test_struct_op/out.sql | 10 +- .../test_timedelta_floor/out.sql | 8 +- .../test_to_timedelta/out.sql | 16 +- .../test_compile_aggregate/out.sql | 40 +- .../test_compile_aggregate_wo_dropna/out.sql | 34 +- .../test_compile_concat/out.sql | 93 ++-- .../test_compile_concat_filter_sorted/out.sql | 141 +++-- .../test_compile_explode_dataframe/out.sql | 72 ++- .../test_compile_explode_series/out.sql | 57 +- .../test_compile_filter/out.sql | 10 +- .../test_compile_fromrange/out.sql | 197 ++++--- .../test_compile_isin/out.sql | 61 +-- .../test_compile_isin_not_nullable/out.sql | 54 +- .../test_compile_join/out.sql | 31 +- .../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 | 33 +- .../test_compile_join_w_on/time_col/out.sql | 33 +- .../test_compile_readlocal/out.sql | 131 +++-- .../test_compile_readlocal_w_json_df/out.sql | 17 +- .../test_compile_readlocal_w_lists_df/out.sql | 31 +- .../out.sql | 31 +- .../out.sql | 19 +- .../test_compile_readtable/out.sql | 34 +- .../out.sql | 16 +- .../out.sql | 2 +- .../test_compile_readtable_w_limit/out.sql | 11 +- .../out.sql | 8 +- .../test_compile_readtable_w_ordering/out.sql | 11 +- .../out.sql | 20 +- .../out.sql | 20 +- .../out.sql | 65 ++- .../out.sql | 35 +- .../out.sql | 27 +- .../out.sql | 27 +- .../test_sql_scalar/out.sql | 6 +- .../test_tpch/test_tpch_query/1/out.sql | 139 +++-- .../test_tpch/test_tpch_query/10/out.sql | 355 ++++++------ .../test_tpch/test_tpch_query/11/out.sql | 305 ++++++----- .../test_tpch/test_tpch_query/12/out.sql | 158 +++--- .../test_tpch/test_tpch_query/13/out.sql | 100 ++-- .../test_tpch/test_tpch_query/14/out.sql | 364 +++++++------ .../test_tpch/test_tpch_query/15/out.sql | 314 +++++++---- .../test_tpch/test_tpch_query/16/out.sql | 219 ++++---- .../test_tpch/test_tpch_query/17/out.sql | 267 +++++---- .../test_tpch/test_tpch_query/18/out.sql | 258 +++++---- .../test_tpch/test_tpch_query/19/out.sql | 354 +++++------- .../test_tpch/test_tpch_query/2/out.sql | 506 +++++++++++------- .../test_tpch/test_tpch_query/20/out.sql | 327 ++++++----- .../test_tpch/test_tpch_query/21/out.sql | 355 +++++++----- .../test_tpch/test_tpch_query/22/out.sql | 346 +++++++----- .../test_tpch/test_tpch_query/3/out.sql | 173 +++--- .../test_tpch/test_tpch_query/4/out.sql | 146 ++--- .../test_tpch/test_tpch_query/5/out.sql | 256 +++++---- .../test_tpch/test_tpch_query/6/out.sql | 115 ++-- .../test_tpch/test_tpch_query/7/out.sql | 321 ++++++----- .../test_tpch/test_tpch_query/8/out.sql | 430 ++++++++------- .../test_tpch/test_tpch_query/9/out.sql | 337 +++++++----- 317 files changed, 7244 insertions(+), 5094 deletions(-) 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..c6ec7dea4ab 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,12 @@ -WITH `bfcte_0` AS ( - SELECT - `int64_col`, - `float64_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 + * +FROM ( + SELECT + CORR(`t1`.`int64_col`, `t1`.`float64_col`) AS `corr_col` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..c6b20e09b5f 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,12 @@ -WITH `bfcte_0` AS ( - SELECT - `int64_col`, - `float64_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 + * +FROM ( + SELECT + COVAR_SAMP(`t1`.`int64_col`, `t1`.`float64_col`) AS `cov_col` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number/out.sql index 7056c8b0af3..e925055fda8 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number/out.sql @@ -1,3 +1,7 @@ SELECT - ROW_NUMBER() OVER () - 1 AS `row_number` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `row_number` +FROM ( + SELECT + * + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number_with_window/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number_with_window/out.sql index 8efea4b51bc..6bf2bb14d16 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number_with_window/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_row_number_with_window/out.sql @@ -1,3 +1,7 @@ SELECT - ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `row_number` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ROW_NUMBER() OVER (ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC) - 1 AS `row_number` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..36226c9f800 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - * - 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 + * +FROM ( + SELECT + COUNT(1) AS `size` + FROM ( + SELECT + `t0`.`rowindex` AS `bfuid_col_1` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..835e8c02a43 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + ARRAY_AGG( + `t1`.`int64_col` IGNORE NULLS ORDER BY (`t1`.`int64_col` IS NULL) ASC, (`t1`.`int64_col`) ASC + ) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..8d1ea80b61b 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,17 @@ -WITH `bfcte_0` AS ( - SELECT - `string_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( +SELECT + * +FROM ( SELECT COALESCE( - STRING_AGG(`string_col`, ',' - ORDER BY - `string_col` IS NULL ASC, - `string_col` ASC), + string_agg( + `t1`.`string_col` ORDER BY (`t1`.`string_col` IS NULL) ASC, (`t1`.`string_col`) ASC, + ',' + ), '' - ) AS `bfcol_1` - FROM `bfcte_0` -) -SELECT - `bfcol_1` AS `string_col` -FROM `bfcte_1` \ No newline at end of file + ) AS `string_col` + FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..325d0cb7d67 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `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 + * +FROM ( + SELECT + COALESCE(LOGICAL_AND(`t1`.`bool_col`), TRUE) AS `bool_col`, + COALESCE(LOGICAL_AND(`t1`.`int64_col` <> 0), TRUE) AS `int64_col` + FROM ( + SELECT + `t0`.`bool_col`, + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all_w_window/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all_w_window/out.sql index 7e4c9d6c3c9..8e7f1c56149 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all_w_window/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_all_w_window/out.sql @@ -1,3 +1,13 @@ SELECT - COALESCE(LOGICAL_AND(`bool_col`) OVER (), TRUE) AS `agg_bool` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COALESCE( + LOGICAL_AND(`t1`.`bool_col`) OVER ( + ORDER BY `t1`.`bool_col` IS NULL ASC, `t1`.`bool_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ), + TRUE + ) AS `agg_bool` +FROM ( + SELECT + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..4abc0f864b5 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `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 + * +FROM ( + SELECT + COALESCE(LOGICAL_OR(`t1`.`bool_col`), FALSE) AS `bool_col`, + COALESCE(LOGICAL_OR(`t1`.`int64_col` <> 0), FALSE) AS `int64_col` + FROM ( + SELECT + `t0`.`bool_col`, + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..5227df46f6e 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + ANY_VALUE(`t1`.`int64_col`) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_out.sql index 020d7603b98..8504715449b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_out.sql @@ -1,3 +1,10 @@ SELECT - ANY_VALUE(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ANY_VALUE(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_partition_out.sql index 577c5929b91..4e0541b8568 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_value/window_partition_out.sql @@ -1,3 +1,12 @@ SELECT - ANY_VALUE(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ANY_VALUE(`t1`.`int64_col`) OVER ( + PARTITION BY `t1`.`string_col` + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_w_window/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_w_window/out.sql index 33045c4b70d..31359fbdfa1 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_w_window/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_any_w_window/out.sql @@ -1,3 +1,13 @@ SELECT - COALESCE(LOGICAL_OR(`bool_col`) OVER (), FALSE) AS `agg_bool` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COALESCE( + LOGICAL_OR(`t1`.`bool_col`) OVER ( + ORDER BY `t1`.`bool_col` IS NULL ASC, `t1`.`bool_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ), + FALSE + ) AS `agg_bool` +FROM ( + SELECT + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..24b4d1963d3 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `int64_col` - 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 + * +FROM ( + SELECT + APPROX_QUANTILES(`t1`.`int64_col`, 4)[safe_offset(1)] AS `q1`, + APPROX_QUANTILES(`t1`.`int64_col`, 4)[safe_offset(2)] AS `q2`, + APPROX_QUANTILES(`t1`.`int64_col`, 4)[safe_offset(3)] AS `q3` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..44837de428f 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + approx_top_count(`t1`.`int64_col`, 10) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..9fb0366d6d4 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + COUNT(`t1`.`int64_col`) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_out.sql index e46b49e7e48..7e19bdd54f5 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_out.sql @@ -1,3 +1,10 @@ SELECT - COUNT(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COUNT(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_partition_out.sql index 98088d97dfc..b24bb11e4ca 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_count/window_partition_out.sql @@ -1,3 +1,12 @@ SELECT - COUNT(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COUNT(`t1`.`int64_col`) OVER ( + PARTITION BY `t1`.`string_col` + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins.sql index ac5525fe63f..47dc588fc27 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins.sql @@ -1,47 +1,78 @@ SELECT CASE - WHEN `int64_col` <= MIN(`int64_col`) OVER () + ( - 1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + WHEN `t1`.`int64_col` <= ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 1 + ) ) THEN STRUCT( ( - MIN(`int64_col`) OVER () + ( - 0 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 0 ) ) - ( ( - MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER () + MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER () ) * 0.001 ) AS `left_exclusive`, - MIN(`int64_col`) OVER () + ( - 1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 1 + ) ) + 0 AS `right_inclusive` ) - WHEN `int64_col` <= MIN(`int64_col`) OVER () + ( - 2 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + WHEN `t1`.`int64_col` <= ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 2 + ) ) THEN STRUCT( ( - MIN(`int64_col`) OVER () + ( - 1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 1 ) ) - 0 AS `left_exclusive`, - MIN(`int64_col`) OVER () + ( - 2 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 2 + ) ) + 0 AS `right_inclusive` ) WHEN ( - `int64_col` + `t1`.`int64_col` ) IS NOT NULL THEN STRUCT( ( - MIN(`int64_col`) OVER () + ( - 2 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 2 ) ) - 0 AS `left_exclusive`, - MIN(`int64_col`) OVER () + ( - 3 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 3 + ) ) + 0 AS `right_inclusive` ) + ELSE CAST(NULL AS STRUCT<`left_exclusive` FLOAT64, `right_inclusive` FLOAT64>) END AS `int_bins` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins_labels.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins_labels.sql index 94e9f57b28e..44d95673ca8 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins_labels.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/int_bins_labels.sql @@ -1,16 +1,29 @@ SELECT CASE - WHEN `int64_col` < MIN(`int64_col`) OVER () + ( - 1 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + WHEN `t1`.`int64_col` < ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 1 + ) ) THEN 'a' - WHEN `int64_col` < MIN(`int64_col`) OVER () + ( - 2 * IEEE_DIVIDE(MAX(`int64_col`) OVER () - MIN(`int64_col`) OVER (), 3) + WHEN `t1`.`int64_col` < ( + MIN(`t1`.`int64_col`) OVER () + ( + ( + ieee_divide(MAX(`t1`.`int64_col`) OVER () - MIN(`t1`.`int64_col`) OVER (), 3) + ) * 2 + ) ) THEN 'b' WHEN ( - `int64_col` + `t1`.`int64_col` ) IS NOT NULL THEN 'c' + ELSE CAST(NULL AS STRING) END AS `int_bins_labels` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins.sql index 10f9778f55e..e77c0284169 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins.sql @@ -1,8 +1,17 @@ SELECT CASE - WHEN `int64_col` > 0 AND `int64_col` <= 1 + WHEN ( + `t0`.`int64_col` > 0 + ) AND ( + `t0`.`int64_col` <= 1 + ) THEN STRUCT(0 AS `left_exclusive`, 1 AS `right_inclusive`) - WHEN `int64_col` > 1 AND `int64_col` <= 2 + WHEN ( + `t0`.`int64_col` > 1 + ) AND ( + `t0`.`int64_col` <= 2 + ) THEN STRUCT(1 AS `left_exclusive`, 2 AS `right_inclusive`) + ELSE CAST(NULL AS STRUCT<`left_exclusive` INT64, `right_inclusive` INT64>) END AS `interval_bins` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins_labels.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins_labels.sql index 247c71a6349..609c5448879 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins_labels.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_cut/interval_bins_labels.sql @@ -1,8 +1,17 @@ SELECT CASE - WHEN `int64_col` > 0 AND `int64_col` <= 1 + WHEN ( + `t0`.`int64_col` > 0 + ) AND ( + `t0`.`int64_col` <= 1 + ) THEN 0 - WHEN `int64_col` > 1 AND `int64_col` <= 2 + WHEN ( + `t0`.`int64_col` > 1 + ) AND ( + `t0`.`int64_col` <= 2 + ) THEN 1 + ELSE CAST(NULL AS INT64) END AS `interval_bins_labels` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_bool/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_bool/out.sql index 592f3e240a4..9abc5991599 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_bool/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_bool/out.sql @@ -1,3 +1,7 @@ SELECT - `bool_col` <> LAG(`bool_col`, 1) OVER (ORDER BY `bool_col` DESC) AS `diff_bool` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t1`.`bool_col` <> LAG(`t1`.`bool_col`, 1) OVER (ORDER BY `t1`.`bool_col` DESC) AS `diff_bool` +FROM ( + SELECT + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_date/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_date/out.sql index 4b41355d948..dc161864756 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_date/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_date/out.sql @@ -1,5 +1,13 @@ SELECT CAST(FLOOR( - DATE_DIFF(`date_col`, LAG(`date_col`, 1) OVER (ORDER BY `date_col` ASC NULLS LAST), DAY) * 86400000000 + DATE_DIFF( + `t1`.`date_col`, + LAG(`t1`.`date_col`, 1) OVER (ORDER BY `t1`.`date_col` IS NULL ASC, `t1`.`date_col` ASC), + DAY + ) * 86400000000 ) AS INT64) AS `diff_date` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`date_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_datetime/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_datetime/out.sql index 866f49b1ed4..941a6a57b02 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_datetime/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_datetime/out.sql @@ -1,7 +1,11 @@ SELECT DATETIME_DIFF( - `datetime_col`, - LAG(`datetime_col`, 1) OVER (ORDER BY `datetime_col` ASC NULLS LAST), + `t1`.`datetime_col`, + LAG(`t1`.`datetime_col`, 1) OVER (ORDER BY `t1`.`datetime_col` IS NULL ASC, `t1`.`datetime_col` ASC), MICROSECOND ) AS `diff_datetime` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`datetime_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_int/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_int/out.sql index 4c8a0880f3b..741d457b776 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_int/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_int/out.sql @@ -1,3 +1,7 @@ SELECT - `int64_col` - LAG(`int64_col`, 1) OVER (ORDER BY `int64_col` ASC NULLS LAST) AS `diff_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t1`.`int64_col` - LAG(`t1`.`int64_col`, 1) OVER (ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC) AS `diff_int` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_timestamp/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_timestamp/out.sql index 364f6b69d84..08ed19f1b6f 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_timestamp/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_diff_w_timestamp/out.sql @@ -1,7 +1,11 @@ SELECT TIMESTAMP_DIFF( - `timestamp_col`, - LAG(`timestamp_col`, 1) OVER (ORDER BY `timestamp_col` DESC), + `t1`.`timestamp_col`, + LAG(`t1`.`timestamp_col`, 1) OVER (ORDER BY `t1`.`timestamp_col` DESC), MICROSECOND ) AS `diff_timestamp` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`timestamp_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first/out.sql index 86aedff91d1..6220d05e088 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first/out.sql @@ -1,6 +1,10 @@ SELECT - FIRST_VALUE(`int64_col`) OVER ( - ORDER BY `int64_col` DESC + FIRST_VALUE(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first_non_null/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first_non_null/out.sql index b7851a350ed..c5fd28c4410 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first_non_null/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_first_non_null/out.sql @@ -1,6 +1,10 @@ SELECT - FIRST_VALUE(`int64_col` IGNORE NULLS) OVER ( - ORDER BY `int64_col` ASC NULLS LAST + FIRST_VALUE(`t1`.`int64_col` IGNORE NULLS) OVER ( + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last/out.sql index d0bb802c333..4eb4281301a 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last/out.sql @@ -1,6 +1,10 @@ SELECT - LAST_VALUE(`int64_col`) OVER ( - ORDER BY `int64_col` DESC + LAST_VALUE(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last_non_null/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last_non_null/out.sql index 39d063a3c99..72ce0f89e07 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last_non_null/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_last_non_null/out.sql @@ -1,6 +1,10 @@ SELECT - LAST_VALUE(`int64_col` IGNORE NULLS) OVER ( - ORDER BY `int64_col` ASC NULLS LAST + LAST_VALUE(`t1`.`int64_col` IGNORE NULLS) OVER ( + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..46f960c1a25 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + MAX(`t1`.`int64_col`) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_out.sql index d6dec51cdb4..ba1d545aacd 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_out.sql @@ -1,3 +1,10 @@ SELECT - MAX(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + MAX(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_partition_out.sql index a35a64a8e5f..a76c354291b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_max/window_partition_out.sql @@ -1,3 +1,12 @@ SELECT - MAX(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + MAX(`t1`.`int64_col`) OVER ( + PARTITION BY `t1`.`string_col` + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..8382d34c214 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,16 @@ -WITH `bfcte_0` AS ( - 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` -), `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 + * +FROM ( + SELECT + AVG(`t1`.`bfuid_col_4`) AS `int64_col`, + AVG(CAST(`t1`.`bfuid_col_5` AS INT64)) AS `bool_col`, + CAST(FLOOR(AVG(`t1`.`bfuid_col_6`)) AS INT64) AS `duration_col`, + CAST(FLOOR(AVG(`t1`.`bfuid_col_4`)) AS INT64) AS `int64_col_w_floor` + FROM ( + SELECT + `t0`.`int64_col` AS `bfuid_col_4`, + `t0`.`bool_col` AS `bfuid_col_5`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `bfuid_col_6` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_out.sql index 3443cd2a680..729de08f01b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_out.sql @@ -1,3 +1,10 @@ SELECT - AVG(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + AVG(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_partition_out.sql index b94b84ddb81..2c6eef307fa 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_mean/window_partition_out.sql @@ -1,3 +1,12 @@ SELECT - AVG(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + AVG(`t1`.`int64_col`) OVER ( + PARTITION BY `t1`.`string_col` + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..585af3e1cc8 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,15 @@ -WITH `bfcte_0` AS ( - SELECT - `date_col`, - `int64_col`, - `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 + * +FROM ( + SELECT + APPROX_QUANTILES(`t1`.`int64_col`, 2)[offset(1)] AS `int64_col`, + APPROX_QUANTILES(`t1`.`date_col`, 2)[offset(1)] AS `date_col`, + APPROX_QUANTILES(`t1`.`string_col`, 2)[offset(1)] AS `string_col` + FROM ( + SELECT + `t0`.`date_col`, + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..0339b0b289e 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + MIN(`t1`.`int64_col`) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_out.sql index 031c19eff16..060318b3be2 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_out.sql @@ -1,3 +1,10 @@ SELECT - MIN(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + MIN(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_partition_out.sql index 2de5bd5f717..d99b1bdd9f4 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_min/window_partition_out.sql @@ -1,3 +1,12 @@ SELECT - MIN(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + MIN(`t1`.`int64_col`) OVER ( + PARTITION BY `t1`.`string_col` + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..865a313e357 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,11 @@ -WITH `bfcte_0` AS ( - SELECT - `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 + * +FROM ( + SELECT + COUNT(DISTINCT `t1`.`int64_col`) AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ 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..97a9b4cbe22 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `int64_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 + * +FROM ( + SELECT + VAR_POP(`t1`.`int64_col`) AS `int64_col`, + VAR_POP(CAST(`t1`.`bool_col` AS INT64)) AS `bool_col` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/window_out.sql index 3bfaedd3953..9a753ac2857 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_pop_var/window_out.sql @@ -1,3 +1,10 @@ SELECT - VAR_POP(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + VAR_POP(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..8afd4617cb1 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,22 @@ -WITH `bfcte_0` AS ( - SELECT - `int64_col` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( +SELECT + * +FROM ( SELECT CASE - WHEN LOGICAL_OR(`int64_col` = 0) + WHEN LOGICAL_OR(`t1`.`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 + ELSE ( + POWER( + 2, + SUM(CASE WHEN `t1`.`int64_col` = 0 THEN 0 ELSE LOG(ABS(`t1`.`int64_col`), 2) END) + ) + ) * ( + POWER(-1, MOD(SUM(CASE WHEN SIGN(`t1`.`int64_col`) = -1 THEN 1 ELSE 0 END), 2)) + ) + END AS `int64_col` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/window_partition_out.sql index 532349d3599..7dacff7f027 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_product/window_partition_out.sql @@ -1,16 +1,25 @@ SELECT CASE - WHEN LOGICAL_OR(`int64_col` = 0) OVER (PARTITION BY `string_col`) + WHEN LOGICAL_OR(`t1`.`int64_col` = 0) OVER (PARTITION BY `t1`.`string_col`) THEN 0 - ELSE POWER( - 2, - SUM(IF(`int64_col` = 0, 0, LOG(ABS(`int64_col`), 2))) OVER (PARTITION BY `string_col`) - ) * POWER( - -1, - MOD( - SUM(CASE WHEN SIGN(`int64_col`) = -1 THEN 1 ELSE 0 END) OVER (PARTITION BY `string_col`), - 2 + ELSE ( + POWER( + 2, + SUM(CASE WHEN `t1`.`int64_col` = 0 THEN 0 ELSE LOG(ABS(`t1`.`int64_col`), 2) END) OVER (PARTITION BY `t1`.`string_col`) + ) + ) * ( + POWER( + -1, + MOD( + SUM(CASE WHEN SIGN(`t1`.`int64_col`) = -1 THEN 1 ELSE 0 END) OVER (PARTITION BY `t1`.`string_col`), + 2 + ) ) ) END AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_qcut/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_qcut/out.sql index cb1541d083b..554bb295fff 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_qcut/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_qcut/out.sql @@ -1,51 +1,88 @@ SELECT - `rowindex`, - `int64_col`, - IF( - ( - `int64_col` - ) IS NOT NULL, - IF( - `int64_col` IS NULL, - NULL, - CAST(GREATEST( - CEIL( - PERCENT_RANK() OVER (PARTITION BY ( - `int64_col` - ) IS NOT NULL ORDER BY `int64_col` ASC) * 4 - ) - 1, - 0 - ) AS INT64) - ), - NULL - ) AS `qcut_w_int`, - IF( - ( - `int64_col` - ) IS NOT NULL, - CASE - WHEN PERCENT_RANK() OVER (PARTITION BY ( - `int64_col` - ) IS NOT NULL ORDER BY `int64_col` ASC) < 0 + `t1`.`rowindex`, + `t1`.`int64_col`, + CASE + WHEN ( + `t1`.`int64_col` + ) IS NOT NULL + THEN IF( + CAST(CEIL( + PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) * 4 + ) AS INT64) IS NULL, + CAST(CEIL( + PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) * 4 + ) AS INT64), + GREATEST( + 1, + CAST(CEIL( + PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) * 4 + ) AS INT64) + ) + ) - 1 + ELSE CAST(NULL AS INT64) + END AS `qcut_w_int`, + CASE + WHEN ( + `t1`.`int64_col` + ) IS NOT NULL + THEN CASE + WHEN PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) < 0 THEN NULL - WHEN PERCENT_RANK() OVER (PARTITION BY ( - `int64_col` - ) IS NOT NULL ORDER BY `int64_col` ASC) <= 0.25 + WHEN PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) <= 0.25 THEN 0 - WHEN PERCENT_RANK() OVER (PARTITION BY ( - `int64_col` - ) IS NOT NULL ORDER BY `int64_col` ASC) <= 0.5 + WHEN PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) <= 0.5 THEN 1 - WHEN PERCENT_RANK() OVER (PARTITION BY ( - `int64_col` - ) IS NOT NULL ORDER BY `int64_col` ASC) <= 0.75 + WHEN PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) <= 0.75 THEN 2 - WHEN PERCENT_RANK() OVER (PARTITION BY ( - `int64_col` - ) IS NOT NULL ORDER BY `int64_col` ASC) <= 1 + WHEN PERCENT_RANK() OVER ( + PARTITION BY ( + `t1`.`int64_col` + ) IS NOT NULL + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ) <= 1 THEN 3 - ELSE NULL - END, - NULL - ) AS `qcut_w_list` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ELSE CAST(NULL AS INT64) + END + ELSE CAST(NULL AS INT64) + END AS `qcut_w_list` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`rowindex` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..ad22ba5ea13 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,14 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `int64_col` - 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 + * +FROM ( + SELECT + PERCENTILE_CONT(`t1`.`int64_col`, 0.5) AS `int64`, + PERCENTILE_CONT(CAST(`t1`.`bool_col` AS INT64), 0.5) AS `bool`, + CAST(FLOOR(PERCENTILE_CONT(`t1`.`int64_col`, 0.5)) AS INT64) AS `int64_w_floor` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_rank/out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_rank/out.sql index 2170d6cdcf7..c2e9e78aa07 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_rank/out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_rank/out.sql @@ -1,3 +1,9 @@ SELECT - RANK() OVER (ORDER BY `int64_col` DESC NULLS FIRST) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ( + RANK() OVER (ORDER BY `t1`.`int64_col` IS NULL DESC, `t1`.`int64_col` DESC) - 1 + ) + 1 AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lag.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lag.sql index 2bea343497f..29f1612d4a5 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lag.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lag.sql @@ -1,3 +1,7 @@ SELECT - LAG(`int64_col`, 1) OVER (ORDER BY `int64_col` ASC) AS `lag` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + LAG(`t1`.`int64_col`, 1) OVER (ORDER BY `t1`.`int64_col` ASC) AS `lag` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lead.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lead.sql index 5055f443718..99903eddfbc 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lead.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/lead.sql @@ -1,3 +1,7 @@ SELECT - LEAD(`int64_col`, 1) OVER (ORDER BY `int64_col` ASC) AS `lead` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + LEAD(`t1`.`int64_col`, 1) OVER (ORDER BY `t1`.`int64_col` ASC) AS `lead` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/noop.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/noop.sql index 65af6af7c79..e1d9a985e6b 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/noop.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_shift/noop.sql @@ -1,3 +1,3 @@ SELECT - `int64_col` AS `noop` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`int64_col` AS `noop` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ 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..4afa5646d75 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,16 @@ -WITH `bfcte_0` AS ( - 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` -), `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 + * +FROM ( + SELECT + STDDEV_SAMP(`t1`.`bfuid_col_31`) AS `int64_col`, + STDDEV_SAMP(CAST(`t1`.`bfuid_col_32` AS INT64)) AS `bool_col`, + CAST(FLOOR(STDDEV_SAMP(`t1`.`bfuid_col_33`)) AS INT64) AS `duration_col`, + CAST(FLOOR(STDDEV_SAMP(`t1`.`bfuid_col_31`)) AS INT64) AS `int64_col_w_floor` + FROM ( + SELECT + `t0`.`int64_col` AS `bfuid_col_31`, + `t0`.`bool_col` AS `bfuid_col_32`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `bfuid_col_33` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/window_out.sql index 225dd5acf66..9ffdd18b41e 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_std/window_out.sql @@ -1,3 +1,10 @@ SELECT - STDDEV(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + STDDEV_SAMP(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..2126c5751b8 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `int64_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 + * +FROM ( + SELECT + COALESCE(SUM(`t1`.`int64_col`), 0) AS `int64_col`, + COALESCE(SUM(CAST(`t1`.`bool_col` AS INT64)), 0) AS `bool_col` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_out.sql index ea5a12edfb5..5c6f85d1897 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_out.sql @@ -1,3 +1,13 @@ SELECT - COALESCE(SUM(`int64_col`) OVER (), 0) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COALESCE( + SUM(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ), + 0 + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_partition_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_partition_out.sql index ec6083b1a9d..2f59004d343 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_partition_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_sum/window_partition_out.sql @@ -1,3 +1,15 @@ SELECT - COALESCE(SUM(`int64_col`) OVER (PARTITION BY `string_col`), 0) AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COALESCE( + SUM(`t1`.`int64_col`) OVER ( + PARTITION BY `t1`.`string_col` + ORDER BY `t1`.`int64_col` IS NULL ASC, `t1`.`int64_col` ASC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ), + 0 + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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..06070473be4 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,13 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col`, - `int64_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 + * +FROM ( + SELECT + VARIANCE(`t1`.`int64_col`) AS `int64_col`, + VARIANCE(CAST(`t1`.`bool_col` AS INT64)) AS `bool_col` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/window_out.sql b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/window_out.sql index e33797d02fb..75526c0f6ab 100644 --- a/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/window_out.sql +++ b/tests/unit/core/compile/sqlglot/aggregations/snapshots/test_unary_compiler/test_var/window_out.sql @@ -1,3 +1,10 @@ SELECT - VARIANCE(`int64_col`) OVER () AS `agg_int64` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + VARIANCE(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`int64_col` DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS `agg_int64` +FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/None/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/None/out.sql index 6771527318f..1e4de8df024 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/None/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/None/out.sql @@ -1,3 +1,6 @@ SELECT - AI.CLASSIFY(input => (`string_col`), categories => ['greeting', 'rejection']) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + AI.CLASSIFY( + input => STRUCT(`t0`.`string_col` AS `_field_1`), + categories => ['greeting', 'rejection'] + ) AS `result` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/bigframes-dev.us.bigframes-default-connection/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/bigframes-dev.us.bigframes-default-connection/out.sql index 63c31d94566..1629f9193b9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/bigframes-dev.us.bigframes-default-connection/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_classify/bigframes-dev.us.bigframes-default-connection/out.sql @@ -1,7 +1,7 @@ SELECT AI.CLASSIFY( - input => (`string_col`), + input => STRUCT(`t0`.`string_col` AS `_field_1`), categories => ['greeting', 'rejection'], connection_id => 'bigframes-dev.us.bigframes-default-connection' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate/out.sql index 9593347238f..78c3b5f1c7e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool/out.sql index 1c259eae673..6861f32388c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE_BOOL( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_connection_id/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_connection_id/out.sql index 27545685509..87359caf2e3 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_connection_id/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_connection_id/out.sql @@ -1,8 +1,12 @@ SELECT AI.GENERATE_BOOL( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), connection_id => 'bigframes-dev.us.bigframes-default-connection', endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_model_param/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_model_param/out.sql index aee8ca8ace0..34eaa4aa814 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_model_param/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_bool_with_model_param/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE_BOOL( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), request_type => 'SHARED', model_params => JSON '{}' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double/out.sql index 124234fb06b..f44cf68b13f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE_DOUBLE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_connection_id/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_connection_id/out.sql index 1826c8a6ee2..c6e407a56b2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_connection_id/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_connection_id/out.sql @@ -1,8 +1,12 @@ SELECT AI.GENERATE_DOUBLE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), connection_id => 'bigframes-dev.us.bigframes-default-connection', endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_model_param/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_model_param/out.sql index 330f32d7c8f..81136b53926 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_model_param/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_double_with_model_param/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE_DOUBLE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), request_type => 'SHARED', model_params => JSON '{}' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int/out.sql index 19d1340f858..03c3318982a 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE_INT( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_connection_id/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_connection_id/out.sql index 870cb4463a2..04a1c83ea2e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_connection_id/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_connection_id/out.sql @@ -1,8 +1,12 @@ SELECT AI.GENERATE_INT( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), connection_id => 'bigframes-dev.us.bigframes-default-connection', endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_model_param/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_model_param/out.sql index 7fd8abe79e7..619a358359f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_model_param/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_int_with_model_param/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE_INT( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), request_type => 'SHARED', model_params => JSON '{}' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_connection_id/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_connection_id/out.sql index 67d670c4a8d..db3f90c4093 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_connection_id/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_connection_id/out.sql @@ -1,8 +1,12 @@ SELECT AI.GENERATE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), connection_id => 'bigframes-dev.us.bigframes-default-connection', endpoint => 'gemini-2.5-flash', request_type => 'SHARED' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_model_param/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_model_param/out.sql index 444d5753038..5109a464c00 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_model_param/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_model_param/out.sql @@ -1,7 +1,11 @@ SELECT AI.GENERATE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), request_type => 'SHARED', model_params => JSON '{}' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_output_schema/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_output_schema/out.sql index 79ff4a79d39..4ed9e6bd572 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_output_schema/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_generate_with_output_schema/out.sql @@ -1,8 +1,12 @@ SELECT AI.GENERATE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), endpoint => 'gemini-2.5-flash', request_type => 'SHARED', output_schema => 'x INT64, y FLOAT64' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/None/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/None/out.sql index bae091982ea..dc9d824b3ca 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/None/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/None/out.sql @@ -1,3 +1,9 @@ SELECT - AI.IF(prompt => (`string_col`, ' is the same as ', `string_col`)) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + AI.IF( + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ) + ) AS `result` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/bigframes-dev.us.bigframes-default-connection/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/bigframes-dev.us.bigframes-default-connection/out.sql index 698523d2e0b..bda5d7a6153 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/bigframes-dev.us.bigframes-default-connection/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_if/bigframes-dev.us.bigframes-default-connection/out.sql @@ -1,6 +1,10 @@ SELECT AI.IF( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), connection_id => 'bigframes-dev.us.bigframes-default-connection' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/None/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/None/out.sql index 6a16276734e..fe67b049452 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/None/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/None/out.sql @@ -1,3 +1,9 @@ SELECT - AI.SCORE(prompt => (`string_col`, ' is the same as ', `string_col`)) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + AI.SCORE( + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ) + ) AS `result` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/bigframes-dev.us.bigframes-default-connection/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/bigframes-dev.us.bigframes-default-connection/out.sql index 92de7cdcdc6..f8050b6059c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/bigframes-dev.us.bigframes-default-connection/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_ai_ops/test_ai_score/bigframes-dev.us.bigframes-default-connection/out.sql @@ -1,6 +1,10 @@ SELECT AI.SCORE( - prompt => (`string_col`, ' is the same as ', `string_col`), + prompt => STRUCT( + `t0`.`string_col` AS `_field_1`, + ' is the same as ' AS `_field_2`, + `t0`.`string_col` AS `_field_3` + ), connection_id => 'bigframes-dev.us.bigframes-default-connection' ) AS `result` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_index/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_index/out.sql index a1f089424a1..9080cc57006 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_index/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_index/out.sql @@ -1,4 +1,12 @@ SELECT - IF(SUBSTRING(`string_col`, 2, 1) <> '', SUBSTRING(`string_col`, 2, 1), NULL) AS `string_index`, - [`int64_col`, `int64_too`][SAFE_OFFSET(1)] AS `array_index` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + SUBSTRING(`t0`.`string_col`, IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(`t0`.`string_col`)), 1) <> '', + SUBSTRING(`t0`.`string_col`, IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(`t0`.`string_col`)), 1), + NULL + ) AS `string_index`, + [`t0`.`int64_col`, `t0`.`int64_too`][safe_offset(1)] AS `array_index` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_reduce_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_reduce_op/out.sql index 1053ec1c2c6..36ccced71d0 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_reduce_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_reduce_op/out.sql @@ -1,27 +1,27 @@ SELECT ( SELECT - COALESCE(SUM(bf_arr_reduce_uid), 0) - FROM UNNEST(`float_list_col`) AS bf_arr_reduce_uid + COALESCE(SUM(__ibis_param_arr_vals__), 0) + FROM UNNEST(`t0`.`float_list_col`) AS __ibis_param_arr_vals__ ) AS `sum_float`, ( SELECT - STDDEV(bf_arr_reduce_uid) - FROM UNNEST(`float_list_col`) AS bf_arr_reduce_uid + STDDEV_SAMP(__ibis_param_arr_vals__) + FROM UNNEST(`t0`.`float_list_col`) AS __ibis_param_arr_vals__ ) AS `std_float`, ( SELECT - COUNT(bf_arr_reduce_uid) - FROM UNNEST(`string_list_col`) AS bf_arr_reduce_uid + COUNT(__ibis_param_arr_vals__) + FROM UNNEST(`t0`.`string_list_col`) AS __ibis_param_arr_vals__ ) AS `count_str`, ( SELECT - COALESCE(LOGICAL_OR(bf_arr_reduce_uid), FALSE) - FROM UNNEST(`bool_list_col`) AS bf_arr_reduce_uid + COALESCE(LOGICAL_OR(__ibis_param_arr_vals__), FALSE) + FROM UNNEST(`t0`.`bool_list_col`) AS __ibis_param_arr_vals__ ) AS `any_bool`, ( SELECT - ARRAY_AGG(bf_arr_reduce_uid IGNORE NULLS) - FROM UNNEST(`string_list_col`) AS bf_arr_reduce_uid + ARRAY_AGG(__ibis_param_arr_vals__ IGNORE NULLS) + FROM UNNEST(`t0`.`string_list_col`) AS __ibis_param_arr_vals__ ) AS `array_agg_str` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_slice/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_slice/out.sql index ffec3b8e934..d5da80a6fed 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_slice/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_slice/out.sql @@ -1,17 +1,48 @@ SELECT - SUBSTRING(`string_col`, 2, 4) AS `string_slice`, + IF( + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + ) >= 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + IF(5 >= 0, 5, GREATEST(0, LENGTH(`t0`.`string_col`) + 5)) - IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + ) + ) <> '', + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + ) >= 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + IF(5 >= 0, 5, GREATEST(0, LENGTH(`t0`.`string_col`) + 5)) - IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + ) + ), + NULL + ) AS `string_slice`, ARRAY( SELECT el - FROM UNNEST([`int64_col`, `int64_too`]) AS el WITH OFFSET AS slice_idx + FROM UNNEST([`t0`.`int64_col`, `t0`.`int64_too`]) AS el WITH OFFSET AS bq_arr_slice WHERE - slice_idx >= 1 + bq_arr_slice >= IF(1 < 0, ARRAY_LENGTH([`t0`.`int64_col`, `t0`.`int64_too`]) + 1, 1) ) AS `slice_only_start`, ARRAY( SELECT el - FROM UNNEST([`int64_col`, `int64_too`]) AS el WITH OFFSET AS slice_idx + FROM UNNEST([`t0`.`int64_col`, `t0`.`int64_too`]) AS el WITH OFFSET AS bq_arr_slice WHERE - slice_idx >= 1 AND slice_idx < 5 + bq_arr_slice >= IF(1 < 0, ARRAY_LENGTH([`t0`.`int64_col`, `t0`.`int64_too`]) + 1, 1) + AND bq_arr_slice < IF(5 < 0, ARRAY_LENGTH([`t0`.`int64_col`, `t0`.`int64_too`]) + 5, 5) ) AS `slice_start_stop` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_to_string/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_to_string/out.sql index 27587771506..a5313a97497 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_to_string/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_array_to_string/out.sql @@ -1,3 +1,3 @@ SELECT - ARRAY_TO_STRING(`string_list_col`, '.') AS `string_list_col` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file + ARRAY_TO_STRING(`t0`.`string_list_col`, '.') AS `string_list_col` +FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_to_array_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_to_array_op/out.sql index f7d8d748b4a..f29a4c00f11 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_to_array_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_array_ops/test_to_array_op/out.sql @@ -1,10 +1,10 @@ SELECT - [COALESCE(`bool_col`, FALSE)] AS `bool_col`, - [COALESCE(`int64_col`, 0)] AS `int64_col`, - [COALESCE(`string_col`, ''), COALESCE(`string_col`, '')] AS `strs_col`, + [COALESCE(`t0`.`bool_col`, FALSE)] AS `bool_col`, + [COALESCE(`t0`.`int64_col`, 0)] AS `int64_col`, + [COALESCE(`t0`.`string_col`, ''), COALESCE(`t0`.`string_col`, '')] AS `strs_col`, [ - COALESCE(`int64_col`, 0), - CAST(COALESCE(`bool_col`, FALSE) AS INT64), - COALESCE(`float64_col`, 0.0) + COALESCE(`t0`.`int64_col`, 0), + CAST(COALESCE(`t0`.`bool_col`, FALSE) AS INT64), + COALESCE(`t0`.`float64_col`, 0.0) ] AS `numeric_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_fetch_metadata/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_fetch_metadata/out.sql index ca6f5842df1..5f1684e56b8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_fetch_metadata/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_fetch_metadata/out.sql @@ -1,6 +1,11 @@ SELECT - `rowindex`, - OBJ.FETCH_METADATA( - OBJ.MAKE_REF(`string_col`, 'bigframes-dev.test-region.bigframes-default-connection') - ).`version` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t1`.`rowindex`, + `OBJ.FETCH_METADATA`( + `OBJ.MAKE_REF`(`t1`.`string_col`, 'bigframes-dev.test-region.bigframes-default-connection') + ).`version` AS `version` +FROM ( + SELECT + `t0`.`rowindex`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url/out.sql index 6d612ee6b87..f341019dee1 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url/out.sql @@ -1,10 +1,15 @@ SELECT - `rowindex`, - JSON_VALUE( - OBJ.GET_ACCESS_URL( - OBJ.MAKE_REF(`string_col`, 'bigframes-dev.test-region.bigframes-default-connection'), + `t1`.`rowindex`, + json_value( + `OBJ.GET_ACCESS_URL`( + `OBJ.MAKE_REF`(`t1`.`string_col`, 'bigframes-dev.test-region.bigframes-default-connection'), 'R' ), '$.access_urls.read_url' ) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + `t0`.`rowindex`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url_with_duration/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url_with_duration/out.sql index 2e8b60230fa..01197421cc4 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url_with_duration/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_get_access_url_with_duration/out.sql @@ -1,3 +1,7 @@ SELECT - OBJ.GET_ACCESS_URL(`string_col`, 'READ', INTERVAL 3600 MICROSECOND) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `OBJ.GET_ACCESS_URL`(`t1`.`string_col`, 'READ', INTERVAL 3600 MICROSECOND) AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref/out.sql index 74ca601cd5d..9c344200b63 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref/out.sql @@ -1,4 +1,9 @@ SELECT - `rowindex`, - OBJ.MAKE_REF(`string_col`, 'bigframes-dev.test-region.bigframes-default-connection') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t1`.`rowindex`, + `OBJ.MAKE_REF`(`t1`.`string_col`, 'bigframes-dev.test-region.bigframes-default-connection') AS `string_col` +FROM ( + SELECT + `t0`.`rowindex`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref_json/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref_json/out.sql index dc84b3bec12..088523719a9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref_json/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_blob_ops/test_obj_make_ref_json/out.sql @@ -1,3 +1,7 @@ SELECT - OBJ.MAKE_REF(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `OBJ.MAKE_REF`(`t1`.`string_col`) AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_and_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_and_op/out.sql index d6f6587ead9..37a8ff8986f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_and_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_and_op/out.sql @@ -1,9 +1,9 @@ SELECT - `rowindex`, - `bool_col`, - `int64_col`, - `int64_col` & `int64_col` AS `int_and_int`, - `bool_col` AND `bool_col` AS `bool_and_bool`, - IF(`bool_col` = FALSE, `bool_col`, NULL) AS `bool_and_null`, - IF(`bool_col` = FALSE, `bool_col`, NULL) AS `null_and_bool` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`bool_col`, + `t0`.`int64_col`, + `t0`.`int64_col` & `t0`.`int64_col` AS `int_and_int`, + `t0`.`bool_col` AND `t0`.`bool_col` AS `bool_and_bool`, + IF(`t0`.`bool_col` = FALSE, `t0`.`bool_col`, NULL) AS `bool_and_null`, + IF(`t0`.`bool_col` = FALSE, `t0`.`bool_col`, NULL) AS `null_and_bool` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_or_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_or_op/out.sql index dad4cee9d0b..0786624cf32 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_or_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_or_op/out.sql @@ -1,9 +1,9 @@ SELECT - `rowindex`, - `bool_col`, - `int64_col`, - `int64_col` | `int64_col` AS `int_and_int`, - `bool_col` OR `bool_col` AS `bool_and_bool`, - IF(`bool_col` = TRUE, `bool_col`, NULL) AS `bool_and_null`, - IF(`bool_col` = TRUE, `bool_col`, NULL) AS `null_and_bool` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`bool_col`, + `t0`.`int64_col`, + `t0`.`int64_col` | `t0`.`int64_col` AS `int_and_int`, + `t0`.`bool_col` OR `t0`.`bool_col` AS `bool_and_bool`, + IF(`t0`.`bool_col` = TRUE, `t0`.`bool_col`, NULL) AS `bool_and_null`, + IF(`t0`.`bool_col` = TRUE, `t0`.`bool_col`, NULL) AS `null_and_bool` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_xor_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_xor_op/out.sql index 4be3b9f94ad..e8916486c63 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_xor_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_bool_ops/test_xor_op/out.sql @@ -1,23 +1,24 @@ SELECT - `rowindex`, - `bool_col`, - `int64_col`, - `int64_col` ^ `int64_col` AS `int_and_int`, + `t0`.`rowindex`, + `t0`.`bool_col`, + `t0`.`int64_col`, + `t0`.`int64_col` ^ `t0`.`int64_col` AS `int_and_int`, ( - `bool_col` AND NOT `bool_col` - ) OR ( - NOT `bool_col` AND `bool_col` + `t0`.`bool_col` AND NOT `t0`.`bool_col` + ) + OR ( + NOT `t0`.`bool_col` AND `t0`.`bool_col` ) AS `bool_and_bool`, ( - `bool_col` AND NOT CAST(NULL AS BOOLEAN) + `t0`.`bool_col` AND NOT CAST(NULL AS BOOL) ) OR ( - NOT `bool_col` AND CAST(NULL AS BOOLEAN) + NOT `t0`.`bool_col` AND CAST(NULL AS BOOL) ) AS `bool_and_null`, ( - `bool_col` AND NOT CAST(NULL AS BOOLEAN) + `t0`.`bool_col` AND NOT CAST(NULL AS BOOL) ) OR ( - NOT `bool_col` AND CAST(NULL AS BOOLEAN) + NOT `t0`.`bool_col` AND CAST(NULL AS BOOL) ) AS `null_and_bool` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_null_match/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_null_match/out.sql index 3d23b8576ec..3c84dc09990 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_null_match/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_null_match/out.sql @@ -1,3 +1,3 @@ SELECT - COALESCE(CAST(`int64_col` AS STRING), '$NULL_SENTINEL$') = COALESCE(CAST(CAST(`bool_col` AS INT64) AS STRING), '$NULL_SENTINEL$') AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COALESCE(CAST(`t0`.`int64_col` AS STRING), '$NULL_SENTINEL$') = COALESCE(CAST(CAST(`t0`.`bool_col` AS INT64) AS STRING), '$NULL_SENTINEL$') AS `int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_numeric/out.sql index 7827731881e..f99e4289192 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_eq_numeric/out.sql @@ -1,11 +1,11 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` = `int64_col` AS `int_eq_int`, - `int64_col` = 1 AS `int_eq_1`, - `int64_col` IS NULL AS `int_eq_null`, - `int64_col` IS NULL AS `null_eq_int`, - `int64_col` = CAST(`bool_col` AS INT64) AS `int_eq_bool`, - CAST(`bool_col` AS INT64) = `int64_col` AS `bool_eq_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` = `t0`.`int64_col` AS `int_eq_int`, + `t0`.`int64_col` = 1 AS `int_eq_1`, + `t0`.`int64_col` IS NULL AS `int_eq_null`, + `t0`.`int64_col` IS NULL AS `null_eq_int`, + `t0`.`int64_col` = CAST(`t0`.`bool_col` AS INT64) AS `int_eq_bool`, + CAST(`t0`.`bool_col` AS INT64) = `t0`.`int64_col` AS `bool_eq_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ge_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ge_numeric/out.sql index 5903cf03699..ce81565ce8e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ge_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ge_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` >= `int64_col` AS `int_ge_int`, - `int64_col` >= 1 AS `int_ge_1`, - NULL AS `null_ge_int`, - `int64_col` >= CAST(`bool_col` AS INT64) AS `int_ge_bool`, - CAST(`bool_col` AS INT64) >= `int64_col` AS `bool_ge_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` >= `t0`.`int64_col` AS `int_ge_int`, + `t0`.`int64_col` >= 1 AS `int_ge_1`, + CAST(NULL AS BOOL) AS `null_ge_int`, + `t0`.`int64_col` >= CAST(`t0`.`bool_col` AS INT64) AS `int_ge_bool`, + CAST(`t0`.`bool_col` AS INT64) >= `t0`.`int64_col` AS `bool_ge_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_gt_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_gt_numeric/out.sql index 42bf029240f..2792e4e715a 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_gt_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_gt_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` > `int64_col` AS `int_gt_int`, - `int64_col` > 1 AS `int_gt_1`, - NULL AS `null_gt_int`, - `int64_col` > CAST(`bool_col` AS INT64) AS `int_gt_bool`, - CAST(`bool_col` AS INT64) > `int64_col` AS `bool_gt_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` > `t0`.`int64_col` AS `int_gt_int`, + `t0`.`int64_col` > 1 AS `int_gt_1`, + CAST(NULL AS BOOL) AS `null_gt_int`, + `t0`.`int64_col` > CAST(`t0`.`bool_col` AS INT64) AS `int_gt_bool`, + CAST(`t0`.`bool_col` AS INT64) > `t0`.`int64_col` AS `bool_gt_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_is_in/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_is_in/out.sql index b6d860d4723..b4f373c6846 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_is_in/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_is_in/out.sql @@ -1,19 +1,23 @@ SELECT - COALESCE(`bool_col` IN (TRUE, FALSE), FALSE) AS `bools`, - COALESCE(`int64_col` IN (1, 2, 3), FALSE) AS `ints`, - `int64_col` IS NULL AS `ints_w_null`, - COALESCE(`int64_col` IN (1.0, 2.0, 3.0), FALSE) AS `floats`, - FALSE AS `strings`, - COALESCE(`int64_col` IN (2.5, 3), FALSE) AS `mixed`, - FALSE AS `empty`, - FALSE AS `empty_wo_match_nulls`, - COALESCE(`int64_col` IN (123456), FALSE) AS `ints_wo_match_nulls`, + COALESCE(`t0`.`bool_col` IN (TRUE, FALSE), FALSE) AS `bools`, + COALESCE(`t0`.`int64_col` IN (1, 2, 3), FALSE) AS `ints`, ( - `float64_col` IS NULL - ) OR `float64_col` IN (1, 2, 3) AS `float_in_ints`, + `t0`.`int64_col` IS NULL + ) OR FALSE AS `ints_w_null`, + COALESCE(`t0`.`int64_col` IN (1.0, 2.0, 3.0), FALSE) AS `floats`, + COALESCE(FALSE, FALSE) AS `strings`, + COALESCE(`t0`.`int64_col` IN (2.5, 3), FALSE) AS `mixed`, + COALESCE(FALSE, FALSE) AS `empty`, + COALESCE(FALSE, FALSE) AS `empty_wo_match_nulls`, + COALESCE(`t0`.`int64_col` IN (123456), FALSE) AS `ints_wo_match_nulls`, ( - `int64_col` IS NULL - ) OR `int64_col` IN (2) AS `mixed_with_null`, - COALESCE(CAST(`bool_col` AS INT64) IN (1, 2.5), FALSE) AS `bool_in_mixed`, - `int64_col` IS NULL AS `only_null_match` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`float64_col` IS NULL + ) OR `t0`.`float64_col` IN (1, 2, 3) AS `float_in_ints`, + ( + `t0`.`int64_col` IS NULL + ) OR `t0`.`int64_col` IN (2) AS `mixed_with_null`, + COALESCE(FALSE, FALSE) AS `bool_in_mixed`, + ( + `t0`.`int64_col` IS NULL + ) OR FALSE AS `only_null_match` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_le_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_le_numeric/out.sql index c6c86510102..8c9dba80b01 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_le_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_le_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` <= `int64_col` AS `int_le_int`, - `int64_col` <= 1 AS `int_le_1`, - NULL AS `null_le_int`, - `int64_col` <= CAST(`bool_col` AS INT64) AS `int_le_bool`, - CAST(`bool_col` AS INT64) <= `int64_col` AS `bool_le_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` <= `t0`.`int64_col` AS `int_le_int`, + `t0`.`int64_col` <= 1 AS `int_le_1`, + CAST(NULL AS BOOL) AS `null_le_int`, + `t0`.`int64_col` <= CAST(`t0`.`bool_col` AS INT64) AS `int_le_bool`, + CAST(`t0`.`bool_col` AS INT64) <= `t0`.`int64_col` AS `bool_le_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_lt_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_lt_numeric/out.sql index ec5c317a8e5..686a75ddf49 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_lt_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_lt_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` < `int64_col` AS `int_lt_int`, - `int64_col` < 1 AS `int_lt_1`, - NULL AS `null_lt_int`, - `int64_col` < CAST(`bool_col` AS INT64) AS `int_lt_bool`, - CAST(`bool_col` AS INT64) < `int64_col` AS `bool_lt_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` < `t0`.`int64_col` AS `int_lt_int`, + `t0`.`int64_col` < 1 AS `int_lt_1`, + CAST(NULL AS BOOL) AS `null_lt_int`, + `t0`.`int64_col` < CAST(`t0`.`bool_col` AS INT64) AS `int_lt_bool`, + CAST(`t0`.`bool_col` AS INT64) < `t0`.`int64_col` AS `bool_lt_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_maximum_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_maximum_op/out.sql index a469fa47cf1..47ca500a479 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_maximum_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_maximum_op/out.sql @@ -1,3 +1,11 @@ SELECT - GREATEST(`int64_col`, `float64_col`) AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CASE + WHEN ( + `t0`.`float64_col` IS NULL + ) OR ( + `t0`.`int64_col` < `t0`.`float64_col` + ) + THEN `t0`.`float64_col` + ELSE `t0`.`int64_col` + END AS `int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_minimum_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_minimum_op/out.sql index ea82af979a3..d8d887c5bb4 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_minimum_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_minimum_op/out.sql @@ -1,3 +1,11 @@ SELECT - LEAST(`int64_col`, `float64_col`) AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CASE + WHEN ( + `t0`.`float64_col` IS NULL + ) OR ( + `t0`.`int64_col` > `t0`.`float64_col` + ) + THEN `t0`.`float64_col` + ELSE `t0`.`int64_col` + END AS `int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ne_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ne_numeric/out.sql index 448a6146294..929c20d8545 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ne_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_comparison_ops/test_ne_numeric/out.sql @@ -1,15 +1,15 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` <> `int64_col` AS `int_ne_int`, - `int64_col` <> 1 AS `int_ne_1`, + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` <> `t0`.`int64_col` AS `int_ne_int`, + `t0`.`int64_col` <> 1 AS `int_ne_1`, ( - `int64_col` + `t0`.`int64_col` ) IS NOT NULL AS `int_ne_null`, ( - `int64_col` + `t0`.`int64_col` ) IS NOT NULL AS `null_ne_int`, - `int64_col` <> CAST(`bool_col` AS INT64) AS `int_ne_bool`, - CAST(`bool_col` AS INT64) <> `int64_col` AS `bool_ne_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`int64_col` <> CAST(`t0`.`bool_col` AS INT64) AS `int_ne_bool`, + CAST(`t0`.`bool_col` AS INT64) <> `t0`.`int64_col` AS `bool_ne_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_add_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_add_timedelta/out.sql index b1ccf096cfa..0670fac9a03 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_add_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_add_timedelta/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `timestamp_col`, - `date_col`, - TIMESTAMP_ADD(CAST(`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `date_add_timedelta`, - TIMESTAMP_ADD(`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timestamp_add_timedelta`, - TIMESTAMP_ADD(CAST(`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_date`, - TIMESTAMP_ADD(`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_timestamp`, + `t0`.`rowindex`, + `t0`.`timestamp_col`, + `t0`.`date_col`, + TIMESTAMP_ADD(CAST(`t0`.`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `date_add_timedelta`, + TIMESTAMP_ADD(`t0`.`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timestamp_add_timedelta`, + TIMESTAMP_ADD(CAST(`t0`.`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_date`, + TIMESTAMP_ADD(`t0`.`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_timestamp`, 172800000000 AS `timedelta_add_timedelta` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_date/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_date/out.sql index eb0d2f11049..aed0a0c1994 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_date/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_date/out.sql @@ -1,3 +1,3 @@ SELECT - DATE(`timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + DATE(`t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_datetime_to_integer_label/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_datetime_to_integer_label/out.sql index 4b0696386c1..aa80e8d375e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_datetime_to_integer_label/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_datetime_to_integer_label/out.sql @@ -1,76 +1,129 @@ SELECT CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`datetime_col` AS TIMESTAMP)) - UNIX_MICROS(CAST(`timestamp_col` AS TIMESTAMP)), - 86400000000 + ieee_divide( + UNIX_MICROS(CAST(`t0`.`datetime_col` AS TIMESTAMP)) - UNIX_MICROS(`t0`.`timestamp_col`), + 86400000000.0 ) ) AS INT64) AS `fixed_freq`, - CAST(FLOOR(IEEE_DIVIDE(UNIX_MICROS(CAST(`datetime_col` AS TIMESTAMP)) - 0, 86400000000)) AS INT64) AS `origin_epoch`, CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS(CAST(`datetime_col` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`timestamp_col` AS DATE) AS TIMESTAMP)), - 86400000000 + ieee_divide(UNIX_MICROS(CAST(`t0`.`datetime_col` AS TIMESTAMP)) - 0, 86400000000.0) + ) AS INT64) AS `origin_epoch`, + CAST(FLOOR( + ieee_divide( + UNIX_MICROS(CAST(`t0`.`datetime_col` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`t0`.`timestamp_col` AS DATE) AS TIMESTAMP)), + 86400000000.0 ) ) AS INT64) AS `origin_start_day`, CASE WHEN UNIX_MICROS( - CAST(TIMESTAMP_TRUNC(`datetime_col`, WEEK(MONDAY)) + INTERVAL 6 DAY AS TIMESTAMP) + CAST(TIMESTAMP_ADD(TIMESTAMP_TRUNC(`t0`.`datetime_col`, WEEK(MONDAY)), INTERVAL '6' DAY) AS TIMESTAMP) ) = UNIX_MICROS( - CAST(TIMESTAMP_TRUNC(`timestamp_col`, WEEK(MONDAY)) + INTERVAL 6 DAY AS TIMESTAMP) + CAST(TIMESTAMP_ADD(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, WEEK(MONDAY)), INTERVAL '6' DAY) AS TIMESTAMP) ) THEN 0 - ELSE CAST(FLOOR( - IEEE_DIVIDE( - UNIX_MICROS( - CAST(TIMESTAMP_TRUNC(`datetime_col`, WEEK(MONDAY)) + INTERVAL 6 DAY AS TIMESTAMP) - ) - UNIX_MICROS( - CAST(TIMESTAMP_TRUNC(`timestamp_col`, WEEK(MONDAY)) + INTERVAL 6 DAY AS TIMESTAMP) - ) - 1, - 604800000000 - ) - ) AS INT64) + 1 + ELSE ( + CAST(FLOOR( + ieee_divide( + ( + UNIX_MICROS( + CAST(TIMESTAMP_ADD(TIMESTAMP_TRUNC(`t0`.`datetime_col`, WEEK(MONDAY)), INTERVAL '6' DAY) AS TIMESTAMP) + ) - UNIX_MICROS( + CAST(TIMESTAMP_ADD(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, WEEK(MONDAY)), INTERVAL '6' DAY) AS TIMESTAMP) + ) + ) - 1, + 604800000000 + ) + ) AS INT64) + ) + 1 END AS `non_fixed_freq_weekly`, CASE WHEN ( - EXTRACT(YEAR FROM `datetime_col`) * 12 + EXTRACT(MONTH FROM `datetime_col`) - 1 + ( + ( + EXTRACT(year FROM `t0`.`datetime_col`) * 12 + ) + EXTRACT(month FROM `t0`.`datetime_col`) + ) - 1 ) = ( - EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1 + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 ) THEN 0 - ELSE CAST(FLOOR( - IEEE_DIVIDE( - ( - EXTRACT(YEAR FROM `datetime_col`) * 12 + EXTRACT(MONTH FROM `datetime_col`) - 1 - ) - ( - EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1 - ) - 1, - 1 - ) - ) AS INT64) + 1 + ELSE ( + CAST(FLOOR( + ieee_divide( + ( + ( + ( + ( + EXTRACT(year FROM `t0`.`datetime_col`) * 12 + ) + EXTRACT(month FROM `t0`.`datetime_col`) + ) - 1 + ) - ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 + ) + ) - 1, + 1 + ) + ) AS INT64) + ) + 1 END AS `non_fixed_freq_monthly`, CASE WHEN ( - EXTRACT(YEAR FROM `datetime_col`) * 4 + EXTRACT(QUARTER FROM `datetime_col`) - 1 + ( + ( + EXTRACT(year FROM `t0`.`datetime_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`datetime_col`) + ) - 1 ) = ( - EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1 + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 ) THEN 0 - ELSE CAST(FLOOR( - IEEE_DIVIDE( - ( - EXTRACT(YEAR FROM `datetime_col`) * 4 + EXTRACT(QUARTER FROM `datetime_col`) - 1 - ) - ( - EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1 - ) - 1, - 1 - ) - ) AS INT64) + 1 + ELSE ( + CAST(FLOOR( + ieee_divide( + ( + ( + ( + ( + EXTRACT(year FROM `t0`.`datetime_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`datetime_col`) + ) - 1 + ) - ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 + ) + ) - 1, + 1 + ) + ) AS INT64) + ) + 1 END AS `non_fixed_freq_quarterly`, CASE - WHEN EXTRACT(YEAR FROM `datetime_col`) = EXTRACT(YEAR FROM `timestamp_col`) + WHEN EXTRACT(year FROM `t0`.`datetime_col`) = EXTRACT(year FROM `t0`.`timestamp_col`) THEN 0 - ELSE CAST(FLOOR( - IEEE_DIVIDE(EXTRACT(YEAR FROM `datetime_col`) - EXTRACT(YEAR FROM `timestamp_col`) - 1, 1) - ) AS INT64) + 1 + ELSE ( + CAST(FLOOR( + ieee_divide( + ( + EXTRACT(year FROM `t0`.`datetime_col`) - EXTRACT(year FROM `t0`.`timestamp_col`) + ) - 1, + 1 + ) + ) AS INT64) + ) + 1 END AS `non_fixed_freq_yearly` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_day/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_day/out.sql index b9c030cb53e..7963ea2a5eb 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_day/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_day/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(DAY FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(day FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofweek/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofweek/out.sql index a25d520d804..24601abf2d1 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofweek/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofweek/out.sql @@ -1,5 +1,5 @@ SELECT - CAST(MOD(EXTRACT(DAYOFWEEK FROM `datetime_col`) + 5, 7) AS INT64) AS `datetime_col`, - CAST(MOD(EXTRACT(DAYOFWEEK FROM `timestamp_col`) + 5, 7) AS INT64) AS `timestamp_col`, - CAST(MOD(EXTRACT(DAYOFWEEK FROM `date_col`) + 5, 7) AS INT64) AS `date_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(MOD(EXTRACT(dayofweek FROM `t0`.`datetime_col`) + 5, 7) AS INT64) AS `datetime_col`, + CAST(MOD(EXTRACT(dayofweek FROM `t0`.`timestamp_col`) + 5, 7) AS INT64) AS `timestamp_col`, + CAST(MOD(EXTRACT(dayofweek FROM `t0`.`date_col`) + 5, 7) AS INT64) AS `date_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofyear/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofyear/out.sql index 87a410911b5..c62b63e766a 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofyear/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_dayofyear/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(DAYOFYEAR FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(dayofyear FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_floor_dt/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_floor_dt/out.sql index 49fb8fe5749..990cd7b5670 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_floor_dt/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_floor_dt/out.sql @@ -1,14 +1,14 @@ SELECT - TIMESTAMP_TRUNC(`timestamp_col`, MICROSECOND) AS `timestamp_col_us`, - TIMESTAMP_TRUNC(`timestamp_col`, MILLISECOND) AS `timestamp_col_ms`, - TIMESTAMP_TRUNC(`timestamp_col`, SECOND) AS `timestamp_col_s`, - TIMESTAMP_TRUNC(`timestamp_col`, MINUTE) AS `timestamp_col_min`, - TIMESTAMP_TRUNC(`timestamp_col`, HOUR) AS `timestamp_col_h`, - TIMESTAMP_TRUNC(`timestamp_col`, DAY) AS `timestamp_col_D`, - TIMESTAMP_TRUNC(`timestamp_col`, WEEK(MONDAY)) AS `timestamp_col_W`, - TIMESTAMP_TRUNC(`timestamp_col`, MONTH) AS `timestamp_col_M`, - TIMESTAMP_TRUNC(`timestamp_col`, QUARTER) AS `timestamp_col_Q`, - TIMESTAMP_TRUNC(`timestamp_col`, YEAR) AS `timestamp_col_Y`, - TIMESTAMP_TRUNC(`datetime_col`, MICROSECOND) AS `datetime_col_q`, - TIMESTAMP_TRUNC(`datetime_col`, MICROSECOND) AS `datetime_col_us` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, MICROSECOND) AS TIMESTAMP) AS `timestamp_col_us`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, MILLISECOND) AS TIMESTAMP) AS `timestamp_col_ms`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, SECOND) AS TIMESTAMP) AS `timestamp_col_s`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, MINUTE) AS TIMESTAMP) AS `timestamp_col_min`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, HOUR) AS TIMESTAMP) AS `timestamp_col_h`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, DAY) AS TIMESTAMP) AS `timestamp_col_D`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, WEEK(MONDAY)) AS TIMESTAMP) AS `timestamp_col_W`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, MONTH) AS TIMESTAMP) AS `timestamp_col_M`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, QUARTER) AS TIMESTAMP) AS `timestamp_col_Q`, + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, YEAR) AS TIMESTAMP) AS `timestamp_col_Y`, + TIMESTAMP_TRUNC(`t0`.`datetime_col`, MICROSECOND) AS `datetime_col_q`, + TIMESTAMP_TRUNC(`t0`.`datetime_col`, MICROSECOND) AS `datetime_col_us` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_hour/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_hour/out.sql index e971057f527..53e3c08a404 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_hour/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_hour/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(HOUR FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(hour FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_fixed/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_fixed/out.sql index 244bd88deb7..3936a1dfb0d 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_fixed/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_fixed/out.sql @@ -1,5 +1,7 @@ SELECT - CAST(TIMESTAMP_MICROS( - CAST(CAST(`rowindex` AS BIGNUMERIC) * 86400000000 + CAST(UNIX_MICROS(CAST(`timestamp_col` AS TIMESTAMP)) AS BIGNUMERIC) AS INT64) + CAST(timestamp_micros( + CAST(trunc(( + `t0`.`rowindex` * 86400000000.0 + ) + UNIX_MICROS(`t0`.`timestamp_col`)) AS INT64) ) AS TIMESTAMP) AS `fixed_freq` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_month/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_month/out.sql index 1ece688b91f..f8026983740 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_month/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_month/out.sql @@ -1,39 +1,94 @@ SELECT - CAST(TIMESTAMP( + CAST(TIMESTAMP_SUB( DATETIME( - CASE - WHEN MOD( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1, - 12 - ) + 1 = 12 - THEN CAST(FLOOR( - IEEE_DIVIDE( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1, - 12 - ) - ) AS INT64) + 1 - ELSE CAST(FLOOR( - IEEE_DIVIDE( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1, + IF( + ( + ( + MOD( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 + ), + 12 + ) + ) + 1 + ) = 12, + ( + CAST(FLOOR( + ieee_divide( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 + ), + 12 + ) + ) AS INT64) + ) + 1, + CAST(FLOOR( + ieee_divide( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 + ), 12 ) ) AS INT64) - END, - CASE - WHEN MOD( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1, - 12 - ) + 1 = 12 - THEN 1 - ELSE MOD( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 12 + EXTRACT(MONTH FROM `timestamp_col`) - 1, - 12 - ) + 1 + 1 - END, + ), + IF( + ( + ( + MOD( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 + ), + 12 + ) + ) + 1 + ) = 12, + 1, + ( + ( + MOD( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 12 + ) + EXTRACT(month FROM `t0`.`timestamp_col`) + ) - 1 + ), + 12 + ) + ) + 1 + ) + 1 + ), 1, 0, 0, 0 - ) - ) - INTERVAL 1 DAY AS TIMESTAMP) AS `non_fixed_freq_monthly` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ), + INTERVAL '1' DAY + ) AS TIMESTAMP) AS `non_fixed_freq_monthly` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_quarter/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_quarter/out.sql index 683b26be91b..b442b538987 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_quarter/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_quarter/out.sql @@ -1,43 +1,100 @@ SELECT - CAST(DATETIME( - CASE - WHEN ( - MOD( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, - 4 + CAST(TIMESTAMP_SUB( + DATETIME( + IF( + ( + ( + ( + MOD( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 + ), + 4 + ) + ) + 1 + ) * 3 + ) = 12, + ( + CAST(FLOOR( + ieee_divide( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 + ), + 4 + ) + ) AS INT64) + ) + 1, + CAST(FLOOR( + ieee_divide( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 + ), + 4 + ) + ) AS INT64) + ), + IF( + ( + ( + ( + MOD( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 + ), + 4 + ) + ) + 1 + ) * 3 + ) = 12, + 1, + ( + ( + ( + MOD( + ( + `t0`.`rowindex` * 1 + ) + ( + ( + ( + EXTRACT(year FROM `t0`.`timestamp_col`) * 4 + ) + EXTRACT(quarter FROM `t0`.`timestamp_col`) + ) - 1 + ), + 4 + ) + ) + 1 + ) * 3 ) + 1 - ) * 3 = 12 - THEN CAST(FLOOR( - IEEE_DIVIDE( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, - 4 - ) - ) AS INT64) + 1 - ELSE CAST(FLOOR( - IEEE_DIVIDE( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, - 4 - ) - ) AS INT64) - END, - CASE - WHEN ( - MOD( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, - 4 - ) + 1 - ) * 3 = 12 - THEN 1 - ELSE ( - MOD( - `rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) * 4 + EXTRACT(QUARTER FROM `timestamp_col`) - 1, - 4 - ) + 1 - ) * 3 + 1 - END, - 1, - 0, - 0, - 0 - ) - INTERVAL 1 DAY AS TIMESTAMP) AS `non_fixed_freq` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ), + 1, + 0, + 0, + 0 + ), + INTERVAL '1' DAY + ) AS TIMESTAMP) AS `non_fixed_freq` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_week/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_week/out.sql index 6196e6976b0..d549e0519cb 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_week/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_week/out.sql @@ -1,7 +1,9 @@ SELECT - CAST(TIMESTAMP_MICROS( - CAST(CAST(`rowindex` AS BIGNUMERIC) * 604800000000 + CAST(UNIX_MICROS( - TIMESTAMP_TRUNC(CAST(`timestamp_col` AS TIMESTAMP), WEEK(MONDAY)) + INTERVAL 6 DAY - ) AS BIGNUMERIC) AS INT64) + CAST(timestamp_micros( + ( + `t0`.`rowindex` * 604800000000 + ) + UNIX_MICROS( + TIMESTAMP_ADD(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, WEEK(MONDAY)), INTERVAL '6' DAY) + ) ) AS TIMESTAMP) AS `non_fixed_freq_weekly` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_year/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_year/out.sql index e0d05ec5b4b..846e53d7a20 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_year/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_integer_label_to_datetime_year/out.sql @@ -1,3 +1,17 @@ SELECT - CAST(TIMESTAMP(DATETIME(`rowindex` * 1 + EXTRACT(YEAR FROM `timestamp_col`) + 1, 1, 1, 0, 0, 0)) - INTERVAL 1 DAY AS TIMESTAMP) AS `non_fixed_freq_yearly` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(TIMESTAMP_SUB( + DATETIME( + ( + ( + `t0`.`rowindex` * 1 + ) + EXTRACT(year FROM `t0`.`timestamp_col`) + ) + 1, + 1, + 1, + 0, + 0, + 0 + ), + INTERVAL '1' DAY + ) AS TIMESTAMP) AS `non_fixed_freq_yearly` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_day/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_day/out.sql index bf7dfea7378..777550ea4ff 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_day/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_day/out.sql @@ -1,3 +1,3 @@ SELECT - CAST(MOD(EXTRACT(DAYOFWEEK FROM `timestamp_col`) + 5, 7) AS INT64) + 1 AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(MOD(EXTRACT(dayofweek FROM `t0`.`timestamp_col`) + 5, 7) AS INT64) + 1 AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_week/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_week/out.sql index ce231592164..2545005d2f8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_week/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_week/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(ISOWEEK FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(isoweek FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_year/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_year/out.sql index aea4bec4371..78c9b97f5b5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_year/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_iso_year/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(ISOYEAR FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(isoyear FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_minute/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_minute/out.sql index ed1ffcee104..a7acafbe158 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_minute/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_minute/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(MINUTE FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(minute FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_month/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_month/out.sql index 8defb0312e9..90d7a2028ab 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_month/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_month/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(MONTH FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(month FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_normalize/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_normalize/out.sql index 0ae08c77ad0..798f592a51e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_normalize/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_normalize/out.sql @@ -1,3 +1,3 @@ SELECT - TIMESTAMP_TRUNC(`timestamp_col`, DAY) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(TIMESTAMP_TRUNC(`t0`.`timestamp_col`, DAY) AS TIMESTAMP) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_quarter/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_quarter/out.sql index 9426f685855..b77731c110f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_quarter/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_quarter/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(QUARTER FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(quarter FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_second/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_second/out.sql index 953a0ff762a..2b302079a36 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_second/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_second/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(SECOND FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(second FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_strftime/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_strftime/out.sql index 308c040640d..2e910c06042 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_strftime/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_strftime/out.sql @@ -1,6 +1,6 @@ SELECT - FORMAT_DATE('%Y-%m-%d', `date_col`) AS `date_col`, - FORMAT_DATETIME('%Y-%m-%d', `datetime_col`) AS `datetime_col`, - FORMAT_TIME('%Y-%m-%d', `time_col`) AS `time_col`, - FORMAT_TIMESTAMP('%Y-%m-%d', `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + format_date('%Y-%m-%d', `t0`.`date_col`) AS `date_col`, + format_datetime('%Y-%m-%d', `t0`.`datetime_col`) AS `datetime_col`, + format_time('%Y-%m-%d', `t0`.`time_col`) AS `time_col`, + format_timestamp('%Y-%m-%d', `t0`.`timestamp_col`, 'UTC') AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_sub_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_sub_timedelta/out.sql index 5c8b130d59d..f643fb8f263 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_sub_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_sub_timedelta/out.sql @@ -1,11 +1,17 @@ SELECT - `rowindex`, - `timestamp_col`, - `duration_col`, - `date_col`, - TIMESTAMP_SUB(CAST(`date_col` AS DATETIME), INTERVAL `duration_col` MICROSECOND) AS `date_sub_timedelta`, - TIMESTAMP_SUB(`timestamp_col`, INTERVAL `duration_col` MICROSECOND) AS `timestamp_sub_timedelta`, - TIMESTAMP_DIFF(CAST(`date_col` AS DATETIME), CAST(`date_col` AS DATETIME), MICROSECOND) AS `timestamp_sub_date`, - TIMESTAMP_DIFF(`timestamp_col`, `timestamp_col`, MICROSECOND) AS `date_sub_timestamp`, - `duration_col` - `duration_col` AS `timedelta_sub_timedelta` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`timestamp_col`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `duration_col`, + `t0`.`date_col`, + TIMESTAMP_SUB( + CAST(`t0`.`date_col` AS DATETIME), + INTERVAL (CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64)) MICROSECOND + ) AS `date_sub_timedelta`, + TIMESTAMP_SUB( + `t0`.`timestamp_col`, + INTERVAL (CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64)) MICROSECOND + ) AS `timestamp_sub_timedelta`, + DATE_DIFF(`t0`.`date_col`, `t0`.`date_col`, DAY) * 86400000000 AS `timestamp_sub_date`, + TIMESTAMP_DIFF(`t0`.`timestamp_col`, `t0`.`timestamp_col`, MICROSECOND) AS `date_sub_timestamp`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) - CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `timedelta_sub_timedelta` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_time/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_time/out.sql index e46ca373909..477d649a6b6 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_time/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_time/out.sql @@ -1,3 +1,3 @@ SELECT - TIME(`timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + TIME(`t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_datetime/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_datetime/out.sql index 5d98e445cc1..3540860df2b 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_datetime/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_datetime/out.sql @@ -1,7 +1,7 @@ SELECT - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`int64_col` * 0.001) AS INT64)) AS DATETIME) AS `int64_col`, - SAFE_CAST(`string_col` AS DATETIME), - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`float64_col` * 0.001) AS INT64)) AS DATETIME) AS `float64_col`, - SAFE_CAST(`timestamp_col` AS DATETIME), - CAST(PARSE_TIMESTAMP('%Y-%m-%d', `string_col`, 'UTC') AS DATETIME) AS `string_col_fmt` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(CAST(timestamp_micros(CAST(trunc(`t0`.`int64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS DATETIME) AS `int64_col`, + SAFE_CAST(`t0`.`string_col` AS DATETIME) AS `string_col`, + CAST(CAST(timestamp_micros(CAST(trunc(`t0`.`float64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS DATETIME) AS `float64_col`, + SAFE_CAST(`t0`.`timestamp_col` AS DATETIME) AS `timestamp_col`, + SAFE_CAST(`t0`.`string_col` AS DATETIME) AS `string_col_fmt` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_timestamp/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_timestamp/out.sql index e0fb530cc6d..ad8baa72539 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_timestamp/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_to_timestamp/out.sql @@ -1,10 +1,17 @@ SELECT - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`int64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS `int64_col`, - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`float64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS `float64_col`, - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`int64_col` * 1000000) AS INT64)) AS TIMESTAMP) AS `int64_col_s`, - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`int64_col` * 1000) AS INT64)) AS TIMESTAMP) AS `int64_col_ms`, - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`int64_col`) AS INT64)) AS TIMESTAMP) AS `int64_col_us`, - CAST(TIMESTAMP_MICROS(CAST(TRUNC(`int64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS `int64_col_ns`, - TIMESTAMP(`datetime_col`) AS `datetime_col`, - PARSE_TIMESTAMP('%Y-%m-%d', `string_col`, 'UTC') AS `string_col_fmt` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(timestamp_micros(CAST(trunc(`t1`.`int64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS `int64_col`, + CAST(timestamp_micros(CAST(trunc(`t1`.`float64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS `float64_col`, + CAST(timestamp_micros(`t1`.`int64_col` * 1000000) AS TIMESTAMP) AS `int64_col_s`, + CAST(timestamp_micros(`t1`.`int64_col` * 1000) AS TIMESTAMP) AS `int64_col_ms`, + CAST(timestamp_micros(`t1`.`int64_col` * 1) AS TIMESTAMP) AS `int64_col_us`, + CAST(timestamp_micros(CAST(trunc(`t1`.`int64_col` * 0.001) AS INT64)) AS TIMESTAMP) AS `int64_col_ns`, + TIMESTAMP(`t1`.`datetime_col`) AS `datetime_col`, + parse_timestamp('%Y-%m-%d', `t1`.`string_col`, 'UTC') AS `string_col_fmt` +FROM ( + SELECT + `t0`.`datetime_col`, + `t0`.`int64_col`, + `t0`.`float64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_micros/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_micros/out.sql index a212164e6ce..bb0965b99b5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_micros/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_micros/out.sql @@ -1,3 +1,7 @@ SELECT - UNIX_MICROS(`timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + UNIX_MICROS(`t1`.`timestamp_col`) AS `timestamp_col` +FROM ( + SELECT + `t0`.`timestamp_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_millis/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_millis/out.sql index 8df5ad956a3..5c47285e4ee 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_millis/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_millis/out.sql @@ -1,3 +1,7 @@ SELECT - UNIX_MILLIS(`timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + UNIX_MILLIS(`t1`.`timestamp_col`) AS `timestamp_col` +FROM ( + SELECT + `t0`.`timestamp_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_seconds/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_seconds/out.sql index 7344ca82949..05200c93a82 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_seconds/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_unix_seconds/out.sql @@ -1,3 +1,3 @@ SELECT - UNIX_SECONDS(`timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + UNIX_SECONDS(`t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_year/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_year/out.sql index f1a1d7085ef..0240b77c07e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_year/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_datetime_ops/test_year/out.sql @@ -1,3 +1,3 @@ SELECT - EXTRACT(YEAR FROM `timestamp_col`) AS `timestamp_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + EXTRACT(year FROM `t0`.`timestamp_col`) AS `timestamp_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_bool/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_bool/out.sql index 2f75cf4cf7f..b897ea263ef 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_bool/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_bool/out.sql @@ -1,5 +1,5 @@ SELECT - `bool_col`, - `float64_col` <> 0 AS `float64_col`, - `float64_col` <> 0 AS `float64_w_safe` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`bool_col`, + `t0`.`float64_col` <> 0 AS `float64_col`, + `t0`.`float64_col` <> 0 AS `float64_w_safe` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_float/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_float/out.sql index 3d48001e77a..29aaa46f64c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_float/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_float/out.sql @@ -1,5 +1,5 @@ SELECT - CAST(CAST(`bool_col` AS INT64) AS FLOAT64), + CAST(CAST(`t0`.`bool_col` AS INT64) AS FLOAT64) AS `bool_col`, CAST('1.34235e4' AS FLOAT64) AS `str_const`, - SAFE_CAST(SAFE_CAST(`bool_col` AS INT64) AS FLOAT64) AS `bool_w_safe` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + SAFE_CAST(SAFE_CAST(`t0`.`bool_col` AS INT64) AS FLOAT64) AS `bool_w_safe` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_from_json/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_from_json/out.sql index 4603f503b5e..c7c914ee891 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_from_json/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_from_json/out.sql @@ -1,7 +1,11 @@ SELECT - INT64(`json_col`) AS `int64_col`, - FLOAT64(`json_col`) AS `float64_col`, - BOOL(`json_col`) AS `bool_col`, - STRING(`json_col`) AS `string_col`, - SAFE.INT64(`json_col`) AS `int64_w_safe` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + INT64(`t1`.`json_col`) AS `int64_col`, + FLOAT64(`t1`.`json_col`) AS `float64_col`, + BOOL(`t1`.`json_col`) AS `bool_col`, + STRING(`t1`.`json_col`) AS `string_col`, + SAFE.INT64(`t1`.`json_col`) AS `int64_w_safe` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_int/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_int/out.sql index 8d44c674dc9..2f96c3c7a86 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_int/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_int/out.sql @@ -1,11 +1,11 @@ SELECT - UNIX_MICROS(CAST(`datetime_col` AS TIMESTAMP)) AS `datetime_col`, - UNIX_MICROS(SAFE_CAST(`datetime_col` AS TIMESTAMP)) AS `datetime_w_safe`, - TIME_DIFF(CAST(`time_col` AS TIME), '00:00:00', MICROSECOND) AS `time_col`, - TIME_DIFF(SAFE_CAST(`time_col` AS TIME), '00:00:00', MICROSECOND) AS `time_w_safe`, - UNIX_MICROS(`timestamp_col`) AS `timestamp_col`, - CAST(TRUNC(`numeric_col`) AS INT64) AS `numeric_col`, - CAST(TRUNC(`float64_col`) AS INT64) AS `float64_col`, - SAFE_CAST(TRUNC(`float64_col`) AS INT64) AS `float64_w_safe`, + UNIX_MICROS(CAST(`t0`.`datetime_col` AS TIMESTAMP)) AS `datetime_col`, + SAFE_CAST(SAFE_CAST(`t0`.`datetime_col` AS TIMESTAMP) AS INT64) AS `datetime_w_safe`, + TIME_DIFF(`t0`.`time_col`, TIME(0, 0, 0), MICROSECOND) AS `time_col`, + TIME_DIFF(`t0`.`time_col`, TIME(0, 0, 0), MICROSECOND) AS `time_w_safe`, + UNIX_MICROS(`t0`.`timestamp_col`) AS `timestamp_col`, + CAST(trunc(`t0`.`numeric_col`) AS INT64) AS `numeric_col`, + CAST(trunc(`t0`.`float64_col`) AS INT64) AS `float64_col`, + SAFE_CAST(`t0`.`float64_col` AS INT64) AS `float64_w_safe`, CAST('100' AS INT64) AS `str_const` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_json/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_json/out.sql index b62cee83a91..58b7defa20f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_json/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_json/out.sql @@ -1,8 +1,61 @@ SELECT - PARSE_JSON(CAST(`int64_col` AS STRING)) AS `int64_col`, - PARSE_JSON(CAST(`float64_col` AS STRING)) AS `float64_col`, - PARSE_JSON(CAST(`bool_col` AS STRING)) AS `bool_col`, - PARSE_JSON(`string_col`) AS `string_col`, - PARSE_JSON(CAST(`bool_col` AS STRING)) AS `bool_w_safe`, - SAFE.PARSE_JSON(`string_col`) AS `string_w_safe` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + PARSE_JSON(CAST(`t1`.`int64_col` AS STRING)) AS `int64_col`, + PARSE_JSON(CAST(`t1`.`float64_col` AS STRING)) AS `float64_col`, + PARSE_JSON( + LOWER( + CONCAT( + UPPER( + SUBSTRING( + CAST(`t1`.`bool_col` AS STRING), + IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(CAST(`t1`.`bool_col` AS STRING))), + 1 + ) + ), + LOWER( + SUBSTRING( + CAST(`t1`.`bool_col` AS STRING), + IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(CAST(`t1`.`bool_col` AS STRING))), + LENGTH(CAST(`t1`.`bool_col` AS STRING)) + ) + ) + ) + ) + ) AS `bool_col`, + PARSE_JSON(`t1`.`string_col`) AS `string_col`, + SAFE.PARSE_JSON( + LOWER( + CONCAT( + UPPER( + SUBSTRING( + SAFE_CAST(`t1`.`bool_col` AS STRING), + IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(SAFE_CAST(`t1`.`bool_col` AS STRING))), + 1 + ) + ), + LOWER( + SUBSTRING( + SAFE_CAST(`t1`.`bool_col` AS STRING), + IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(SAFE_CAST(`t1`.`bool_col` AS STRING))), + LENGTH(SAFE_CAST(`t1`.`bool_col` AS STRING)) + ) + ) + ) + ) + ) AS `bool_w_safe`, + SAFE.PARSE_JSON(`t1`.`string_col`) AS `string_w_safe` +FROM ( + SELECT + `t0`.`bool_col`, + `t0`.`int64_col`, + `t0`.`float64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_string/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_string/out.sql index 3ea2299cc4f..1d3a924019c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_string/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_string/out.sql @@ -1,5 +1,43 @@ SELECT - CAST(`int64_col` AS STRING), - INITCAP(CAST(`bool_col` AS STRING)) AS `bool_col`, - INITCAP(SAFE_CAST(`bool_col` AS STRING)) AS `bool_w_safe` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(`t0`.`int64_col` AS STRING) AS `int64_col`, + CONCAT( + UPPER( + SUBSTRING( + CAST(`t0`.`bool_col` AS STRING), + IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(CAST(`t0`.`bool_col` AS STRING))), + 1 + ) + ), + LOWER( + SUBSTRING( + CAST(`t0`.`bool_col` AS STRING), + IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(CAST(`t0`.`bool_col` AS STRING))), + LENGTH(CAST(`t0`.`bool_col` AS STRING)) + ) + ) + ) AS `bool_col`, + CONCAT( + UPPER( + SUBSTRING( + SAFE_CAST(`t0`.`bool_col` AS STRING), + IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(SAFE_CAST(`t0`.`bool_col` AS STRING))), + 1 + ) + ), + LOWER( + SUBSTRING( + SAFE_CAST(`t0`.`bool_col` AS STRING), + IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(SAFE_CAST(`t0`.`bool_col` AS STRING))), + LENGTH(SAFE_CAST(`t0`.`bool_col` AS STRING)) + ) + ) + ) AS `bool_w_safe` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_time_like/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_time_like/out.sql index f50505592bb..b438994c73d 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_time_like/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_astype_time_like/out.sql @@ -1,6 +1,6 @@ SELECT - CAST(TIMESTAMP_MICROS(`int64_col`) AS DATETIME) AS `int64_to_datetime`, - CAST(TIMESTAMP_MICROS(`int64_col`) AS TIME) AS `int64_to_time`, - CAST(TIMESTAMP_MICROS(`int64_col`) AS TIMESTAMP) AS `int64_to_timestamp`, - SAFE_CAST(TIMESTAMP_MICROS(`int64_col`) AS TIME) AS `int64_to_time_safe` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(CAST(timestamp_micros(`t0`.`int64_col` * 1) AS TIMESTAMP) AS DATETIME) AS `int64_to_datetime`, + TIME(CAST(timestamp_micros(`t0`.`int64_col` * 1) AS TIMESTAMP)) AS `int64_to_time`, + CAST(timestamp_micros(`t0`.`int64_col` * 1) AS TIMESTAMP) AS `int64_to_timestamp`, + TIME(CAST(timestamp_micros(`t0`.`int64_col` * 1) AS TIMESTAMP)) AS `int64_to_time_safe` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_binary_remote_function_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_binary_remote_function_op/out.sql index 29f9d69cb25..2a3ff528079 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_binary_remote_function_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_binary_remote_function_op/out.sql @@ -1,3 +1,14 @@ SELECT - `my_project`.`my_dataset`.`my_routine`(`int64_col`, `float64_col`) AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t2`.`bfuid_col_663` AS `int64_col` +FROM ( + SELECT + `t1`.`int64_col`, + `t1`.`float64_col`, + `my_project.my_dataset.my_routine`(`t1`.`int64_col`, `t1`.`float64_col`) AS `bfuid_col_663` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_case_when_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_case_when_op/out.sql index 58e901fecc0..e8e227628d9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_case_when_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_case_when_op/out.sql @@ -1,13 +1,26 @@ SELECT - CASE WHEN `bool_col` THEN `int64_col` END AS `single_case`, - CASE WHEN `bool_col` THEN `int64_col` WHEN `bool_col` THEN `int64_too` END AS `double_case`, - CASE WHEN `bool_col` THEN `bool_col` WHEN `bool_col` THEN `bool_col` END AS `bool_types_case`, + CASE WHEN `t0`.`bool_col` THEN `t0`.`int64_col` ELSE CAST(NULL AS INT64) END AS `single_case`, CASE - WHEN `bool_col` - THEN `int64_col` - WHEN `bool_col` - THEN CAST(`bool_col` AS INT64) - WHEN `bool_col` - THEN `float64_col` + WHEN `t0`.`bool_col` + THEN `t0`.`int64_col` + WHEN `t0`.`bool_col` + THEN `t0`.`int64_too` + ELSE CAST(NULL AS INT64) + END AS `double_case`, + CASE + WHEN `t0`.`bool_col` + THEN `t0`.`bool_col` + WHEN `t0`.`bool_col` + THEN `t0`.`bool_col` + ELSE CAST(NULL AS BOOL) + END AS `bool_types_case`, + CASE + WHEN `t0`.`bool_col` + THEN `t0`.`int64_col` + WHEN `t0`.`bool_col` + THEN CAST(`t0`.`bool_col` AS INT64) + WHEN `t0`.`bool_col` + THEN `t0`.`float64_col` + ELSE CAST(NULL AS FLOAT64) END AS `mixed_types_cast` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_clip/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_clip/out.sql index bbfeb304181..22c4c34c1cc 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_clip/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_clip/out.sql @@ -1,3 +1,3 @@ SELECT - GREATEST(LEAST(`rowindex`, `int64_too`), `int64_col`) AS `result_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + GREATEST(LEAST(`t0`.`rowindex`, `t0`.`int64_too`), `t0`.`int64_col`) AS `result_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_coalesce/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_coalesce/out.sql index 4f88ec71d88..93ec10b57a9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_coalesce/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_coalesce/out.sql @@ -1,4 +1,4 @@ SELECT - `int64_col`, - COALESCE(`int64_too`, `int64_col`) AS `int64_too` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`int64_col`, + COALESCE(`t0`.`int64_too`, `t0`.`int64_col`) AS `int64_too` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_fillna/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_fillna/out.sql index ae6f975da5a..4d49261d0dc 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_fillna/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_fillna/out.sql @@ -1,3 +1,3 @@ SELECT - COALESCE(`int64_col`, `float64_col`) AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COALESCE(`t0`.`int64_col`, `t0`.`float64_col`) AS `int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_hash/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_hash/out.sql index b1afe9db39b..52d0c3e667c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_hash/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_hash/out.sql @@ -1,3 +1,3 @@ SELECT - FARM_FINGERPRINT(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + FARM_FINGERPRINT(`t0`.`string_col`) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_invert/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_invert/out.sql index 5cd1b15a776..836d7e4afb6 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_invert/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_invert/out.sql @@ -1,11 +1,7 @@ SELECT - ~( - `int64_col` - ) AS `int64_col`, - ~( - `bytes_col` - ) AS `bytes_col`, + ~`t0`.`int64_col` AS `int64_col`, + ~`t0`.`bytes_col` AS `bytes_col`, NOT ( - `bool_col` + `t0`.`bool_col` ) AS `bool_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_isnull/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_isnull/out.sql index cfe38ae3600..2726b766eb9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_isnull/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_isnull/out.sql @@ -1,5 +1,3 @@ SELECT - ( - `float64_col` - ) IS NULL AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`float64_col` IS NULL AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_map/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_map/out.sql index 3b1d0446b3b..bfca465a9c8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_map/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_map/out.sql @@ -1,9 +1,9 @@ SELECT CASE - WHEN `string_col` = 'value1' + WHEN `t0`.`string_col` = 'value1' THEN 'mapped1' - WHEN `string_col` IS NULL + WHEN `t0`.`string_col` IS NULL THEN 'UNKNOWN' - ELSE `string_col` + ELSE `t0`.`string_col` END AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_nary_remote_function_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_nary_remote_function_op/out.sql index a1977d809f7..e3e6cafd006 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_nary_remote_function_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_nary_remote_function_op/out.sql @@ -1,3 +1,16 @@ SELECT - `my_project`.`my_dataset`.`my_routine`(`int64_col`, `float64_col`, `string_col`) AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t2`.`bfuid_col_664` AS `int64_col` +FROM ( + SELECT + `t1`.`int64_col`, + `t1`.`float64_col`, + `t1`.`string_col`, + `my_project.my_dataset.my_routine`(`t1`.`int64_col`, `t1`.`float64_col`, `t1`.`string_col`) AS `bfuid_col_664` + FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`float64_col`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_notnull/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_notnull/out.sql index 97b9f54f429..30ec6b10049 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_notnull/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_notnull/out.sql @@ -1,5 +1,5 @@ SELECT ( - `float64_col` + `t0`.`float64_col` ) IS NOT NULL AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_remote_function_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_remote_function_op/out.sql index 1854c025882..f23a1092e06 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_remote_function_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_remote_function_op/out.sql @@ -1,8 +1,18 @@ SELECT - `my_project`.`my_dataset`.`my_routine`(`int64_col`) AS `apply_on_null_true`, - IF( - `int64_col` IS NULL, - `int64_col`, - `my_project`.`my_dataset`.`my_routine`(`int64_col`) - ) AS `apply_on_null_false` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t2`.`bfuid_col_661` AS `apply_on_null_true`, + `t2`.`bfuid_col_662` AS `apply_on_null_false` +FROM ( + SELECT + `t1`.`int64_col`, + `my_project.my_dataset.my_routine`(`t1`.`int64_col`) AS `bfuid_col_661`, + CASE + WHEN `t1`.`int64_col` IS NULL + THEN `t1`.`int64_col` + ELSE `my_project.my_dataset.my_routine`(`t1`.`int64_col`) + END AS `bfuid_col_662` + FROM ( + SELECT + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` +) AS `t2` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_row_key/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_row_key/out.sql index f5bf9b3b6ee..4f3b727f40b 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_row_key/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_row_key/out.sql @@ -2,45 +2,51 @@ SELECT CONCAT( CAST(FARM_FINGERPRINT( CONCAT( - CONCAT('\\', REPLACE(COALESCE(CAST(`rowindex` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`bool_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`bytes_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`date_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`datetime_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(ST_ASTEXT(`geography_col`), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`int64_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`int64_too` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`numeric_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`float64_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`rowindex` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`rowindex_2` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(`string_col`, ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`time_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`timestamp_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`duration_col` AS STRING), ''), '\\', '\\\\')) + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`rowindex` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`bool_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`bytes_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`date_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`datetime_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(st_astext(`t1`.`geography_col`), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`int64_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`int64_too` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`numeric_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`float64_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`rowindex` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`rowindex_2` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(`t1`.`string_col`, ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`time_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`timestamp_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`duration_col` AS STRING), ''), '\\', '\\\\')) ) ) AS STRING), CAST(FARM_FINGERPRINT( CONCAT( - CONCAT('\\', REPLACE(COALESCE(CAST(`rowindex` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`bool_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`bytes_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`date_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`datetime_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(ST_ASTEXT(`geography_col`), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`int64_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`int64_too` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`numeric_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`float64_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`rowindex` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`rowindex_2` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(`string_col`, ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`time_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`timestamp_col` AS STRING), ''), '\\', '\\\\')), - CONCAT('\\', REPLACE(COALESCE(CAST(`duration_col` AS STRING), ''), '\\', '\\\\')), + CONCAT( + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`rowindex` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`bool_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`bytes_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`date_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`datetime_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(st_astext(`t1`.`geography_col`), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`int64_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`int64_too` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`numeric_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`float64_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`rowindex` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`rowindex_2` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(`t1`.`string_col`, ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`time_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`timestamp_col` AS STRING), ''), '\\', '\\\\')), + CONCAT('\\', REPLACE(COALESCE(CAST(`t1`.`duration_col` AS STRING), ''), '\\', '\\\\')) + ), '_' ) ) AS STRING), CAST(RAND() AS STRING) ) AS `row_key` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM ( + SELECT + * + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_sql_scalar_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_sql_scalar_op/out.sql index 8f50ff28ca4..ccfe1b5a47c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_sql_scalar_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_sql_scalar_op/out.sql @@ -1,3 +1,3 @@ SELECT - CAST(`bool_col` AS INT64) + BYTE_LENGTH(`bytes_col`) AS `bool_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CAST(`t0`.`bool_col` AS INT64) + BYTE_LENGTH(`t0`.`bytes_col`) AS `bool_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_where/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_where/out.sql index 1ca3b009898..a5dba8f5c13 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_where/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_generic_ops/test_where/out.sql @@ -1,3 +1,3 @@ SELECT - IF(`bool_col`, `int64_col`, `float64_col`) AS `result_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CASE WHEN `t0`.`bool_col` THEN `t0`.`int64_col` ELSE `t0`.`float64_col` END AS `result_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_area/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_area/out.sql index 78c786b036e..684faca2201 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_area/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_area/out.sql @@ -1,3 +1,3 @@ SELECT - ST_AREA(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_area(`t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_astext/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_astext/out.sql index 526c0c37d7e..8aa1d9d1f9c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_astext/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_astext/out.sql @@ -1,3 +1,3 @@ SELECT - ST_ASTEXT(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_astext(`t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_boundary/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_boundary/out.sql index 4bf43469cf5..8d23a150ddb 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_boundary/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_boundary/out.sql @@ -1,3 +1,7 @@ SELECT - ST_BOUNDARY(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_boundary(`t1`.`geography_col`) AS `geography_col` +FROM ( + SELECT + `t0`.`geography_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_buffer/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_buffer/out.sql index 40669569fbb..0137882f076 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_buffer/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_buffer/out.sql @@ -1,3 +1,7 @@ SELECT - ST_BUFFER(`geography_col`, 1.0, 8.0, FALSE) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_buffer(`t1`.`geography_col`, 1.0, 8.0, FALSE) AS `geography_col` +FROM ( + SELECT + `t0`.`geography_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_centroid/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_centroid/out.sql index accd33bd627..9eee7dbcb64 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_centroid/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_centroid/out.sql @@ -1,3 +1,3 @@ SELECT - ST_CENTROID(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_centroid(`t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_convexhull/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_convexhull/out.sql index e4a718d42a9..2a49d0a89bb 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_convexhull/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_convexhull/out.sql @@ -1,3 +1,7 @@ SELECT - ST_CONVEXHULL(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_convexhull(`t1`.`geography_col`) AS `geography_col` +FROM ( + SELECT + `t0`.`geography_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_difference/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_difference/out.sql index 2a17ef1c7c8..05b101f7007 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_difference/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_difference/out.sql @@ -1,3 +1,3 @@ SELECT - ST_DIFFERENCE(`geography_col`, `geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_difference(`t0`.`geography_col`, `t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_distance/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_distance/out.sql index 4c55ddd0824..95c3dd965d0 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_distance/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_distance/out.sql @@ -1,4 +1,8 @@ SELECT - ST_DISTANCE(`geography_col`, `geography_col`, TRUE) AS `spheroid`, - ST_DISTANCE(`geography_col`, `geography_col`, FALSE) AS `no_spheroid` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ST_DISTANCE(`t1`.`geography_col`, `t1`.`geography_col`, TRUE) AS `spheroid`, + ST_DISTANCE(`t1`.`geography_col`, `t1`.`geography_col`, FALSE) AS `no_spheroid` +FROM ( + SELECT + `t0`.`geography_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogfromtext/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogfromtext/out.sql index db62766d4c9..2dd49a93dad 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogfromtext/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogfromtext/out.sql @@ -1,3 +1,7 @@ SELECT - SAFE.ST_GEOGFROMTEXT(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_geogfromtext(`t1`.`string_col`) AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql index 3299ef0bd2d..40b663797e6 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_geogpoint/out.sql @@ -1,3 +1,3 @@ SELECT - ST_GEOGPOINT(`rowindex`, `rowindex_2`) AS `rowindex` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_geogpoint(`t0`.`rowindex`, `t0`.`rowindex_2`) AS `rowindex` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_intersection/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_intersection/out.sql index a615ddf042e..e8bb186e419 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_intersection/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_intersection/out.sql @@ -1,3 +1,3 @@ SELECT - ST_INTERSECTION(`geography_col`, `geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_intersection(`t0`.`geography_col`, `t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_isclosed/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_isclosed/out.sql index 4f04e70b569..8f68760b104 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_isclosed/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_isclosed/out.sql @@ -1,3 +1,7 @@ SELECT - ST_ISCLOSED(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_isclosed(`t1`.`geography_col`) AS `geography_col` +FROM ( + SELECT + `t0`.`geography_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_length/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_length/out.sql index ee64b20ca46..269c962f3ed 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_length/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_st_length/out.sql @@ -1,3 +1,7 @@ SELECT - ST_LENGTH(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_length(`t1`.`geography_col`, TRUE) AS `geography_col` +FROM ( + SELECT + `t0`.`geography_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_x/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_x/out.sql index c1ab623d9a1..91893d0b11f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_x/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_x/out.sql @@ -1,3 +1,3 @@ SELECT - ST_X(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_x(`t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_y/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_y/out.sql index e7575606e6e..d8733ebee3d 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_y/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_geo_ops/test_geo_y/out.sql @@ -1,3 +1,3 @@ SELECT - ST_Y(`geography_col`) AS `geography_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + st_y(`t0`.`geography_col`) AS `geography_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract/out.sql index 7a7ad2f394d..c085b801204 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_EXTRACT(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + JSON_EXTRACT(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_array/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_array/out.sql index f2c4cd72985..dc70b47e6c5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_array/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_array/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_EXTRACT_ARRAY(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + JSON_EXTRACT_ARRAY(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_string_array/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_string_array/out.sql index 61e8bae8a32..8cac1d81e4a 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_string_array/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_extract_string_array/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_EXTRACT_STRING_ARRAY(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + json_extract_string_array(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_keys/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_keys/out.sql index 78004c1180c..247478a5131 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_keys/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_keys/out.sql @@ -1,4 +1,8 @@ SELECT - JSON_KEYS(`json_col`, NULL) AS `json_keys`, - JSON_KEYS(`json_col`, 2) AS `json_keys_w_max_depth` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + json_keys(`t1`.`json_col`, NULL) AS `json_keys`, + json_keys(`t1`.`json_col`, 2) AS `json_keys_w_max_depth` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query/out.sql index 8aa312e9d75..fa4c3d178c2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_QUERY(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + json_query(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query_array/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query_array/out.sql index 898068fe595..983c1e9e127 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query_array/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_query_array/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_QUERY_ARRAY(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + json_query_array(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_set/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_set/out.sql index e515d5fdc3b..62bd3586002 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_set/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_set/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_SET(`json_col`, '$.a', 100) AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + JSON_SET(`t1`.`json_col`, '$.a', 100) AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value/out.sql index c9a73ae1942..d7b3317dbb9 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_VALUE(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + json_value(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value_array/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value_array/out.sql index 8250c02934e..fe10567a519 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value_array/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_json_value_array/out.sql @@ -1,3 +1,7 @@ SELECT - JSON_VALUE_ARRAY(`json_col`, '$') AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + json_value_array(`t1`.`json_col`, '$') AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_parse_json/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_parse_json/out.sql index 55a195edf20..581cadeb5d4 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_parse_json/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_parse_json/out.sql @@ -1,3 +1,7 @@ SELECT - PARSE_JSON(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + PARSE_JSON(`t1`.`string_col`) AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json/out.sql index ef89efa653b..f7489874d89 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json/out.sql @@ -1,3 +1,7 @@ SELECT - TO_JSON(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + to_json(`t1`.`string_col`) AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json_string/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json_string/out.sql index 62886c26ed9..ab2cc98d031 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json_string/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_json_ops/test_to_json_string/out.sql @@ -1,3 +1,7 @@ SELECT - TO_JSON_STRING(`json_col`) AS `json_col` -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file + to_json_string(`t1`.`json_col`) AS `json_col` +FROM ( + SELECT + `t0`.`json_col` + FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_abs/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_abs/out.sql index bc53c60895a..00b441e86ce 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_abs/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_abs/out.sql @@ -1,3 +1,3 @@ SELECT - ABS(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ABS(`t0`.`float64_col`) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_numeric/out.sql index 3aa06fe16e3..e369fbf516f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` + `int64_col` AS `int_add_int`, - `int64_col` + 1 AS `int_add_1`, - NULL AS `int_add_null`, - `int64_col` + CAST(`bool_col` AS INT64) AS `int_add_bool`, - CAST(`bool_col` AS INT64) + `int64_col` AS `bool_add_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` + `t0`.`int64_col` AS `int_add_int`, + `t0`.`int64_col` + 1 AS `int_add_1`, + CAST(NULL AS INT64) AS `int_add_null`, + `t0`.`int64_col` + CAST(`t0`.`bool_col` AS INT64) AS `int_add_bool`, + CAST(`t0`.`bool_col` AS INT64) + `t0`.`int64_col` AS `bool_add_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_string/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_string/out.sql index cf4051464b7..ebdec70eed5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_string/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_string/out.sql @@ -1,3 +1,3 @@ SELECT - CONCAT(`string_col`, 'a') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CONCAT(`t0`.`string_col`, 'a') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_timedelta/out.sql index b1ccf096cfa..0670fac9a03 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_add_timedelta/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `timestamp_col`, - `date_col`, - TIMESTAMP_ADD(CAST(`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `date_add_timedelta`, - TIMESTAMP_ADD(`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timestamp_add_timedelta`, - TIMESTAMP_ADD(CAST(`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_date`, - TIMESTAMP_ADD(`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_timestamp`, + `t0`.`rowindex`, + `t0`.`timestamp_col`, + `t0`.`date_col`, + TIMESTAMP_ADD(CAST(`t0`.`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `date_add_timedelta`, + TIMESTAMP_ADD(`t0`.`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timestamp_add_timedelta`, + TIMESTAMP_ADD(CAST(`t0`.`date_col` AS DATETIME), INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_date`, + TIMESTAMP_ADD(`t0`.`timestamp_col`, INTERVAL 86400000000 MICROSECOND) AS `timedelta_add_timestamp`, 172800000000 AS `timedelta_add_timedelta` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccos/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccos/out.sql index d00086dfde8..5793fff44f5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccos/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccos/out.sql @@ -1,7 +1,9 @@ SELECT - CASE - WHEN ABS(`float64_col`) > 1 - THEN CAST('NaN' AS FLOAT64) - ELSE ACOS(`float64_col`) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ABS(`t0`.`float64_col`) <= 1 + ), + CAST('NaN' AS FLOAT64), + ACOS(`t0`.`float64_col`) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccosh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccosh/out.sql index f1a04757a0a..1849069c611 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccosh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arccosh/out.sql @@ -1,7 +1,11 @@ SELECT - CASE - WHEN `float64_col` < 1 - THEN CAST('NaN' AS FLOAT64) - ELSE ACOSH(`float64_col`) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + `t0`.`float64_col` >= 1 + ), + CAST('NaN' AS FLOAT64), + LN(`t0`.`float64_col` + SQRT(( + `t0`.`float64_col` * `t0`.`float64_col` + ) - 1)) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsin/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsin/out.sql index eff8f1f5007..5d84730f5c0 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsin/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsin/out.sql @@ -1,7 +1,9 @@ SELECT - CASE - WHEN ABS(`float64_col`) > 1 - THEN CAST('NaN' AS FLOAT64) - ELSE ASIN(`float64_col`) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ABS(`t0`.`float64_col`) <= 1 + ), + CAST('NaN' AS FLOAT64), + ASIN(`t0`.`float64_col`) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsinh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsinh/out.sql index 557407f09ee..7747757e866 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsinh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arcsinh/out.sql @@ -1,3 +1,7 @@ SELECT - ASINH(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + LN( + ABS(`t0`.`float64_col`) + SQRT(( + `t0`.`float64_col` * `t0`.`float64_col` + ) + 1) + ) * SIGN(`t0`.`float64_col`) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan/out.sql index d99b62f2cdb..81add822e09 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan/out.sql @@ -1,3 +1,3 @@ SELECT - ATAN(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ATAN(`t0`.`float64_col`) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql index 463896e981f..bac125d2794 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctan2/out.sql @@ -1,4 +1,4 @@ SELECT - ATAN2(`int64_col`, `float64_col`) AS `int64_col`, - ATAN2(CAST(`bool_col` AS INT64), `float64_col`) AS `bool_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ATAN2(`t0`.`int64_col`, `t0`.`float64_col`) AS `int64_col`, + ATAN2(`t0`.`bool_col`, `t0`.`float64_col`) AS `bool_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctanh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctanh/out.sql index 9b016071480..b6f9b371dc1 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctanh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_arctanh/out.sql @@ -1,9 +1,13 @@ SELECT - CASE - WHEN ABS(`float64_col`) < 1 - THEN ATANH(`float64_col`) - WHEN ABS(`float64_col`) > 1 - THEN CAST('NaN' AS FLOAT64) - ELSE CAST('Infinity' AS FLOAT64) * `float64_col` - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ABS(`t0`.`float64_col`) < 1 + ), + IF( + ABS(`t0`.`float64_col`) = 1, + CAST('Infinity' AS FLOAT64) * `t0`.`float64_col`, + CAST('NaN' AS FLOAT64) + ), + ieee_divide(LN(ieee_divide(`t0`.`float64_col` + 1, 1 - `t0`.`float64_col`)), 2) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ceil/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ceil/out.sql index f69ae7f2760..0bfa23f95e7 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ceil/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ceil/out.sql @@ -1,3 +1,7 @@ SELECT - CEIL(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CEIL(`t1`.`float64_col`) AS `float64_col` +FROM ( + SELECT + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cos/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cos/out.sql index 427dfbb9a93..ce32af15cf0 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cos/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cos/out.sql @@ -1,3 +1,3 @@ SELECT - COS(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + COS(`t0`.`float64_col`) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosh/out.sql index 0f119c254f0..11a385d8c31 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosh/out.sql @@ -1,7 +1,11 @@ SELECT - CASE - WHEN ABS(`float64_col`) > 709.78 - THEN CAST('Infinity' AS FLOAT64) - ELSE COSH(`float64_col`) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ABS(`t0`.`float64_col`) < 709.78 + ), + CAST('Infinity' AS FLOAT64), + ieee_divide(EXP(`t0`.`float64_col`) + EXP(-( + `t0`.`float64_col` + )), 2) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosine_distance/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosine_distance/out.sql index 1c482fc8a78..4dc27d2d163 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosine_distance/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_cosine_distance/out.sql @@ -1,4 +1,9 @@ SELECT - ML.DISTANCE(`int_list_col`, `int_list_col`, 'COSINE') AS `int_list_col`, - ML.DISTANCE(`float_list_col`, `float_list_col`, 'COSINE') AS `float_list_col` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file + `ML.DISTANCE`(`t1`.`int_list_col`, `t1`.`int_list_col`, 'COSINE') AS `int_list_col`, + `ML.DISTANCE`(`t1`.`float_list_col`, `t1`.`float_list_col`, 'COSINE') AS `float_list_col` +FROM ( + SELECT + `t0`.`int_list_col`, + `t0`.`float_list_col` + FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_numeric/out.sql index 3f5ff73326a..5f943eafa2e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_numeric/out.sql @@ -1,15 +1,15 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `float64_col`, - IEEE_DIVIDE(`int64_col`, `int64_col`) AS `int_div_int`, - IEEE_DIVIDE(`int64_col`, 1) AS `int_div_1`, - IEEE_DIVIDE(`int64_col`, 0.0) AS `int_div_0`, - IEEE_DIVIDE(`int64_col`, NULL) AS `int_div_null`, - IEEE_DIVIDE(`int64_col`, `float64_col`) AS `int_div_float`, - IEEE_DIVIDE(`float64_col`, `int64_col`) AS `float_div_int`, - IEEE_DIVIDE(`float64_col`, 0.0) AS `float_div_0`, - IEEE_DIVIDE(`int64_col`, CAST(`bool_col` AS INT64)) AS `int_div_bool`, - IEEE_DIVIDE(CAST(`bool_col` AS INT64), `int64_col`) AS `bool_div_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`float64_col`, + ieee_divide(`t0`.`int64_col`, `t0`.`int64_col`) AS `int_div_int`, + ieee_divide(`t0`.`int64_col`, 1) AS `int_div_1`, + ieee_divide(`t0`.`int64_col`, 0.0) AS `int_div_0`, + CAST(NULL AS FLOAT64) AS `int_div_null`, + ieee_divide(`t0`.`int64_col`, `t0`.`float64_col`) AS `int_div_float`, + ieee_divide(`t0`.`float64_col`, `t0`.`int64_col`) AS `float_div_int`, + ieee_divide(`t0`.`float64_col`, 0.0) AS `float_div_0`, + ieee_divide(`t0`.`int64_col`, CAST(`t0`.`bool_col` AS INT64)) AS `int_div_bool`, + ieee_divide(CAST(`t0`.`bool_col` AS INT64), `t0`.`int64_col`) AS `bool_div_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_timedelta/out.sql index a733ed81278..bb7222e0c26 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_div_timedelta/out.sql @@ -1,10 +1,12 @@ SELECT - `rowindex`, - `timestamp_col`, - `int64_col`, - CAST(IF( - IEEE_DIVIDE(86400000000, `int64_col`) > 0, - FLOOR(IEEE_DIVIDE(86400000000, `int64_col`)), - CEIL(IEEE_DIVIDE(86400000000, `int64_col`)) - ) AS INT64) AS `timedelta_div_numeric` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`timestamp_col`, + `t0`.`int64_col`, + CASE + WHEN ( + ieee_divide(86400000000, `t0`.`int64_col`) + ) > 0 + THEN CAST(FLOOR(ieee_divide(86400000000, `t0`.`int64_col`)) AS INT64) + ELSE CAST(CEIL(ieee_divide(86400000000, `t0`.`int64_col`)) AS INT64) + END AS `timedelta_div_numeric` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_euclidean_distance/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_euclidean_distance/out.sql index 349d78584a9..13505c7212e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_euclidean_distance/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_euclidean_distance/out.sql @@ -1,4 +1,9 @@ SELECT - ML.DISTANCE(`int_list_col`, `int_list_col`, 'EUCLIDEAN') AS `int_list_col`, - ML.DISTANCE(`numeric_list_col`, `numeric_list_col`, 'EUCLIDEAN') AS `numeric_list_col` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file + `ML.DISTANCE`(`t1`.`int_list_col`, `t1`.`int_list_col`, 'EUCLIDEAN') AS `int_list_col`, + `ML.DISTANCE`(`t1`.`numeric_list_col`, `t1`.`numeric_list_col`, 'EUCLIDEAN') AS `numeric_list_col` +FROM ( + SELECT + `t0`.`int_list_col`, + `t0`.`numeric_list_col` + FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_exp/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_exp/out.sql index 178282ca087..b14171e01dc 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_exp/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_exp/out.sql @@ -1,7 +1,9 @@ SELECT - CASE - WHEN `float64_col` > 709.78 - THEN CAST('Infinity' AS FLOAT64) - ELSE EXP(`float64_col`) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + `t0`.`float64_col` < 709.78 + ), + CAST('Infinity' AS FLOAT64), + EXP(`t0`.`float64_col`) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_expm1/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_expm1/out.sql index 6c896448f24..159c8de0bb5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_expm1/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_expm1/out.sql @@ -1,3 +1,9 @@ SELECT - IF(`float64_col` > 709.78, CAST('Infinity' AS FLOAT64), EXP(`float64_col`) - 1) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + `t0`.`float64_col` < 709.78 + ), + CAST('Infinity' AS FLOAT64), + EXP(`t0`.`float64_col`) + ) - 1 AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floor/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floor/out.sql index 31b715623cb..fb5fb1a6185 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floor/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floor/out.sql @@ -1,3 +1,7 @@ SELECT - FLOOR(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + FLOOR(`t1`.`float64_col`) AS `float64_col` +FROM ( + SELECT + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_numeric/out.sql index c7fa74e48fa..ae63a4be5c8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_numeric/out.sql @@ -1,47 +1,47 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `float64_col`, - CASE - WHEN `int64_col` = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`int64_col`, `int64_col`)) AS INT64) + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`float64_col`, + CASE + WHEN `t0`.`int64_col` = 0 + THEN 0 * `t0`.`int64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`int64_col`, `t0`.`int64_col`)) AS INT64) END AS `int_div_int`, CASE - WHEN 1 = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`int64_col`, 1)) AS INT64) + WHEN 1 = 0 + THEN 0 * `t0`.`int64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`int64_col`, 1)) AS INT64) END AS `int_div_1`, CASE - WHEN 0.0 = CAST(0 AS INT64) - THEN CAST('Infinity' AS FLOAT64) * `int64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`int64_col`, 0.0)) AS INT64) + WHEN 0.0 = 0 + THEN CAST('Infinity' AS FLOAT64) * `t0`.`int64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`int64_col`, 0.0)) AS INT64) END AS `int_div_0`, - NULL AS `int_div_null`, + CAST(NULL AS INT64) AS `int_div_null`, CASE - WHEN `float64_col` = CAST(0 AS INT64) - THEN CAST('Infinity' AS FLOAT64) * `int64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`int64_col`, `float64_col`)) AS INT64) + WHEN `t0`.`float64_col` = 0 + THEN CAST('Infinity' AS FLOAT64) * `t0`.`int64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`int64_col`, `t0`.`float64_col`)) AS INT64) END AS `int_div_float`, CASE - WHEN `int64_col` = CAST(0 AS INT64) - THEN CAST('Infinity' AS FLOAT64) * `float64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`float64_col`, `int64_col`)) AS INT64) + WHEN `t0`.`int64_col` = 0 + THEN CAST('Infinity' AS FLOAT64) * `t0`.`float64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`float64_col`, `t0`.`int64_col`)) AS INT64) END AS `float_div_int`, CASE - WHEN 0.0 = CAST(0 AS INT64) - THEN CAST('Infinity' AS FLOAT64) * `float64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`float64_col`, 0.0)) AS INT64) + WHEN 0.0 = 0 + THEN CAST('Infinity' AS FLOAT64) * `t0`.`float64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`float64_col`, 0.0)) AS INT64) END AS `float_div_0`, CASE - WHEN CAST(`bool_col` AS INT64) = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - ELSE CAST(FLOOR(IEEE_DIVIDE(`int64_col`, CAST(`bool_col` AS INT64))) AS INT64) + WHEN CAST(`t0`.`bool_col` AS INT64) = 0 + THEN 0 * `t0`.`int64_col` + ELSE CAST(FLOOR(ieee_divide(`t0`.`int64_col`, CAST(`t0`.`bool_col` AS INT64))) AS INT64) END AS `int_div_bool`, CASE - WHEN `int64_col` = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * CAST(`bool_col` AS INT64) - ELSE CAST(FLOOR(IEEE_DIVIDE(CAST(`bool_col` AS INT64), `int64_col`)) AS INT64) + WHEN `t0`.`int64_col` = 0 + THEN 0 * CAST(`t0`.`bool_col` AS INT64) + ELSE CAST(FLOOR(ieee_divide(CAST(`t0`.`bool_col` AS INT64), `t0`.`int64_col`)) AS INT64) END AS `bool_div_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_timedelta/out.sql index 4d978991eb5..bd04d7f4fed 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_floordiv_timedelta/out.sql @@ -1,6 +1,6 @@ SELECT - `rowindex`, - `timestamp_col`, - `date_col`, + `t0`.`rowindex`, + `t0`.`timestamp_col`, + `t0`.`date_col`, 43200000000 AS `timedelta_div_numeric` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_isfinite/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_isfinite/out.sql index 54cbe2dd689..a5c13c5e0ce 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_isfinite/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_isfinite/out.sql @@ -1,3 +1,7 @@ SELECT - NOT IS_INF(`float64_col`) OR IS_NAN(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + NOT ( + IS_INF(`t0`.`float64_col`) + ) AND NOT ( + IS_NAN(`t0`.`float64_col`) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ln/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ln/out.sql index 53ab88b7fc3..5d88590efab 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ln/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_ln/out.sql @@ -1,11 +1,9 @@ SELECT - CASE - WHEN `float64_col` IS NULL - THEN NULL - WHEN `float64_col` > 0 - THEN LN(`float64_col`) - WHEN `float64_col` < 0 - THEN CAST('NaN' AS FLOAT64) - ELSE CAST('-Infinity' AS FLOAT64) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + `t0`.`float64_col` > 0 + ), + IF(`t0`.`float64_col` = 0, CAST('-Infinity' AS FLOAT64), CAST('NaN' AS FLOAT64)), + LN(`t0`.`float64_col`) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log10/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log10/out.sql index 2037649332f..cc01fc196f2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log10/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log10/out.sql @@ -1,11 +1,9 @@ SELECT - CASE - WHEN `float64_col` IS NULL - THEN NULL - WHEN `float64_col` > 0 - THEN LOG(`float64_col`, 10) - WHEN `float64_col` < 0 - THEN CAST('NaN' AS FLOAT64) - ELSE CAST('-Infinity' AS FLOAT64) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + `t0`.`float64_col` > 0 + ), + IF(`t0`.`float64_col` = 0, CAST('-Infinity' AS FLOAT64), CAST('NaN' AS FLOAT64)), + LOG(`t0`.`float64_col`, 10) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log1p/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log1p/out.sql index f7ddf4c223f..878da9b96bb 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log1p/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_log1p/out.sql @@ -1,11 +1,17 @@ SELECT - CASE - WHEN `float64_col` IS NULL - THEN NULL - WHEN `float64_col` > -1 - THEN LN(1 + `float64_col`) - WHEN `float64_col` < -1 - THEN CAST('NaN' AS FLOAT64) - ELSE CAST('-Infinity' AS FLOAT64) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ( + 1 + `t0`.`float64_col` + ) > 0 + ), + IF( + ( + 1 + `t0`.`float64_col` + ) = 0, + CAST('-Infinity' AS FLOAT64), + CAST('NaN' AS FLOAT64) + ), + LN(1 + `t0`.`float64_col`) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_manhattan_distance/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_manhattan_distance/out.sql index b6132a9fd6e..097963c61af 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_manhattan_distance/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_manhattan_distance/out.sql @@ -1,4 +1,9 @@ SELECT - ML.DISTANCE(`float_list_col`, `float_list_col`, 'MANHATTAN') AS `float_list_col`, - ML.DISTANCE(`numeric_list_col`, `numeric_list_col`, 'MANHATTAN') AS `numeric_list_col` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file + `ML.DISTANCE`(`t1`.`float_list_col`, `t1`.`float_list_col`, 'MANHATTAN') AS `float_list_col`, + `ML.DISTANCE`(`t1`.`numeric_list_col`, `t1`.`numeric_list_col`, 'MANHATTAN') AS `numeric_list_col` +FROM ( + SELECT + `t0`.`float_list_col`, + `t0`.`numeric_list_col` + FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mod_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mod_numeric/out.sql index 2a79820635c..7907bb5fc76 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mod_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mod_numeric/out.sql @@ -1,193 +1,222 @@ SELECT - `rowindex`, - `int64_col`, - `float64_col`, + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`float64_col`, CASE - WHEN `int64_col` = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - WHEN `int64_col` < CAST(0 AS INT64) + WHEN `t0`.`int64_col` = 0 + THEN 0 * `t0`.`int64_col` + WHEN ( + `t0`.`int64_col` < 0 + ) AND ( - MOD(`int64_col`, `int64_col`) - ) > CAST(0 AS INT64) - THEN `int64_col` + ( - MOD(`int64_col`, `int64_col`) + ( + MOD(`t0`.`int64_col`, `t0`.`int64_col`) + ) > 0 + ) + THEN `t0`.`int64_col` + ( + MOD(`t0`.`int64_col`, `t0`.`int64_col`) + ) + WHEN ( + `t0`.`int64_col` > 0 ) - WHEN `int64_col` > CAST(0 AS INT64) AND ( - MOD(`int64_col`, `int64_col`) - ) < CAST(0 AS INT64) - THEN `int64_col` + ( - MOD(`int64_col`, `int64_col`) + ( + MOD(`t0`.`int64_col`, `t0`.`int64_col`) + ) < 0 ) - ELSE MOD(`int64_col`, `int64_col`) + THEN `t0`.`int64_col` + ( + MOD(`t0`.`int64_col`, `t0`.`int64_col`) + ) + ELSE MOD(`t0`.`int64_col`, `t0`.`int64_col`) END AS `int_mod_int`, CASE WHEN -( - `int64_col` - ) = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - WHEN -( - `int64_col` - ) < CAST(0 AS INT64) + `t0`.`int64_col` + ) = 0 + THEN 0 * `t0`.`int64_col` + WHEN ( + -( + `t0`.`int64_col` + ) < 0 + ) AND ( - MOD(`int64_col`, -( - `int64_col` - )) - ) > CAST(0 AS INT64) + ( + MOD(`t0`.`int64_col`, -( + `t0`.`int64_col` + )) + ) > 0 + ) THEN -( - `int64_col` + `t0`.`int64_col` ) + ( - MOD(`int64_col`, -( - `int64_col` + MOD(`t0`.`int64_col`, -( + `t0`.`int64_col` )) ) - WHEN -( - `int64_col` - ) > CAST(0 AS INT64) + WHEN ( + -( + `t0`.`int64_col` + ) > 0 + ) AND ( - MOD(`int64_col`, -( - `int64_col` - )) - ) < CAST(0 AS INT64) + ( + MOD(`t0`.`int64_col`, -( + `t0`.`int64_col` + )) + ) < 0 + ) THEN -( - `int64_col` + `t0`.`int64_col` ) + ( - MOD(`int64_col`, -( - `int64_col` + MOD(`t0`.`int64_col`, -( + `t0`.`int64_col` )) ) - ELSE MOD(`int64_col`, -( - `int64_col` + ELSE MOD(`t0`.`int64_col`, -( + `t0`.`int64_col` )) END AS `int_mod_int_neg`, CASE - WHEN 1 = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - WHEN 1 < CAST(0 AS INT64) AND ( - MOD(`int64_col`, 1) - ) > CAST(0 AS INT64) + WHEN 1 = 0 + THEN 0 * `t0`.`int64_col` + WHEN ( + 1 < 0 + ) AND ( + ( + MOD(`t0`.`int64_col`, 1) + ) > 0 + ) THEN 1 + ( - MOD(`int64_col`, 1) + MOD(`t0`.`int64_col`, 1) + ) + WHEN ( + 1 > 0 + ) AND ( + ( + MOD(`t0`.`int64_col`, 1) + ) < 0 ) - WHEN 1 > CAST(0 AS INT64) AND ( - MOD(`int64_col`, 1) - ) < CAST(0 AS INT64) THEN 1 + ( - MOD(`int64_col`, 1) + MOD(`t0`.`int64_col`, 1) ) - ELSE MOD(`int64_col`, 1) + ELSE MOD(`t0`.`int64_col`, 1) END AS `int_mod_1`, - CASE - WHEN 0 = CAST(0 AS INT64) - THEN CAST(0 AS INT64) * `int64_col` - WHEN 0 < CAST(0 AS INT64) AND ( - MOD(`int64_col`, 0) - ) > CAST(0 AS INT64) - THEN 0 + ( - MOD(`int64_col`, 0) - ) - WHEN 0 > CAST(0 AS INT64) AND ( - MOD(`int64_col`, 0) - ) < CAST(0 AS INT64) - THEN 0 + ( - MOD(`int64_col`, 0) - ) - ELSE MOD(`int64_col`, 0) - END AS `int_mod_0`, - CASE - WHEN CAST(`float64_col` AS BIGNUMERIC) = CAST(0 AS INT64) - THEN CAST('NaN' AS FLOAT64) * CAST(`float64_col` AS BIGNUMERIC) - WHEN CAST(`float64_col` AS BIGNUMERIC) < CAST(0 AS INT64) + CAST(NULL AS INT64) AS `int_mod_0`, + CAST(CASE + WHEN CAST(`t0`.`float64_col` AS BIGNUMERIC) = 0 + THEN CAST('NaN' AS FLOAT64) * CAST(`t0`.`float64_col` AS BIGNUMERIC) + WHEN ( + CAST(`t0`.`float64_col` AS BIGNUMERIC) < 0 + ) AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(`float64_col` AS BIGNUMERIC)) - ) > CAST(0 AS INT64) - THEN CAST(`float64_col` AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(`float64_col` AS BIGNUMERIC)) + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(`t0`.`float64_col` AS BIGNUMERIC)) + ) > 0 + ) + THEN CAST(`t0`.`float64_col` AS BIGNUMERIC) + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(`t0`.`float64_col` AS BIGNUMERIC)) + ) + WHEN ( + CAST(`t0`.`float64_col` AS BIGNUMERIC) > 0 ) - WHEN CAST(`float64_col` AS BIGNUMERIC) > CAST(0 AS INT64) AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(`float64_col` AS BIGNUMERIC)) - ) < CAST(0 AS INT64) - THEN CAST(`float64_col` AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(`float64_col` AS BIGNUMERIC)) + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(`t0`.`float64_col` AS BIGNUMERIC)) + ) < 0 ) - ELSE MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(`float64_col` AS BIGNUMERIC)) - END AS `float_mod_float`, - CASE - WHEN CAST(-( - `float64_col` - ) AS BIGNUMERIC) = CAST(0 AS INT64) - THEN CAST('NaN' AS FLOAT64) * CAST(`float64_col` AS BIGNUMERIC) + THEN CAST(`t0`.`float64_col` AS BIGNUMERIC) + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(`t0`.`float64_col` AS BIGNUMERIC)) + ) + ELSE MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(`t0`.`float64_col` AS BIGNUMERIC)) + END AS FLOAT64) AS `float_mod_float`, + CAST(CASE WHEN CAST(-( - `float64_col` - ) AS BIGNUMERIC) < CAST(0 AS INT64) + `t0`.`float64_col` + ) AS BIGNUMERIC) = 0 + THEN CAST('NaN' AS FLOAT64) * CAST(`t0`.`float64_col` AS BIGNUMERIC) + WHEN ( + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) < 0 + ) AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(-( - `float64_col` - ) AS BIGNUMERIC)) - ) > CAST(0 AS INT64) + ( + MOD( + CAST(`t0`.`float64_col` AS BIGNUMERIC), + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) + ) + ) > 0 + ) THEN CAST(-( - `float64_col` + `t0`.`float64_col` ) AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(-( - `float64_col` - ) AS BIGNUMERIC)) + MOD( + CAST(`t0`.`float64_col` AS BIGNUMERIC), + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) + ) + ) + WHEN ( + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) > 0 ) - WHEN CAST(-( - `float64_col` - ) AS BIGNUMERIC) > CAST(0 AS INT64) AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(-( - `float64_col` - ) AS BIGNUMERIC)) - ) < CAST(0 AS INT64) + ( + MOD( + CAST(`t0`.`float64_col` AS BIGNUMERIC), + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) + ) + ) < 0 + ) THEN CAST(-( - `float64_col` + `t0`.`float64_col` ) AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(-( - `float64_col` - ) AS BIGNUMERIC)) - ) - ELSE MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(-( - `float64_col` - ) AS BIGNUMERIC)) - END AS `float_mod_float_neg`, - CASE - WHEN CAST(1 AS BIGNUMERIC) = CAST(0 AS INT64) - THEN CAST('NaN' AS FLOAT64) * CAST(`float64_col` AS BIGNUMERIC) - WHEN CAST(1 AS BIGNUMERIC) < CAST(0 AS INT64) - AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) - ) > CAST(0 AS INT64) - THEN CAST(1 AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) + MOD( + CAST(`t0`.`float64_col` AS BIGNUMERIC), + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) + ) + ) + ELSE MOD( + CAST(`t0`.`float64_col` AS BIGNUMERIC), + CAST(-( + `t0`.`float64_col` + ) AS BIGNUMERIC) + ) + END AS FLOAT64) AS `float_mod_float_neg`, + CAST(CASE + WHEN CAST(1 AS BIGNUMERIC) = 0 + THEN CAST('NaN' AS FLOAT64) * CAST(`t0`.`float64_col` AS BIGNUMERIC) + WHEN ( + CAST(1 AS BIGNUMERIC) < 0 ) - WHEN CAST(1 AS BIGNUMERIC) > CAST(0 AS INT64) AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) - ) < CAST(0 AS INT64) + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) + ) > 0 + ) THEN CAST(1 AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) ) - ELSE MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) - END AS `float_mod_1`, - CASE - WHEN CAST(0 AS BIGNUMERIC) = CAST(0 AS INT64) - THEN CAST('NaN' AS FLOAT64) * CAST(`float64_col` AS BIGNUMERIC) - WHEN CAST(0 AS BIGNUMERIC) < CAST(0 AS INT64) - AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(0 AS BIGNUMERIC)) - ) > CAST(0 AS INT64) - THEN CAST(0 AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(0 AS BIGNUMERIC)) + WHEN ( + CAST(1 AS BIGNUMERIC) > 0 ) - WHEN CAST(0 AS BIGNUMERIC) > CAST(0 AS INT64) AND ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(0 AS BIGNUMERIC)) - ) < CAST(0 AS INT64) - THEN CAST(0 AS BIGNUMERIC) + ( - MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(0 AS BIGNUMERIC)) - ) - ELSE MOD(CAST(`float64_col` AS BIGNUMERIC), CAST(0 AS BIGNUMERIC)) - END AS `float_mod_0` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) + ) < 0 + ) + THEN CAST(1 AS BIGNUMERIC) + ( + MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) + ) + ELSE MOD(CAST(`t0`.`float64_col` AS BIGNUMERIC), CAST(1 AS BIGNUMERIC)) + END AS FLOAT64) AS `float_mod_1`, + CAST(NULL AS FLOAT64) AS `float_mod_0` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_numeric/out.sql index ebe8d571d65..9fb8df2ef65 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` * `int64_col` AS `int_mul_int`, - `int64_col` * 1 AS `int_mul_1`, - NULL AS `int_mul_null`, - `int64_col` * CAST(`bool_col` AS INT64) AS `int_mul_bool`, - CAST(`bool_col` AS INT64) * `int64_col` AS `bool_mul_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` * `t0`.`int64_col` AS `int_mul_int`, + `t0`.`int64_col` * 1 AS `int_mul_1`, + CAST(NULL AS INT64) AS `int_mul_null`, + `t0`.`int64_col` * CAST(`t0`.`bool_col` AS INT64) AS `int_mul_bool`, + CAST(`t0`.`bool_col` AS INT64) * `t0`.`int64_col` AS `bool_mul_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_timedelta/out.sql index 8285d1e7d4a..7467fe878f6 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_mul_timedelta/out.sql @@ -1,16 +1,20 @@ SELECT - `rowindex`, - `timestamp_col`, - `int64_col`, - `duration_col`, - CAST(IF( - `duration_col` * `int64_col` > 0, - FLOOR(`duration_col` * `int64_col`), - CEIL(`duration_col` * `int64_col`) - ) AS INT64) AS `timedelta_mul_numeric`, - CAST(IF( - `int64_col` * `duration_col` > 0, - FLOOR(`int64_col` * `duration_col`), - CEIL(`int64_col` * `duration_col`) - ) AS INT64) AS `numeric_mul_timedelta` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`timestamp_col`, + `t0`.`int64_col`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `duration_col`, + CASE + WHEN ( + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) * `t0`.`int64_col` + ) > 0 + THEN CAST(FLOOR(CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) * `t0`.`int64_col`) AS INT64) + ELSE CAST(CEIL(CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) * `t0`.`int64_col`) AS INT64) + END AS `timedelta_mul_numeric`, + CASE + WHEN ( + `t0`.`int64_col` * CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) + ) > 0 + THEN CAST(FLOOR(`t0`.`int64_col` * CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64)) AS INT64) + ELSE CAST(CEIL(`t0`.`int64_col` * CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64)) AS INT64) + END AS `numeric_mul_timedelta` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_neg/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_neg/out.sql index 13a9f3f6734..e08a6e49f1d 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_neg/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_neg/out.sql @@ -1,5 +1,5 @@ SELECT -( - `float64_col` + `t0`.`float64_col` ) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pos/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pos/out.sql index 1890218bdd9..0b71d304d61 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pos/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pos/out.sql @@ -1,3 +1,3 @@ SELECT - `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pow/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pow/out.sql index 8f72522262c..0170b02ba74 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pow/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_pow/out.sql @@ -1,245 +1,330 @@ SELECT - `rowindex`, - `int64_col`, - `float64_col`, + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`float64_col`, CASE - WHEN `int64_col` <> 0 AND `int64_col` * LN(ABS(`int64_col`)) > 43.66827237527655 + WHEN ( + ( + POWER(CAST(`t0`.`int64_col` AS NUMERIC), `t0`.`int64_col`) + ) > 9223372036854775807 + ) + OR ( + ( + POWER(CAST(`t0`.`int64_col` AS NUMERIC), `t0`.`int64_col`) + ) < -9223372036854775808 + ) THEN NULL - ELSE CAST(POWER(CAST(`int64_col` AS NUMERIC), `int64_col`) AS INT64) + ELSE CAST(trunc(POWER(CAST(`t0`.`int64_col` AS NUMERIC), `t0`.`int64_col`)) AS INT64) END AS `int_pow_int`, CASE - WHEN `float64_col` = CAST(0 AS INT64) + WHEN `t0`.`float64_col` = 0 THEN 1 - WHEN `int64_col` = 1 + WHEN `t0`.`int64_col` = 1 THEN 1 - WHEN `int64_col` = CAST(0 AS INT64) AND `float64_col` < CAST(0 AS INT64) + WHEN ( + `t0`.`int64_col` = 0 + ) AND ( + `t0`.`float64_col` < 0 + ) THEN CAST('Infinity' AS FLOAT64) - WHEN ABS(`int64_col`) = CAST('Infinity' AS FLOAT64) + WHEN ABS(`t0`.`int64_col`) = CAST('Infinity' AS FLOAT64) THEN POWER( - `int64_col`, - CASE - WHEN ABS(`float64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`float64_col`) - ELSE `float64_col` - END - ) - WHEN ABS(`float64_col`) > 9007199254740992 + `t0`.`int64_col`, + IF( + ABS(`t0`.`float64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + `t0`.`float64_col` + ) + ) + WHEN ABS(`t0`.`float64_col`) > 9007199254740992 THEN POWER( - `int64_col`, - CASE - WHEN ABS(`float64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`float64_col`) - ELSE `float64_col` - END - ) - WHEN `int64_col` < CAST(0 AS INT64) + `t0`.`int64_col`, + IF( + ABS(`t0`.`float64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + `t0`.`float64_col` + ) + ) + WHEN ( + `t0`.`int64_col` < 0 + ) AND NOT ( - CAST(`float64_col` AS INT64) = `float64_col` + CAST(trunc(`t0`.`float64_col`) AS INT64) = `t0`.`float64_col` ) THEN CAST('NaN' AS FLOAT64) - WHEN `int64_col` <> CAST(0 AS INT64) AND `float64_col` * LN(ABS(`int64_col`)) > 709.78 - THEN CAST('Infinity' AS FLOAT64) * CASE - WHEN `int64_col` < CAST(0 AS INT64) AND MOD(CAST(`float64_col` AS INT64), 2) = 1 - THEN -1 - ELSE 1 - END + WHEN ( + `t0`.`int64_col` <> 0 + ) + AND ( + ( + `t0`.`float64_col` * LN(ABS(`t0`.`int64_col`)) + ) > 709.78 + ) + THEN CAST('Infinity' AS FLOAT64) * IF( + ( + `t0`.`int64_col` < 0 + ) + AND ( + ( + MOD(CAST(trunc(`t0`.`float64_col`) AS INT64), 2) + ) = 1 + ), + -1, + 1 + ) ELSE POWER( - `int64_col`, - CASE - WHEN ABS(`float64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`float64_col`) - ELSE `float64_col` - END + `t0`.`int64_col`, + IF( + ABS(`t0`.`float64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + `t0`.`float64_col` + ) ) END AS `int_pow_float`, CASE - WHEN `int64_col` = CAST(0 AS INT64) + WHEN `t0`.`int64_col` = 0 THEN 1 - WHEN `float64_col` = 1 + WHEN `t0`.`float64_col` = 1 THEN 1 - WHEN `float64_col` = CAST(0 AS INT64) AND `int64_col` < CAST(0 AS INT64) + WHEN ( + `t0`.`float64_col` = 0 + ) AND ( + `t0`.`int64_col` < 0 + ) THEN CAST('Infinity' AS FLOAT64) - WHEN ABS(`float64_col`) = CAST('Infinity' AS FLOAT64) + WHEN ABS(`t0`.`float64_col`) = CAST('Infinity' AS FLOAT64) THEN POWER( - `float64_col`, - CASE - WHEN ABS(`int64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`int64_col`) - ELSE `int64_col` - END - ) - WHEN ABS(`int64_col`) > 9007199254740992 + `t0`.`float64_col`, + IF( + ABS(`t0`.`int64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`int64_col`), + `t0`.`int64_col` + ) + ) + WHEN ABS(`t0`.`int64_col`) > 9007199254740992 THEN POWER( - `float64_col`, - CASE - WHEN ABS(`int64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`int64_col`) - ELSE `int64_col` - END - ) - WHEN `float64_col` < CAST(0 AS INT64) - AND NOT ( - CAST(`int64_col` AS INT64) = `int64_col` + `t0`.`float64_col`, + IF( + ABS(`t0`.`int64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`int64_col`), + `t0`.`int64_col` + ) + ) + WHEN ( + `t0`.`float64_col` < 0 + ) AND NOT ( + `t0`.`int64_col` = `t0`.`int64_col` ) THEN CAST('NaN' AS FLOAT64) - WHEN `float64_col` <> CAST(0 AS INT64) - AND `int64_col` * LN(ABS(`float64_col`)) > 709.78 - THEN CAST('Infinity' AS FLOAT64) * CASE - WHEN `float64_col` < CAST(0 AS INT64) AND MOD(CAST(`int64_col` AS INT64), 2) = 1 - THEN -1 - ELSE 1 - END + WHEN ( + `t0`.`float64_col` <> 0 + ) + AND ( + ( + `t0`.`int64_col` * LN(ABS(`t0`.`float64_col`)) + ) > 709.78 + ) + THEN CAST('Infinity' AS FLOAT64) * IF(( + `t0`.`float64_col` < 0 + ) AND ( + ( + MOD(`t0`.`int64_col`, 2) + ) = 1 + ), -1, 1) ELSE POWER( - `float64_col`, - CASE - WHEN ABS(`int64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`int64_col`) - ELSE `int64_col` - END + `t0`.`float64_col`, + IF( + ABS(`t0`.`int64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`int64_col`), + `t0`.`int64_col` + ) ) END AS `float_pow_int`, CASE - WHEN `float64_col` = CAST(0 AS INT64) + WHEN `t0`.`float64_col` = 0 THEN 1 - WHEN `float64_col` = 1 + WHEN `t0`.`float64_col` = 1 THEN 1 - WHEN `float64_col` = CAST(0 AS INT64) AND `float64_col` < CAST(0 AS INT64) + WHEN ( + `t0`.`float64_col` = 0 + ) AND ( + `t0`.`float64_col` < 0 + ) THEN CAST('Infinity' AS FLOAT64) - WHEN ABS(`float64_col`) = CAST('Infinity' AS FLOAT64) + WHEN ABS(`t0`.`float64_col`) = CAST('Infinity' AS FLOAT64) THEN POWER( - `float64_col`, - CASE - WHEN ABS(`float64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`float64_col`) - ELSE `float64_col` - END - ) - WHEN ABS(`float64_col`) > 9007199254740992 + `t0`.`float64_col`, + IF( + ABS(`t0`.`float64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + `t0`.`float64_col` + ) + ) + WHEN ABS(`t0`.`float64_col`) > 9007199254740992 THEN POWER( - `float64_col`, - CASE - WHEN ABS(`float64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`float64_col`) - ELSE `float64_col` - END - ) - WHEN `float64_col` < CAST(0 AS INT64) + `t0`.`float64_col`, + IF( + ABS(`t0`.`float64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + `t0`.`float64_col` + ) + ) + WHEN ( + `t0`.`float64_col` < 0 + ) AND NOT ( - CAST(`float64_col` AS INT64) = `float64_col` + CAST(trunc(`t0`.`float64_col`) AS INT64) = `t0`.`float64_col` ) THEN CAST('NaN' AS FLOAT64) - WHEN `float64_col` <> CAST(0 AS INT64) - AND `float64_col` * LN(ABS(`float64_col`)) > 709.78 - THEN CAST('Infinity' AS FLOAT64) * CASE - WHEN `float64_col` < CAST(0 AS INT64) AND MOD(CAST(`float64_col` AS INT64), 2) = 1 - THEN -1 - ELSE 1 - END + WHEN ( + `t0`.`float64_col` <> 0 + ) + AND ( + ( + `t0`.`float64_col` * LN(ABS(`t0`.`float64_col`)) + ) > 709.78 + ) + THEN CAST('Infinity' AS FLOAT64) * IF( + ( + `t0`.`float64_col` < 0 + ) + AND ( + ( + MOD(CAST(trunc(`t0`.`float64_col`) AS INT64), 2) + ) = 1 + ), + -1, + 1 + ) ELSE POWER( - `float64_col`, - CASE - WHEN ABS(`float64_col`) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(`float64_col`) - ELSE `float64_col` - END + `t0`.`float64_col`, + IF( + ABS(`t0`.`float64_col`) > 9007199254740992, + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + `t0`.`float64_col` + ) ) END AS `float_pow_float`, CASE - WHEN `int64_col` <> 0 AND 0 * LN(ABS(`int64_col`)) > 43.66827237527655 + WHEN ( + ( + POWER(CAST(`t0`.`int64_col` AS NUMERIC), 0) + ) > 9223372036854775807 + ) + OR ( + ( + POWER(CAST(`t0`.`int64_col` AS NUMERIC), 0) + ) < -9223372036854775808 + ) THEN NULL - ELSE CAST(POWER(CAST(`int64_col` AS NUMERIC), 0) AS INT64) + ELSE CAST(trunc(POWER(CAST(`t0`.`int64_col` AS NUMERIC), 0)) AS INT64) END AS `int_pow_0`, CASE - WHEN 0 = CAST(0 AS INT64) + WHEN 0 = 0 THEN 1 - WHEN `float64_col` = 1 + WHEN `t0`.`float64_col` = 1 THEN 1 - WHEN `float64_col` = CAST(0 AS INT64) AND 0 < CAST(0 AS INT64) + WHEN ( + `t0`.`float64_col` = 0 + ) AND ( + 0 < 0 + ) THEN CAST('Infinity' AS FLOAT64) - WHEN ABS(`float64_col`) = CAST('Infinity' AS FLOAT64) + WHEN ABS(`t0`.`float64_col`) = CAST('Infinity' AS FLOAT64) THEN POWER( - `float64_col`, - CASE - WHEN ABS(0) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(0) - ELSE 0 - END + `t0`.`float64_col`, + IF(ABS(0) > 9007199254740992, CAST('Infinity' AS FLOAT64) * SIGN(0), 0) ) WHEN ABS(0) > 9007199254740992 THEN POWER( - `float64_col`, - CASE - WHEN ABS(0) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(0) - ELSE 0 - END + `t0`.`float64_col`, + IF(ABS(0) > 9007199254740992, CAST('Infinity' AS FLOAT64) * SIGN(0), 0) ) - WHEN `float64_col` < CAST(0 AS INT64) AND NOT ( - CAST(0 AS INT64) = 0 + WHEN ( + `t0`.`float64_col` < 0 + ) AND NOT ( + 0 = 0 ) THEN CAST('NaN' AS FLOAT64) - WHEN `float64_col` <> CAST(0 AS INT64) AND 0 * LN(ABS(`float64_col`)) > 709.78 - THEN CAST('Infinity' AS FLOAT64) * CASE - WHEN `float64_col` < CAST(0 AS INT64) AND MOD(CAST(0 AS INT64), 2) = 1 - THEN -1 - ELSE 1 - END + WHEN ( + `t0`.`float64_col` <> 0 + ) + AND ( + ( + 0 * LN(ABS(`t0`.`float64_col`)) + ) > 709.78 + ) + THEN CAST('Infinity' AS FLOAT64) * IF(( + `t0`.`float64_col` < 0 + ) AND ( + ( + MOD(0, 2) + ) = 1 + ), -1, 1) ELSE POWER( - `float64_col`, - CASE - WHEN ABS(0) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(0) - ELSE 0 - END + `t0`.`float64_col`, + IF(ABS(0) > 9007199254740992, CAST('Infinity' AS FLOAT64) * SIGN(0), 0) ) END AS `float_pow_0`, CASE - WHEN `int64_col` <> 0 AND 1 * LN(ABS(`int64_col`)) > 43.66827237527655 + WHEN ( + ( + POWER(CAST(`t0`.`int64_col` AS NUMERIC), 1) + ) > 9223372036854775807 + ) + OR ( + ( + POWER(CAST(`t0`.`int64_col` AS NUMERIC), 1) + ) < -9223372036854775808 + ) THEN NULL - ELSE CAST(POWER(CAST(`int64_col` AS NUMERIC), 1) AS INT64) + ELSE CAST(trunc(POWER(CAST(`t0`.`int64_col` AS NUMERIC), 1)) AS INT64) END AS `int_pow_1`, CASE - WHEN 1 = CAST(0 AS INT64) + WHEN 1 = 0 THEN 1 - WHEN `float64_col` = 1 + WHEN `t0`.`float64_col` = 1 THEN 1 - WHEN `float64_col` = CAST(0 AS INT64) AND 1 < CAST(0 AS INT64) + WHEN ( + `t0`.`float64_col` = 0 + ) AND ( + 1 < 0 + ) THEN CAST('Infinity' AS FLOAT64) - WHEN ABS(`float64_col`) = CAST('Infinity' AS FLOAT64) + WHEN ABS(`t0`.`float64_col`) = CAST('Infinity' AS FLOAT64) THEN POWER( - `float64_col`, - CASE - WHEN ABS(1) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(1) - ELSE 1 - END + `t0`.`float64_col`, + IF(ABS(1) > 9007199254740992, CAST('Infinity' AS FLOAT64) * SIGN(1), 1) ) WHEN ABS(1) > 9007199254740992 THEN POWER( - `float64_col`, - CASE - WHEN ABS(1) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(1) - ELSE 1 - END + `t0`.`float64_col`, + IF(ABS(1) > 9007199254740992, CAST('Infinity' AS FLOAT64) * SIGN(1), 1) ) - WHEN `float64_col` < CAST(0 AS INT64) AND NOT ( - CAST(1 AS INT64) = 1 + WHEN ( + `t0`.`float64_col` < 0 + ) AND NOT ( + 1 = 1 ) THEN CAST('NaN' AS FLOAT64) - WHEN `float64_col` <> CAST(0 AS INT64) AND 1 * LN(ABS(`float64_col`)) > 709.78 - THEN CAST('Infinity' AS FLOAT64) * CASE - WHEN `float64_col` < CAST(0 AS INT64) AND MOD(CAST(1 AS INT64), 2) = 1 - THEN -1 - ELSE 1 - END + WHEN ( + `t0`.`float64_col` <> 0 + ) + AND ( + ( + 1 * LN(ABS(`t0`.`float64_col`)) + ) > 709.78 + ) + THEN CAST('Infinity' AS FLOAT64) * IF(( + `t0`.`float64_col` < 0 + ) AND ( + ( + MOD(1, 2) + ) = 1 + ), -1, 1) ELSE POWER( - `float64_col`, - CASE - WHEN ABS(1) > 9007199254740992 - THEN CAST('Infinity' AS FLOAT64) * SIGN(1) - ELSE 1 - END + `t0`.`float64_col`, + IF(ABS(1) > 9007199254740992, CAST('Infinity' AS FLOAT64) * SIGN(1), 1) ) END AS `float_pow_1` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_round/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_round/out.sql index 9ac8e1065b5..ddfec399921 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_round/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_round/out.sql @@ -1,11 +1,11 @@ SELECT - `rowindex`, - `int64_col`, - `float64_col`, - CAST(ROUND(`int64_col`, 0) AS INT64) AS `int_round_0`, - CAST(ROUND(`int64_col`, 1) AS INT64) AS `int_round_1`, - CAST(ROUND(`int64_col`, -1) AS INT64) AS `int_round_m1`, - ROUND(`float64_col`, 0) AS `float_round_0`, - ROUND(`float64_col`, 1) AS `float_round_1`, - ROUND(`float64_col`, -1) AS `float_round_m1` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`float64_col`, + CAST(trunc(ROUND(`t0`.`int64_col`, 0)) AS INT64) AS `int_round_0`, + CAST(trunc(ROUND(`t0`.`int64_col`, 1)) AS INT64) AS `int_round_1`, + CAST(trunc(ROUND(`t0`.`int64_col`, -1)) AS INT64) AS `int_round_m1`, + ROUND(`t0`.`float64_col`, 0) AS `float_round_0`, + ROUND(`t0`.`float64_col`, 1) AS `float_round_1`, + ROUND(`t0`.`float64_col`, -1) AS `float_round_m1` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sin/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sin/out.sql index ddc7cfab6ce..9bccc3c6fe0 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sin/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sin/out.sql @@ -1,3 +1,3 @@ SELECT - SIN(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + SIN(`t0`.`float64_col`) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sinh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sinh/out.sql index a1d71a7a065..97abc38f2e2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sinh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sinh/out.sql @@ -1,7 +1,11 @@ SELECT - CASE - WHEN ABS(`float64_col`) > 709.78 - THEN SIGN(`float64_col`) * CAST('Infinity' AS FLOAT64) - ELSE SINH(`float64_col`) - END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ABS(`t0`.`float64_col`) < 709.78 + ), + CAST('Infinity' AS FLOAT64) * SIGN(`t0`.`float64_col`), + ieee_divide(EXP(`t0`.`float64_col`) - EXP(-( + `t0`.`float64_col` + )), 2) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sqrt/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sqrt/out.sql index 6162a69d571..928c82ee5ba 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sqrt/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sqrt/out.sql @@ -1,3 +1,5 @@ SELECT - CASE WHEN `float64_col` < 0 THEN CAST('NaN' AS FLOAT64) ELSE SQRT(`float64_col`) END AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF(NOT ( + `t0`.`float64_col` >= 0 + ), CAST('NaN' AS FLOAT64), SQRT(`t0`.`float64_col`)) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_numeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_numeric/out.sql index c1d0350a664..68afe5cc56b 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_numeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_numeric/out.sql @@ -1,10 +1,10 @@ SELECT - `rowindex`, - `int64_col`, - `bool_col`, - `int64_col` - `int64_col` AS `int_sub_int`, - `int64_col` - 1 AS `int_sub_1`, - NULL AS `int_sub_null`, - `int64_col` - CAST(`bool_col` AS INT64) AS `int_sub_bool`, - CAST(`bool_col` AS INT64) - `int64_col` AS `bool_sub_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`bool_col`, + `t0`.`int64_col` - `t0`.`int64_col` AS `int_sub_int`, + `t0`.`int64_col` - 1 AS `int_sub_1`, + CAST(NULL AS INT64) AS `int_sub_null`, + `t0`.`int64_col` - CAST(`t0`.`bool_col` AS INT64) AS `int_sub_bool`, + CAST(`t0`.`bool_col` AS INT64) - `t0`.`int64_col` AS `bool_sub_int` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_timedelta/out.sql index 5c8b130d59d..f643fb8f263 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_sub_timedelta/out.sql @@ -1,11 +1,17 @@ SELECT - `rowindex`, - `timestamp_col`, - `duration_col`, - `date_col`, - TIMESTAMP_SUB(CAST(`date_col` AS DATETIME), INTERVAL `duration_col` MICROSECOND) AS `date_sub_timedelta`, - TIMESTAMP_SUB(`timestamp_col`, INTERVAL `duration_col` MICROSECOND) AS `timestamp_sub_timedelta`, - TIMESTAMP_DIFF(CAST(`date_col` AS DATETIME), CAST(`date_col` AS DATETIME), MICROSECOND) AS `timestamp_sub_date`, - TIMESTAMP_DIFF(`timestamp_col`, `timestamp_col`, MICROSECOND) AS `date_sub_timestamp`, - `duration_col` - `duration_col` AS `timedelta_sub_timedelta` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`timestamp_col`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `duration_col`, + `t0`.`date_col`, + TIMESTAMP_SUB( + CAST(`t0`.`date_col` AS DATETIME), + INTERVAL (CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64)) MICROSECOND + ) AS `date_sub_timedelta`, + TIMESTAMP_SUB( + `t0`.`timestamp_col`, + INTERVAL (CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64)) MICROSECOND + ) AS `timestamp_sub_timedelta`, + DATE_DIFF(`t0`.`date_col`, `t0`.`date_col`, DAY) * 86400000000 AS `timestamp_sub_date`, + TIMESTAMP_DIFF(`t0`.`timestamp_col`, `t0`.`timestamp_col`, MICROSECOND) AS `date_sub_timestamp`, + CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) - CAST(FLOOR(`t0`.`duration_col` * 1) AS INT64) AS `timedelta_sub_timedelta` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tan/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tan/out.sql index 138b5f84a3b..88f6f2cc58e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tan/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tan/out.sql @@ -1,3 +1,3 @@ SELECT - TAN(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + TAN(`t0`.`float64_col`) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tanh/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tanh/out.sql index c5db31c9579..fbd89ac47a8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tanh/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_tanh/out.sql @@ -1,3 +1,16 @@ SELECT - TANH(`float64_col`) AS `float64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + IF( + NOT ( + ABS(`t0`.`float64_col`) < 20 + ), + SIGN(`t0`.`float64_col`), + ieee_divide( + EXP(`t0`.`float64_col`) - EXP(-( + `t0`.`float64_col` + )), + EXP(`t0`.`float64_col`) + EXP(-( + `t0`.`float64_col` + )) + ) + ) AS `float64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_unsafe_pow_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_unsafe_pow_op/out.sql index 0795b64a209..35b34e22a99 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_unsafe_pow_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_numeric_ops/test_unsafe_pow_op/out.sql @@ -1,14 +1,21 @@ SELECT - POWER(`int64_col`, `int64_col`) AS `int_pow_int`, - POWER(`int64_col`, `float64_col`) AS `int_pow_float`, - POWER(`float64_col`, `int64_col`) AS `float_pow_int`, - POWER(`float64_col`, `float64_col`) AS `float_pow_float`, - POWER(`int64_col`, CAST(`bool_col` AS INT64)) AS `int_pow_bool`, - POWER(CAST(`bool_col` AS INT64), `int64_col`) AS `bool_pow_int` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + POWER(`t1`.`bfuid_col_1432`, `t1`.`bfuid_col_1432`) AS `int_pow_int`, + POWER(`t1`.`bfuid_col_1432`, `t1`.`bfuid_col_1435`) AS `int_pow_float`, + POWER(`t1`.`bfuid_col_1435`, `t1`.`bfuid_col_1432`) AS `float_pow_int`, + POWER(`t1`.`bfuid_col_1435`, `t1`.`bfuid_col_1435`) AS `float_pow_float`, + POWER(`t1`.`bfuid_col_1432`, CAST(`t1`.`bfuid_col_1427` AS INT64)) AS `int_pow_bool`, + POWER(CAST(`t1`.`bfuid_col_1427` AS INT64), `t1`.`bfuid_col_1432`) AS `bool_pow_int` +FROM ( + SELECT + `t0`.`bool_col` AS `bfuid_col_1427`, + `t0`.`int64_col` AS `bfuid_col_1432`, + `t0`.`float64_col` AS `bfuid_col_1435`, + ( + `t0`.`int64_col` >= 0 + ) AND ( + `t0`.`int64_col` <= 10 + ) AS `bfuid_col_1442` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` WHERE - ( - `int64_col` >= 0 - ) AND ( - `int64_col` <= 10 - ) \ No newline at end of file + `t1`.`bfuid_col_1442` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_add_string/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_add_string/out.sql index cf4051464b7..ebdec70eed5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_add_string/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_add_string/out.sql @@ -1,3 +1,3 @@ SELECT - CONCAT(`string_col`, 'a') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CONCAT(`t0`.`string_col`, 'a') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_capitalize/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_capitalize/out.sql index d11ce9b9934..824a1d521dc 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_capitalize/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_capitalize/out.sql @@ -1,3 +1,18 @@ SELECT - INITCAP(`string_col`, '') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CONCAT( + UPPER( + SUBSTRING(`t0`.`string_col`, IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(`t0`.`string_col`)), 1) + ), + LOWER( + SUBSTRING( + `t0`.`string_col`, + IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(`t0`.`string_col`)), + LENGTH(`t0`.`string_col`) + ) + ) + ) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_endswith/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_endswith/out.sql index 0295af27992..45f50b9d4d8 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_endswith/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_endswith/out.sql @@ -1,5 +1,5 @@ SELECT - ENDS_WITH(`string_col`, 'ab') AS `single`, - ENDS_WITH(`string_col`, 'ab') OR ENDS_WITH(`string_col`, 'cd') AS `double`, + ENDS_WITH(`t0`.`string_col`, 'ab') AS `single`, + ENDS_WITH(`t0`.`string_col`, 'ab') OR ENDS_WITH(`t0`.`string_col`, 'cd') AS `double`, FALSE AS `empty` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalnum/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalnum/out.sql index 7654299c79e..2b8254929ae 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalnum/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalnum/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_CONTAINS(`string_col`, '^(\\p{N}|\\p{L})+$') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '^(\\p{N}|\\p{Lm}|\\p{Lt}|\\p{Lu}|\\p{Ll}|\\p{Lo})+$') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalpha/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalpha/out.sql index 33a08ff054d..63b73b399ee 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalpha/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isalpha/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_CONTAINS(`string_col`, '^\\p{L}+$') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '^(\\p{Lm}|\\p{Lt}|\\p{Lu}|\\p{Ll}|\\p{Lo})+$') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdecimal/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdecimal/out.sql index 7f266cbf604..fe686421823 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdecimal/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdecimal/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_CONTAINS(`string_col`, '^(\\p{Nd})+$') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '^(\\p{Nd})+$') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdigit/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdigit/out.sql index 9134d035153..056674ac9a1 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdigit/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isdigit/out.sql @@ -1,6 +1,6 @@ SELECT - REGEXP_CONTAINS( - `string_col`, + regexp_contains( + `t0`.`string_col`, '^[\\p{Nd}\\x{00B9}\\x{00B2}\\x{00B3}\\x{2070}\\x{2074}-\\x{2079}\\x{2080}-\\x{2089}]+$' ) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_islower/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_islower/out.sql index bce92035e5c..f0fd996c684 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_islower/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_islower/out.sql @@ -1,3 +1,6 @@ SELECT - LOWER(`string_col`) = `string_col` AND UPPER(`string_col`) <> `string_col` AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '\\p{Ll}') + AND NOT ( + regexp_contains(`t0`.`string_col`, '\\p{Lu}|\\p{Lt}') + ) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isnumeric/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isnumeric/out.sql index 82baa081f54..c5ce5e1def7 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isnumeric/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isnumeric/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_CONTAINS(`string_col`, '^\\pN+$') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '^(\\pN+)$') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isspace/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isspace/out.sql index 2b44a592d93..c3e23887aea 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isspace/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isspace/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_CONTAINS(`string_col`, '^\\s+$') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '^\\s+$') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isupper/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isupper/out.sql index 17ac14ac53f..c313f956744 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isupper/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_isupper/out.sql @@ -1,3 +1,6 @@ SELECT - UPPER(`string_col`) = `string_col` AND LOWER(`string_col`) <> `string_col` AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, '\\p{Lu}') + AND NOT ( + regexp_contains(`t0`.`string_col`, '\\p{Ll}|\\p{Lt}') + ) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len/out.sql index cff109d09dc..24d02e7a82f 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len/out.sql @@ -1,3 +1,3 @@ SELECT - LENGTH(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + LENGTH(`t0`.`string_col`) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len_w_array/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len_w_array/out.sql index 1862deb6015..9b8e8da6131 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len_w_array/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_len_w_array/out.sql @@ -1,3 +1,3 @@ SELECT - ARRAY_LENGTH(`int_list_col`) AS `int_list_col` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file + ARRAY_LENGTH(`t0`.`int_list_col`) AS `int_list_col` +FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lower/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lower/out.sql index 851de35ecb0..adb0abb11c6 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lower/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lower/out.sql @@ -1,3 +1,3 @@ SELECT - LOWER(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + LOWER(`t0`.`string_col`) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lstrip/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lstrip/out.sql index 4023605f8c9..19e962745d7 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lstrip/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_lstrip/out.sql @@ -1,3 +1,7 @@ SELECT - LTRIM(`string_col`, ' ') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + LTRIM(`t1`.`string_col`, ' ') AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_regex_replace_str/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_regex_replace_str/out.sql index 4728c961ab3..d5cbf731a59 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_regex_replace_str/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_regex_replace_str/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_REPLACE(`string_col`, 'e', 'a') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + REGEXP_REPLACE(`t0`.`string_col`, 'e', 'a') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_replace_str/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_replace_str/out.sql index 154af44b500..b3ac03b2d92 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_replace_str/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_replace_str/out.sql @@ -1,3 +1,3 @@ SELECT - REPLACE(`string_col`, 'e', 'a') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + REPLACE(`t0`.`string_col`, 'e', 'a') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_reverse/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_reverse/out.sql index 97bf57f79e1..ecf2bf376e4 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_reverse/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_reverse/out.sql @@ -1,3 +1,3 @@ SELECT - REVERSE(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + REVERSE(`t0`.`string_col`) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_rstrip/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_rstrip/out.sql index c3d25b56e24..b3b3597f31e 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_rstrip/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_rstrip/out.sql @@ -1,3 +1,7 @@ SELECT - RTRIM(`string_col`, ' ') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + RTRIM(`t1`.`string_col`, ' ') AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_startswith/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_startswith/out.sql index 760d3db7745..97be6ccd93b 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_startswith/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_startswith/out.sql @@ -1,5 +1,5 @@ SELECT - STARTS_WITH(`string_col`, 'ab') AS `single`, - STARTS_WITH(`string_col`, 'ab') OR STARTS_WITH(`string_col`, 'cd') AS `double`, + STARTS_WITH(`t0`.`string_col`, 'ab') AS `single`, + STARTS_WITH(`t0`.`string_col`, 'ab') OR STARTS_WITH(`t0`.`string_col`, 'cd') AS `double`, FALSE AS `empty` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains/out.sql index 9071a252bc1..5f21bd21615 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains/out.sql @@ -1,3 +1,3 @@ SELECT - `string_col` LIKE '%e%' AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + INSTR(`t0`.`string_col`, 'e') > 0 AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains_regex/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains_regex/out.sql index 958f9af6f39..797ccb82929 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains_regex/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_contains_regex/out.sql @@ -1,3 +1,3 @@ SELECT - REGEXP_CONTAINS(`string_col`, 'e') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + regexp_contains(`t0`.`string_col`, 'e') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_extract/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_extract/out.sql index a87f5d9836d..3a976236c7c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_extract/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_extract/out.sql @@ -1,12 +1,20 @@ SELECT IF( - REGEXP_CONTAINS(`string_col`, '([a-z]*)'), - REGEXP_REPLACE(`string_col`, CONCAT('.*?(', '([a-z]*)', ').*'), '\\1'), + regexp_contains(`t0`.`string_col`, '([a-z]*)'), + IF( + 0 = 0, + REGEXP_REPLACE(`t0`.`string_col`, CONCAT('.*?', CONCAT('(', '([a-z]*)', ')'), '.*'), '\\1'), + REGEXP_REPLACE(`t0`.`string_col`, CONCAT('.*?', '([a-z]*)', '.*'), CONCAT('\\', CAST(0 AS STRING))) + ), NULL ) AS `zero`, IF( - REGEXP_CONTAINS(`string_col`, '([a-z]*)'), - REGEXP_REPLACE(`string_col`, CONCAT('.*?', '([a-z]*)', '.*'), '\\1'), + regexp_contains(`t0`.`string_col`, '([a-z]*)'), + IF( + 1 = 0, + REGEXP_REPLACE(`t0`.`string_col`, CONCAT('.*?', CONCAT('(', '([a-z]*)', ')'), '.*'), '\\1'), + REGEXP_REPLACE(`t0`.`string_col`, CONCAT('.*?', '([a-z]*)', '.*'), CONCAT('\\', CAST(1 AS STRING))) + ), NULL ) AS `one` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_get/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_get/out.sql index b4c7c504fc9..6fa2ba7cbc2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_get/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_get/out.sql @@ -1,3 +1,8 @@ SELECT - IF(SUBSTRING(`string_col`, 2, 1) <> '', SUBSTRING(`string_col`, 2, 1), NULL) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + NULLIF( + SUBSTRING(`t0`.`string_col`, IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(`t0`.`string_col`)), 1), + '' + ) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_pad/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_pad/out.sql index 29766cca6c1..22024bba91c 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_pad/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_pad/out.sql @@ -1,13 +1,17 @@ SELECT - LPAD(`string_col`, GREATEST(LENGTH(`string_col`), 10), '-') AS `left`, - RPAD(`string_col`, GREATEST(LENGTH(`string_col`), 10), '-') AS `right`, + LPAD(`t0`.`string_col`, GREATEST(LENGTH(`t0`.`string_col`), 10), '-') AS `left`, + RPAD(`t0`.`string_col`, GREATEST(LENGTH(`t0`.`string_col`), 10), '-') AS `right`, RPAD( LPAD( - `string_col`, - CAST(FLOOR(SAFE_DIVIDE(GREATEST(LENGTH(`string_col`), 10) - LENGTH(`string_col`), 2)) AS INT64) + LENGTH(`string_col`), + `t0`.`string_col`, + ( + CAST(FLOOR( + ieee_divide(GREATEST(LENGTH(`t0`.`string_col`), 10) - LENGTH(`t0`.`string_col`), 2) + ) AS INT64) + ) + LENGTH(`t0`.`string_col`), '-' ), - GREATEST(LENGTH(`string_col`), 10), + GREATEST(LENGTH(`t0`.`string_col`), 10), '-' ) AS `both` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_repeat/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_repeat/out.sql index ed3d06ed35a..8577b9cfc9a 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_repeat/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_repeat/out.sql @@ -1,3 +1,3 @@ SELECT - REPEAT(`string_col`, 2) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + REPEAT(`t0`.`string_col`, 2) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_slice/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_slice/out.sql index b10f4b29e60..e937b329820 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_slice/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_slice/out.sql @@ -1,18 +1,100 @@ SELECT - SUBSTRING(`string_col`, 2, 2) AS `1_3`, - SUBSTRING(`string_col`, 1, 3) AS `none_3`, - SUBSTRING(`string_col`, 2) AS `1_none`, - SUBSTRING(`string_col`, -3) AS `m3_none`, - SUBSTRING(`string_col`, 1, GREATEST(0, LENGTH(`string_col`) + -3)) AS `none_m3`, - SUBSTRING( - `string_col`, - GREATEST(1, LENGTH(`string_col`) + -4), - GREATEST(0, LENGTH(`string_col`) + -3) - GREATEST(0, LENGTH(`string_col`) + -5) + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + ) >= 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + IF(3 >= 0, 3, GREATEST(0, LENGTH(`t0`.`string_col`) + 3)) - IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + ) + ) AS `1_3`, + SUBSTRING( + `t0`.`string_col`, + IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(`t0`.`string_col`)), + GREATEST(0, IF(3 >= 0, 3, GREATEST(0, LENGTH(`t0`.`string_col`) + 3)) - 0) + ) AS `none_3`, + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + ) >= 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + LENGTH(`t0`.`string_col`) - IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + ) + ) AS `1_none`, + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + 1 + ) >= 1, + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + 1, + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + LENGTH(`t0`.`string_col`) - IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + ) + ) AS `m3_none`, + SUBSTRING( + `t0`.`string_col`, + IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(`t0`.`string_col`)), + GREATEST(0, IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) - 0) + ) AS `none_m3`, + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(-5 >= 0, -5, GREATEST(0, LENGTH(`t0`.`string_col`) + -5)) + 1 + ) >= 1, + IF(-5 >= 0, -5, GREATEST(0, LENGTH(`t0`.`string_col`) + -5)) + 1, + IF(-5 >= 0, -5, GREATEST(0, LENGTH(`t0`.`string_col`) + -5)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) - IF(-5 >= 0, -5, GREATEST(0, LENGTH(`t0`.`string_col`) + -5)) + ) ) AS `m5_m3`, - SUBSTRING(`string_col`, 2, GREATEST(0, LENGTH(`string_col`) + -4)) AS `1_m3`, SUBSTRING( - `string_col`, - GREATEST(1, LENGTH(`string_col`) + -2), - 5 - GREATEST(0, LENGTH(`string_col`) + -3) + `t0`.`string_col`, + IF( + ( + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + ) >= 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1, + IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) - IF(1 >= 0, 1, GREATEST(0, LENGTH(`t0`.`string_col`) + 1)) + ) + ) AS `1_m3`, + SUBSTRING( + `t0`.`string_col`, + IF( + ( + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + 1 + ) >= 1, + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + 1, + IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + 1 + LENGTH(`t0`.`string_col`) + ), + GREATEST( + 0, + IF(5 >= 0, 5, GREATEST(0, LENGTH(`t0`.`string_col`) + 5)) - IF(-3 >= 0, -3, GREATEST(0, LENGTH(`t0`.`string_col`) + -3)) + ) ) AS `m3_5` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql index cf4051464b7..ebdec70eed5 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strconcat/out.sql @@ -1,3 +1,3 @@ SELECT - CONCAT(`string_col`, 'a') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CONCAT(`t0`.`string_col`, 'a') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_string_split/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_string_split/out.sql index 5145d6686a8..6014bd9b342 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_string_split/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_string_split/out.sql @@ -1,3 +1,3 @@ SELECT - SPLIT(`string_col`, ',') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + SPLIT(`t0`.`string_col`, ',') AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strip/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strip/out.sql index e07185292bb..a4781b21fc2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strip/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_strip/out.sql @@ -1,3 +1,7 @@ SELECT - TRIM(`string_col`, ' ') AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + TRIM(`t1`.`string_col`, ' ') AS `string_col` +FROM ( + SELECT + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_upper/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_upper/out.sql index 88bd78bd095..27ac52e78d6 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_upper/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_upper/out.sql @@ -1,3 +1,3 @@ SELECT - UPPER(`string_col`) AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + UPPER(`t0`.`string_col`) AS `string_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_zfill/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_zfill/out.sql index 818d2907add..f768c62c222 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_zfill/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_zfill/out.sql @@ -1,7 +1,25 @@ SELECT CASE - WHEN STARTS_WITH(`string_col`, '-') - THEN CONCAT('-', LPAD(SUBSTRING(`string_col`, 2), GREATEST(LENGTH(`string_col`), 10) - 1, '0')) - ELSE LPAD(`string_col`, GREATEST(LENGTH(`string_col`), 10), '0') + WHEN SUBSTRING(`t0`.`string_col`, IF(( + 0 + 1 + ) >= 1, 0 + 1, 0 + 1 + LENGTH(`t0`.`string_col`)), 1) = '-' + THEN CONCAT( + '-', + LPAD( + SUBSTRING(`t0`.`string_col`, IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(`t0`.`string_col`))), + GREATEST( + LENGTH( + SUBSTRING(`t0`.`string_col`, IF(( + 1 + 1 + ) >= 1, 1 + 1, 1 + 1 + LENGTH(`t0`.`string_col`))) + ), + 9 + ), + '0' + ) + ) + ELSE LPAD(`t0`.`string_col`, GREATEST(LENGTH(`t0`.`string_col`), 10), '0') END AS `string_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_field/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_field/out.sql index 6c3760aa36e..99128904cc2 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_field/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_field/out.sql @@ -1,4 +1,4 @@ SELECT - `people`.`name` AS `string`, - `people`.`name` AS `int` -FROM `bigframes-dev`.`sqlglot_test`.`nested_structs_types` AS `bft_0` \ No newline at end of file + `t0`.`people`.`name` AS `string`, + `t0`.`people`.`name` AS `int` +FROM `bigframes-dev.sqlglot_test.nested_structs_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_op/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_op/out.sql index 3549149609a..9cecc317bd1 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_op/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_struct_ops/test_struct_op/out.sql @@ -1,8 +1,8 @@ SELECT STRUCT( - `bool_col` AS bool_col, - `int64_col` AS int64_col, - `float64_col` AS float64_col, - `string_col` AS string_col + `t0`.`bool_col` AS `bool_col`, + `t0`.`int64_col` AS `int64_col`, + `t0`.`float64_col` AS `float64_col`, + `t0`.`string_col` AS `string_col` ) AS `result_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_timedelta_floor/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_timedelta_floor/out.sql index 6eb6f8e989d..020defd3402 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_timedelta_floor/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_timedelta_floor/out.sql @@ -1,3 +1,7 @@ SELECT - FLOOR(`int64_col`) AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + CASE + WHEN `t0`.`int64_col` > 0 + THEN CAST(FLOOR(`t0`.`int64_col`) AS INT64) + ELSE CAST(CEIL(`t0`.`int64_col`) AS INT64) + END AS `int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_to_timedelta/out.sql b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_to_timedelta/out.sql index 59aa3d9b0b3..6a993a9b637 100644 --- a/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_to_timedelta/out.sql +++ b/tests/unit/core/compile/sqlglot/expressions/snapshots/test_timedelta_ops/test_to_timedelta/out.sql @@ -1,9 +1,9 @@ SELECT - `rowindex`, - `int64_col`, - `float64_col`, - `int64_col` AS `duration_us`, - CAST(FLOOR(`float64_col` * 1000000) AS INT64) AS `duration_s`, - `int64_col` * 3600000000 AS `duration_w`, - `int64_col` AS `duration_on_duration` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`float64_col`, + CAST(FLOOR(`t0`.`int64_col` * 1) AS INT64) AS `duration_us`, + CAST(FLOOR(`t0`.`float64_col` * 1000000) AS INT64) AS `duration_s`, + CAST(FLOOR(`t0`.`int64_col` * 3600000000) AS INT64) AS `duration_w`, + CAST(FLOOR(`t0`.`int64_col` * 1) AS INT64) AS `duration_on_duration` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ 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..63997730960 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,21 @@ -WITH `bfcte_0` AS ( +SELECT `bool_col`, `int64_too` FROM (SELECT + `t2`.`bfuid_col_1532` AS `bool_col`, + `t2`.`bfuid_col_1533` AS `int64_too` +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` -), `bfcte_1` AS ( - SELECT - `bfcol_3`, - COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` - FROM `bfcte_0` - WHERE - NOT `bfcol_3` IS NULL + `t1`.`bfuid_col_1532`, + COALESCE(SUM(`t1`.`bfuid_col_1531`), 0) AS `bfuid_col_1533` + FROM ( + SELECT + `t0`.`int64_too` AS `bfuid_col_1531`, + `t0`.`bool_col` AS `bfuid_col_1532` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` 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 + 1 +) AS `t2` +WHERE + ( + `t2`.`bfuid_col_1532` + ) IS NOT NULL) AS `t` +ORDER BY `bool_col` 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..c69bdd77695 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,17 @@ -WITH `bfcte_0` AS ( +SELECT `bool_col`, `int64_too` FROM (SELECT + `t2`.`bfuid_col_1536` AS `bool_col`, + `t2`.`bfuid_col_1537` AS `int64_too` +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` -), `bfcte_1` AS ( - SELECT - `bfcol_3`, - COALESCE(SUM(`bfcol_2`), 0) AS `bfcol_6` - FROM `bfcte_0` + `t1`.`bfuid_col_1536`, + COALESCE(SUM(`t1`.`bfuid_col_1535`), 0) AS `bfuid_col_1537` + FROM ( + SELECT + `t0`.`int64_too` AS `bfuid_col_1535`, + `t0`.`bool_col` AS `bfuid_col_1536` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t1` 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 + 1 +) AS `t2`) AS `t` +ORDER BY `bool_col` 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 48614357865..71aaef2059f 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,48 +1,55 @@ -WITH `bfcte_0` AS ( +SELECT `rowindex`, `rowindex_1`, `int64_col`, `string_col` FROM (WITH `t1` 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_1` AS ( + `t0`.`int64_col`, + `t0`.`rowindex`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) +SELECT + * +FROM ( SELECT - `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 + `t3`.`bfuid_col_1` AS `rowindex`, + `t3`.`rowindex` AS `rowindex_1`, + `t3`.`int64_col`, + `t3`.`string_col`, + `t3`.`bfuid_col_1543` AS `bfuid_col_1547`, + `t3`.`bfuid_col_1542` AS `bfuid_col_1546` + FROM ( SELECT - `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 - ( + `t2`.`rowindex` AS `bfuid_col_1`, + `t2`.`rowindex`, + `t2`.`int64_col`, + `t2`.`string_col`, + 0 AS `bfuid_col_1543`, + ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `bfuid_col_1542` + FROM `t1` AS `t2` + ) AS `t3` + ) AS `t5` + UNION ALL + SELECT + * + FROM ( + SELECT + `t4`.`bfuid_col_1` AS `rowindex`, + `t4`.`rowindex` AS `rowindex_1`, + `t4`.`int64_col`, + `t4`.`string_col`, + `t4`.`bfuid_col_1545` AS `bfuid_col_1547`, + `t4`.`bfuid_col_1544` AS `bfuid_col_1546` + FROM ( SELECT - `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` - ) - ) -) -SELECT - `bfcol_23` AS `rowindex`, - `bfcol_24` AS `rowindex_1`, - `bfcol_25` AS `int64_col`, - `bfcol_26` AS `string_col` -FROM `bfcte_1` -ORDER BY - `bfcol_27` ASC NULLS LAST, - `bfcol_28` ASC NULLS LAST \ No newline at end of file + `t2`.`rowindex` AS `bfuid_col_1`, + `t2`.`rowindex`, + `t2`.`int64_col`, + `t2`.`string_col`, + 1 AS `bfuid_col_1545`, + ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `bfuid_col_1544` + FROM `t1` AS `t2` + ) AS `t4` + ) AS `t6` +) AS `t7`) AS `t` +ORDER BY `bfuid_col_1547` ASC NULLS LAST ,`bfuid_col_1546` 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 477a47036ae..4b05d8caaf4 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,63 +1,98 @@ -WITH `bfcte_0` AS ( +SELECT `float64_col`, `int64_col` FROM (WITH `t1` AS ( SELECT - `float64_col` AS `bfcol_7`, - `int64_too` AS `bfcol_8` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` - WHERE - `bool_col` -), `bfcte_1` AS ( + `t0`.`int64_col`, + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +), `t2` AS ( SELECT - `float64_col` AS `bfcol_5`, - `int64_col` AS `bfcol_6` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( + `t0`.`bool_col`, + `t0`.`int64_too`, + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + WHERE + `t0`.`bool_col` +) +SELECT + * +FROM ( SELECT - `bfcol_21` AS `bfcol_33`, - `bfcol_22` AS `bfcol_34`, - `bfcol_23` AS `bfcol_35`, - `bfcol_24` AS `bfcol_36` + * FROM ( - ( + SELECT + * + FROM ( SELECT - `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_1` - ) + `t9`.`float64_col`, + `t9`.`int64_col`, + `t9`.`bfuid_col_1551` AS `bfuid_col_1559`, + `t9`.`bfuid_col_1550` AS `bfuid_col_1558` + FROM ( + SELECT + `t3`.`float64_col`, + `t3`.`int64_col`, + 0 AS `bfuid_col_1551`, + ROW_NUMBER() OVER (ORDER BY `t3`.`int64_col` IS NULL ASC, `t3`.`int64_col` ASC) - 1 AS `bfuid_col_1550` + FROM `t1` AS `t3` + ) AS `t9` + ) AS `t11` UNION ALL - ( + SELECT + * + FROM ( SELECT - `bfcol_7` AS `bfcol_29`, - `bfcol_8` AS `bfcol_30`, - 1 AS `bfcol_31`, - ROW_NUMBER() OVER () - 1 AS `bfcol_32` - FROM `bfcte_0` - ) - UNION ALL - ( + `t5`.`float64_col`, + `t5`.`int64_too` AS `int64_col`, + `t5`.`bfuid_col_1553` AS `bfuid_col_1559`, + `t5`.`bfuid_col_1552` AS `bfuid_col_1558` + FROM ( + SELECT + `t4`.`float64_col`, + `t4`.`int64_too`, + 1 AS `bfuid_col_1553`, + ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `bfuid_col_1552` + FROM `t2` AS `t4` + ) AS `t5` + ) AS `t7` + ) AS `t13` + UNION ALL + SELECT + * + FROM ( + SELECT + * + FROM ( SELECT - `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_1` - ) + `t10`.`float64_col`, + `t10`.`int64_col`, + `t10`.`bfuid_col_1555` AS `bfuid_col_1559`, + `t10`.`bfuid_col_1554` AS `bfuid_col_1558` + FROM ( + SELECT + `t3`.`float64_col`, + `t3`.`int64_col`, + 2 AS `bfuid_col_1555`, + ROW_NUMBER() OVER (ORDER BY `t3`.`int64_col` IS NULL ASC, `t3`.`int64_col` ASC) - 1 AS `bfuid_col_1554` + FROM `t1` AS `t3` + ) AS `t10` + ) AS `t12` UNION ALL - ( + SELECT + * + FROM ( SELECT - `bfcol_7` AS `bfcol_25`, - `bfcol_8` AS `bfcol_26`, - 3 AS `bfcol_27`, - ROW_NUMBER() OVER () - 1 AS `bfcol_28` - FROM `bfcte_0` - ) - ) -) -SELECT - `bfcol_33` AS `float64_col`, - `bfcol_34` AS `int64_col` -FROM `bfcte_2` -ORDER BY - `bfcol_35` ASC NULLS LAST, - `bfcol_36` ASC NULLS LAST \ No newline at end of file + `t6`.`float64_col`, + `t6`.`int64_too` AS `int64_col`, + `t6`.`bfuid_col_1557` AS `bfuid_col_1559`, + `t6`.`bfuid_col_1556` AS `bfuid_col_1558` + FROM ( + SELECT + `t4`.`float64_col`, + `t4`.`int64_too`, + 3 AS `bfuid_col_1557`, + ROW_NUMBER() OVER (ORDER BY NULL ASC) - 1 AS `bfuid_col_1556` + FROM `t2` AS `t4` + ) AS `t6` + ) AS `t8` + ) AS `t14` +) AS `t15`) AS `t` +ORDER BY `bfuid_col_1559` ASC NULLS LAST ,`bfuid_col_1558` 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..92d5827eaee 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,53 @@ -WITH `bfcte_0` AS ( +SELECT `rowindex`, `rowindex_1`, `int_list_col`, `string_list_col` FROM (SELECT + `t2`.`bfuid_col_54` AS `rowindex`, + `t2`.`rowindex` AS `rowindex_1`, + `t2`.`int_list_col`[safe_offset(`t2`.`bfuid_col_1563`)] AS `int_list_col`, + `t2`.`string_list_col`[safe_offset(`t2`.`bfuid_col_1563`)] AS `string_list_col`, + `t2`.`bfuid_col_1563` AS `bfuid_col_1564` +FROM ( SELECT - `rowindex`, - `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 + IF(pos = pos_2, `bfuid_col_1563`, NULL) AS `bfuid_col_1563`, + `t1`.`bfuid_col_54`, + `t1`.`rowindex`, + `t1`.`int_list_col`, + `t1`.`string_list_col` + FROM ( + SELECT + IF( + NOT NULLIF(1, 0) IS NULL + AND SIGN(1) = SIGN( + GREATEST(1, LEAST(ARRAY_LENGTH(`t0`.`int_list_col`), ARRAY_LENGTH(`t0`.`string_list_col`))) - 0 + ), + ARRAY( + SELECT + ibis_bq_arr_range_cxfav7xwufe3zgavaggj3sqncm + FROM UNNEST(generate_array( + 0, + GREATEST(1, LEAST(ARRAY_LENGTH(`t0`.`int_list_col`), ARRAY_LENGTH(`t0`.`string_list_col`))), + 1 + )) AS ibis_bq_arr_range_cxfav7xwufe3zgavaggj3sqncm + WHERE + ibis_bq_arr_range_cxfav7xwufe3zgavaggj3sqncm <> GREATEST(1, LEAST(ARRAY_LENGTH(`t0`.`int_list_col`), ARRAY_LENGTH(`t0`.`string_list_col`))) + ), + [] + ) AS `bfuid_offset_array_1565`, + `t0`.`rowindex` AS `bfuid_col_54`, + `t0`.`rowindex`, + `t0`.`int_list_col`, + `t0`.`string_list_col` + FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` + ) AS `t1` + CROSS JOIN UNNEST(GENERATE_ARRAY(0, GREATEST(ARRAY_LENGTH(`t1`.`bfuid_offset_array_1565`)) - 1)) AS pos + CROSS JOIN UNNEST(`t1`.`bfuid_offset_array_1565`) AS `bfuid_col_1563` WITH OFFSET AS pos_2 + WHERE + pos = pos_2 + OR ( + pos > ( + ARRAY_LENGTH(`t1`.`bfuid_offset_array_1565`) - 1 + ) + AND pos_2 = ( + ARRAY_LENGTH(`t1`.`bfuid_offset_array_1565`) - 1 + ) + ) +) AS `t2`) AS `t` +ORDER BY `bfuid_col_1564` 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..1e712c115e7 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,41 @@ -WITH `bfcte_0` AS ( +SELECT `rowindex`, `int_list_col` FROM (SELECT + `t2`.`bfuid_col_54` AS `rowindex`, + `t2`.`int_list_col`[safe_offset(`t2`.`bfuid_col_1560`)] AS `int_list_col`, + `t2`.`bfuid_col_1560` AS `bfuid_col_1561` +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 + IF(pos = pos_2, `bfuid_col_1560`, NULL) AS `bfuid_col_1560`, + `t1`.`bfuid_col_54`, + `t1`.`int_list_col` + FROM ( + SELECT + IF( + NOT NULLIF(1, 0) IS NULL + AND SIGN(1) = SIGN(GREATEST(1, LEAST(ARRAY_LENGTH(`t0`.`int_list_col`))) - 0), + ARRAY( + SELECT + ibis_bq_arr_range_ffjuun3qqfhrzcuj5fnct6bghq + FROM UNNEST(generate_array(0, GREATEST(1, LEAST(ARRAY_LENGTH(`t0`.`int_list_col`))), 1)) AS ibis_bq_arr_range_ffjuun3qqfhrzcuj5fnct6bghq + WHERE + ibis_bq_arr_range_ffjuun3qqfhrzcuj5fnct6bghq <> GREATEST(1, LEAST(ARRAY_LENGTH(`t0`.`int_list_col`))) + ), + [] + ) AS `bfuid_offset_array_1562`, + `t0`.`rowindex` AS `bfuid_col_54`, + `t0`.`int_list_col` + FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` + ) AS `t1` + CROSS JOIN UNNEST(GENERATE_ARRAY(0, GREATEST(ARRAY_LENGTH(`t1`.`bfuid_offset_array_1562`)) - 1)) AS pos + CROSS JOIN UNNEST(`t1`.`bfuid_offset_array_1562`) AS `bfuid_col_1560` WITH OFFSET AS pos_2 + WHERE + pos = pos_2 + OR ( + pos > ( + ARRAY_LENGTH(`t1`.`bfuid_offset_array_1562`) - 1 + ) + AND pos_2 = ( + ARRAY_LENGTH(`t1`.`bfuid_offset_array_1562`) - 1 + ) + ) +) AS `t2`) AS `t` +ORDER BY `bfuid_col_1561` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_filter/test_compile_filter/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_filter/test_compile_filter/out.sql index 3e367c1e1e2..d0ab658b698 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_filter/test_compile_filter/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_filter/test_compile_filter/out.sql @@ -1,7 +1,7 @@ SELECT - `rowindex`, - `rowindex` AS `rowindex_1`, - `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` + `t0`.`rowindex`, + `t0`.`rowindex` AS `rowindex_1`, + `t0`.`int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` WHERE - `rowindex` >= 1 \ No newline at end of file + `t0`.`rowindex` >= 1 \ 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 0b0e07056ab..a9994cca97b 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,75 +1,140 @@ -WITH `bfcte_0` AS ( +SELECT `bigframes_unnamed_index`, `int64_col`, `int64_too` FROM (WITH `t3` 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_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_2` AS ( - SELECT - `bfcol_0` AS `bfcol_4` - FROM `bfcte_0` -), `bfcte_3` AS ( + `t1`.`column_0` AS `bfuid_col_1571` + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(DATETIME('2021-01-01T13:00:00')), STRUCT(DATETIME('2021-01-01T13:00:01')), STRUCT(DATETIME('2021-01-01T13:00:02')), STRUCT(DATETIME('2021-01-01T13:00:03')), STRUCT(DATETIME('2021-01-01T13:00:04')), STRUCT(DATETIME('2021-01-01T13:00:05')), STRUCT(DATETIME('2021-01-01T13:00:06')), STRUCT(DATETIME('2021-01-01T13:00:07')), STRUCT(DATETIME('2021-01-01T13:00:08')), STRUCT(DATETIME('2021-01-01T13:00:09')), STRUCT(DATETIME('2021-01-01T13:00:10')), STRUCT(DATETIME('2021-01-01T13:00:11')), STRUCT(DATETIME('2021-01-01T13:00:12')), STRUCT(DATETIME('2021-01-01T13:00:13')), STRUCT(DATETIME('2021-01-01T13:00:14')), STRUCT(DATETIME('2021-01-01T13:00:15')), STRUCT(DATETIME('2021-01-01T13:00:16')), STRUCT(DATETIME('2021-01-01T13:00:17')), STRUCT(DATETIME('2021-01-01T13:00:18')), STRUCT(DATETIME('2021-01-01T13:00:19')), STRUCT(DATETIME('2021-01-01T13:00:20')), STRUCT(DATETIME('2021-01-01T13:00:21')), STRUCT(DATETIME('2021-01-01T13:00:22')), STRUCT(DATETIME('2021-01-01T13:00:23')), STRUCT(DATETIME('2021-01-01T13:00:24')), STRUCT(DATETIME('2021-01-01T13:00:25')), STRUCT(DATETIME('2021-01-01T13:00:26')), STRUCT(DATETIME('2021-01-01T13:00:27')), STRUCT(DATETIME('2021-01-01T13:00:28')), STRUCT(DATETIME('2021-01-01T13:00:29'))]) AS `column_0` + ) AS `t1` +), `t11` AS ( SELECT - `bfcol_1` AS `bfcol_5`, - `bfcol_2` AS `bfcol_6`, - `bfcol_3` AS `bfcol_7` - FROM `bfcte_1` -), `bfcte_4` AS ( - SELECT - MIN(`bfcol_4`) AS `bfcol_8` - FROM `bfcte_2` -), `bfcte_5` AS ( - 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 + ieee_divide( + UNIX_MICROS(CAST(`t6`.`bfuid_col_1571` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`t9`.`bfuid_col_1572` AS DATE) AS TIMESTAMP)), + 7000000.0 ) - ) AS INT64) AS `bfcol_13` - FROM `bfcte_3` - CROSS JOIN `bfcte_4` -), `bfcte_6` 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 `bfcte_2` - CROSS JOIN `bfcte_4` -), `bfcte_7` AS ( - SELECT - MAX(`bfcol_14`) AS `bfcol_15` - FROM `bfcte_6` -), `bfcte_8` AS ( - SELECT - MIN(`bfcol_14`) AS `bfcol_16` - FROM `bfcte_6` -), `bfcte_9` AS ( - SELECT - `bfcol_27` AS `bfcol_17` - FROM `bfcte_8` - CROSS JOIN `bfcte_7` - CROSS JOIN UNNEST(GENERATE_ARRAY(`bfcol_16`, `bfcol_15`, 1)) AS `bfcol_27` + ) AS INT64) AS `bfuid_col_1573` + FROM `t3` AS `t6` + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + MIN(`t5`.`bfuid_col_1571`) AS `bfuid_col_1572` + FROM `t3` AS `t5` + ) AS `t7` + ) AS `t9` ) SELECT - CAST(TIMESTAMP_MICROS( - 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_11` AS `int64_col`, - `bfcol_12` AS `int64_too` + CAST(CAST(timestamp_micros( + CAST(trunc( + ( + `t27`.`labels` * 7000000.0 + ) + UNIX_MICROS(CAST(CAST(`t27`.`bfuid_col_1572` AS DATE) AS TIMESTAMP)) + ) AS INT64) + ) AS TIMESTAMP) AS DATETIME) AS `bigframes_unnamed_index`, + `t14`.`column_1` AS `int64_col`, + `t14`.`column_2` AS `int64_too`, + `t27`.`labels` AS `bfuid_col_1578` FROM ( SELECT * - FROM `bfcte_9` - CROSS JOIN `bfcte_4` -) -LEFT JOIN `bfcte_5` - ON `bfcol_17` = `bfcol_13` -ORDER BY - `bfcol_17` ASC NULLS LAST \ No newline at end of file + FROM ( + SELECT + `t24`.`labels`, + `t9`.`bfuid_col_1572` + FROM ( + SELECT + * + FROM ( + SELECT + `t21`.* + REPLACE (`ibis_table_unnest_column_fq25i2xrkzew3pldbtkhcneozu` AS `labels`) + FROM ( + SELECT + IF( + NOT NULLIF(1, 0) IS NULL + AND SIGN(1) = SIGN(( + `t20`.`bfuid_col_1575` + 1 + ) - `t19`.`bfuid_col_1574`), + ARRAY( + SELECT + ibis_bq_arr_range_fqkrald5tbbe5m6vt2tohfy3fi + FROM UNNEST(generate_array(`t19`.`bfuid_col_1574`, `t20`.`bfuid_col_1575` + 1, 1)) AS ibis_bq_arr_range_fqkrald5tbbe5m6vt2tohfy3fi + WHERE + ibis_bq_arr_range_fqkrald5tbbe5m6vt2tohfy3fi <> ( + `t20`.`bfuid_col_1575` + 1 + ) + ), + [] + ) AS `labels` + FROM ( + SELECT + * + FROM ( + SELECT + MIN(`t12`.`bfuid_col_1573`) AS `bfuid_col_1574` + FROM `t11` AS `t12` + ) AS `t15` + ) AS `t19` + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + MAX(`t12`.`bfuid_col_1573`) AS `bfuid_col_1575` + FROM `t11` AS `t12` + ) AS `t16` + ) AS `t20` + ) AS `t21` + CROSS JOIN UNNEST(`t21`.`labels`) AS `ibis_table_unnest_column_fq25i2xrkzew3pldbtkhcneozu` + ) AS `t22` + ) AS `t24` + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + MIN(`t5`.`bfuid_col_1571`) AS `bfuid_col_1572` + FROM `t3` AS `t5` + ) AS `t7` + ) AS `t9` + ) AS `t25` +) AS `t27` +LEFT OUTER JOIN ( + SELECT + * + FROM ( + SELECT + `t4`.`column_1`, + `t4`.`column_2`, + CAST(FLOOR( + ieee_divide( + UNIX_MICROS(CAST(`t4`.`bfuid_col_1571` AS TIMESTAMP)) - UNIX_MICROS(CAST(CAST(`t9`.`bfuid_col_1572` AS DATE) AS TIMESTAMP)), + 7000000.0 + ) + ) AS INT64) AS `bfuid_col_1573` + FROM ( + SELECT + `t0`.`column_0` AS `bfuid_col_1571`, + `t0`.`column_1`, + `t0`.`column_2` + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(DATETIME('2021-01-01T13:00:00'), 0, 10), STRUCT(DATETIME('2021-01-01T13:00:01'), 1, 11), STRUCT(DATETIME('2021-01-01T13:00:02'), 2, 12), STRUCT(DATETIME('2021-01-01T13:00:03'), 3, 13), STRUCT(DATETIME('2021-01-01T13:00:04'), 4, 14), STRUCT(DATETIME('2021-01-01T13:00:05'), 5, 15), STRUCT(DATETIME('2021-01-01T13:00:06'), 6, 16), STRUCT(DATETIME('2021-01-01T13:00:07'), 7, 17), STRUCT(DATETIME('2021-01-01T13:00:08'), 8, 18), STRUCT(DATETIME('2021-01-01T13:00:09'), 9, 19), STRUCT(DATETIME('2021-01-01T13:00:10'), 10, 20), STRUCT(DATETIME('2021-01-01T13:00:11'), 11, 21), STRUCT(DATETIME('2021-01-01T13:00:12'), 12, 22), STRUCT(DATETIME('2021-01-01T13:00:13'), 13, 23), STRUCT(DATETIME('2021-01-01T13:00:14'), 14, 24), STRUCT(DATETIME('2021-01-01T13:00:15'), 15, 25), STRUCT(DATETIME('2021-01-01T13:00:16'), 16, 26), STRUCT(DATETIME('2021-01-01T13:00:17'), 17, 27), STRUCT(DATETIME('2021-01-01T13:00:18'), 18, 28), STRUCT(DATETIME('2021-01-01T13:00:19'), 19, 29), STRUCT(DATETIME('2021-01-01T13:00:20'), 20, 30), STRUCT(DATETIME('2021-01-01T13:00:21'), 21, 31), STRUCT(DATETIME('2021-01-01T13:00:22'), 22, 32), STRUCT(DATETIME('2021-01-01T13:00:23'), 23, 33), STRUCT(DATETIME('2021-01-01T13:00:24'), 24, 34), STRUCT(DATETIME('2021-01-01T13:00:25'), 25, 35), STRUCT(DATETIME('2021-01-01T13:00:26'), 26, 36), STRUCT(DATETIME('2021-01-01T13:00:27'), 27, 37), STRUCT(DATETIME('2021-01-01T13:00:28'), 28, 38), STRUCT(DATETIME('2021-01-01T13:00:29'), 29, 39)]) AS `column_0` + ) AS `t0` + ) AS `t4` + CROSS JOIN ( + SELECT + * + FROM ( + SELECT + MIN(`t5`.`bfuid_col_1571`) AS `bfuid_col_1572` + FROM `t3` AS `t5` + ) AS `t7` + ) AS `t9` + ) AS `t10` +) AS `t14` + ON `t27`.`labels` = `t14`.`bfuid_col_1573`) AS `t` +ORDER BY `bfuid_col_1578` 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 f4c2a494a3a..827b943ccba 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,35 +1,30 @@ -WITH `bfcte_0` AS ( - SELECT - `int64_too` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `rowindex` AS `bfcol_3`, - `int64_col` AS `bfcol_4` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - `int64_too` - FROM `bfcte_0` - GROUP BY - `int64_too` -), `bfcte_3` AS ( - SELECT - `int64_too` AS `bfcol_0` - FROM `bfcte_2` -), `bfcte_4` AS ( - SELECT - *, - STRUCT(COALESCE(`bfcol_4`, 0) AS `bfpart1`, COALESCE(`bfcol_4`, 1) AS `bfpart2`) IN ( - ( +SELECT + `t1`.`bfuid_col_1` AS `rowindex`, + EXISTS( + SELECT + 1 + FROM ( + SELECT + `t2`.`int64_too` + FROM ( SELECT - STRUCT(COALESCE(`bfcol_0`, 0) AS `bfpart1`, COALESCE(`bfcol_0`, 1) AS `bfpart2`) - FROM `bfcte_3` + `t0`.`int64_too` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t2` + GROUP BY + 1 + ) AS `t3` + WHERE + ( + COALESCE(`t1`.`int64_col`, 0) = COALESCE(`t3`.`int64_too`, 0) ) - ) AS `bfcol_5` - FROM `bfcte_1` -) -SELECT - `bfcol_3` AS `rowindex`, - `bfcol_5` AS `int64_col` -FROM `bfcte_4` \ No newline at end of file + AND ( + COALESCE(`t1`.`int64_col`, 1) = COALESCE(`t3`.`int64_too`, 1) + ) + ) AS `int64_col` +FROM ( + SELECT + `t0`.`rowindex` AS `bfuid_col_1`, + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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 cc1633d3a3a..30e0dc29160 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,33 +1,23 @@ -WITH `bfcte_0` AS ( - SELECT - `rowindex_2` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( - SELECT - `rowindex` AS `bfcol_3`, - `rowindex_2` AS `bfcol_4` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_2` AS ( - SELECT - `rowindex_2` - FROM `bfcte_0` - GROUP BY - `rowindex_2` -), `bfcte_3` AS ( - SELECT - `rowindex_2` AS `bfcol_0` - FROM `bfcte_2` -), `bfcte_4` AS ( - SELECT - *, - `bfcol_4` IN (( - SELECT - * - FROM `bfcte_3` - )) AS `bfcol_5` - FROM `bfcte_1` -) SELECT - `bfcol_3` AS `rowindex`, - `bfcol_5` AS `rowindex_2` -FROM `bfcte_4` \ No newline at end of file + `t1`.`bfuid_col_1` AS `rowindex`, + `t1`.`rowindex_2` IN ( + SELECT + * + FROM ( + SELECT + `t2`.`rowindex_2` + FROM ( + SELECT + `t0`.`rowindex_2` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + ) AS `t2` + GROUP BY + 1 + ) AS `t3` + ) AS `rowindex_2` +FROM ( + SELECT + `t0`.`rowindex` AS `bfuid_col_1`, + `t0`.`rowindex_2` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1` \ 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 cac57d0c8c8..770460b9ce5 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,18 +1,17 @@ -WITH `bfcte_0` AS ( +SELECT + `t3`.`int64_col`, + `t4`.`int64_too` +FROM ( SELECT - `int64_col` AS `bfcol_4`, - `int64_too` AS `bfcol_5` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( + `t0`.`rowindex` AS `bfuid_col_1`, + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +LEFT OUTER JOIN ( SELECT - `rowindex` AS `bfcol_6`, - `int64_col` AS `bfcol_7` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -) -SELECT - `bfcol_7` AS `int64_col`, - `bfcol_5` AS `int64_too` -FROM `bfcte_1` -LEFT JOIN `bfcte_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 + `t0`.`int64_col` AS `bfuid_col_1654`, + `t0`.`int64_too` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON COALESCE(`t3`.`bfuid_col_1`, 0) = COALESCE(`t4`.`bfuid_col_1654`, 0) + AND COALESCE(`t3`.`bfuid_col_1`, 1) = COALESCE(`t4`.`bfuid_col_1654`, 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 5042f91cd95..487f85fae92 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,24 +1,18 @@ -WITH `bfcte_0` AS ( - SELECT - `bool_col` AS `bfcol_0`, - `rowindex` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( +SELECT + `t3`.`rowindex` AS `rowindex_x`, + `t3`.`bool_col`, + `t4`.`bfuid_col_1657` AS `rowindex_y` +FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` -), `bfcte_2` AS ( + `t0`.`rowindex`, + `t0`.`bool_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +INNER JOIN ( SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `rowindex_x`, - `bfcol_5` AS `bool_col`, - `bfcol_2` AS `rowindex_y` -FROM `bfcte_2` -INNER JOIN `bfcte_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 + `t0`.`rowindex` AS `bfuid_col_1657`, + `t0`.`bool_col` AS `bfuid_col_1658` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON COALESCE(CAST(`t3`.`bool_col` AS STRING), '0') = COALESCE(CAST(`t4`.`bfuid_col_1658` AS STRING), '0') + AND COALESCE(CAST(`t3`.`bool_col` AS STRING), '1') = COALESCE(CAST(`t4`.`bfuid_col_1658` 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 544fedadc5b..a66fa4ad742 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,24 +1,18 @@ -WITH `bfcte_0` AS ( - SELECT - `float64_col` AS `bfcol_0`, - `rowindex` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( +SELECT + `t3`.`rowindex` AS `rowindex_x`, + `t3`.`float64_col`, + `t4`.`bfuid_col_1663` AS `rowindex_y` +FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` -), `bfcte_2` AS ( + `t0`.`rowindex`, + `t0`.`float64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +INNER JOIN ( SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `rowindex_x`, - `bfcol_5` AS `float64_col`, - `bfcol_2` AS `rowindex_y` -FROM `bfcte_2` -INNER JOIN `bfcte_1` - ON IF(IS_NAN(`bfcol_5`), 2.0, COALESCE(`bfcol_5`, 0.0)) = IF(IS_NAN(`bfcol_3`), 2.0, COALESCE(`bfcol_3`, 0.0)) - AND IF(IS_NAN(`bfcol_5`), 3, COALESCE(`bfcol_5`, 1.0)) = IF(IS_NAN(`bfcol_3`), 3, COALESCE(`bfcol_3`, 1.0)) \ No newline at end of file + `t0`.`rowindex` AS `bfuid_col_1663`, + `t0`.`float64_col` AS `bfuid_col_1664` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON IF(IS_NAN(`t3`.`float64_col`), 2, COALESCE(`t3`.`float64_col`, 0)) = IF(IS_NAN(`t4`.`bfuid_col_1664`), 2, COALESCE(`t4`.`bfuid_col_1664`, 0)) + AND IF(IS_NAN(`t3`.`float64_col`), 3, COALESCE(`t3`.`float64_col`, 1)) = IF(IS_NAN(`t4`.`bfuid_col_1664`), 3, COALESCE(`t4`.`bfuid_col_1664`, 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 05b9ceec4de..6ee6d2100af 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,24 +1,18 @@ -WITH `bfcte_0` AS ( - SELECT - `int64_col` AS `bfcol_0`, - `rowindex` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( +SELECT + `t3`.`rowindex` AS `rowindex_x`, + `t3`.`int64_col`, + `t4`.`bfuid_col_1660` AS `rowindex_y` +FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` -), `bfcte_2` AS ( + `t0`.`rowindex`, + `t0`.`int64_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +INNER JOIN ( SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `rowindex_x`, - `bfcol_5` AS `int64_col`, - `bfcol_2` AS `rowindex_y` -FROM `bfcte_2` -INNER JOIN `bfcte_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 + `t0`.`rowindex` AS `bfuid_col_1660`, + `t0`.`int64_col` AS `bfuid_col_1661` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON COALESCE(`t3`.`int64_col`, 0) = COALESCE(`t4`.`bfuid_col_1661`, 0) + AND COALESCE(`t3`.`int64_col`, 1) = COALESCE(`t4`.`bfuid_col_1661`, 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 2e0114593e7..d5fd823e316 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,24 +1,18 @@ -WITH `bfcte_0` AS ( - SELECT - `numeric_col` AS `bfcol_0`, - `rowindex` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( +SELECT + `t3`.`rowindex` AS `rowindex_x`, + `t3`.`numeric_col`, + `t4`.`bfuid_col_1672` AS `rowindex_y` +FROM ( SELECT - `bfcol_1` AS `bfcol_2`, - `bfcol_0` AS `bfcol_3` - FROM `bfcte_0` -), `bfcte_2` AS ( + `t0`.`rowindex`, + `t0`.`numeric_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +INNER JOIN ( SELECT - `bfcol_1` AS `bfcol_4`, - `bfcol_0` AS `bfcol_5` - FROM `bfcte_0` -) -SELECT - `bfcol_4` AS `rowindex_x`, - `bfcol_5` AS `numeric_col`, - `bfcol_2` AS `rowindex_y` -FROM `bfcte_2` -INNER JOIN `bfcte_1` - 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 + `t0`.`rowindex` AS `bfuid_col_1672`, + `t0`.`numeric_col` AS `bfuid_col_1673` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON COALESCE(`t3`.`numeric_col`, 0) = COALESCE(`t4`.`bfuid_col_1673`, 0) + AND COALESCE(`t3`.`numeric_col`, 1) = COALESCE(`t4`.`bfuid_col_1673`, 1) \ 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 36aad503435..62569510229 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,19 +1,18 @@ -WITH `bfcte_0` AS ( +SELECT + `t3`.`rowindex` AS `rowindex_x`, + `t3`.`string_col`, + `t4`.`bfuid_col_1666` AS `rowindex_y` +FROM ( SELECT - `rowindex` AS `bfcol_0`, - `string_col` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( + `t0`.`rowindex`, + `t0`.`string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +INNER JOIN ( SELECT - `bfcol_0` AS `bfcol_2`, - `bfcol_1` AS `bfcol_3` - FROM `bfcte_0` -) -SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `string_col`, - `bfcol_2` AS `rowindex_y` -FROM `bfcte_0` -INNER JOIN `bfcte_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 + `t0`.`rowindex` AS `bfuid_col_1666`, + `t0`.`string_col` AS `bfuid_col_1667` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON COALESCE(`t3`.`string_col`, '0') = COALESCE(`t4`.`bfuid_col_1667`, '0') + AND COALESCE(`t3`.`string_col`, '1') = COALESCE(`t4`.`bfuid_col_1667`, '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 b945a1cbf38..a5b0d7d65c1 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,19 +1,18 @@ -WITH `bfcte_0` AS ( +SELECT + `t3`.`rowindex` AS `rowindex_x`, + `t3`.`time_col`, + `t4`.`bfuid_col_1669` AS `rowindex_y` +FROM ( SELECT - `rowindex` AS `bfcol_0`, - `time_col` AS `bfcol_1` - FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -), `bfcte_1` AS ( + `t0`.`rowindex`, + `t0`.`time_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t3` +INNER JOIN ( SELECT - `bfcol_0` AS `bfcol_2`, - `bfcol_1` AS `bfcol_3` - FROM `bfcte_0` -) -SELECT - `bfcol_0` AS `rowindex_x`, - `bfcol_1` AS `time_col`, - `bfcol_2` AS `rowindex_y` -FROM `bfcte_0` -INNER JOIN `bfcte_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 + `t0`.`rowindex` AS `bfuid_col_1669`, + `t0`.`time_col` AS `bfuid_col_1670` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t4` + ON COALESCE(CAST(`t3`.`time_col` AS STRING), '0') = COALESCE(CAST(`t4`.`bfuid_col_1670` AS STRING), '0') + AND COALESCE(CAST(`t3`.`time_col` AS STRING), '1') = COALESCE(CAST(`t4`.`bfuid_col_1670` AS STRING), '1') \ 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..a3b5cf8525b 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,63 +1,81 @@ -WITH `bfcte_0` AS ( +SELECT `rowindex`, `bool_col`, `bytes_col`, `date_col`, `datetime_col`, `geography_col`, `int64_col`, `int64_too`, `numeric_col`, `float64_col`, `rowindex_1`, `rowindex_2`, `string_col`, `time_col`, `timestamp_col`, `duration_col` FROM (SELECT + `t0`.`level_0` AS `rowindex`, + `t0`.`column_0` AS `bool_col`, + `t0`.`column_1` AS `bytes_col`, + `t0`.`column_2` AS `date_col`, + `t0`.`column_3` AS `datetime_col`, + `t0`.`column_4` AS `geography_col`, + `t0`.`column_5` AS `int64_col`, + `t0`.`column_6` AS `int64_too`, + `t0`.`column_7` AS `numeric_col`, + `t0`.`column_8` AS `float64_col`, + `t0`.`column_9` AS `rowindex_1`, + `t0`.`column_10` AS `rowindex_2`, + `t0`.`column_11` AS `string_col`, + `t0`.`column_12` AS `time_col`, + `t0`.`column_13` AS `timestamp_col`, + `t0`.`column_14` AS `duration_col`, + `t0`.`bfuid_col_1675` AS `bfuid_col_1676` +FROM ( SELECT * - FROM UNNEST(ARRAY>[STRUCT( + 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)'), + CAST('48656c6c6f2c20576f726c6421' AS BYTES FORMAT 'HEX'), + DATE(2021, 7, 21), + DATETIME('2021-07-21T11:39:45'), + st_geogfromtext('POINT(-122.0838511 37.3860517)'), 123456789, 0, - CAST(1.234567890 AS NUMERIC), + 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), + TIME_ADD(TIME(11, 41, 43), INTERVAL 76160 MICROSECOND), + TIMESTAMP('2021-07-21T17:43:43.945289+00:00'), 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)'), + CAST('e38193e38293e381abe381a1e381af' AS BYTES FORMAT 'HEX'), + DATE(1991, 2, 3), + DATETIME('1991-01-02T03:45:06'), + st_geogfromtext('POINT(-71.104 42.315)'), -987654321, 1, - CAST(1.234567890 AS NUMERIC), + 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), + TIME_ADD(TIME(11, 14, 34), INTERVAL 701606 MICROSECOND), + TIMESTAMP('2021-07-21T17:43:43.945289+00:00'), -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)'), + CAST('c2a1486f6c61204d756e646f21' AS BYTES FORMAT 'HEX'), + DATE(2023, 3, 1), + DATETIME('2023-03-01T10:55:13'), + st_geogfromtext('POINT(-0.124474760143016 51.5007826749545)'), 314159, 0, - CAST(101.101010100 AS NUMERIC), + 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), + TIME_ADD(TIME(23, 59, 59), INTERVAL 999999 MICROSECOND), + TIMESTAMP('2023-03-01T10:55:13.250125+00:00'), 0, 2 ), STRUCT( 3, - CAST(NULL AS BOOLEAN), + CAST(NULL AS BOOL), CAST(NULL AS BYTES), CAST(NULL AS DATE), CAST(NULL AS DATETIME), @@ -76,8 +94,8 @@ WITH `bfcte_0` AS ( ), 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('e38193e38293e381abe381a1e381af' AS BYTES FORMAT 'HEX'), + DATE(2021, 7, 21), CAST(NULL AS DATETIME), CAST(NULL AS GEOGRAPHY), -234892, @@ -94,55 +112,55 @@ WITH `bfcte_0` AS ( ), 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('47c3bc74656e20546167' AS BYTES FORMAT 'HEX'), + DATE(1980, 3, 14), + DATETIME('1980-03-14T15:16:17'), CAST(NULL AS GEOGRAPHY), 55555, 0, - CAST(5.555555000 AS NUMERIC), + 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), + TIME_ADD(TIME(15, 16, 17), INTERVAL 181921 MICROSECOND), + TIMESTAMP('1980-03-14T15:16:17.181921+00:00'), 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)'), + CAST('48656c6c6f094269674672616d65732107' AS BYTES FORMAT 'HEX'), + DATE(2023, 5, 23), + DATETIME('2023-05-23T11:37:01'), + st_geogfromtext('LINESTRING(-0.127959 51.507728, -0.127026 51.507473)'), 101202303, 2, - CAST(-10.090807000 AS NUMERIC), + 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), + TIME_ADD(TIME(1, 2, 3), INTERVAL 456789 MICROSECOND), + TIMESTAMP('2023-05-23T11:42:55.000001+00:00'), 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), + DATE(2038, 1, 20), + DATETIME('2038-01-19T03:14:08'), CAST(NULL AS GEOGRAPHY), -214748367, 2, - CAST(11111111.100000000 AS NUMERIC), + 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), + TIME_ADD(TIME(12, 0, 0), INTERVAL 1 MICROSECOND), + TIMESTAMP('2038-01-19T03:14:17.999999+00:00'), 4, 7 ), STRUCT( @@ -163,25 +181,6 @@ WITH `bfcte_0` AS ( CAST(NULL AS TIMESTAMP), 432000000000, 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 + )]) AS `level_0` +) AS `t0`) AS `t` +ORDER BY `bfuid_col_1676` 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..599ba21f9ad 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,10 @@ -WITH `bfcte_0` AS ( +SELECT `rowindex`, `json_col` FROM (SELECT + `t0`.`level_0` AS `rowindex`, + `t0`.`column_0` AS `json_col`, + `t0`.`bfuid_col_1681` AS `bfuid_col_1682` +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)]) -) -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 + FROM UNNEST(ARRAY>[STRUCT(0, JSON 'null', 0), STRUCT(1, JSON 'true', 1), STRUCT(2, JSON '100', 2), STRUCT(3, JSON '0.98', 3), STRUCT(4, JSON '"a string"', 4), STRUCT(5, JSON '[]', 5), STRUCT(6, JSON '[1,2,3]', 6), STRUCT(7, JSON '[{"a":1},{"a":2},{"a":null},{}]', 7), STRUCT(8, JSON '"100"', 8), STRUCT(9, JSON '{"date":"2024-07-16"}', 9), STRUCT(10, JSON '{"int_value":2,"null_filed":null}', 10), STRUCT(11, JSON '{"list_data":[10,20,30]}', 11)]) AS `level_0` +) AS `t0`) AS `t` +ORDER BY `bfuid_col_1682` 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..4f349741c17 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,7 +1,17 @@ -WITH `bfcte_0` AS ( +SELECT `rowindex`, `int_list_col`, `bool_list_col`, `float_list_col`, `date_list_col`, `date_time_list_col`, `numeric_list_col`, `string_list_col` FROM (SELECT + `t0`.`level_0` AS `rowindex`, + `t0`.`column_0` AS `int_list_col`, + `t0`.`column_1` AS `bool_list_col`, + `t0`.`column_2` AS `float_list_col`, + `t0`.`column_3` AS `date_list_col`, + `t0`.`column_4` AS `date_time_list_col`, + `t0`.`column_5` AS `numeric_list_col`, + `t0`.`column_6` AS `string_list_col`, + `t0`.`bfuid_col_1679` AS `bfuid_col_1680` +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( + FROM UNNEST(ARRAY, `column_1` ARRAY, `column_2` ARRAY, `column_3` ARRAY, `column_4` ARRAY, `column_5` ARRAY, `column_6` ARRAY, `bfuid_col_1679` INT64>>[STRUCT( 0, [1], [TRUE], @@ -31,17 +41,6 @@ WITH `bfcte_0` AS ( [1.7000000000000002], ['', 'a'], 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 + )]) AS `level_0` +) AS `t0`) AS `t` +ORDER BY `bfuid_col_1680` 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..7df4668f90f 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,25 +1,24 @@ -WITH `bfcte_0` AS ( +SELECT `col_none`, `col_inf`, `col_neginf`, `col_nan`, `col_struct_none`, `col_struct_w_none`, `col_list_none` FROM (SELECT + `t0`.`column_0` AS `col_none`, + `t0`.`column_1` AS `col_inf`, + `t0`.`column_2` AS `col_neginf`, + `t0`.`column_3` AS `col_nan`, + `t0`.`column_4` AS `col_struct_none`, + `t0`.`column_5` AS `col_struct_w_none`, + `t0`.`column_6` AS `col_list_none`, + `t0`.`bfuid_col_1683` AS `bfuid_col_1684` +FROM ( SELECT * - FROM UNNEST(ARRAY, `bfcol_5` STRUCT, `bfcol_6` ARRAY, `bfcol_7` INT64>>[STRUCT( + FROM UNNEST(ARRAY, `column_5` STRUCT, `column_6` ARRAY, `bfuid_col_1683` INT64>>[STRUCT( CAST(NULL AS FLOAT64), CAST('Infinity' AS FLOAT64), CAST('-Infinity' AS FLOAT64), CAST(NULL AS FLOAT64), - CAST(NULL AS STRUCT), + CAST(NULL AS STRUCT<`foo` INT64>), 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)]) -) -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 + ), 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)]) AS `column_0` +) AS `t0`) AS `t` +ORDER BY `bfuid_col_1684` 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..257de19a701 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,11 @@ -WITH `bfcte_0` AS ( +SELECT `id`, `person` FROM (SELECT + `t0`.`level_0` AS `id`, + `t0`.`column_0` AS `person`, + `t0`.`bfuid_col_1677` AS `bfuid_col_1678` +FROM ( SELECT * - FROM UNNEST(ARRAY>, `bfcol_2` INT64>>[STRUCT( + FROM UNNEST(ARRAY>, `bfuid_col_1677` INT64>>[STRUCT( 1, STRUCT( 'Alice' AS `name`, @@ -17,11 +21,6 @@ WITH `bfcte_0` AS ( STRUCT('London' AS `city`, 'UK' AS `country`) AS `address` ), 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 + )]) AS `level_0` +) AS `t0`) AS `t` +ORDER BY `bfuid_col_1678` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable/out.sql index 626ef80d518..7f967a48ca0 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable/out.sql @@ -1,18 +1,18 @@ SELECT - `rowindex`, - `bool_col`, - `bytes_col`, - `date_col`, - `datetime_col`, - `geography_col`, - `int64_col`, - `int64_too`, - `numeric_col`, - `float64_col`, - `rowindex` AS `rowindex_1`, - `rowindex_2`, - `string_col`, - `time_col`, - `timestamp_col`, - `duration_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`bool_col`, + `t0`.`bytes_col`, + `t0`.`date_col`, + `t0`.`datetime_col`, + `t0`.`geography_col`, + `t0`.`int64_col`, + `t0`.`int64_too`, + `t0`.`numeric_col`, + `t0`.`float64_col`, + `t0`.`rowindex` AS `rowindex_1`, + `t0`.`rowindex_2`, + `t0`.`string_col`, + `t0`.`time_col`, + `t0`.`timestamp_col`, + `t0`.`duration_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ 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 2b71ef917d9..77335e404f1 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,5 +1,13 @@ 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 + `t0`.`rowindex`, + `t0`.`int64_col`, + `t0`.`string_col` +FROM ( + SELECT + `rowindex`, + `int64_col`, + `string_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` + WHERE + `rowindex` > 0 AND `string_col` IN ('Hello, World!') +) AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_json_types/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_json_types/out.sql index 054e850fd36..d8e2f36527d 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_json_types/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_json_types/out.sql @@ -1,3 +1,3 @@ SELECT * -FROM `bigframes-dev`.`sqlglot_test`.`json_types` AS `bft_0` \ No newline at end of file +FROM `bigframes-dev.sqlglot_test.json_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_limit/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_limit/out.sql index ff4f0656b12..8e900b859eb 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_limit/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_limit/out.sql @@ -1,7 +1,6 @@ -SELECT - `rowindex`, - `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -ORDER BY - `rowindex` ASC NULLS LAST +SELECT `rowindex`, `int64_col` FROM (SELECT + `t0`.`rowindex`, + `t0`.`int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`) AS `t` +ORDER BY `rowindex` ASC NULLS LAST LIMIT 10 \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_nested_structs_types/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_nested_structs_types/out.sql index f75fa6f722c..ffcb3dcf493 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_nested_structs_types/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_nested_structs_types/out.sql @@ -1,5 +1,5 @@ SELECT - `id`, - `id` AS `id_1`, - `people` -FROM `bigframes-dev`.`sqlglot_test`.`nested_structs_types` AS `bft_0` \ No newline at end of file + `t0`.`id`, + `t0`.`id` AS `id_1`, + `t0`.`people` +FROM `bigframes-dev.sqlglot_test.nested_structs_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_ordering/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_ordering/out.sql index 7e6ddfd568f..d35d14cab03 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_ordering/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_ordering/out.sql @@ -1,6 +1,5 @@ -SELECT - `rowindex`, - `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -ORDER BY - `int64_col` ASC NULLS LAST \ No newline at end of file +SELECT `rowindex`, `int64_col` FROM (SELECT + `t0`.`rowindex`, + `t0`.`int64_col` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0`) AS `t` +ORDER BY `int64_col` 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_repeated_types/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_repeated_types/out.sql index 34b02b5209b..5acbf7ea295 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_repeated_types/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_repeated_types/out.sql @@ -1,11 +1,11 @@ SELECT - `rowindex`, - `rowindex` AS `rowindex_1`, - `int_list_col`, - `bool_list_col`, - `float_list_col`, - `date_list_col`, - `date_time_list_col`, - `numeric_list_col`, - `string_list_col` -FROM `bigframes-dev`.`sqlglot_test`.`repeated_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + `t0`.`rowindex` AS `rowindex_1`, + `t0`.`int_list_col`, + `t0`.`bool_list_col`, + `t0`.`float_list_col`, + `t0`.`date_list_col`, + `t0`.`date_time_list_col`, + `t0`.`numeric_list_col`, + `t0`.`string_list_col` +FROM `bigframes-dev.sqlglot_test.repeated_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_system_time/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_system_time/out.sql index dcd40d78485..bec08b6ad98 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_system_time/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_readtable/test_compile_readtable_w_system_time/out.sql @@ -1,3 +1,21 @@ SELECT * -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` FOR SYSTEM_TIME AS OF '2025-11-09T03:04:05.678901+00:00' \ No newline at end of file +FROM ( + SELECT + `bool_col`, + `bytes_col`, + `date_col`, + `datetime_col`, + `geography_col`, + `int64_col`, + `int64_too`, + `numeric_col`, + `float64_col`, + `rowindex`, + `rowindex_2`, + `string_col`, + `time_col`, + `timestamp_col`, + `duration_col` + FROM `bigframes-dev.sqlglot_test.scalar_types` FOR SYSTEM_TIME AS OF CAST('2025-11-09T03:04:05.678901+00:00' AS TIMESTAMP) +) AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_groupby_rolling/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_groupby_rolling/out.sql index 1051a0fb4c1..6b715b76411 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_groupby_rolling/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_groupby_rolling/out.sql @@ -1,55 +1,64 @@ -SELECT - `bool_col`, - `rowindex`, +SELECT `bool_col`, `rowindex`, `bool_col_1`, `int64_col` FROM (SELECT + `t1`.`bfuid_col_1690` AS `bool_col`, + `t1`.`bfuid_col_1687` AS `rowindex`, CASE WHEN COALESCE( SUM(CAST(( - `bool_col` + `t1`.`bfuid_col_1688` ) IS NOT NULL AS INT64)) OVER ( - PARTITION BY `bool_col` - ORDER BY `bool_col` ASC NULLS LAST, `rowindex` ASC NULLS LAST - ROWS BETWEEN 3 PRECEDING AND CURRENT ROW + PARTITION BY `t1`.`bfuid_col_1690` + ORDER BY `t1`.`bfuid_col_1690` IS NULL ASC, `t1`.`bfuid_col_1690` ASC, `t1`.`bfuid_col_1695` IS NULL ASC, `t1`.`bfuid_col_1695` ASC + ROWS BETWEEN 3 preceding AND CURRENT ROW ), 0 ) < 3 THEN NULL WHEN TRUE THEN COALESCE( - SUM(CAST(`bool_col` AS INT64)) OVER ( - PARTITION BY `bool_col` - ORDER BY `bool_col` ASC NULLS LAST, `rowindex` ASC NULLS LAST - ROWS BETWEEN 3 PRECEDING AND CURRENT ROW + SUM(CAST(`t1`.`bfuid_col_1688` AS INT64)) OVER ( + PARTITION BY `t1`.`bfuid_col_1690` + ORDER BY `t1`.`bfuid_col_1690` IS NULL ASC, `t1`.`bfuid_col_1690` ASC, `t1`.`bfuid_col_1695` IS NULL ASC, `t1`.`bfuid_col_1695` ASC + ROWS BETWEEN 3 preceding AND CURRENT ROW ), 0 ) + ELSE CAST(NULL AS INT64) END AS `bool_col_1`, CASE WHEN COALESCE( SUM(CAST(( - `int64_col` + `t1`.`bfuid_col_1689` ) IS NOT NULL AS INT64)) OVER ( - PARTITION BY `bool_col` - ORDER BY `bool_col` ASC NULLS LAST, `rowindex` ASC NULLS LAST - ROWS BETWEEN 3 PRECEDING AND CURRENT ROW + PARTITION BY `t1`.`bfuid_col_1690` + ORDER BY `t1`.`bfuid_col_1690` IS NULL ASC, `t1`.`bfuid_col_1690` ASC, `t1`.`bfuid_col_1695` IS NULL ASC, `t1`.`bfuid_col_1695` ASC + ROWS BETWEEN 3 preceding AND CURRENT ROW ), 0 ) < 3 THEN NULL WHEN TRUE THEN COALESCE( - SUM(`int64_col`) OVER ( - PARTITION BY `bool_col` - ORDER BY `bool_col` ASC NULLS LAST, `rowindex` ASC NULLS LAST - ROWS BETWEEN 3 PRECEDING AND CURRENT ROW + SUM(`t1`.`bfuid_col_1689`) OVER ( + PARTITION BY `t1`.`bfuid_col_1690` + ORDER BY `t1`.`bfuid_col_1690` IS NULL ASC, `t1`.`bfuid_col_1690` ASC, `t1`.`bfuid_col_1695` IS NULL ASC, `t1`.`bfuid_col_1695` ASC + ROWS BETWEEN 3 preceding AND CURRENT ROW ), 0 ) - END AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -WHERE - ( - `bool_col` - ) IS NOT NULL -ORDER BY - `bool_col` ASC NULLS LAST, - `rowindex` ASC NULLS LAST \ No newline at end of file + ELSE CAST(NULL AS INT64) + END AS `int64_col`, + `t1`.`bfuid_col_1695` AS `bfuid_col_1696` +FROM ( + SELECT + `t0`.`rowindex` AS `bfuid_col_1687`, + `t0`.`bool_col` AS `bfuid_col_1688`, + `t0`.`int64_col` AS `bfuid_col_1689`, + `t0`.`bool_col` AS `bfuid_col_1690`, + `t0`.`rowindex` AS `bfuid_col_1695` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` + WHERE + ( + `t0`.`bool_col` + ) IS NOT NULL +) AS `t1`) AS `t` +ORDER BY `bool_col` ASC NULLS LAST ,`bfuid_col_1696` 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 887e7e9212d..82c5b30c9c8 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,30 @@ -WITH `bfcte_0` AS ( - 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)]) -) -SELECT - `bfcol_0` AS `ts_col`, +SELECT `ts_col`, `int_col` FROM (SELECT + `t0`.`column_0` AS `ts_col`, CASE WHEN COALESCE( SUM(CAST(( - `bfcol_1` + `t0`.`column_1` ) IS NOT NULL AS INT64)) OVER ( - ORDER BY UNIX_MICROS(`bfcol_0`) ASC - RANGE BETWEEN 2999999 PRECEDING AND CURRENT ROW + ORDER BY UNIX_MICROS(`t0`.`column_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 + SUM(`t0`.`column_1`) OVER ( + ORDER BY UNIX_MICROS(`t0`.`column_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 + ELSE CAST(NULL AS INT64) + END AS `int_col`, + `t0`.`bfuid_col_1699` AS `bfuid_col_1701` +FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(TIMESTAMP('2025-01-01T00:00:00+00:00'), 0, 0), STRUCT(TIMESTAMP('2025-01-01T00:00:01+00:00'), 1, 1), STRUCT(TIMESTAMP('2025-01-01T00:00:02+00:00'), 2, 2), STRUCT(TIMESTAMP('2025-01-01T00:00:03+00:00'), 3, 3), STRUCT(TIMESTAMP('2025-01-01T00:00:04+00:00'), 0, 4), STRUCT(TIMESTAMP('2025-01-01T00:00:05+00:00'), 1, 5), STRUCT(TIMESTAMP('2025-01-01T00:00:06+00:00'), 2, 6), STRUCT(TIMESTAMP('2025-01-01T00:00:07+00:00'), 3, 7), STRUCT(TIMESTAMP('2025-01-01T00:00:08+00:00'), 0, 8), STRUCT(TIMESTAMP('2025-01-01T00:00:09+00:00'), 1, 9), STRUCT(TIMESTAMP('2025-01-01T00:00:10+00:00'), 2, 10), STRUCT(TIMESTAMP('2025-01-01T00:00:11+00:00'), 3, 11), STRUCT(TIMESTAMP('2025-01-01T00:00:12+00:00'), 0, 12), STRUCT(TIMESTAMP('2025-01-01T00:00:13+00:00'), 1, 13), STRUCT(TIMESTAMP('2025-01-01T00:00:14+00:00'), 2, 14), STRUCT(TIMESTAMP('2025-01-01T00:00:15+00:00'), 3, 15), STRUCT(TIMESTAMP('2025-01-01T00:00:16+00:00'), 0, 16), STRUCT(TIMESTAMP('2025-01-01T00:00:17+00:00'), 1, 17), STRUCT(TIMESTAMP('2025-01-01T00:00:18+00:00'), 2, 18), STRUCT(TIMESTAMP('2025-01-01T00:00:19+00:00'), 3, 19)]) AS `column_0` +) AS `t0`) AS `t` +ORDER BY `ts_col` ASC NULLS LAST ,`bfuid_col_1701` 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_skips_nulls_op/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_skips_nulls_op/out.sql index 21bb8d5f088..eb0263c6ba2 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_skips_nulls_op/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_w_skips_nulls_op/out.sql @@ -1,19 +1,30 @@ -SELECT - `rowindex`, +SELECT `rowindex`, `int64_col` FROM (SELECT + `t1`.`rowindex`, CASE WHEN COALESCE( SUM(CAST(( - `int64_col` - ) IS NOT NULL AS INT64)) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW), + `t1`.`int64_col` + ) IS NOT NULL AS INT64)) OVER ( + ORDER BY `t1`.`rowindex` IS NULL ASC, `t1`.`rowindex` ASC + ROWS BETWEEN 2 preceding AND CURRENT ROW + ), 0 ) < 3 THEN NULL WHEN TRUE THEN COALESCE( - SUM(`int64_col`) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 2 PRECEDING AND CURRENT ROW), + SUM(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`rowindex` IS NULL ASC, `t1`.`rowindex` ASC + ROWS BETWEEN 2 preceding AND CURRENT ROW + ), 0 ) + ELSE CAST(NULL AS INT64) END AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -ORDER BY - `rowindex` ASC NULLS LAST \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`rowindex` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1`) AS `t` +ORDER BY `rowindex` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_wo_skips_nulls_op/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_wo_skips_nulls_op/out.sql index 6ae1fffab7a..676b7dc0bae 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_wo_skips_nulls_op/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_compile_window/test_compile_window_wo_skips_nulls_op/out.sql @@ -1,13 +1,24 @@ -SELECT - `rowindex`, +SELECT `rowindex`, `int64_col` FROM (SELECT + `t1`.`rowindex`, CASE WHEN COUNT(( - `int64_col` - ) IS NOT NULL) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) < 5 + `t1`.`int64_col` + ) IS NOT NULL) OVER ( + ORDER BY `t1`.`rowindex` IS NULL ASC, `t1`.`rowindex` ASC + ROWS BETWEEN 4 preceding AND CURRENT ROW + ) < 5 THEN NULL WHEN TRUE - THEN COUNT(`int64_col`) OVER (ORDER BY `rowindex` ASC NULLS LAST ROWS BETWEEN 4 PRECEDING AND CURRENT ROW) + THEN COUNT(`t1`.`int64_col`) OVER ( + ORDER BY `t1`.`rowindex` IS NULL ASC, `t1`.`rowindex` ASC + ROWS BETWEEN 4 preceding AND CURRENT ROW + ) + ELSE CAST(NULL AS INT64) END AS `int64_col` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` -ORDER BY - `rowindex` ASC NULLS LAST \ No newline at end of file +FROM ( + SELECT + `t0`.`int64_col`, + `t0`.`rowindex` + FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` +) AS `t1`) AS `t` +ORDER BY `rowindex` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/snapshots/test_dataframe_accessor/test_sql_scalar/out.sql b/tests/unit/core/compile/sqlglot/snapshots/test_dataframe_accessor/test_sql_scalar/out.sql index 14853067c70..121c2ab899e 100644 --- a/tests/unit/core/compile/sqlglot/snapshots/test_dataframe_accessor/test_sql_scalar/out.sql +++ b/tests/unit/core/compile/sqlglot/snapshots/test_dataframe_accessor/test_sql_scalar/out.sql @@ -1,4 +1,4 @@ SELECT - `rowindex`, - ROUND(`int64_col` + `int64_too`) AS `0` -FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0` \ No newline at end of file + `t0`.`rowindex`, + ROUND(`t0`.`int64_col` + `t0`.`int64_too`) AS `0` +FROM `bigframes-dev.sqlglot_test.scalar_types` AS `t0` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/1/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/1/out.sql index 1afccf820c1..7057bcdb75f 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/1/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/1/out.sql @@ -1,77 +1,66 @@ -WITH `bfcte_0` AS ( +SELECT `L_RETURNFLAG`, `L_LINESTATUS`, `SUM_QTY`, `SUM_BASE_PRICE`, `SUM_DISC_PRICE`, `SUM_CHARGE`, `AVG_QTY`, `AVG_PRICE`, `AVG_DISC`, `COUNT_ORDER` FROM (SELECT + `t2`.`bfuid_col_1891` AS `L_RETURNFLAG`, + `t2`.`bfuid_col_1892` AS `L_LINESTATUS`, + `t2`.`bfuid_col_1901` AS `SUM_QTY`, + `t2`.`bfuid_col_1902` AS `SUM_BASE_PRICE`, + `t2`.`bfuid_col_1903` AS `SUM_DISC_PRICE`, + `t2`.`bfuid_col_1904` AS `SUM_CHARGE`, + `t2`.`bfuid_col_1905` AS `AVG_QTY`, + `t2`.`bfuid_col_1906` AS `AVG_PRICE`, + `t2`.`bfuid_col_1907` AS `AVG_DISC`, + `t2`.`bfuid_col_1908` AS `COUNT_ORDER` +FROM ( SELECT - `L_QUANTITY`, - `L_EXTENDEDPRICE`, - `L_DISCOUNT`, - `L_TAX`, - `L_RETURNFLAG`, - `L_LINESTATUS`, - `L_SHIPDATE`, - `L_QUANTITY` AS `bfcol_7`, - `L_EXTENDEDPRICE` AS `bfcol_8`, - `L_DISCOUNT` AS `bfcol_9`, - `L_TAX` AS `bfcol_10`, - `L_RETURNFLAG` AS `bfcol_11`, - `L_LINESTATUS` AS `bfcol_12`, - `L_SHIPDATE` <= CAST('1998-09-02' AS DATE) AS `bfcol_13`, - `L_QUANTITY` AS `bfcol_27`, - `L_EXTENDEDPRICE` AS `bfcol_28`, - `L_DISCOUNT` AS `bfcol_29`, - `L_TAX` AS `bfcol_30`, - `L_RETURNFLAG` AS `bfcol_31`, - `L_LINESTATUS` AS `bfcol_32`, - `L_EXTENDEDPRICE` * ( - 1.0 - `L_DISCOUNT` - ) AS `bfcol_33`, - `L_QUANTITY` AS `bfcol_41`, - `L_EXTENDEDPRICE` AS `bfcol_42`, - `L_DISCOUNT` AS `bfcol_43`, - `L_RETURNFLAG` AS `bfcol_44`, - `L_LINESTATUS` AS `bfcol_45`, - `L_EXTENDEDPRICE` * ( - 1.0 - `L_DISCOUNT` - ) AS `bfcol_46`, - ( - `L_EXTENDEDPRICE` * ( - 1.0 - `L_DISCOUNT` - ) - ) * ( - 1.0 + `L_TAX` - ) AS `bfcol_47` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `L_SHIPDATE` <= CAST('1998-09-02' AS DATE) -), `bfcte_1` AS ( - SELECT - `bfcol_44`, - `bfcol_45`, - COALESCE(SUM(`bfcol_41`), 0) AS `bfcol_55`, - COALESCE(SUM(`bfcol_42`), 0) AS `bfcol_56`, - COALESCE(SUM(`bfcol_46`), 0) AS `bfcol_57`, - COALESCE(SUM(`bfcol_47`), 0) AS `bfcol_58`, - AVG(`bfcol_41`) AS `bfcol_59`, - AVG(`bfcol_42`) AS `bfcol_60`, - AVG(`bfcol_43`) AS `bfcol_61`, - COUNT(`bfcol_41`) AS `bfcol_62` - FROM `bfcte_0` - WHERE - NOT `bfcol_44` IS NULL AND NOT `bfcol_45` IS NULL + `t1`.`bfuid_col_1891`, + `t1`.`bfuid_col_1892`, + COALESCE(SUM(`t1`.`bfuid_col_1887`), 0) AS `bfuid_col_1901`, + COALESCE(SUM(`t1`.`bfuid_col_1888`), 0) AS `bfuid_col_1902`, + COALESCE(SUM(`t1`.`bfuid_col_1899`), 0) AS `bfuid_col_1903`, + COALESCE(SUM(`t1`.`bfuid_col_1900`), 0) AS `bfuid_col_1904`, + AVG(`t1`.`bfuid_col_1887`) AS `bfuid_col_1905`, + AVG(`t1`.`bfuid_col_1888`) AS `bfuid_col_1906`, + AVG(`t1`.`bfuid_col_1889`) AS `bfuid_col_1907`, + COUNT(`t1`.`bfuid_col_1887`) AS `bfuid_col_1908` + FROM ( + SELECT + `t0`.`L_QUANTITY` AS `bfuid_col_1887`, + `t0`.`L_EXTENDEDPRICE` AS `bfuid_col_1888`, + `t0`.`L_DISCOUNT` AS `bfuid_col_1889`, + `t0`.`L_RETURNFLAG` AS `bfuid_col_1891`, + `t0`.`L_LINESTATUS` AS `bfuid_col_1892`, + `t0`.`L_EXTENDEDPRICE` * ( + 1.0 - `t0`.`L_DISCOUNT` + ) AS `bfuid_col_1899`, + ( + `t0`.`L_EXTENDEDPRICE` * ( + 1.0 - `t0`.`L_DISCOUNT` + ) + ) * ( + 1.0 + `t0`.`L_TAX` + ) AS `bfuid_col_1900` + FROM ( + SELECT + `L_QUANTITY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_TAX`, + `L_RETURNFLAG`, + `L_LINESTATUS`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + WHERE + `t0`.`L_SHIPDATE` <= DATE(1998, 9, 2) + ) AS `t1` GROUP BY - `bfcol_44`, - `bfcol_45` -) -SELECT - `bfcol_44` AS `L_RETURNFLAG`, - `bfcol_45` AS `L_LINESTATUS`, - `bfcol_55` AS `SUM_QTY`, - `bfcol_56` AS `SUM_BASE_PRICE`, - `bfcol_57` AS `SUM_DISC_PRICE`, - `bfcol_58` AS `SUM_CHARGE`, - `bfcol_59` AS `AVG_QTY`, - `bfcol_60` AS `AVG_PRICE`, - `bfcol_61` AS `AVG_DISC`, - `bfcol_62` AS `COUNT_ORDER` -FROM `bfcte_1` -ORDER BY - `bfcol_44` ASC NULLS LAST, - `bfcol_45` ASC NULLS LAST \ No newline at end of file + 1, + 2 +) AS `t2` +WHERE + ( + `t2`.`bfuid_col_1891` + ) IS NOT NULL + AND ( + `t2`.`bfuid_col_1892` + ) IS NOT NULL) AS `t` +ORDER BY `L_RETURNFLAG` ASC NULLS LAST ,`L_LINESTATUS` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/10/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/10/out.sql index 8362d3afca1..32b110d4209 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/10/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/10/out.sql @@ -1,171 +1,190 @@ -WITH `bfcte_0` AS ( +SELECT `C_CUSTKEY`, `C_NAME`, `REVENUE`, `C_ACCTBAL`, `N_NAME`, `C_ADDRESS`, `C_PHONE`, `C_COMMENT` FROM (SELECT + `t20`.`bfuid_col_3099` AS `C_CUSTKEY`, + `t20`.`bfuid_col_3100` AS `C_NAME`, + `t20`.`bfuid_col_3137` AS `REVENUE`, + `t20`.`bfuid_col_3104` AS `C_ACCTBAL`, + `t20`.`bfuid_col_3133` AS `N_NAME`, + `t20`.`bfuid_col_3101` AS `C_ADDRESS`, + `t20`.`bfuid_col_3103` AS `C_PHONE`, + `t20`.`bfuid_col_3106` AS `C_COMMENT` +FROM ( SELECT - `N_NATIONKEY` AS `bfcol_0`, - `N_NAME` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_2`, - `L_EXTENDEDPRICE` AS `bfcol_3`, - `L_DISCOUNT` AS `bfcol_4`, - `L_RETURNFLAG` AS `bfcol_5` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_6`, - `O_CUSTKEY` AS `bfcol_7`, - `O_ORDERDATE` AS `bfcol_8` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_9`, - `C_NAME` AS `bfcol_10`, - `C_ADDRESS` AS `bfcol_11`, - `C_NATIONKEY` AS `bfcol_12`, - `C_PHONE` AS `bfcol_13`, - `C_ACCTBAL` AS `bfcol_14`, - `C_COMMENT` AS `bfcol_15` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `bfcol_9` AS `bfcol_16`, - `bfcol_10` AS `bfcol_17`, - `bfcol_11` AS `bfcol_18`, - `bfcol_12` AS `bfcol_19`, - `bfcol_13` AS `bfcol_20`, - `bfcol_14` AS `bfcol_21`, - `bfcol_15` AS `bfcol_22`, - `bfcol_6` AS `bfcol_23`, - `bfcol_8` AS `bfcol_24` - FROM `bfcte_3` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_9`, 0) = COALESCE(`bfcol_7`, 0) - AND COALESCE(`bfcol_9`, 1) = COALESCE(`bfcol_7`, 1) -), `bfcte_5` AS ( - SELECT - `bfcol_16` AS `bfcol_25`, - `bfcol_17` AS `bfcol_26`, - `bfcol_18` AS `bfcol_27`, - `bfcol_19` AS `bfcol_28`, - `bfcol_20` AS `bfcol_29`, - `bfcol_21` AS `bfcol_30`, - `bfcol_22` AS `bfcol_31`, - `bfcol_24` AS `bfcol_32`, - `bfcol_3` AS `bfcol_33`, - `bfcol_4` AS `bfcol_34`, - `bfcol_5` AS `bfcol_35` - FROM `bfcte_4` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_23`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_23`, 1) = COALESCE(`bfcol_2`, 1) -), `bfcte_6` AS ( - SELECT - `bfcol_25`, - `bfcol_26`, - `bfcol_27`, - `bfcol_28`, - `bfcol_29`, - `bfcol_30`, - `bfcol_31`, - `bfcol_32`, - `bfcol_33`, - `bfcol_34`, - `bfcol_35`, - `bfcol_0`, - `bfcol_1`, - `bfcol_25` AS `bfcol_47`, - `bfcol_26` AS `bfcol_48`, - `bfcol_27` AS `bfcol_49`, - `bfcol_29` AS `bfcol_50`, - `bfcol_30` AS `bfcol_51`, - `bfcol_31` AS `bfcol_52`, - `bfcol_33` AS `bfcol_53`, - `bfcol_34` AS `bfcol_54`, - `bfcol_1` AS `bfcol_55`, - ( - ( - `bfcol_32` >= CAST('1993-10-01' AS DATE) - ) - AND ( - `bfcol_32` < CAST('1994-01-01' AS DATE) - ) - ) - AND ( - `bfcol_35` = 'R' - ) AS `bfcol_56`, - `bfcol_25` AS `bfcol_76`, - `bfcol_26` AS `bfcol_77`, - `bfcol_27` AS `bfcol_78`, - `bfcol_29` AS `bfcol_79`, - `bfcol_30` AS `bfcol_80`, - `bfcol_31` AS `bfcol_81`, - `bfcol_1` AS `bfcol_82`, - ROUND(( - `bfcol_33` * ( - 1 - `bfcol_34` - ) - ), 2) AS `bfcol_83` - FROM `bfcte_5` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_28`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_28`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - ( - ( - `bfcol_32` >= CAST('1993-10-01' AS DATE) - ) - AND ( - `bfcol_32` < CAST('1994-01-01' AS DATE) - ) - ) - AND ( - `bfcol_35` = 'R' - ) -), `bfcte_7` AS ( - SELECT - `bfcol_76`, - `bfcol_77`, - `bfcol_80`, - `bfcol_79`, - `bfcol_82`, - `bfcol_78`, - `bfcol_81`, - COALESCE(SUM(`bfcol_83`), 0) AS `bfcol_92` - FROM `bfcte_6` - WHERE - NOT `bfcol_76` IS NULL - AND NOT `bfcol_77` IS NULL - AND NOT `bfcol_80` IS NULL - AND NOT `bfcol_79` IS NULL - AND NOT `bfcol_82` IS NULL - AND NOT `bfcol_78` IS NULL - AND NOT `bfcol_81` IS NULL + `t19`.`bfuid_col_3099`, + `t19`.`bfuid_col_3100`, + `t19`.`bfuid_col_3104`, + `t19`.`bfuid_col_3103`, + `t19`.`bfuid_col_3133`, + `t19`.`bfuid_col_3101`, + `t19`.`bfuid_col_3106`, + COALESCE(SUM(`t19`.`bfuid_col_3136`), 0) AS `bfuid_col_3137` + FROM ( + SELECT + `t18`.`bfuid_col_3056` AS `bfuid_col_3099`, + `t18`.`bfuid_col_3057` AS `bfuid_col_3100`, + `t18`.`bfuid_col_3058` AS `bfuid_col_3101`, + `t18`.`bfuid_col_3060` AS `bfuid_col_3103`, + `t18`.`bfuid_col_3061` AS `bfuid_col_3104`, + `t18`.`bfuid_col_3063` AS `bfuid_col_3106`, + `t18`.`bfuid_col_3090` AS `bfuid_col_3133`, + ROUND(`t18`.`bfuid_col_3078` * ( + 1 - `t18`.`bfuid_col_3079` + ), 2) AS `bfuid_col_3136` + FROM ( + SELECT + `t17`.`C_CUSTKEY` AS `bfuid_col_3056`, + `t17`.`C_NAME` AS `bfuid_col_3057`, + `t17`.`C_ADDRESS` AS `bfuid_col_3058`, + `t17`.`C_PHONE` AS `bfuid_col_3060`, + `t17`.`C_ACCTBAL` AS `bfuid_col_3061`, + `t17`.`C_COMMENT` AS `bfuid_col_3063`, + `t17`.`L_EXTENDEDPRICE` AS `bfuid_col_3078`, + `t17`.`L_DISCOUNT` AS `bfuid_col_3079`, + `t8`.`N_NAME` AS `bfuid_col_3090`, + ( + ( + `t17`.`O_ORDERDATE` >= DATE(1993, 10, 1) + ) + AND ( + `t17`.`O_ORDERDATE` < DATE(1994, 1, 1) + ) + ) + AND ( + `t17`.`L_RETURNFLAG` = 'R' + ) AS `bfuid_col_3093` + FROM ( + SELECT + * + FROM ( + SELECT + `t14`.`C_CUSTKEY`, + `t14`.`C_NAME`, + `t14`.`C_ADDRESS`, + `t14`.`C_NATIONKEY`, + `t14`.`C_PHONE`, + `t14`.`C_ACCTBAL`, + `t14`.`C_COMMENT`, + `t14`.`O_ORDERDATE`, + `t9`.`L_EXTENDEDPRICE`, + `t9`.`L_DISCOUNT`, + `t9`.`L_RETURNFLAG` + FROM ( + SELECT + * + FROM ( + SELECT + `t10`.`C_CUSTKEY`, + `t10`.`C_NAME`, + `t10`.`C_ADDRESS`, + `t10`.`C_NATIONKEY`, + `t10`.`C_PHONE`, + `t10`.`C_ACCTBAL`, + `t10`.`C_COMMENT`, + `t11`.`O_ORDERKEY`, + `t11`.`O_ORDERDATE` + FROM ( + SELECT + `t2`.`C_CUSTKEY`, + `t2`.`C_NAME`, + `t2`.`C_ADDRESS`, + `t2`.`C_NATIONKEY`, + `t2`.`C_PHONE`, + `t2`.`C_ACCTBAL`, + `t2`.`C_COMMENT` + FROM ( + SELECT + `C_CUSTKEY`, + `C_NAME`, + `C_ADDRESS`, + `C_NATIONKEY`, + `C_PHONE`, + `C_ACCTBAL`, + `C_COMMENT` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t10` + INNER JOIN ( + SELECT + `t3`.`O_ORDERKEY`, + `t3`.`O_CUSTKEY`, + `t3`.`O_ORDERDATE` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY`, + `O_ORDERDATE` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t11` + ON COALESCE(`t10`.`C_CUSTKEY`, 0) = COALESCE(`t11`.`O_CUSTKEY`, 0) + AND COALESCE(`t10`.`C_CUSTKEY`, 1) = COALESCE(`t11`.`O_CUSTKEY`, 1) + ) AS `t12` + ) AS `t14` + INNER JOIN ( + SELECT + `t1`.`L_ORDERKEY`, + `t1`.`L_EXTENDEDPRICE`, + `t1`.`L_DISCOUNT`, + `t1`.`L_RETURNFLAG` + FROM ( + SELECT + `L_ORDERKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_RETURNFLAG` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t9` + ON COALESCE(`t14`.`O_ORDERKEY`, 0) = COALESCE(`t9`.`L_ORDERKEY`, 0) + AND COALESCE(`t14`.`O_ORDERKEY`, 1) = COALESCE(`t9`.`L_ORDERKEY`, 1) + ) AS `t15` + ) AS `t17` + INNER JOIN ( + SELECT + `t0`.`N_NATIONKEY`, + `t0`.`N_NAME` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t8` + ON COALESCE(`t17`.`C_NATIONKEY`, 0) = COALESCE(`t8`.`N_NATIONKEY`, 0) + AND COALESCE(`t17`.`C_NATIONKEY`, 1) = COALESCE(`t8`.`N_NATIONKEY`, 1) + ) AS `t18` + WHERE + `t18`.`bfuid_col_3093` + ) AS `t19` GROUP BY - `bfcol_76`, - `bfcol_77`, - `bfcol_80`, - `bfcol_79`, - `bfcol_82`, - `bfcol_78`, - `bfcol_81` -) -SELECT - `bfcol_76` AS `C_CUSTKEY`, - `bfcol_77` AS `C_NAME`, - `bfcol_92` AS `REVENUE`, - `bfcol_80` AS `C_ACCTBAL`, - `bfcol_82` AS `N_NAME`, - `bfcol_78` AS `C_ADDRESS`, - `bfcol_79` AS `C_PHONE`, - `bfcol_81` AS `C_COMMENT` -FROM `bfcte_7` -ORDER BY - `bfcol_92` DESC, - `bfcol_76` ASC NULLS LAST, - `bfcol_77` ASC NULLS LAST, - `bfcol_80` ASC NULLS LAST, - `bfcol_79` ASC NULLS LAST, - `bfcol_82` ASC NULLS LAST, - `bfcol_78` ASC NULLS LAST, - `bfcol_81` ASC NULLS LAST + 1, + 2, + 3, + 4, + 5, + 6, + 7 +) AS `t20` +WHERE + ( + `t20`.`bfuid_col_3099` + ) IS NOT NULL + AND ( + `t20`.`bfuid_col_3100` + ) IS NOT NULL + AND ( + `t20`.`bfuid_col_3104` + ) IS NOT NULL + AND ( + `t20`.`bfuid_col_3103` + ) IS NOT NULL + AND ( + `t20`.`bfuid_col_3133` + ) IS NOT NULL + AND ( + `t20`.`bfuid_col_3101` + ) IS NOT NULL + AND ( + `t20`.`bfuid_col_3106` + ) IS NOT NULL) AS `t` +ORDER BY `REVENUE` DESC NULLS LAST ,`C_CUSTKEY` ASC NULLS LAST ,`C_NAME` ASC NULLS LAST ,`C_ACCTBAL` ASC NULLS LAST ,`C_PHONE` ASC NULLS LAST ,`N_NAME` ASC NULLS LAST ,`C_ADDRESS` ASC NULLS LAST ,`C_COMMENT` ASC NULLS LAST LIMIT 20 \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/11/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/11/out.sql index 2b296be7448..9a9e58b63be 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/11/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/11/out.sql @@ -1,122 +1,187 @@ -WITH `bfcte_0` AS ( +SELECT `PS_PARTKEY`, `VALUE` FROM (SELECT + `t30`.`bfuid_col_3183` AS `PS_PARTKEY`, + `t30`.`bfuid_col_3184` AS `VALUE` +FROM ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT(0.0, 0, 0)]) -), `bfcte_1` AS ( - SELECT - `PS_SUPPKEY` AS `bfcol_0`, - `PS_AVAILQTY` AS `bfcol_1`, - `PS_SUPPLYCOST` AS `bfcol_2` - FROM `bigframes-dev`.`tpch`.`PARTSUPP` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `PS_PARTKEY` AS `bfcol_10`, - `PS_SUPPKEY` AS `bfcol_11`, - `PS_AVAILQTY` AS `bfcol_12`, - `PS_SUPPLYCOST` AS `bfcol_13` - FROM `bigframes-dev`.`tpch`.`PARTSUPP` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_3`, - `S_NATIONKEY` AS `bfcol_4` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_18` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `N_NAME` = 'GERMANY' -), `bfcte_5` AS ( - SELECT - `bfcol_3` AS `bfcol_19` - FROM `bfcte_4` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_18`, 0) = COALESCE(`bfcol_4`, 0) - AND COALESCE(`bfcol_18`, 1) = COALESCE(`bfcol_4`, 1) -), `bfcte_6` AS ( - SELECT - `bfcol_19`, - `bfcol_0`, - `bfcol_1`, - `bfcol_2`, - `bfcol_1` AS `bfcol_25`, - `bfcol_2` AS `bfcol_26`, - `bfcol_2` AS `bfcol_33`, - `bfcol_1` AS `bfcol_34`, - `bfcol_2` * `bfcol_1` AS `bfcol_40` - FROM `bfcte_5` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_19`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_19`, 1) = COALESCE(`bfcol_0`, 1) -), `bfcte_7` AS ( - SELECT - `bfcol_19`, - `bfcol_10`, - `bfcol_11`, - `bfcol_12`, - `bfcol_13`, - `bfcol_10` AS `bfcol_27`, - `bfcol_13` * `bfcol_12` AS `bfcol_28` - FROM `bfcte_5` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_19`, 0) = COALESCE(`bfcol_11`, 0) - AND COALESCE(`bfcol_19`, 1) = COALESCE(`bfcol_11`, 1) -), `bfcte_8` AS ( - SELECT - COALESCE(SUM(`bfcol_40`), 0) AS `bfcol_44` - FROM `bfcte_6` -), `bfcte_9` AS ( - SELECT - `bfcol_27`, - COALESCE(SUM(`bfcol_28`), 0) AS `bfcol_35` - FROM `bfcte_7` - WHERE - NOT `bfcol_27` IS NULL - GROUP BY - `bfcol_27` -), `bfcte_10` AS ( - SELECT - `bfcol_44`, - 0 AS `bfcol_45` - FROM `bfcte_8` -), `bfcte_11` AS ( - SELECT - `bfcol_27` AS `bfcol_41`, - ROUND(`bfcol_35`, 2) AS `bfcol_42` - FROM `bfcte_9` -), `bfcte_12` AS ( - SELECT - `bfcol_7`, - `bfcol_8`, - `bfcol_9`, - `bfcol_44`, - `bfcol_45`, - CASE WHEN `bfcol_9` = 0 THEN `bfcol_44` END AS `bfcol_46`, - IF(`bfcol_45` = 0, CASE WHEN `bfcol_9` = 0 THEN `bfcol_44` END, NULL) AS `bfcol_51` - FROM `bfcte_0` - CROSS JOIN `bfcte_10` -), `bfcte_13` AS ( - SELECT - `bfcol_7`, - `bfcol_8`, - ANY_VALUE(`bfcol_51`) AS `bfcol_55` - FROM `bfcte_12` - WHERE - NOT `bfcol_7` IS NULL AND NOT `bfcol_8` IS NULL - GROUP BY - `bfcol_7`, - `bfcol_8` -), `bfcte_14` AS ( - SELECT - `bfcol_55` * 0.0001 AS `bfcol_58` - FROM `bfcte_13` -) -SELECT - `bfcol_41` AS `PS_PARTKEY`, - `bfcol_42` AS `VALUE` -FROM `bfcte_11` -CROSS JOIN `bfcte_14` + `t25`.`bfuid_col_3166` AS `bfuid_col_3183`, + `t25`.`bfuid_col_3167` AS `bfuid_col_3184`, + `t25`.`bfuid_col_3167` > `t29`.`bfuid_col_3179` AS `bfuid_col_3186` + FROM ( + SELECT + `t20`.`bfuid_col_3158` AS `bfuid_col_3166`, + ROUND(`t20`.`bfuid_col_3164`, 2) AS `bfuid_col_3167` + FROM ( + SELECT + `t18`.`bfuid_col_3158`, + COALESCE(SUM(`t18`.`bfuid_col_3163`), 0) AS `bfuid_col_3164` + FROM ( + SELECT + `t9`.`PS_PARTKEY` AS `bfuid_col_3158`, + `t9`.`PS_SUPPLYCOST` * `t9`.`PS_AVAILQTY` AS `bfuid_col_3163` + FROM ( + SELECT + * + FROM ( + SELECT + `t12`.`S_SUPPKEY` + FROM ( + SELECT + `t2`.`N_NATIONKEY` AS `bfuid_col_3139` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + WHERE + `t2`.`N_NAME` = 'GERMANY' + ) AS `t14` + INNER JOIN ( + SELECT + `t3`.`S_SUPPKEY`, + `t3`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t12` + ON COALESCE(`t14`.`bfuid_col_3139`, 0) = COALESCE(`t12`.`S_NATIONKEY`, 0) + AND COALESCE(`t14`.`bfuid_col_3139`, 1) = COALESCE(`t12`.`S_NATIONKEY`, 1) + ) AS `t15` + ) AS `t17` + INNER JOIN ( + SELECT + `t0`.`PS_PARTKEY`, + `t0`.`PS_SUPPKEY`, + `t0`.`PS_AVAILQTY`, + `t0`.`PS_SUPPLYCOST` + FROM ( + SELECT + `PS_PARTKEY`, + `PS_SUPPKEY`, + `PS_AVAILQTY`, + `PS_SUPPLYCOST` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t9` + ON COALESCE(`t17`.`S_SUPPKEY`, 0) = COALESCE(`t9`.`PS_SUPPKEY`, 0) + AND COALESCE(`t17`.`S_SUPPKEY`, 1) = COALESCE(`t9`.`PS_SUPPKEY`, 1) + ) AS `t18` + GROUP BY + 1 + ) AS `t20` + WHERE + ( + `t20`.`bfuid_col_3158` + ) IS NOT NULL + ) AS `t25` + CROSS JOIN ( + SELECT + `t27`.`bfuid_col_3178` * 0.0001 AS `bfuid_col_3179` + FROM ( + SELECT + `t26`.`bfuid_col_3175`, + `t26`.`bfuid_col_3176`, + ANY_VALUE(`t26`.`bfuid_col_3177`) AS `bfuid_col_3178` + FROM ( + SELECT + `t10`.`col_0` AS `bfuid_col_3175`, + `t10`.`col_1` AS `bfuid_col_3176`, + CASE + WHEN `t24`.`bfuid_col_3173` = 0 + THEN CASE + WHEN `t10`.`col_2` = 0 + THEN `t24`.`bfuid_col_3171` + ELSE CAST(NULL AS FLOAT64) + END + ELSE CAST(NULL AS FLOAT64) + END AS `bfuid_col_3177` + FROM ( + SELECT + * + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(0.0, 0, 0)]) AS `col_0` + ) AS `t1` + ) AS `t10` + CROSS JOIN ( + SELECT + `t21`.`bfuid_col_3171`, + 0 AS `bfuid_col_3173` + FROM ( + SELECT + COALESCE(SUM(`t19`.`bfuid_col_3171`), 0) AS `bfuid_col_3171` + FROM ( + SELECT + `t13`.`PS_SUPPLYCOST` * `t13`.`PS_AVAILQTY` AS `bfuid_col_3171` + FROM ( + SELECT + * + FROM ( + SELECT + `t12`.`S_SUPPKEY` + FROM ( + SELECT + `t2`.`N_NATIONKEY` AS `bfuid_col_3139` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + WHERE + `t2`.`N_NAME` = 'GERMANY' + ) AS `t14` + INNER JOIN ( + SELECT + `t3`.`S_SUPPKEY`, + `t3`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t12` + ON COALESCE(`t14`.`bfuid_col_3139`, 0) = COALESCE(`t12`.`S_NATIONKEY`, 0) + AND COALESCE(`t14`.`bfuid_col_3139`, 1) = COALESCE(`t12`.`S_NATIONKEY`, 1) + ) AS `t15` + ) AS `t17` + INNER JOIN ( + SELECT + `t4`.`PS_SUPPKEY`, + `t4`.`PS_AVAILQTY`, + `t4`.`PS_SUPPLYCOST` + FROM ( + SELECT + `PS_SUPPKEY`, + `PS_AVAILQTY`, + `PS_SUPPLYCOST` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + ) AS `t13` + ON COALESCE(`t17`.`S_SUPPKEY`, 0) = COALESCE(`t13`.`PS_SUPPKEY`, 0) + AND COALESCE(`t17`.`S_SUPPKEY`, 1) = COALESCE(`t13`.`PS_SUPPKEY`, 1) + ) AS `t19` + ) AS `t21` + ) AS `t24` + ) AS `t26` + GROUP BY + 1, + 2 + ) AS `t27` + WHERE + ( + `t27`.`bfuid_col_3175` + ) IS NOT NULL + AND ( + `t27`.`bfuid_col_3176` + ) IS NOT NULL + ) AS `t29` +) AS `t30` WHERE - `bfcol_42` > `bfcol_58` -ORDER BY - `bfcol_42` DESC \ No newline at end of file + `t30`.`bfuid_col_3186`) AS `t` +ORDER BY `VALUE` DESC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/12/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/12/out.sql index 4d91dcdac19..e5d9065ea8b 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/12/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/12/out.sql @@ -1,93 +1,81 @@ -WITH `bfcte_0` AS ( +SELECT `L_SHIPMODE`, `HIGH_LINE_COUNT`, `LOW_LINE_COUNT` FROM (SELECT + `t8`.`bfuid_col_3291` AS `L_SHIPMODE`, + `t8`.`bfuid_col_3295` AS `HIGH_LINE_COUNT`, + `t8`.`bfuid_col_3296` AS `LOW_LINE_COUNT` +FROM ( SELECT - `L_ORDERKEY` AS `bfcol_0`, - `L_SHIPDATE` AS `bfcol_1`, - `L_COMMITDATE` AS `bfcol_2`, - `L_RECEIPTDATE` AS `bfcol_3`, - `L_SHIPMODE` AS `bfcol_4` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_5`, - `O_ORDERPRIORITY` AS `bfcol_6` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `bfcol_5`, - `bfcol_6`, - `bfcol_0`, - `bfcol_1`, - `bfcol_2`, - `bfcol_3`, - `bfcol_4`, - `bfcol_6` AS `bfcol_12`, - `bfcol_4` AS `bfcol_13`, - ( - ( + `t7`.`bfuid_col_3291`, + COALESCE(SUM(`t7`.`bfuid_col_3293`), 0) AS `bfuid_col_3295`, + COALESCE(SUM(`t7`.`bfuid_col_3294`), 0) AS `bfuid_col_3296` + FROM ( + SELECT + `t6`.`bfuid_col_3232` AS `bfuid_col_3291`, + CAST(COALESCE(COALESCE(`t6`.`bfuid_col_3214` IN ('1-URGENT', '2-HIGH'), FALSE), FALSE) AS INT64) AS `bfuid_col_3293`, + CAST(NOT ( + COALESCE(COALESCE(`t6`.`bfuid_col_3214` IN ('1-URGENT', '2-HIGH'), FALSE), FALSE) + ) AS INT64) AS `bfuid_col_3294` + FROM ( + SELECT + `t4`.`O_ORDERPRIORITY` AS `bfuid_col_3214`, + `t5`.`L_SHIPMODE` AS `bfuid_col_3232`, ( - COALESCE(COALESCE(`bfcol_4` IN ('MAIL', 'SHIP'), FALSE), FALSE) - AND ( - `bfcol_2` < `bfcol_3` + ( + ( + COALESCE(COALESCE(`t5`.`L_SHIPMODE` IN ('MAIL', 'SHIP'), FALSE), FALSE) + AND ( + `t5`.`L_COMMITDATE` < `t5`.`L_RECEIPTDATE` + ) + ) + AND ( + `t5`.`L_SHIPDATE` < `t5`.`L_COMMITDATE` + ) ) - ) - AND ( - `bfcol_1` < `bfcol_2` - ) - ) - AND ( - `bfcol_3` >= CAST('1994-01-01' AS DATE) - ) - ) - AND ( - `bfcol_3` < CAST('1995-01-01' AS DATE) - ) AS `bfcol_14`, - `bfcol_6` AS `bfcol_20`, - `bfcol_4` AS `bfcol_21`, - CAST(COALESCE(COALESCE(`bfcol_6` IN ('1-URGENT', '2-HIGH'), FALSE), FALSE) AS INT64) AS `bfcol_22`, - `bfcol_4` AS `bfcol_26`, - CAST(COALESCE(COALESCE(`bfcol_6` IN ('1-URGENT', '2-HIGH'), FALSE), FALSE) AS INT64) AS `bfcol_27`, - CAST(NOT ( - COALESCE(COALESCE(`bfcol_6` IN ('1-URGENT', '2-HIGH'), FALSE), FALSE) - ) AS INT64) AS `bfcol_28` - FROM `bfcte_1` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_5`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_5`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - ( - ( - ( - COALESCE(COALESCE(`bfcol_4` IN ('MAIL', 'SHIP'), FALSE), FALSE) AND ( - `bfcol_2` < `bfcol_3` + `t5`.`L_RECEIPTDATE` >= DATE(1994, 1, 1) ) ) AND ( - `bfcol_1` < `bfcol_2` - ) - ) - AND ( - `bfcol_3` >= CAST('1994-01-01' AS DATE) - ) - ) - AND ( - `bfcol_3` < CAST('1995-01-01' AS DATE) - ) -), `bfcte_3` AS ( - SELECT - `bfcol_26`, - COALESCE(SUM(`bfcol_27`), 0) AS `bfcol_32`, - COALESCE(SUM(`bfcol_28`), 0) AS `bfcol_33` - FROM `bfcte_2` - WHERE - NOT `bfcol_26` IS NULL + `t5`.`L_RECEIPTDATE` < DATE(1995, 1, 1) + ) AS `bfuid_col_3234` + FROM ( + SELECT + `t0`.`O_ORDERKEY`, + `t0`.`O_ORDERPRIORITY` + FROM ( + SELECT + `O_ORDERKEY`, + `O_ORDERPRIORITY` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t4` + INNER JOIN ( + SELECT + `t1`.`L_ORDERKEY`, + `t1`.`L_SHIPDATE`, + `t1`.`L_COMMITDATE`, + `t1`.`L_RECEIPTDATE`, + `t1`.`L_SHIPMODE` + FROM ( + SELECT + `L_ORDERKEY`, + `L_SHIPDATE`, + `L_COMMITDATE`, + `L_RECEIPTDATE`, + `L_SHIPMODE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t5` + ON COALESCE(`t4`.`O_ORDERKEY`, 0) = COALESCE(`t5`.`L_ORDERKEY`, 0) + AND COALESCE(`t4`.`O_ORDERKEY`, 1) = COALESCE(`t5`.`L_ORDERKEY`, 1) + ) AS `t6` + WHERE + `t6`.`bfuid_col_3234` + ) AS `t7` GROUP BY - `bfcol_26` -) -SELECT - `bfcol_26` AS `L_SHIPMODE`, - `bfcol_32` AS `HIGH_LINE_COUNT`, - `bfcol_33` AS `LOW_LINE_COUNT` -FROM `bfcte_3` -ORDER BY - `bfcol_26` ASC NULLS LAST \ No newline at end of file + 1 +) AS `t8` +WHERE + ( + `t8`.`bfuid_col_3291` + ) IS NOT NULL) AS `t` +ORDER BY `L_SHIPMODE` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/13/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/13/out.sql index 728738a15e0..12934d7280e 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/13/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/13/out.sql @@ -1,42 +1,62 @@ -WITH `bfcte_0` AS ( +SELECT `C_COUNT`, `CUSTDIST` FROM (SELECT + `t9`.`bfuid_col_3309` AS `C_COUNT`, + `t9`.`bfuid_col_3310` AS `CUSTDIST` +FROM ( SELECT - `O_ORDERKEY` AS `bfcol_10`, - `O_CUSTKEY` AS `bfcol_11` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - NOT ( - REGEXP_CONTAINS(`O_COMMENT`, 'special.*requests') - ) -), `bfcte_1` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `bfcol_3`, - COUNT(`bfcol_10`) AS `bfcol_14` - FROM `bfcte_1` - LEFT JOIN `bfcte_0` - ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_11`, 0) - AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_11`, 1) - WHERE - NOT `bfcol_3` IS NULL - GROUP BY - `bfcol_3` -), `bfcte_3` AS ( - SELECT - `bfcol_14`, - COUNT(1) AS `bfcol_16` - FROM `bfcte_2` - WHERE - NOT `bfcol_14` IS NULL + `t8`.`bfuid_col_3309`, + COUNT(1) AS `bfuid_col_3310` + FROM ( + SELECT + `t7`.`bfuid_col_3309` + FROM ( + SELECT + `t6`.`C_CUSTKEY`, + COUNT(`t6`.`bfuid_col_3299`) AS `bfuid_col_3309` + FROM ( + SELECT + `t3`.`C_CUSTKEY`, + `t5`.`bfuid_col_3299` + FROM ( + SELECT + `t0`.`C_CUSTKEY` + FROM ( + SELECT + `C_CUSTKEY` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t3` + LEFT OUTER JOIN ( + SELECT + `t1`.`O_ORDERKEY` AS `bfuid_col_3299`, + `t1`.`O_CUSTKEY` AS `bfuid_col_3300` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY`, + `O_COMMENT` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + WHERE + NOT ( + regexp_contains(`t1`.`O_COMMENT`, 'special.*requests') + ) + ) AS `t5` + ON COALESCE(`t3`.`C_CUSTKEY`, 0) = COALESCE(`t5`.`bfuid_col_3300`, 0) + AND COALESCE(`t3`.`C_CUSTKEY`, 1) = COALESCE(`t5`.`bfuid_col_3300`, 1) + ) AS `t6` + GROUP BY + 1 + ) AS `t7` + WHERE + ( + `t7`.`C_CUSTKEY` + ) IS NOT NULL + ) AS `t8` GROUP BY - `bfcol_14` -) -SELECT - `bfcol_14` AS `C_COUNT`, - `bfcol_16` AS `CUSTDIST` -FROM `bfcte_3` -ORDER BY - `bfcol_16` DESC, - `bfcol_14` DESC \ No newline at end of file + 1 +) AS `t9` +WHERE + ( + `t9`.`bfuid_col_3309` + ) IS NOT NULL) AS `t` +ORDER BY `CUSTDIST` DESC NULLS LAST ,`C_COUNT` DESC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/14/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/14/out.sql index a4644a86def..66ad2ab2d3b 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/14/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/14/out.sql @@ -1,170 +1,206 @@ -WITH `bfcte_0` AS ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT('TEMP', 0, 0)]) -), `bfcte_1` AS ( - SELECT - * - FROM UNNEST(ARRAY>[STRUCT('TEMP', 0, 0)]) -), `bfcte_2` AS ( - SELECT - `L_PARTKEY` AS `bfcol_0`, - `L_EXTENDEDPRICE` AS `bfcol_1`, - `L_DISCOUNT` AS `bfcol_2`, - `L_SHIPDATE` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `P_PARTKEY` AS `bfcol_4` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `P_PARTKEY` AS `bfcol_8`, - `P_TYPE` AS `bfcol_9` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `bfcol_4`, - `bfcol_0`, - `bfcol_1`, - `bfcol_2`, - `bfcol_3`, - `bfcol_1` AS `bfcol_20`, - `bfcol_2` AS `bfcol_21`, - ( - `bfcol_3` >= CAST('1995-09-01' AS DATE) - ) - AND ( - `bfcol_3` < CAST('1995-10-01' AS DATE) - ) AS `bfcol_22`, - `bfcol_1` AS `bfcol_39`, - `bfcol_2` AS `bfcol_40`, - `bfcol_1` AS `bfcol_45`, - 1 - `bfcol_2` AS `bfcol_46`, - `bfcol_1` * ( - 1 - `bfcol_2` - ) AS `bfcol_51` - FROM `bfcte_3` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_4`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_4`, 1) = COALESCE(`bfcol_0`, 1) +SELECT `PROMO_REVENUE` FROM (SELECT + ROUND(ieee_divide(`t30`.`bfuid_col_3395`, `t32`.`bfuid_col_3387`), 2) AS `PROMO_REVENUE`, + COALESCE(`t30`.`bfuid_col_3391`, `t32`.`bfuid_col_3384`) AS `bfuid_col_3403` +FROM ( + SELECT + `t27`.`bfuid_col_3391`, + 100.0 * `t27`.`bfuid_col_3394` AS `bfuid_col_3395` + FROM ( + SELECT + `t25`.`bfuid_col_3391`, + `t25`.`bfuid_col_3392`, + ANY_VALUE(`t25`.`bfuid_col_3393`) AS `bfuid_col_3394` + FROM ( + SELECT + `t10`.`col_0` AS `bfuid_col_3391`, + `t10`.`col_1` AS `bfuid_col_3392`, + CASE + WHEN `t22`.`bfuid_col_3389` = 0 + THEN CASE + WHEN `t10`.`col_2` = 0 + THEN `t22`.`bfuid_col_3376` + ELSE CAST(NULL AS FLOAT64) + END + ELSE CAST(NULL AS FLOAT64) + END AS `bfuid_col_3393` + FROM ( + SELECT + * + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT('TEMP', 0, 0)]) AS `col_0` + ) AS `t0` + ) AS `t10` + CROSS JOIN ( + SELECT + `t19`.`bfuid_col_3376`, + 0 AS `bfuid_col_3389` + FROM ( + SELECT + COALESCE(SUM(`t17`.`bfuid_col_3376`), 0) AS `bfuid_col_3376` + FROM ( + SELECT + ( + `t15`.`bfuid_col_3330` * ( + 1 - `t15`.`bfuid_col_3331` + ) + ) * CAST(regexp_contains(`t15`.`bfuid_col_3320`, 'PROMO') AS INT64) AS `bfuid_col_3376` + FROM ( + SELECT + `t12`.`P_TYPE` AS `bfuid_col_3320`, + `t13`.`L_EXTENDEDPRICE` AS `bfuid_col_3330`, + `t13`.`L_DISCOUNT` AS `bfuid_col_3331`, + ( + `t13`.`L_SHIPDATE` >= DATE(1995, 9, 1) + ) + AND ( + `t13`.`L_SHIPDATE` < DATE(1995, 10, 1) + ) AS `bfuid_col_3341` + FROM ( + SELECT + `t2`.`P_PARTKEY`, + `t2`.`P_TYPE` + FROM ( + SELECT + `P_PARTKEY`, + `P_TYPE` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t12` + INNER JOIN ( + SELECT + `t3`.`L_PARTKEY`, + `t3`.`L_EXTENDEDPRICE`, + `t3`.`L_DISCOUNT`, + `t3`.`L_SHIPDATE` + FROM ( + SELECT + `L_PARTKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t13` + ON COALESCE(`t12`.`P_PARTKEY`, 0) = COALESCE(`t13`.`L_PARTKEY`, 0) + AND COALESCE(`t12`.`P_PARTKEY`, 1) = COALESCE(`t13`.`L_PARTKEY`, 1) + ) AS `t15` + WHERE + `t15`.`bfuid_col_3341` + ) AS `t17` + ) AS `t19` + ) AS `t22` + ) AS `t25` + GROUP BY + 1, + 2 + ) AS `t27` WHERE ( - `bfcol_3` >= CAST('1995-09-01' AS DATE) - ) - AND ( - `bfcol_3` < CAST('1995-10-01' AS DATE) - ) -), `bfcte_6` AS ( - SELECT - `bfcol_8`, - `bfcol_9`, - `bfcol_0`, - `bfcol_1`, - `bfcol_2`, - `bfcol_3`, - `bfcol_9` AS `bfcol_23`, - `bfcol_1` AS `bfcol_24`, - `bfcol_2` AS `bfcol_25`, - ( - `bfcol_3` >= CAST('1995-09-01' AS DATE) - ) + `t27`.`bfuid_col_3391` + ) IS NOT NULL AND ( - `bfcol_3` < CAST('1995-10-01' AS DATE) - ) AS `bfcol_26`, - ( - `bfcol_1` * ( - 1 - `bfcol_2` - ) - ) * CAST(REGEXP_CONTAINS(`bfcol_9`, 'PROMO') AS INT64) AS `bfcol_41` - FROM `bfcte_4` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_8`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_8`, 1) = COALESCE(`bfcol_0`, 1) + `t27`.`bfuid_col_3392` + ) IS NOT NULL +) AS `t30` +FULL OUTER JOIN ( + SELECT + `t28`.`bfuid_col_3384`, + `t28`.`bfuid_col_3387` + FROM ( + SELECT + `t26`.`bfuid_col_3384`, + `t26`.`bfuid_col_3385`, + ANY_VALUE(`t26`.`bfuid_col_3386`) AS `bfuid_col_3387` + FROM ( + SELECT + `t11`.`col_0` AS `bfuid_col_3384`, + `t11`.`col_1` AS `bfuid_col_3385`, + CASE + WHEN `t24`.`bfuid_col_3382` = 0 + THEN CASE + WHEN `t11`.`col_2` = 0 + THEN `t24`.`bfuid_col_3380` + ELSE CAST(NULL AS FLOAT64) + END + ELSE CAST(NULL AS FLOAT64) + END AS `bfuid_col_3386` + FROM ( + SELECT + * + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT('TEMP', 0, 0)]) AS `col_0` + ) AS `t1` + ) AS `t11` + CROSS JOIN ( + SELECT + `t20`.`bfuid_col_3380`, + 0 AS `bfuid_col_3382` + FROM ( + SELECT + COALESCE(SUM(`t18`.`bfuid_col_3380`), 0) AS `bfuid_col_3380` + FROM ( + SELECT + `t16`.`bfuid_col_3330` * ( + 1 - `t16`.`bfuid_col_3331` + ) AS `bfuid_col_3380` + FROM ( + SELECT + `t13`.`L_EXTENDEDPRICE` AS `bfuid_col_3330`, + `t13`.`L_DISCOUNT` AS `bfuid_col_3331`, + ( + `t13`.`L_SHIPDATE` >= DATE(1995, 9, 1) + ) + AND ( + `t13`.`L_SHIPDATE` < DATE(1995, 10, 1) + ) AS `bfuid_col_3341` + FROM ( + SELECT + `t4`.`P_PARTKEY` + FROM ( + SELECT + `P_PARTKEY` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + ) AS `t14` + INNER JOIN ( + SELECT + `t3`.`L_PARTKEY`, + `t3`.`L_EXTENDEDPRICE`, + `t3`.`L_DISCOUNT`, + `t3`.`L_SHIPDATE` + FROM ( + SELECT + `L_PARTKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t13` + ON COALESCE(`t14`.`P_PARTKEY`, 0) = COALESCE(`t13`.`L_PARTKEY`, 0) + AND COALESCE(`t14`.`P_PARTKEY`, 1) = COALESCE(`t13`.`L_PARTKEY`, 1) + ) AS `t16` + WHERE + `t16`.`bfuid_col_3341` + ) AS `t18` + ) AS `t20` + ) AS `t24` + ) AS `t26` + GROUP BY + 1, + 2 + ) AS `t28` WHERE ( - `bfcol_3` >= CAST('1995-09-01' AS DATE) - ) + `t28`.`bfuid_col_3384` + ) IS NOT NULL AND ( - `bfcol_3` < CAST('1995-10-01' AS DATE) - ) -), `bfcte_7` AS ( - SELECT - COALESCE(SUM(`bfcol_51`), 0) AS `bfcol_54` - FROM `bfcte_5` -), `bfcte_8` AS ( - SELECT - COALESCE(SUM(`bfcol_41`), 0) AS `bfcol_47` - FROM `bfcte_6` -), `bfcte_9` AS ( - SELECT - `bfcol_54`, - 0 AS `bfcol_59` - FROM `bfcte_7` -), `bfcte_10` AS ( - SELECT - `bfcol_47`, - 0 AS `bfcol_50` - FROM `bfcte_8` -), `bfcte_11` AS ( - SELECT - `bfcol_5`, - `bfcol_6`, - `bfcol_7`, - `bfcol_54`, - `bfcol_59`, - CASE WHEN `bfcol_7` = 0 THEN `bfcol_54` END AS `bfcol_64`, - IF(`bfcol_59` = 0, CASE WHEN `bfcol_7` = 0 THEN `bfcol_54` END, NULL) AS `bfcol_72` - FROM `bfcte_0` - CROSS JOIN `bfcte_9` -), `bfcte_12` AS ( - SELECT - `bfcol_10`, - `bfcol_11`, - `bfcol_12`, - `bfcol_47`, - `bfcol_50`, - CASE WHEN `bfcol_12` = 0 THEN `bfcol_47` END AS `bfcol_53`, - IF(`bfcol_50` = 0, CASE WHEN `bfcol_12` = 0 THEN `bfcol_47` END, NULL) AS `bfcol_60` - FROM `bfcte_1` - CROSS JOIN `bfcte_10` -), `bfcte_13` AS ( - SELECT - `bfcol_5`, - `bfcol_6`, - ANY_VALUE(`bfcol_72`) AS `bfcol_79` - FROM `bfcte_11` - WHERE - NOT `bfcol_5` IS NULL AND NOT `bfcol_6` IS NULL - GROUP BY - `bfcol_5`, - `bfcol_6` -), `bfcte_14` AS ( - SELECT - `bfcol_10`, - `bfcol_11`, - ANY_VALUE(`bfcol_60`) AS `bfcol_65` - FROM `bfcte_12` - WHERE - NOT `bfcol_10` IS NULL AND NOT `bfcol_11` IS NULL - GROUP BY - `bfcol_10`, - `bfcol_11` -), `bfcte_15` AS ( - SELECT - `bfcol_5` AS `bfcol_80`, - `bfcol_79` AS `bfcol_81` - FROM `bfcte_13` -), `bfcte_16` AS ( - SELECT - `bfcol_10` AS `bfcol_77`, - 100.0 * `bfcol_65` AS `bfcol_78` - FROM `bfcte_14` -) -SELECT - ROUND(IEEE_DIVIDE(`bfcol_78`, `bfcol_81`), 2) AS `PROMO_REVENUE` -FROM `bfcte_16` -FULL OUTER JOIN `bfcte_15` - ON `bfcol_77` = `bfcol_80` -ORDER BY - COALESCE(`bfcol_77`, `bfcol_80`) ASC NULLS LAST \ No newline at end of file + `t28`.`bfuid_col_3385` + ) IS NOT NULL +) AS `t32` + ON `t30`.`bfuid_col_3391` = `t32`.`bfuid_col_3384`) AS `t` +ORDER BY `bfuid_col_3403` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/15/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/15/out.sql index 929418a09b2..1a6ebb08eb4 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/15/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/15/out.sql @@ -1,116 +1,202 @@ -WITH `bfcte_0` AS ( +SELECT `S_SUPPKEY`, `S_NAME`, `S_ADDRESS`, `S_PHONE`, `TOTAL_REVENUE` FROM (SELECT + `t26`.`bfuid_col_3466` AS `S_SUPPKEY`, + `t26`.`bfuid_col_3467` AS `S_NAME`, + `t26`.`bfuid_col_3468` AS `S_ADDRESS`, + `t26`.`bfuid_col_3470` AS `S_PHONE`, + `t26`.`bfuid_col_3474` AS `TOTAL_REVENUE` +FROM ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT('TOTAL_REVENUE', 0, 0)]) -), `bfcte_1` AS ( - SELECT - `L_SUPPKEY`, - `L_EXTENDEDPRICE`, - `L_DISCOUNT`, - `L_SHIPDATE`, - `L_SUPPKEY` AS `bfcol_12`, - `L_EXTENDEDPRICE` AS `bfcol_13`, - `L_DISCOUNT` AS `bfcol_14`, - ( - `L_SHIPDATE` >= CAST('1996-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` < CAST('1996-04-01' AS DATE) - ) AS `bfcol_15`, - `L_SUPPKEY` AS `bfcol_23`, - `L_EXTENDEDPRICE` * ( - 1 - `L_DISCOUNT` - ) AS `bfcol_24` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - ( - `L_SHIPDATE` >= CAST('1996-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` < CAST('1996-04-01' AS DATE) - ) -), `bfcte_2` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_4` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_8`, - `S_NAME` AS `bfcol_9`, - `S_ADDRESS` AS `bfcol_10`, - `S_PHONE` AS `bfcol_11` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `bfcol_23`, - COALESCE(SUM(`bfcol_24`), 0) AS `bfcol_27` - FROM `bfcte_1` - WHERE - NOT `bfcol_23` IS NULL - GROUP BY - `bfcol_23` -), `bfcte_5` AS ( - SELECT - `bfcol_23` AS `bfcol_30`, - ROUND(`bfcol_27`, 2) AS `bfcol_31` - FROM `bfcte_4` -), `bfcte_6` AS ( - SELECT - MAX(`bfcol_31`) AS `bfcol_38` - FROM `bfcte_2` - INNER JOIN `bfcte_5` - ON `bfcol_4` = `bfcol_30` -), `bfcte_7` AS ( - SELECT - `bfcol_8` AS `bfcol_33`, - `bfcol_9` AS `bfcol_34`, - `bfcol_10` AS `bfcol_35`, - `bfcol_11` AS `bfcol_36`, - `bfcol_31` AS `bfcol_37` - FROM `bfcte_3` - INNER JOIN `bfcte_5` - ON `bfcol_8` = `bfcol_30` -), `bfcte_8` AS ( - SELECT - `bfcol_38`, - 0 AS `bfcol_39` - FROM `bfcte_6` -), `bfcte_9` AS ( - SELECT - `bfcol_5`, - `bfcol_6`, - `bfcol_7`, - `bfcol_38`, - `bfcol_39`, - CASE WHEN `bfcol_7` = 0 THEN `bfcol_38` END AS `bfcol_40`, - IF(`bfcol_39` = 0, CASE WHEN `bfcol_7` = 0 THEN `bfcol_38` END, NULL) AS `bfcol_45` - FROM `bfcte_0` - CROSS JOIN `bfcte_8` -), `bfcte_10` AS ( - SELECT - `bfcol_5`, - `bfcol_6`, - ANY_VALUE(`bfcol_45`) AS `bfcol_49` - FROM `bfcte_9` - WHERE - NOT `bfcol_5` IS NULL AND NOT `bfcol_6` IS NULL - GROUP BY - `bfcol_5`, - `bfcol_6` -), `bfcte_11` AS ( - SELECT - `bfcol_49` AS `bfcol_50` - FROM `bfcte_10` -) -SELECT - `bfcol_33` AS `S_SUPPKEY`, - `bfcol_34` AS `S_NAME`, - `bfcol_35` AS `S_ADDRESS`, - `bfcol_36` AS `S_PHONE`, - `bfcol_37` AS `TOTAL_REVENUE` -FROM `bfcte_7` -CROSS JOIN `bfcte_11` + `t18`.`S_SUPPKEY` AS `bfuid_col_3466`, + `t18`.`S_NAME` AS `bfuid_col_3467`, + `t18`.`S_ADDRESS` AS `bfuid_col_3468`, + `t18`.`S_PHONE` AS `bfuid_col_3470`, + `t18`.`bfuid_col_3450` AS `bfuid_col_3474`, + `t18`.`bfuid_col_3450` = `t25`.`bfuid_col_3458` AS `bfuid_col_3476` + FROM ( + SELECT + * + FROM ( + SELECT + `t7`.`S_SUPPKEY`, + `t7`.`S_NAME`, + `t7`.`S_ADDRESS`, + `t7`.`S_PHONE`, + `t14`.`bfuid_col_3450` + FROM ( + SELECT + `t0`.`S_SUPPKEY`, + `t0`.`S_NAME`, + `t0`.`S_ADDRESS`, + `t0`.`S_PHONE` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NAME`, + `S_ADDRESS`, + `S_PHONE` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t7` + INNER JOIN ( + SELECT + `t12`.`bfuid_col_3432` AS `bfuid_col_3449`, + ROUND(`t12`.`bfuid_col_3447`, 2) AS `bfuid_col_3450` + FROM ( + SELECT + `t11`.`bfuid_col_3432`, + COALESCE(SUM(`t11`.`bfuid_col_3446`), 0) AS `bfuid_col_3447` + FROM ( + SELECT + `t10`.`bfuid_col_3411` AS `bfuid_col_3432`, + `t10`.`bfuid_col_3414` * ( + 1 - `t10`.`bfuid_col_3415` + ) AS `bfuid_col_3446` + FROM ( + SELECT + `t2`.`L_SUPPKEY` AS `bfuid_col_3411`, + `t2`.`L_EXTENDEDPRICE` AS `bfuid_col_3414`, + `t2`.`L_DISCOUNT` AS `bfuid_col_3415`, + ( + `t2`.`L_SHIPDATE` >= DATE(1996, 1, 1) + ) + AND ( + `t2`.`L_SHIPDATE` < DATE(1996, 4, 1) + ) AS `bfuid_col_3425` + FROM ( + SELECT + `L_SUPPKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t10` + WHERE + `t10`.`bfuid_col_3425` + ) AS `t11` + GROUP BY + 1 + ) AS `t12` + WHERE + ( + `t12`.`bfuid_col_3432` + ) IS NOT NULL + ) AS `t14` + ON `t7`.`S_SUPPKEY` = `t14`.`bfuid_col_3449` + ) AS `t15` + ) AS `t18` + CROSS JOIN ( + SELECT + `t23`.`bfuid_col_3458` + FROM ( + SELECT + `t22`.`bfuid_col_3455`, + `t22`.`bfuid_col_3456`, + ANY_VALUE(`t22`.`bfuid_col_3457`) AS `bfuid_col_3458` + FROM ( + SELECT + `t8`.`col_0` AS `bfuid_col_3455`, + `t8`.`col_1` AS `bfuid_col_3456`, + CASE + WHEN `t21`.`bfuid_col_3453` = 0 + THEN CASE + WHEN `t8`.`col_2` = 0 + THEN `t21`.`bfuid_col_3450` + ELSE CAST(NULL AS FLOAT64) + END + ELSE CAST(NULL AS FLOAT64) + END AS `bfuid_col_3457` + FROM ( + SELECT + * + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT('TOTAL_REVENUE', 0, 0)]) AS `col_0` + ) AS `t1` + ) AS `t8` + CROSS JOIN ( + SELECT + `t19`.`bfuid_col_3450`, + 0 AS `bfuid_col_3453` + FROM ( + SELECT + MAX(`t16`.`bfuid_col_3450`) AS `bfuid_col_3450` + FROM ( + SELECT + `t14`.`bfuid_col_3450` + FROM ( + SELECT + `t3`.`S_SUPPKEY` + FROM ( + SELECT + `S_SUPPKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t9` + INNER JOIN ( + SELECT + `t12`.`bfuid_col_3432` AS `bfuid_col_3449`, + ROUND(`t12`.`bfuid_col_3447`, 2) AS `bfuid_col_3450` + FROM ( + SELECT + `t11`.`bfuid_col_3432`, + COALESCE(SUM(`t11`.`bfuid_col_3446`), 0) AS `bfuid_col_3447` + FROM ( + SELECT + `t10`.`bfuid_col_3411` AS `bfuid_col_3432`, + `t10`.`bfuid_col_3414` * ( + 1 - `t10`.`bfuid_col_3415` + ) AS `bfuid_col_3446` + FROM ( + SELECT + `t2`.`L_SUPPKEY` AS `bfuid_col_3411`, + `t2`.`L_EXTENDEDPRICE` AS `bfuid_col_3414`, + `t2`.`L_DISCOUNT` AS `bfuid_col_3415`, + ( + `t2`.`L_SHIPDATE` >= DATE(1996, 1, 1) + ) + AND ( + `t2`.`L_SHIPDATE` < DATE(1996, 4, 1) + ) AS `bfuid_col_3425` + FROM ( + SELECT + `L_SUPPKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t10` + WHERE + `t10`.`bfuid_col_3425` + ) AS `t11` + GROUP BY + 1 + ) AS `t12` + WHERE + ( + `t12`.`bfuid_col_3432` + ) IS NOT NULL + ) AS `t14` + ON `t9`.`S_SUPPKEY` = `t14`.`bfuid_col_3449` + ) AS `t16` + ) AS `t19` + ) AS `t21` + ) AS `t22` + GROUP BY + 1, + 2 + ) AS `t23` + WHERE + ( + `t23`.`bfuid_col_3455` + ) IS NOT NULL + AND ( + `t23`.`bfuid_col_3456` + ) IS NOT NULL + ) AS `t25` +) AS `t26` WHERE - `bfcol_37` = `bfcol_50` -ORDER BY - `bfcol_33` ASC NULLS LAST \ No newline at end of file + `t26`.`bfuid_col_3476`) AS `t` +ORDER BY `S_SUPPKEY` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/16/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/16/out.sql index bd637ec3063..b38ca332e58 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/16/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/16/out.sql @@ -1,93 +1,132 @@ -WITH `bfcte_0` AS ( +SELECT `P_BRAND`, `P_TYPE`, `P_SIZE`, `SUPPLIER_CNT` FROM (SELECT + `t15`.`bfuid_col_3525` AS `P_BRAND`, + `t15`.`bfuid_col_3526` AS `P_TYPE`, + `t15`.`bfuid_col_3527` AS `P_SIZE`, + `t15`.`bfuid_col_3554` AS `SUPPLIER_CNT` +FROM ( SELECT - `S_SUPPKEY`, - `S_COMMENT`, - `S_SUPPKEY` AS `bfcol_8`, - NOT ( - REGEXP_CONTAINS(`S_COMMENT`, 'Customer.*Complaints') - ) AS `bfcol_9` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - NOT ( - REGEXP_CONTAINS(`S_COMMENT`, 'Customer.*Complaints') - ) -), `bfcte_1` AS ( - SELECT - `PS_PARTKEY` AS `bfcol_2`, - `PS_SUPPKEY` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`PARTSUPP` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `P_PARTKEY` AS `bfcol_4`, - `P_BRAND` AS `bfcol_5`, - `P_TYPE` AS `bfcol_6`, - `P_SIZE` AS `bfcol_7` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `bfcol_8` - FROM `bfcte_0` - GROUP BY - `bfcol_8` -), `bfcte_4` AS ( - SELECT - `bfcol_5` AS `bfcol_55`, - `bfcol_6` AS `bfcol_56`, - `bfcol_7` AS `bfcol_57`, - `bfcol_3` AS `bfcol_58` - FROM `bfcte_2` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_4`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_4`, 1) = COALESCE(`bfcol_2`, 1) - WHERE - `bfcol_5` <> 'Brand#45' - AND NOT ( - REGEXP_CONTAINS(`bfcol_6`, 'MEDIUM POLISHED') - ) - AND COALESCE(COALESCE(`bfcol_7` IN (49, 14, 23, 45, 19, 3, 36, 9), FALSE), FALSE) -), `bfcte_5` AS ( - SELECT - `bfcol_8` AS `bfcol_21` - FROM `bfcte_3` -), `bfcte_6` AS ( - SELECT - *, - STRUCT(COALESCE(`bfcol_58`, 0) AS `bfpart1`, COALESCE(`bfcol_58`, 1) AS `bfpart2`) IN ( - ( + `t14`.`bfuid_col_3525`, + `t14`.`bfuid_col_3526`, + `t14`.`bfuid_col_3527`, + COUNT(DISTINCT `t14`.`bfuid_col_3532`) AS `bfuid_col_3554` + FROM ( + SELECT + `t13`.`bfuid_col_3525`, + `t13`.`bfuid_col_3526`, + `t13`.`bfuid_col_3527`, + `t13`.`bfuid_col_3532` + FROM ( + SELECT + `t11`.`bfuid_col_3525`, + `t11`.`bfuid_col_3526`, + `t11`.`bfuid_col_3527`, + `t11`.`bfuid_col_3532`, + EXISTS( + SELECT + 1 + FROM ( + SELECT + `t7`.`bfuid_col_3479` + FROM ( + SELECT + `t0`.`S_SUPPKEY` AS `bfuid_col_3479` + FROM ( + SELECT + `S_SUPPKEY`, + `S_COMMENT` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + WHERE + NOT ( + regexp_contains(`t0`.`S_COMMENT`, 'Customer.*Complaints') + ) + ) AS `t7` + GROUP BY + 1 + ) AS `t8` + WHERE + ( + COALESCE(`t11`.`bfuid_col_3532`, 0) = COALESCE(`t8`.`bfuid_col_3479`, 0) + ) + AND ( + COALESCE(`t11`.`bfuid_col_3532`, 1) = COALESCE(`t8`.`bfuid_col_3479`, 1) + ) + ) AS `bfuid_col_3537` + FROM ( SELECT - STRUCT(COALESCE(`bfcol_21`, 0) AS `bfpart1`, COALESCE(`bfcol_21`, 1) AS `bfpart2`) - FROM `bfcte_5` - ) - ) AS `bfcol_59` - FROM `bfcte_4` -), `bfcte_7` AS ( - SELECT - * - FROM `bfcte_6` - WHERE - `bfcol_59` -), `bfcte_8` AS ( - SELECT - `bfcol_55`, - `bfcol_56`, - `bfcol_57`, - COUNT(DISTINCT `bfcol_58`) AS `bfcol_69` - FROM `bfcte_7` - WHERE - NOT `bfcol_55` IS NULL AND NOT `bfcol_56` IS NULL AND NOT `bfcol_57` IS NULL + `t10`.`bfuid_col_3525`, + `t10`.`bfuid_col_3526`, + `t10`.`bfuid_col_3527`, + `t10`.`bfuid_col_3532` + FROM ( + SELECT + `t9`.`bfuid_col_3491` AS `bfuid_col_3525`, + `t9`.`bfuid_col_3492` AS `bfuid_col_3526`, + `t9`.`bfuid_col_3493` AS `bfuid_col_3527`, + `t9`.`bfuid_col_3498` AS `bfuid_col_3532`, + COALESCE(COALESCE(`t9`.`bfuid_col_3493` IN (49, 14, 23, 45, 19, 3, 36, 9), FALSE), FALSE) AS `bfuid_col_3536` + FROM ( + SELECT + `t5`.`P_BRAND` AS `bfuid_col_3491`, + `t5`.`P_TYPE` AS `bfuid_col_3492`, + `t5`.`P_SIZE` AS `bfuid_col_3493`, + `t6`.`PS_SUPPKEY` AS `bfuid_col_3498`, + `t5`.`P_BRAND` <> 'Brand#45' AS `bfuid_col_3502` + FROM ( + SELECT + `t1`.`P_PARTKEY`, + `t1`.`P_BRAND`, + `t1`.`P_TYPE`, + `t1`.`P_SIZE` + FROM ( + SELECT + `P_PARTKEY`, + `P_BRAND`, + `P_TYPE`, + `P_SIZE` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t5` + INNER JOIN ( + SELECT + `t2`.`PS_PARTKEY`, + `t2`.`PS_SUPPKEY` + FROM ( + SELECT + `PS_PARTKEY`, + `PS_SUPPKEY` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t6` + ON COALESCE(`t5`.`P_PARTKEY`, 0) = COALESCE(`t6`.`PS_PARTKEY`, 0) + AND COALESCE(`t5`.`P_PARTKEY`, 1) = COALESCE(`t6`.`PS_PARTKEY`, 1) + ) AS `t9` + WHERE + `t9`.`bfuid_col_3502` + AND NOT ( + regexp_contains(`t9`.`bfuid_col_3492`, 'MEDIUM POLISHED') + ) + ) AS `t10` + WHERE + `t10`.`bfuid_col_3536` + ) AS `t11` + ) AS `t13` + WHERE + `t13`.`bfuid_col_3537` + ) AS `t14` GROUP BY - `bfcol_55`, - `bfcol_56`, - `bfcol_57` -) -SELECT - `bfcol_55` AS `P_BRAND`, - `bfcol_56` AS `P_TYPE`, - `bfcol_57` AS `P_SIZE`, - `bfcol_69` AS `SUPPLIER_CNT` -FROM `bfcte_8` -ORDER BY - `bfcol_69` DESC, - `bfcol_55` ASC NULLS LAST, - `bfcol_56` ASC NULLS LAST, - `bfcol_57` ASC NULLS LAST \ No newline at end of file + 1, + 2, + 3 +) AS `t15` +WHERE + ( + `t15`.`bfuid_col_3525` + ) IS NOT NULL + AND ( + `t15`.`bfuid_col_3526` + ) IS NOT NULL + AND ( + `t15`.`bfuid_col_3527` + ) IS NOT NULL) AS `t` +ORDER BY `SUPPLIER_CNT` DESC NULLS LAST ,`P_BRAND` ASC NULLS LAST ,`P_TYPE` ASC NULLS LAST ,`P_SIZE` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/17/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/17/out.sql index b9816ff0bf7..9b6486cb768 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/17/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/17/out.sql @@ -1,103 +1,168 @@ -WITH `bfcte_0` AS ( +SELECT `AVG_YEARLY` FROM (SELECT + ROUND(ieee_divide(`t26`.`bfuid_col_3612`, 7.0), 2) AS `AVG_YEARLY`, + `t26`.`bfuid_col_3610` AS `bfuid_col_3620`, + `t26`.`bfuid_col_3609` AS `bfuid_col_3621` +FROM ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT('L_EXTENDEDPRICE', 0, 0)]) -), `bfcte_1` AS ( - SELECT - `P_PARTKEY` AS `bfcol_15` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - ( - `P_BRAND` = 'Brand#23' - ) AND ( - `P_CONTAINER` = 'MED BOX' - ) -), `bfcte_2` AS ( - SELECT - `L_PARTKEY` AS `bfcol_3`, - `L_QUANTITY` AS `bfcol_4`, - `L_EXTENDEDPRICE` AS `bfcol_5` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `L_PARTKEY` AS `bfcol_6`, - `L_QUANTITY` AS `bfcol_7` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `bfcol_4` AS `bfcol_16`, - `bfcol_5` AS `bfcol_17`, - `bfcol_15` AS `bfcol_18` - FROM `bfcte_2` - RIGHT JOIN `bfcte_1` - ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_15`, 0) - AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_15`, 1) -), `bfcte_5` AS ( - SELECT - `bfcol_15`, - AVG(`bfcol_7`) AS `bfcol_21` - FROM `bfcte_3` - RIGHT JOIN `bfcte_1` - ON COALESCE(`bfcol_6`, 0) = COALESCE(`bfcol_15`, 0) - AND COALESCE(`bfcol_6`, 1) = COALESCE(`bfcol_15`, 1) - WHERE - NOT `bfcol_15` IS NULL - GROUP BY - `bfcol_15` -), `bfcte_6` AS ( - SELECT - `bfcol_15` AS `bfcol_24`, - `bfcol_21` * 0.2 AS `bfcol_25` - FROM `bfcte_5` -), `bfcte_7` AS ( - SELECT - `bfcol_24`, - `bfcol_25`, - `bfcol_16`, - `bfcol_17`, - `bfcol_18`, - `bfcol_17` AS `bfcol_29`, - `bfcol_16` < `bfcol_25` AS `bfcol_30` - FROM `bfcte_6` - INNER JOIN `bfcte_4` - ON `bfcol_24` = `bfcol_18` - WHERE - `bfcol_16` < `bfcol_25` -), `bfcte_8` AS ( - SELECT - COALESCE(SUM(`bfcol_29`), 0) AS `bfcol_34` - FROM `bfcte_7` -), `bfcte_9` AS ( - SELECT - `bfcol_34`, - 0 AS `bfcol_35` - FROM `bfcte_8` -), `bfcte_10` AS ( - SELECT - `bfcol_8`, - `bfcol_9`, - `bfcol_10`, - `bfcol_34`, - `bfcol_35`, - CASE WHEN `bfcol_10` = 0 THEN `bfcol_34` END AS `bfcol_36`, - IF(`bfcol_35` = 0, CASE WHEN `bfcol_10` = 0 THEN `bfcol_34` END, NULL) AS `bfcol_41` - FROM `bfcte_0` - CROSS JOIN `bfcte_9` -), `bfcte_11` AS ( - SELECT - `bfcol_8`, - `bfcol_9`, - ANY_VALUE(`bfcol_41`) AS `bfcol_45` - FROM `bfcte_10` - WHERE - NOT `bfcol_8` IS NULL AND NOT `bfcol_9` IS NULL + `t25`.`bfuid_col_3609`, + `t25`.`bfuid_col_3610`, + ANY_VALUE(`t25`.`bfuid_col_3611`) AS `bfuid_col_3612` + FROM ( + SELECT + `t7`.`col_0` AS `bfuid_col_3609`, + `t7`.`col_1` AS `bfuid_col_3610`, + CASE + WHEN `t24`.`bfuid_col_3607` = 0 + THEN CASE + WHEN `t7`.`col_2` = 0 + THEN `t24`.`bfuid_col_3585` + ELSE CAST(NULL AS FLOAT64) + END + ELSE CAST(NULL AS FLOAT64) + END AS `bfuid_col_3611` + FROM ( + SELECT + * + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT('L_EXTENDEDPRICE', 0, 0)]) AS `col_0` + ) AS `t0` + ) AS `t7` + CROSS JOIN ( + SELECT + `t22`.`bfuid_col_3585`, + 0 AS `bfuid_col_3607` + FROM ( + SELECT + COALESCE(SUM(`t21`.`bfuid_col_3585`), 0) AS `bfuid_col_3585` + FROM ( + SELECT + `t20`.`bfuid_col_3585` + FROM ( + SELECT + `t17`.`L_EXTENDEDPRICE` AS `bfuid_col_3585`, + `t17`.`L_QUANTITY` < `t19`.`bfuid_col_3573` AS `bfuid_col_3605` + FROM ( + SELECT + `t16`.`bfuid_col_3560` AS `bfuid_col_3572`, + `t16`.`bfuid_col_3570` * 0.2 AS `bfuid_col_3573` + FROM ( + SELECT + `t13`.`bfuid_col_3560`, + AVG(`t13`.`L_QUANTITY`) AS `bfuid_col_3570` + FROM ( + SELECT + `t8`.`L_QUANTITY`, + `t12`.`bfuid_col_3560` + FROM ( + SELECT + `t1`.`L_PARTKEY`, + `t1`.`L_QUANTITY` + FROM ( + SELECT + `L_PARTKEY`, + `L_QUANTITY` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t8` + RIGHT OUTER JOIN ( + SELECT + `t10`.`bfuid_col_3560` + FROM ( + SELECT + `t3`.`P_PARTKEY` AS `bfuid_col_3560`, + ( + `t3`.`P_BRAND` = 'Brand#23' + ) AND ( + `t3`.`P_CONTAINER` = 'MED BOX' + ) AS `bfuid_col_3569` + FROM ( + SELECT + `P_PARTKEY`, + `P_BRAND`, + `P_CONTAINER` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t10` + WHERE + `t10`.`bfuid_col_3569` + ) AS `t12` + ON COALESCE(`t8`.`L_PARTKEY`, 0) = COALESCE(`t12`.`bfuid_col_3560`, 0) + AND COALESCE(`t8`.`L_PARTKEY`, 1) = COALESCE(`t12`.`bfuid_col_3560`, 1) + ) AS `t13` + GROUP BY + 1 + ) AS `t16` + WHERE + ( + `t16`.`bfuid_col_3560` + ) IS NOT NULL + ) AS `t19` + INNER JOIN ( + SELECT + * + FROM ( + SELECT + `t9`.`L_QUANTITY`, + `t9`.`L_EXTENDEDPRICE`, + `t12`.`bfuid_col_3560` + FROM ( + SELECT + `t2`.`L_PARTKEY`, + `t2`.`L_QUANTITY`, + `t2`.`L_EXTENDEDPRICE` + FROM ( + SELECT + `L_PARTKEY`, + `L_QUANTITY`, + `L_EXTENDEDPRICE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t9` + RIGHT OUTER JOIN ( + SELECT + `t10`.`bfuid_col_3560` + FROM ( + SELECT + `t3`.`P_PARTKEY` AS `bfuid_col_3560`, + ( + `t3`.`P_BRAND` = 'Brand#23' + ) AND ( + `t3`.`P_CONTAINER` = 'MED BOX' + ) AS `bfuid_col_3569` + FROM ( + SELECT + `P_PARTKEY`, + `P_BRAND`, + `P_CONTAINER` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t10` + WHERE + `t10`.`bfuid_col_3569` + ) AS `t12` + ON COALESCE(`t9`.`L_PARTKEY`, 0) = COALESCE(`t12`.`bfuid_col_3560`, 0) + AND COALESCE(`t9`.`L_PARTKEY`, 1) = COALESCE(`t12`.`bfuid_col_3560`, 1) + ) AS `t14` + ) AS `t17` + ON `t19`.`bfuid_col_3572` = `t17`.`bfuid_col_3560` + ) AS `t20` + WHERE + `t20`.`bfuid_col_3605` + ) AS `t21` + ) AS `t22` + ) AS `t24` + ) AS `t25` GROUP BY - `bfcol_8`, - `bfcol_9` -) -SELECT - ROUND(IEEE_DIVIDE(`bfcol_45`, 7.0), 2) AS `AVG_YEARLY` -FROM `bfcte_11` -ORDER BY - `bfcol_9` ASC NULLS LAST, - `bfcol_8` ASC NULLS LAST \ No newline at end of file + 1, + 2 +) AS `t26` +WHERE + ( + `t26`.`bfuid_col_3609` + ) IS NOT NULL + AND ( + `t26`.`bfuid_col_3610` + ) IS NOT NULL) AS `t` +ORDER BY `bfuid_col_3620` ASC NULLS LAST ,`bfuid_col_3621` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/18/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/18/out.sql index b5720bc932a..0be697dbe23 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/18/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/18/out.sql @@ -1,116 +1,152 @@ -WITH `bfcte_0` AS ( +SELECT `C_NAME`, `C_CUSTKEY`, `O_ORDERKEY`, `O_ORDERDAT`, `O_TOTALPRICE`, `COL6` FROM (WITH `t5` AS ( SELECT - `C_CUSTKEY` AS `bfcol_0`, - `C_NAME` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_2`, - `L_QUANTITY` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_4`, - `O_CUSTKEY` AS `bfcol_5`, - `O_TOTALPRICE` AS `bfcol_6`, - `O_ORDERDATE` AS `bfcol_7` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `bfcol_2`, - COALESCE(SUM(`bfcol_3`), 0) AS `bfcol_8` - FROM `bfcte_1` - WHERE - NOT `bfcol_2` IS NULL - GROUP BY - `bfcol_2` -), `bfcte_4` AS ( - SELECT - `bfcol_2`, - `bfcol_8`, - `bfcol_2` AS `bfcol_9`, - `bfcol_8` > 300 AS `bfcol_10` - FROM `bfcte_3` - WHERE - `bfcol_8` > 300 -), `bfcte_5` AS ( - SELECT - `bfcol_9` - FROM `bfcte_4` - GROUP BY - `bfcol_9` -), `bfcte_6` AS ( - SELECT - `bfcol_9` AS `bfcol_13` - FROM `bfcte_5` -), `bfcte_7` AS ( + `t2`.`L_ORDERKEY`, + `t2`.`L_QUANTITY` + FROM ( + SELECT + `L_ORDERKEY`, + `L_QUANTITY` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` +) +SELECT + `t20`.`C_NAME`, + `t20`.`C_CUSTKEY`, + `t20`.`O_ORDERKEY`, + `t20`.`O_ORDERDATE` AS `O_ORDERDAT`, + `t20`.`O_TOTALPRICE`, + `t20`.`bfuid_col_3639` AS `COL6` +FROM ( SELECT - *, - STRUCT(COALESCE(`bfcol_4`, 0) AS `bfpart1`, COALESCE(`bfcol_4`, 1) AS `bfpart2`) IN ( - ( + `t19`.`C_NAME`, + `t19`.`C_CUSTKEY`, + `t19`.`O_ORDERKEY`, + `t19`.`O_ORDERDATE`, + `t19`.`O_TOTALPRICE`, + COALESCE(SUM(`t19`.`L_QUANTITY`), 0) AS `bfuid_col_3639` + FROM ( + SELECT + `t18`.`O_ORDERKEY`, + `t18`.`O_TOTALPRICE`, + `t18`.`O_ORDERDATE`, + `t18`.`L_QUANTITY`, + `t6`.`C_CUSTKEY`, + `t6`.`C_NAME` + FROM ( + SELECT + * + FROM ( SELECT - STRUCT(COALESCE(`bfcol_13`, 0) AS `bfpart1`, COALESCE(`bfcol_13`, 1) AS `bfpart2`) - FROM `bfcte_6` - ) - ) AS `bfcol_14` - FROM `bfcte_2` -), `bfcte_8` AS ( - SELECT - `bfcol_4` AS `bfcol_20`, - `bfcol_5` AS `bfcol_21`, - `bfcol_6` AS `bfcol_22`, - `bfcol_7` AS `bfcol_23` - FROM `bfcte_7` - WHERE - `bfcol_14` -), `bfcte_9` AS ( - SELECT - `bfcol_20` AS `bfcol_24`, - `bfcol_21` AS `bfcol_25`, - `bfcol_22` AS `bfcol_26`, - `bfcol_23` AS `bfcol_27`, - `bfcol_3` AS `bfcol_28` - FROM `bfcte_8` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_20`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_20`, 1) = COALESCE(`bfcol_2`, 1) -), `bfcte_10` AS ( - SELECT - `bfcol_1`, - `bfcol_0`, - `bfcol_24`, - `bfcol_27`, - `bfcol_26`, - COALESCE(SUM(`bfcol_28`), 0) AS `bfcol_35` - FROM `bfcte_9` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_25`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_25`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - NOT `bfcol_1` IS NULL - AND NOT `bfcol_0` IS NULL - AND NOT `bfcol_24` IS NULL - AND NOT `bfcol_27` IS NULL - AND NOT `bfcol_26` IS NULL + `t15`.`O_ORDERKEY`, + `t15`.`O_CUSTKEY`, + `t15`.`O_TOTALPRICE`, + `t15`.`O_ORDERDATE`, + `t8`.`L_QUANTITY` + FROM ( + SELECT + `t13`.`O_ORDERKEY`, + `t13`.`O_CUSTKEY`, + `t13`.`O_TOTALPRICE`, + `t13`.`O_ORDERDATE` + FROM ( + SELECT + `t4`.`O_ORDERKEY`, + `t4`.`O_CUSTKEY`, + `t4`.`O_TOTALPRICE`, + `t4`.`O_ORDERDATE`, + EXISTS( + SELECT + 1 + FROM ( + SELECT + `t10`.`bfuid_col_3624` + FROM ( + SELECT + `t9`.`L_ORDERKEY` AS `bfuid_col_3624` + FROM ( + SELECT + `t7`.`L_ORDERKEY`, + COALESCE(SUM(`t7`.`L_QUANTITY`), 0) AS `bfuid_col_3622` + FROM `t5` AS `t7` + GROUP BY + 1 + ) AS `t9` + WHERE + ( + `t9`.`L_ORDERKEY` + ) IS NOT NULL AND `t9`.`bfuid_col_3622` > 300 + ) AS `t10` + GROUP BY + 1 + ) AS `t11` + WHERE + ( + COALESCE(`t4`.`O_ORDERKEY`, 0) = COALESCE(`t11`.`bfuid_col_3624`, 0) + ) + AND ( + COALESCE(`t4`.`O_ORDERKEY`, 1) = COALESCE(`t11`.`bfuid_col_3624`, 1) + ) + ) AS `bfuid_col_3627` + FROM ( + SELECT + `t1`.`O_ORDERKEY`, + `t1`.`O_CUSTKEY`, + `t1`.`O_TOTALPRICE`, + `t1`.`O_ORDERDATE` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY`, + `O_TOTALPRICE`, + `O_ORDERDATE` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t4` + ) AS `t13` + WHERE + `t13`.`bfuid_col_3627` + ) AS `t15` + INNER JOIN `t5` AS `t8` + ON COALESCE(`t15`.`O_ORDERKEY`, 0) = COALESCE(`t8`.`L_ORDERKEY`, 0) + AND COALESCE(`t15`.`O_ORDERKEY`, 1) = COALESCE(`t8`.`L_ORDERKEY`, 1) + ) AS `t16` + ) AS `t18` + INNER JOIN ( + SELECT + `t0`.`C_CUSTKEY`, + `t0`.`C_NAME` + FROM ( + SELECT + `C_CUSTKEY`, + `C_NAME` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t6` + ON COALESCE(`t18`.`O_CUSTKEY`, 0) = COALESCE(`t6`.`C_CUSTKEY`, 0) + AND COALESCE(`t18`.`O_CUSTKEY`, 1) = COALESCE(`t6`.`C_CUSTKEY`, 1) + ) AS `t19` GROUP BY - `bfcol_1`, - `bfcol_0`, - `bfcol_24`, - `bfcol_27`, - `bfcol_26` -) -SELECT - `bfcol_1` AS `C_NAME`, - `bfcol_0` AS `C_CUSTKEY`, - `bfcol_24` AS `O_ORDERKEY`, - `bfcol_27` AS `O_ORDERDAT`, - `bfcol_26` AS `O_TOTALPRICE`, - `bfcol_35` AS `COL6` -FROM `bfcte_10` -ORDER BY - `bfcol_26` DESC, - `bfcol_27` ASC NULLS LAST, - `bfcol_1` ASC NULLS LAST, - `bfcol_0` ASC NULLS LAST, - `bfcol_24` ASC NULLS LAST + 1, + 2, + 3, + 4, + 5 +) AS `t20` +WHERE + ( + `t20`.`C_NAME` + ) IS NOT NULL + AND ( + `t20`.`C_CUSTKEY` + ) IS NOT NULL + AND ( + `t20`.`O_ORDERKEY` + ) IS NOT NULL + AND ( + `t20`.`O_ORDERDATE` + ) IS NOT NULL + AND ( + `t20`.`O_TOTALPRICE` + ) IS NOT NULL) AS `t` +ORDER BY `O_TOTALPRICE` DESC NULLS LAST ,`O_ORDERDAT` ASC NULLS LAST ,`C_NAME` ASC NULLS LAST ,`C_CUSTKEY` ASC NULLS LAST ,`O_ORDERKEY` ASC NULLS LAST LIMIT 100 \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/19/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/19/out.sql index 9672739d645..a3c21f3124b 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/19/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/19/out.sql @@ -1,227 +1,163 @@ -WITH `bfcte_0` AS ( +SELECT + CASE + WHEN `t6`.`col_1` = 0 + THEN `t13`.`bfuid_col_3750-sum` + ELSE CAST(NULL AS FLOAT64) + END AS `REVENUE` +FROM ( SELECT * - FROM UNNEST(ARRAY>[STRUCT(0)]) -), `bfcte_1` AS ( - SELECT - `L_PARTKEY` AS `bfcol_1`, - `L_QUANTITY` AS `bfcol_2`, - `L_EXTENDEDPRICE` AS `bfcol_3`, - `L_DISCOUNT` AS `bfcol_4`, - `L_SHIPINSTRUCT` AS `bfcol_5`, - `L_SHIPMODE` AS `bfcol_6` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `P_PARTKEY` AS `bfcol_7`, - `P_BRAND` AS `bfcol_8`, - `P_SIZE` AS `bfcol_9`, - `P_CONTAINER` AS `bfcol_10` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `bfcol_7`, - `bfcol_8`, - `bfcol_9`, - `bfcol_10`, - `bfcol_1`, - `bfcol_2`, - `bfcol_3`, - `bfcol_4`, - `bfcol_5`, - `bfcol_6`, - `bfcol_3` AS `bfcol_19`, - `bfcol_4` AS `bfcol_20`, - ( - COALESCE(COALESCE(`bfcol_6` IN ('AIR', 'AIR REG'), FALSE), FALSE) - AND ( - `bfcol_5` = 'DELIVER IN PERSON' - ) - ) - AND ( - ( - ( + FROM ( + SELECT + COALESCE(SUM(`t10`.`bfuid_col_3750`), 0) AS `bfuid_col_3750-sum` + FROM ( + SELECT + `t9`.`bfuid_col_3735` * ( + 1 - `t9`.`bfuid_col_3736` + ) AS `bfuid_col_3750` + FROM ( + SELECT + `t8`.`L_EXTENDEDPRICE` AS `bfuid_col_3735`, + `t8`.`L_DISCOUNT` AS `bfuid_col_3736`, ( - ( - ( - `bfcol_8` = 'Brand#12' - ) - AND COALESCE(COALESCE(`bfcol_10` IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG'), FALSE), FALSE) - ) + COALESCE(COALESCE(`t8`.`L_SHIPMODE` IN ('AIR', 'AIR REG'), FALSE), FALSE) AND ( - ( - `bfcol_2` >= 1 - ) AND ( - `bfcol_2` <= 11 - ) + `t8`.`L_SHIPINSTRUCT` = 'DELIVER IN PERSON' ) ) AND ( - ( - `bfcol_9` >= 1 - ) AND ( - `bfcol_9` <= 5 - ) - ) - ) - OR ( - ( - ( - ( - `bfcol_8` = 'Brand#23' - ) - AND COALESCE( - COALESCE(`bfcol_10` IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK'), FALSE), - FALSE - ) - ) - AND ( - ( - `bfcol_2` >= 10 - ) AND ( - `bfcol_2` <= 20 - ) - ) - ) - AND ( - ( - `bfcol_9` >= 1 - ) AND ( - `bfcol_9` <= 10 - ) - ) - ) - ) - OR ( - ( - ( - ( - `bfcol_8` = 'Brand#34' - ) - AND COALESCE(COALESCE(`bfcol_10` IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG'), FALSE), FALSE) - ) - AND ( - ( - `bfcol_2` >= 20 - ) AND ( - `bfcol_2` <= 30 - ) - ) - ) - AND ( - ( - `bfcol_9` >= 1 - ) AND ( - `bfcol_9` <= 15 - ) - ) - ) - ) AS `bfcol_21`, - `bfcol_3` AS `bfcol_27`, - 1 - `bfcol_4` AS `bfcol_28`, - `bfcol_3` * ( - 1 - `bfcol_4` - ) AS `bfcol_31` - FROM `bfcte_2` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_7`, 0) = COALESCE(`bfcol_1`, 0) - AND COALESCE(`bfcol_7`, 1) = COALESCE(`bfcol_1`, 1) - WHERE - ( - COALESCE(COALESCE(`bfcol_6` IN ('AIR', 'AIR REG'), FALSE), FALSE) - AND ( - `bfcol_5` = 'DELIVER IN PERSON' - ) - ) - AND ( - ( - ( - ( ( ( - `bfcol_8` = 'Brand#12' + ( + ( + ( + `t7`.`P_BRAND` = 'Brand#12' + ) + AND COALESCE( + COALESCE(`t7`.`P_CONTAINER` IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG'), FALSE), + FALSE + ) + ) + AND ( + ( + `t8`.`L_QUANTITY` >= 1 + ) AND ( + `t8`.`L_QUANTITY` <= 11 + ) + ) + ) + AND ( + ( + `t7`.`P_SIZE` >= 1 + ) AND ( + `t7`.`P_SIZE` <= 5 + ) + ) ) - AND COALESCE(COALESCE(`bfcol_10` IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG'), FALSE), FALSE) - ) - AND ( - ( - `bfcol_2` >= 1 - ) AND ( - `bfcol_2` <= 11 + OR ( + ( + ( + ( + `t7`.`P_BRAND` = 'Brand#23' + ) + AND COALESCE( + COALESCE(`t7`.`P_CONTAINER` IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK'), FALSE), + FALSE + ) + ) + AND ( + ( + `t8`.`L_QUANTITY` >= 10 + ) AND ( + `t8`.`L_QUANTITY` <= 20 + ) + ) + ) + AND ( + ( + `t7`.`P_SIZE` >= 1 + ) AND ( + `t7`.`P_SIZE` <= 10 + ) + ) ) ) - ) - AND ( - ( - `bfcol_9` >= 1 - ) AND ( - `bfcol_9` <= 5 - ) - ) - ) - OR ( - ( - ( + OR ( ( - `bfcol_8` = 'Brand#23' + ( + ( + `t7`.`P_BRAND` = 'Brand#34' + ) + AND COALESCE( + COALESCE(`t7`.`P_CONTAINER` IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG'), FALSE), + FALSE + ) + ) + AND ( + ( + `t8`.`L_QUANTITY` >= 20 + ) AND ( + `t8`.`L_QUANTITY` <= 30 + ) + ) ) - AND COALESCE( - COALESCE(`bfcol_10` IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK'), FALSE), - FALSE - ) - ) - AND ( - ( - `bfcol_2` >= 10 - ) AND ( - `bfcol_2` <= 20 + AND ( + ( + `t7`.`P_SIZE` >= 1 + ) AND ( + `t7`.`P_SIZE` <= 15 + ) ) ) - ) - AND ( - ( - `bfcol_9` >= 1 - ) AND ( - `bfcol_9` <= 10 - ) - ) - ) - ) - OR ( - ( - ( - ( - `bfcol_8` = 'Brand#34' - ) - AND COALESCE(COALESCE(`bfcol_10` IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG'), FALSE), FALSE) - ) - AND ( - ( - `bfcol_2` >= 20 - ) AND ( - `bfcol_2` <= 30 - ) - ) - ) - AND ( - ( - `bfcol_9` >= 1 - ) AND ( - `bfcol_9` <= 15 - ) - ) - ) - ) -), `bfcte_4` AS ( - SELECT - COALESCE(SUM(`bfcol_31`), 0) AS `bfcol_33` - FROM `bfcte_3` -), `bfcte_5` AS ( + ) AS `bfuid_col_3746` + FROM ( + SELECT + `t1`.`P_PARTKEY`, + `t1`.`P_BRAND`, + `t1`.`P_SIZE`, + `t1`.`P_CONTAINER` + FROM ( + SELECT + `P_PARTKEY`, + `P_BRAND`, + `P_SIZE`, + `P_CONTAINER` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t7` + INNER JOIN ( + SELECT + `t2`.`L_PARTKEY`, + `t2`.`L_QUANTITY`, + `t2`.`L_EXTENDEDPRICE`, + `t2`.`L_DISCOUNT`, + `t2`.`L_SHIPINSTRUCT`, + `t2`.`L_SHIPMODE` + FROM ( + SELECT + `L_PARTKEY`, + `L_QUANTITY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPINSTRUCT`, + `L_SHIPMODE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t8` + ON COALESCE(`t7`.`P_PARTKEY`, 0) = COALESCE(`t8`.`L_PARTKEY`, 0) + AND COALESCE(`t7`.`P_PARTKEY`, 1) = COALESCE(`t8`.`L_PARTKEY`, 1) + ) AS `t9` + WHERE + `t9`.`bfuid_col_3746` + ) AS `t10` + ) AS `t11` +) AS `t13` +CROSS JOIN ( SELECT * - FROM `bfcte_4` -) -SELECT - CASE WHEN `bfcol_0` = 0 THEN `bfcol_33` END AS `REVENUE` -FROM `bfcte_5` -CROSS JOIN `bfcte_0` \ No newline at end of file + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(0)]) AS `col_1` + ) AS `t0` +) AS `t6` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/2/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/2/out.sql index 9130dc95fce..72cb6e80941 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/2/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/2/out.sql @@ -1,210 +1,306 @@ -WITH `bfcte_0` AS ( +SELECT `S_ACCTBAL`, `S_NAME`, `N_NAME`, `P_PARTKEY`, `P_MFGR`, `S_ADDRESS`, `S_PHONE`, `S_COMMENT` FROM (SELECT + `t46`.`bfuid_col_1989` AS `S_ACCTBAL`, + `t46`.`bfuid_col_1985` AS `S_NAME`, + `t46`.`bfuid_col_1992` AS `N_NAME`, + `t49`.`bfuid_col_1970` AS `P_PARTKEY`, + `t46`.`bfuid_col_1972` AS `P_MFGR`, + `t46`.`bfuid_col_1986` AS `S_ADDRESS`, + `t46`.`bfuid_col_1988` AS `S_PHONE`, + `t46`.`bfuid_col_1990` AS `S_COMMENT` +FROM ( SELECT - `R_REGIONKEY` AS `bfcol_0`, - `R_NAME` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`REGION` AS `bft_4` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_2`, - `N_NAME` AS `bfcol_3`, - `N_REGIONKEY` AS `bfcol_4` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_19`, - `N_REGIONKEY` AS `bfcol_20` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_5`, - `S_NAME` AS `bfcol_6`, - `S_ADDRESS` AS `bfcol_7`, - `S_NATIONKEY` AS `bfcol_8`, - `S_PHONE` AS `bfcol_9`, - `S_ACCTBAL` AS `bfcol_10`, - `S_COMMENT` AS `bfcol_11` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_21`, - `S_NATIONKEY` AS `bfcol_22` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `PS_PARTKEY` AS `bfcol_12`, - `PS_SUPPKEY` AS `bfcol_13`, - `PS_SUPPLYCOST` AS `bfcol_14` - FROM `bigframes-dev`.`tpch`.`PARTSUPP` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_6` AS ( - SELECT - `P_PARTKEY` AS `bfcol_15`, - `P_MFGR` AS `bfcol_16`, - `P_TYPE` AS `bfcol_17`, - `P_SIZE` AS `bfcol_18` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_7` AS ( - SELECT - `P_PARTKEY` AS `bfcol_23`, - `P_TYPE` AS `bfcol_24`, - `P_SIZE` AS `bfcol_25` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_8` AS ( - SELECT - `bfcol_15` AS `bfcol_26`, - `bfcol_16` AS `bfcol_27`, - `bfcol_17` AS `bfcol_28`, - `bfcol_18` AS `bfcol_29`, - `bfcol_13` AS `bfcol_30`, - `bfcol_14` AS `bfcol_31` - FROM `bfcte_6` - INNER JOIN `bfcte_5` - ON COALESCE(`bfcol_15`, 0) = COALESCE(`bfcol_12`, 0) - AND COALESCE(`bfcol_15`, 1) = COALESCE(`bfcol_12`, 1) -), `bfcte_9` AS ( - SELECT - `bfcol_23` AS `bfcol_32`, - `bfcol_24` AS `bfcol_33`, - `bfcol_25` AS `bfcol_34`, - `bfcol_13` AS `bfcol_35`, - `bfcol_14` AS `bfcol_36` - FROM `bfcte_7` - INNER JOIN `bfcte_5` - ON COALESCE(`bfcol_23`, 0) = COALESCE(`bfcol_12`, 0) - AND COALESCE(`bfcol_23`, 1) = COALESCE(`bfcol_12`, 1) -), `bfcte_10` AS ( - SELECT - `bfcol_26` AS `bfcol_37`, - `bfcol_27` AS `bfcol_38`, - `bfcol_28` AS `bfcol_39`, - `bfcol_29` AS `bfcol_40`, - `bfcol_31` AS `bfcol_41`, - `bfcol_6` AS `bfcol_42`, - `bfcol_7` AS `bfcol_43`, - `bfcol_8` AS `bfcol_44`, - `bfcol_9` AS `bfcol_45`, - `bfcol_10` AS `bfcol_46`, - `bfcol_11` AS `bfcol_47` - FROM `bfcte_8` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_30`, 0) = COALESCE(`bfcol_5`, 0) - AND COALESCE(`bfcol_30`, 1) = COALESCE(`bfcol_5`, 1) -), `bfcte_11` AS ( - SELECT - `bfcol_32` AS `bfcol_48`, - `bfcol_33` AS `bfcol_49`, - `bfcol_34` AS `bfcol_50`, - `bfcol_36` AS `bfcol_51`, - `bfcol_22` AS `bfcol_52` - FROM `bfcte_9` - INNER JOIN `bfcte_4` - ON COALESCE(`bfcol_35`, 0) = COALESCE(`bfcol_21`, 0) - AND COALESCE(`bfcol_35`, 1) = COALESCE(`bfcol_21`, 1) -), `bfcte_12` AS ( - SELECT - `bfcol_37` AS `bfcol_53`, - `bfcol_38` AS `bfcol_54`, - `bfcol_39` AS `bfcol_55`, - `bfcol_40` AS `bfcol_56`, - `bfcol_41` AS `bfcol_57`, - `bfcol_42` AS `bfcol_58`, - `bfcol_43` AS `bfcol_59`, - `bfcol_45` AS `bfcol_60`, - `bfcol_46` AS `bfcol_61`, - `bfcol_47` AS `bfcol_62`, - `bfcol_3` AS `bfcol_63`, - `bfcol_4` AS `bfcol_64` - FROM `bfcte_10` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_44`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_44`, 1) = COALESCE(`bfcol_2`, 1) -), `bfcte_13` AS ( - SELECT - `bfcol_48` AS `bfcol_65`, - `bfcol_49` AS `bfcol_66`, - `bfcol_50` AS `bfcol_67`, - `bfcol_51` AS `bfcol_68`, - `bfcol_20` AS `bfcol_69` - FROM `bfcte_11` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_52`, 0) = COALESCE(`bfcol_19`, 0) - AND COALESCE(`bfcol_52`, 1) = COALESCE(`bfcol_19`, 1) -), `bfcte_14` AS ( - SELECT - `bfcol_53` AS `bfcol_205`, - `bfcol_54` AS `bfcol_206`, - `bfcol_57` AS `bfcol_207`, - `bfcol_58` AS `bfcol_208`, - `bfcol_59` AS `bfcol_209`, - `bfcol_60` AS `bfcol_210`, - `bfcol_61` AS `bfcol_211`, - `bfcol_62` AS `bfcol_212`, - `bfcol_63` AS `bfcol_213` - FROM `bfcte_12` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_64`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_64`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - `bfcol_56` = 15 AND ENDS_WITH(`bfcol_55`, 'BRASS') AND `bfcol_1` = 'EUROPE' -), `bfcte_15` AS ( - SELECT - `bfcol_65`, - `bfcol_66`, - `bfcol_67`, - `bfcol_68`, - `bfcol_69`, - `bfcol_0`, - `bfcol_1`, - `bfcol_65` AS `bfcol_99`, - `bfcol_66` AS `bfcol_100`, - `bfcol_68` AS `bfcol_101`, - `bfcol_1` AS `bfcol_102`, - `bfcol_67` = 15 AS `bfcol_103`, - `bfcol_65` AS `bfcol_147`, - `bfcol_68` AS `bfcol_148`, - `bfcol_1` AS `bfcol_149`, - ENDS_WITH(`bfcol_66`, 'BRASS') AS `bfcol_150`, - `bfcol_65` AS `bfcol_189`, - `bfcol_68` AS `bfcol_190`, - `bfcol_1` = 'EUROPE' AS `bfcol_191` - FROM `bfcte_13` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_69`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_69`, 1) = COALESCE(`bfcol_0`, 1) + * + FROM ( + SELECT + `t45`.`bfuid_col_1970`, + MIN(`t45`.`bfuid_col_1982`) AS `bfuid_col_1999` + FROM ( + SELECT + `t43`.`bfuid_col_1910` AS `bfuid_col_1970`, + `t43`.`bfuid_col_1922` AS `bfuid_col_1982` + FROM ( + SELECT + `t41`.`P_PARTKEY` AS `bfuid_col_1910`, + `t41`.`P_TYPE` AS `bfuid_col_1914`, + `t41`.`PS_SUPPLYCOST` AS `bfuid_col_1922`, + `t16`.`R_NAME` AS `bfuid_col_1936`, + `t41`.`P_SIZE` = 15 AS `bfuid_col_1938` + FROM ( + SELECT + * + FROM ( + SELECT + `t35`.`P_PARTKEY`, + `t35`.`P_TYPE`, + `t35`.`P_SIZE`, + `t35`.`PS_SUPPLYCOST`, + `t18`.`N_REGIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t29`.`P_PARTKEY`, + `t29`.`P_TYPE`, + `t29`.`P_SIZE`, + `t29`.`PS_SUPPLYCOST`, + `t20`.`S_NATIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t22`.`P_PARTKEY`, + `t22`.`P_TYPE`, + `t22`.`P_SIZE`, + `t23`.`PS_SUPPKEY`, + `t23`.`PS_SUPPLYCOST` + FROM ( + SELECT + `t6`.`P_PARTKEY`, + `t6`.`P_TYPE`, + `t6`.`P_SIZE` + FROM ( + SELECT + `P_PARTKEY`, + `P_TYPE`, + `P_SIZE` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t6` + ) AS `t22` + INNER JOIN ( + SELECT + `t7`.`PS_PARTKEY`, + `t7`.`PS_SUPPKEY`, + `t7`.`PS_SUPPLYCOST` + FROM ( + SELECT + `PS_PARTKEY`, + `PS_SUPPKEY`, + `PS_SUPPLYCOST` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t7` + ) AS `t23` + ON COALESCE(`t22`.`P_PARTKEY`, 0) = COALESCE(`t23`.`PS_PARTKEY`, 0) + AND COALESCE(`t22`.`P_PARTKEY`, 1) = COALESCE(`t23`.`PS_PARTKEY`, 1) + ) AS `t25` + ) AS `t29` + INNER JOIN ( + SELECT + `t4`.`S_SUPPKEY`, + `t4`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + ) AS `t20` + ON COALESCE(`t29`.`PS_SUPPKEY`, 0) = COALESCE(`t20`.`S_SUPPKEY`, 0) + AND COALESCE(`t29`.`PS_SUPPKEY`, 1) = COALESCE(`t20`.`S_SUPPKEY`, 1) + ) AS `t31` + ) AS `t35` + INNER JOIN ( + SELECT + `t2`.`N_NATIONKEY`, + `t2`.`N_REGIONKEY` + FROM ( + SELECT + `N_NATIONKEY`, + `N_REGIONKEY` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t18` + ON COALESCE(`t35`.`S_NATIONKEY`, 0) = COALESCE(`t18`.`N_NATIONKEY`, 0) + AND COALESCE(`t35`.`S_NATIONKEY`, 1) = COALESCE(`t18`.`N_NATIONKEY`, 1) + ) AS `t37` + ) AS `t41` + INNER JOIN ( + SELECT + `t0`.`R_REGIONKEY`, + `t0`.`R_NAME` + FROM ( + SELECT + `R_REGIONKEY`, + `R_NAME` + FROM `bigframes-dev.tpch.REGION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t16` + ON COALESCE(`t41`.`N_REGIONKEY`, 0) = COALESCE(`t16`.`R_REGIONKEY`, 0) + AND COALESCE(`t41`.`N_REGIONKEY`, 1) = COALESCE(`t16`.`R_REGIONKEY`, 1) + ) AS `t43` + WHERE + `t43`.`bfuid_col_1938` + AND ENDS_WITH(`t43`.`bfuid_col_1914`, 'BRASS') + AND `t43`.`bfuid_col_1936` = 'EUROPE' + ) AS `t45` + GROUP BY + 1 + ) AS `t47` WHERE - `bfcol_67` = 15 AND ENDS_WITH(`bfcol_66`, 'BRASS') AND `bfcol_1` = 'EUROPE' -), `bfcte_16` AS ( + ( + `t47`.`bfuid_col_1970` + ) IS NOT NULL +) AS `t49` +INNER JOIN ( SELECT - `bfcol_189`, - MIN(`bfcol_190`) AS `bfcol_216` - FROM `bfcte_15` + `t42`.`bfuid_col_1910` AS `bfuid_col_2000`, + `t42`.`bfuid_col_1912` AS `bfuid_col_1972`, + `t42`.`bfuid_col_1922` AS `bfuid_col_1982`, + `t42`.`bfuid_col_1925` AS `bfuid_col_1985`, + `t42`.`bfuid_col_1926` AS `bfuid_col_1986`, + `t42`.`bfuid_col_1928` AS `bfuid_col_1988`, + `t42`.`bfuid_col_1929` AS `bfuid_col_1989`, + `t42`.`bfuid_col_1930` AS `bfuid_col_1990`, + `t42`.`bfuid_col_1932` AS `bfuid_col_1992` + FROM ( + SELECT + `t40`.`P_PARTKEY` AS `bfuid_col_1910`, + `t40`.`P_MFGR` AS `bfuid_col_1912`, + `t40`.`P_TYPE` AS `bfuid_col_1914`, + `t40`.`PS_SUPPLYCOST` AS `bfuid_col_1922`, + `t40`.`S_NAME` AS `bfuid_col_1925`, + `t40`.`S_ADDRESS` AS `bfuid_col_1926`, + `t40`.`S_PHONE` AS `bfuid_col_1928`, + `t40`.`S_ACCTBAL` AS `bfuid_col_1929`, + `t40`.`S_COMMENT` AS `bfuid_col_1930`, + `t40`.`N_NAME` AS `bfuid_col_1932`, + `t16`.`R_NAME` AS `bfuid_col_1936`, + `t40`.`P_SIZE` = 15 AS `bfuid_col_1938` + FROM ( + SELECT + * + FROM ( + SELECT + `t34`.`P_PARTKEY`, + `t34`.`P_MFGR`, + `t34`.`P_TYPE`, + `t34`.`P_SIZE`, + `t34`.`PS_SUPPLYCOST`, + `t34`.`S_NAME`, + `t34`.`S_ADDRESS`, + `t34`.`S_PHONE`, + `t34`.`S_ACCTBAL`, + `t34`.`S_COMMENT`, + `t17`.`N_NAME`, + `t17`.`N_REGIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t28`.`P_PARTKEY`, + `t28`.`P_MFGR`, + `t28`.`P_TYPE`, + `t28`.`P_SIZE`, + `t28`.`PS_SUPPLYCOST`, + `t19`.`S_NAME`, + `t19`.`S_ADDRESS`, + `t19`.`S_NATIONKEY`, + `t19`.`S_PHONE`, + `t19`.`S_ACCTBAL`, + `t19`.`S_COMMENT` + FROM ( + SELECT + * + FROM ( + SELECT + `t21`.`P_PARTKEY`, + `t21`.`P_MFGR`, + `t21`.`P_TYPE`, + `t21`.`P_SIZE`, + `t23`.`PS_SUPPKEY`, + `t23`.`PS_SUPPLYCOST` + FROM ( + SELECT + `t5`.`P_PARTKEY`, + `t5`.`P_MFGR`, + `t5`.`P_TYPE`, + `t5`.`P_SIZE` + FROM ( + SELECT + `P_PARTKEY`, + `P_MFGR`, + `P_TYPE`, + `P_SIZE` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t5` + ) AS `t21` + INNER JOIN ( + SELECT + `t7`.`PS_PARTKEY`, + `t7`.`PS_SUPPKEY`, + `t7`.`PS_SUPPLYCOST` + FROM ( + SELECT + `PS_PARTKEY`, + `PS_SUPPKEY`, + `PS_SUPPLYCOST` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t7` + ) AS `t23` + ON COALESCE(`t21`.`P_PARTKEY`, 0) = COALESCE(`t23`.`PS_PARTKEY`, 0) + AND COALESCE(`t21`.`P_PARTKEY`, 1) = COALESCE(`t23`.`PS_PARTKEY`, 1) + ) AS `t24` + ) AS `t28` + INNER JOIN ( + SELECT + * + FROM ( + SELECT + `S_SUPPKEY`, + `S_NAME`, + `S_ADDRESS`, + `S_NATIONKEY`, + `S_PHONE`, + `S_ACCTBAL`, + `S_COMMENT` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t19` + ON COALESCE(`t28`.`PS_SUPPKEY`, 0) = COALESCE(`t19`.`S_SUPPKEY`, 0) + AND COALESCE(`t28`.`PS_SUPPKEY`, 1) = COALESCE(`t19`.`S_SUPPKEY`, 1) + ) AS `t30` + ) AS `t34` + INNER JOIN ( + SELECT + `t1`.`N_NATIONKEY`, + `t1`.`N_NAME`, + `t1`.`N_REGIONKEY` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME`, + `N_REGIONKEY` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t17` + ON COALESCE(`t34`.`S_NATIONKEY`, 0) = COALESCE(`t17`.`N_NATIONKEY`, 0) + AND COALESCE(`t34`.`S_NATIONKEY`, 1) = COALESCE(`t17`.`N_NATIONKEY`, 1) + ) AS `t36` + ) AS `t40` + INNER JOIN ( + SELECT + `t0`.`R_REGIONKEY`, + `t0`.`R_NAME` + FROM ( + SELECT + `R_REGIONKEY`, + `R_NAME` + FROM `bigframes-dev.tpch.REGION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t16` + ON COALESCE(`t40`.`N_REGIONKEY`, 0) = COALESCE(`t16`.`R_REGIONKEY`, 0) + AND COALESCE(`t40`.`N_REGIONKEY`, 1) = COALESCE(`t16`.`R_REGIONKEY`, 1) + ) AS `t42` WHERE - NOT `bfcol_189` IS NULL - GROUP BY - `bfcol_189` -), `bfcte_17` AS ( - SELECT - `bfcol_189` AS `bfcol_214`, - `bfcol_216` - FROM `bfcte_16` -) -SELECT - `bfcol_211` AS `S_ACCTBAL`, - `bfcol_208` AS `S_NAME`, - `bfcol_213` AS `N_NAME`, - `bfcol_214` AS `P_PARTKEY`, - `bfcol_206` AS `P_MFGR`, - `bfcol_209` AS `S_ADDRESS`, - `bfcol_210` AS `S_PHONE`, - `bfcol_212` AS `S_COMMENT` -FROM `bfcte_17` -INNER JOIN `bfcte_14` - ON COALESCE(`bfcol_214`, 0) = COALESCE(`bfcol_205`, 0) - AND COALESCE(`bfcol_214`, 1) = COALESCE(`bfcol_205`, 1) - AND IF(IS_NAN(`bfcol_216`), 2.0, COALESCE(`bfcol_216`, 0.0)) = IF(IS_NAN(`bfcol_207`), 2.0, COALESCE(`bfcol_207`, 0.0)) - AND IF(IS_NAN(`bfcol_216`), 3, COALESCE(`bfcol_216`, 1.0)) = IF(IS_NAN(`bfcol_207`), 3, COALESCE(`bfcol_207`, 1.0)) -ORDER BY - `bfcol_211` DESC, - `bfcol_213` ASC NULLS LAST, - `bfcol_208` ASC NULLS LAST, - `bfcol_214` ASC NULLS LAST + `t42`.`bfuid_col_1938` + AND ENDS_WITH(`t42`.`bfuid_col_1914`, 'BRASS') + AND `t42`.`bfuid_col_1936` = 'EUROPE' +) AS `t46` + ON COALESCE(`t49`.`bfuid_col_1970`, 0) = COALESCE(`t46`.`bfuid_col_2000`, 0) + AND COALESCE(`t49`.`bfuid_col_1970`, 1) = COALESCE(`t46`.`bfuid_col_2000`, 1) + AND IF(IS_NAN(`t49`.`bfuid_col_1999`), 2, COALESCE(`t49`.`bfuid_col_1999`, 0)) = IF(IS_NAN(`t46`.`bfuid_col_1982`), 2, COALESCE(`t46`.`bfuid_col_1982`, 0)) + AND IF(IS_NAN(`t49`.`bfuid_col_1999`), 3, COALESCE(`t49`.`bfuid_col_1999`, 1)) = IF(IS_NAN(`t46`.`bfuid_col_1982`), 3, COALESCE(`t46`.`bfuid_col_1982`, 1))) AS `t` +ORDER BY `S_ACCTBAL` DESC NULLS LAST ,`N_NAME` ASC NULLS LAST ,`S_NAME` ASC NULLS LAST ,`P_PARTKEY` ASC NULLS LAST LIMIT 100 \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/20/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/20/out.sql index 8c9cd9bb763..65c69b8dfd2 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/20/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/20/out.sql @@ -1,151 +1,182 @@ -WITH `bfcte_0` AS ( - SELECT - `P_PARTKEY`, - `P_NAME`, - `P_PARTKEY` AS `bfcol_15`, - STARTS_WITH(`P_NAME`, 'forest') AS `bfcol_16` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_4` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - STARTS_WITH(`P_NAME`, 'forest') -), `bfcte_1` AS ( - SELECT - `PS_PARTKEY` AS `bfcol_2`, - `PS_SUPPKEY` AS `bfcol_3`, - `PS_AVAILQTY` AS `bfcol_4` - FROM `bigframes-dev`.`tpch`.`PARTSUPP` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `L_PARTKEY`, - `L_SUPPKEY`, - `L_QUANTITY`, - `L_SHIPDATE`, - `L_PARTKEY` AS `bfcol_17`, - `L_SUPPKEY` AS `bfcol_18`, - `L_QUANTITY` AS `bfcol_19`, - ( - `L_SHIPDATE` >= CAST('1994-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` < CAST('1995-01-01' AS DATE) - ) AS `bfcol_20` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - ( - `L_SHIPDATE` >= CAST('1994-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` < CAST('1995-01-01' AS DATE) - ) -), `bfcte_3` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_35` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `N_NAME` = 'CANADA' -), `bfcte_4` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_11`, - `S_NAME` AS `bfcol_12`, - `S_ADDRESS` AS `bfcol_13`, - `S_NATIONKEY` AS `bfcol_14` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `bfcol_15` - FROM `bfcte_0` - GROUP BY - `bfcol_15` -), `bfcte_6` AS ( - SELECT - `bfcol_17`, - `bfcol_18`, - COALESCE(SUM(`bfcol_19`), 0) AS `bfcol_36` - FROM `bfcte_2` - WHERE - NOT `bfcol_17` IS NULL AND NOT `bfcol_18` IS NULL - GROUP BY - `bfcol_17`, - `bfcol_18` -), `bfcte_7` AS ( - SELECT - `bfcol_11` AS `bfcol_41`, - `bfcol_12` AS `bfcol_42`, - `bfcol_13` AS `bfcol_43` - FROM `bfcte_4` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_14`, 0) = COALESCE(`bfcol_35`, 0) - AND COALESCE(`bfcol_14`, 1) = COALESCE(`bfcol_35`, 1) -), `bfcte_8` AS ( - SELECT - `bfcol_15` AS `bfcol_31` - FROM `bfcte_5` -), `bfcte_9` AS ( - SELECT - `bfcol_17` AS `bfcol_48`, - `bfcol_18` AS `bfcol_49`, - `bfcol_36` * 0.5 AS `bfcol_50` - FROM `bfcte_6` -), `bfcte_10` AS ( - SELECT - *, - STRUCT(COALESCE(`bfcol_2`, 0) AS `bfpart1`, COALESCE(`bfcol_2`, 1) AS `bfpart2`) IN ( - ( +SELECT `S_NAME`, `S_ADDRESS` FROM (SELECT + `t26`.`S_NAME`, + `t26`.`S_ADDRESS` +FROM ( + SELECT + `t14`.`S_NAME`, + `t14`.`S_ADDRESS`, + EXISTS( + SELECT + 1 + FROM ( SELECT - STRUCT(COALESCE(`bfcol_31`, 0) AS `bfpart1`, COALESCE(`bfcol_31`, 1) AS `bfpart2`) - FROM `bfcte_8` - ) - ) AS `bfcol_37` - FROM `bfcte_1` -), `bfcte_11` AS ( - SELECT - `bfcol_2` AS `bfcol_51`, - `bfcol_3` AS `bfcol_52`, - `bfcol_4` AS `bfcol_53` - FROM `bfcte_10` - WHERE - `bfcol_37` -), `bfcte_12` AS ( - SELECT - `bfcol_48`, - `bfcol_49`, - `bfcol_50`, - `bfcol_51`, - `bfcol_52`, - `bfcol_53`, - `bfcol_52` AS `bfcol_57`, - `bfcol_53` > `bfcol_50` AS `bfcol_58` - FROM `bfcte_9` - INNER JOIN `bfcte_11` - ON `bfcol_49` = `bfcol_52` AND `bfcol_48` = `bfcol_51` - WHERE - `bfcol_53` > `bfcol_50` -), `bfcte_13` AS ( - SELECT - `bfcol_57` - FROM `bfcte_12` - GROUP BY - `bfcol_57` -), `bfcte_14` AS ( - SELECT - `bfcol_57` AS `bfcol_61` - FROM `bfcte_13` -), `bfcte_15` AS ( - SELECT - *, - STRUCT(COALESCE(`bfcol_41`, 0) AS `bfpart1`, COALESCE(`bfcol_41`, 1) AS `bfpart2`) IN ( - ( + `t23`.`bfuid_col_3812` + FROM ( + SELECT + `t22`.`bfuid_col_3812` + FROM ( + SELECT + `t21`.`PS_SUPPKEY` AS `bfuid_col_3812`, + `t21`.`PS_AVAILQTY` > `t19`.`bfuid_col_3778` AS `bfuid_col_3816` + FROM ( + SELECT + `t15`.`bfuid_col_3758` AS `bfuid_col_3776`, + `t15`.`bfuid_col_3759` AS `bfuid_col_3777`, + `t15`.`bfuid_col_3774` * 0.5 AS `bfuid_col_3778` + FROM ( + SELECT + `t13`.`bfuid_col_3758`, + `t13`.`bfuid_col_3759`, + COALESCE(SUM(`t13`.`bfuid_col_3761`), 0) AS `bfuid_col_3774` + FROM ( + SELECT + `t11`.`bfuid_col_3758`, + `t11`.`bfuid_col_3759`, + `t11`.`bfuid_col_3761` + FROM ( + SELECT + `t2`.`L_PARTKEY` AS `bfuid_col_3758`, + `t2`.`L_SUPPKEY` AS `bfuid_col_3759`, + `t2`.`L_QUANTITY` AS `bfuid_col_3761`, + ( + `t2`.`L_SHIPDATE` >= DATE(1994, 1, 1) + ) + AND ( + `t2`.`L_SHIPDATE` < DATE(1995, 1, 1) + ) AS `bfuid_col_3773` + FROM ( + SELECT + `L_PARTKEY`, + `L_SUPPKEY`, + `L_QUANTITY`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t11` + WHERE + `t11`.`bfuid_col_3773` + ) AS `t13` + GROUP BY + 1, + 2 + ) AS `t15` + WHERE + ( + `t15`.`bfuid_col_3758` + ) IS NOT NULL + AND ( + `t15`.`bfuid_col_3759` + ) IS NOT NULL + ) AS `t19` + INNER JOIN ( + SELECT + `t17`.`PS_PARTKEY`, + `t17`.`PS_SUPPKEY`, + `t17`.`PS_AVAILQTY` + FROM ( + SELECT + `t6`.`PS_PARTKEY`, + `t6`.`PS_SUPPKEY`, + `t6`.`PS_AVAILQTY`, + EXISTS( + SELECT + 1 + FROM ( + SELECT + `t9`.`bfuid_col_3787` + FROM ( + SELECT + `t4`.`P_PARTKEY` AS `bfuid_col_3787` + FROM ( + SELECT + `P_PARTKEY`, + `P_NAME` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + WHERE + STARTS_WITH(`t4`.`P_NAME`, 'forest') + ) AS `t9` + GROUP BY + 1 + ) AS `t12` + WHERE + ( + COALESCE(`t6`.`PS_PARTKEY`, 0) = COALESCE(`t12`.`bfuid_col_3787`, 0) + ) + AND ( + COALESCE(`t6`.`PS_PARTKEY`, 1) = COALESCE(`t12`.`bfuid_col_3787`, 1) + ) + ) AS `bfuid_col_3797` + FROM ( + SELECT + `t3`.`PS_PARTKEY`, + `t3`.`PS_SUPPKEY`, + `t3`.`PS_AVAILQTY` + FROM ( + SELECT + `PS_PARTKEY`, + `PS_SUPPKEY`, + `PS_AVAILQTY` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t6` + ) AS `t17` + WHERE + `t17`.`bfuid_col_3797` + ) AS `t21` + ON `t19`.`bfuid_col_3777` = `t21`.`PS_SUPPKEY` + AND `t19`.`bfuid_col_3776` = `t21`.`PS_PARTKEY` + ) AS `t22` + WHERE + `t22`.`bfuid_col_3816` + ) AS `t23` + GROUP BY + 1 + ) AS `t24` + WHERE + ( + COALESCE(`t14`.`S_SUPPKEY`, 0) = COALESCE(`t24`.`bfuid_col_3812`, 0) + ) + AND ( + COALESCE(`t14`.`S_SUPPKEY`, 1) = COALESCE(`t24`.`bfuid_col_3812`, 1) + ) + ) AS `bfuid_col_3817` + FROM ( + SELECT + `t7`.`S_SUPPKEY`, + `t7`.`S_NAME`, + `t7`.`S_ADDRESS` + FROM ( + SELECT + `t0`.`S_SUPPKEY`, + `t0`.`S_NAME`, + `t0`.`S_ADDRESS`, + `t0`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NAME`, + `S_ADDRESS`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t7` + INNER JOIN ( + SELECT + `t1`.`N_NATIONKEY` AS `bfuid_col_3781` + FROM ( SELECT - STRUCT(COALESCE(`bfcol_61`, 0) AS `bfpart1`, COALESCE(`bfcol_61`, 1) AS `bfpart2`) - FROM `bfcte_14` - ) - ) AS `bfcol_62` - FROM `bfcte_7` -) -SELECT - `bfcol_42` AS `S_NAME`, - `bfcol_43` AS `S_ADDRESS` -FROM `bfcte_15` + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + WHERE + `t1`.`N_NAME` = 'CANADA' + ) AS `t10` + ON COALESCE(`t7`.`S_NATIONKEY`, 0) = COALESCE(`t10`.`bfuid_col_3781`, 0) + AND COALESCE(`t7`.`S_NATIONKEY`, 1) = COALESCE(`t10`.`bfuid_col_3781`, 1) + ) AS `t14` +) AS `t26` WHERE - `bfcol_62` -ORDER BY - `bfcol_42` ASC NULLS LAST \ No newline at end of file + `t26`.`bfuid_col_3817`) AS `t` +ORDER BY `S_NAME` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/21/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/21/out.sql index 93a44e529d9..ac4054451a8 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/21/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/21/out.sql @@ -1,148 +1,211 @@ -WITH `bfcte_0` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_0`, - `O_ORDERSTATUS` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_2`, - `N_NAME` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_4`, - `S_NAME` AS `bfcol_5`, - `S_NATIONKEY` AS `bfcol_6` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_30`, - `L_SUPPKEY` AS `bfcol_31` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `L_RECEIPTDATE` > `L_COMMITDATE` -), `bfcte_4` AS ( - SELECT - `L_ORDERKEY` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_32` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `L_RECEIPTDATE` > `L_COMMITDATE` -), `bfcte_6` AS ( - SELECT - `L_ORDERKEY`, - COUNT(1) AS `bfcol_18` - FROM `bfcte_4` - WHERE - NOT `L_ORDERKEY` IS NULL - GROUP BY - `L_ORDERKEY` -), `bfcte_7` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_33` - FROM `bfcte_6` - WHERE - `bfcol_18` > 1 -), `bfcte_8` AS ( - SELECT - `bfcol_33` AS `bfcol_34`, - `bfcol_31` AS `bfcol_35` - FROM `bfcte_7` - INNER JOIN `bfcte_3` - ON `bfcol_33` = `bfcol_30` -), `bfcte_9` AS ( - SELECT - `bfcol_33`, - COUNT(1) AS `bfcol_37` - FROM `bfcte_7` - INNER JOIN `bfcte_5` - ON `bfcol_33` = `bfcol_32` - GROUP BY - `bfcol_33` -), `bfcte_10` AS ( - SELECT - `bfcol_33` AS `bfcol_36`, - `bfcol_37` - FROM `bfcte_9` -), `bfcte_11` AS ( - SELECT - `bfcol_36` AS `bfcol_38`, - `bfcol_37` AS `bfcol_39`, - `bfcol_35` AS `bfcol_40` - FROM `bfcte_10` - INNER JOIN `bfcte_8` - ON `bfcol_36` = `bfcol_34` -), `bfcte_12` AS ( - SELECT - `bfcol_38` AS `bfcol_41`, - `bfcol_39` AS `bfcol_42`, - `bfcol_5` AS `bfcol_43`, - `bfcol_6` AS `bfcol_44` - FROM `bfcte_11` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_40`, 0) = COALESCE(`bfcol_4`, 0) - AND COALESCE(`bfcol_40`, 1) = COALESCE(`bfcol_4`, 1) -), `bfcte_13` AS ( - SELECT - `bfcol_41` AS `bfcol_45`, - `bfcol_42` AS `bfcol_46`, - `bfcol_43` AS `bfcol_47`, - `bfcol_3` AS `bfcol_48` - FROM `bfcte_12` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_44`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_44`, 1) = COALESCE(`bfcol_2`, 1) -), `bfcte_14` AS ( - SELECT - `bfcol_45`, - `bfcol_46`, - `bfcol_47`, - `bfcol_48`, - `bfcol_0`, - `bfcol_1`, - `bfcol_47` AS `bfcol_53`, - ( - ( - `bfcol_46` = 1 - ) AND ( - `bfcol_48` = 'SAUDI ARABIA' - ) - ) - AND ( - `bfcol_1` = 'F' - ) AS `bfcol_54` - FROM `bfcte_13` - INNER JOIN `bfcte_0` - ON `bfcol_45` = `bfcol_0` - WHERE - ( - ( - `bfcol_46` = 1 - ) AND ( - `bfcol_48` = 'SAUDI ARABIA' - ) - ) - AND ( - `bfcol_1` = 'F' - ) -), `bfcte_15` AS ( - SELECT - `bfcol_53`, - COUNT(1) AS `bfcol_58` - FROM `bfcte_14` - WHERE - NOT `bfcol_53` IS NULL +SELECT `S_NAME`, `NUMWAIT` FROM (SELECT + `t38`.`bfuid_col_3886` AS `S_NAME`, + `t38`.`bfuid_col_3906` AS `NUMWAIT` +FROM ( + SELECT + `t37`.`bfuid_col_3886`, + COUNT(1) AS `bfuid_col_3906` + FROM ( + SELECT + `t36`.`bfuid_col_3886` + FROM ( + SELECT + `t35`.`S_NAME` AS `bfuid_col_3886`, + ( + ( + `t35`.`bfuid_col_3856` = 1 + ) AND ( + `t35`.`N_NAME` = 'SAUDI ARABIA' + ) + ) + AND ( + `t10`.`O_ORDERSTATUS` = 'F' + ) AS `bfuid_col_3905` + FROM ( + SELECT + * + FROM ( + SELECT + `t32`.`bfuid_col_3833`, + `t32`.`bfuid_col_3856`, + `t32`.`S_NAME`, + `t11`.`N_NAME` + FROM ( + SELECT + * + FROM ( + SELECT + `t29`.`bfuid_col_3833`, + `t29`.`bfuid_col_3856`, + `t12`.`S_NAME`, + `t12`.`S_NATIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t26`.`bfuid_col_3833`, + `t26`.`bfuid_col_3856`, + `t24`.`bfuid_col_3841` + FROM ( + SELECT + * + FROM ( + SELECT + `t20`.`bfuid_col_3833`, + COUNT(1) AS `bfuid_col_3856` + FROM ( + SELECT + `t19`.`bfuid_col_3833` + FROM ( + SELECT + `t17`.`L_ORDERKEY` AS `bfuid_col_3833` + FROM ( + SELECT + `t9`.`L_ORDERKEY`, + COUNT(1) AS `bfuid_col_3831` + FROM ( + SELECT + `t5`.`L_ORDERKEY` + FROM ( + SELECT + `L_ORDERKEY` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t5` + ) AS `t9` + GROUP BY + 1 + ) AS `t17` + WHERE + ( + `t17`.`L_ORDERKEY` + ) IS NOT NULL AND `t17`.`bfuid_col_3831` > 1 + ) AS `t19` + INNER JOIN ( + SELECT + `t3`.`L_ORDERKEY` AS `bfuid_col_3839` + FROM ( + SELECT + `L_ORDERKEY`, + `L_COMMITDATE`, + `L_RECEIPTDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + WHERE + `t3`.`L_RECEIPTDATE` > `t3`.`L_COMMITDATE` + ) AS `t15` + ON `t19`.`bfuid_col_3833` = `t15`.`bfuid_col_3839` + ) AS `t20` + GROUP BY + 1 + ) AS `t22` + ) AS `t26` + INNER JOIN ( + SELECT + * + FROM ( + SELECT + `t19`.`bfuid_col_3833` AS `bfuid_col_3857`, + `t16`.`bfuid_col_3841` + FROM ( + SELECT + `t17`.`L_ORDERKEY` AS `bfuid_col_3833` + FROM ( + SELECT + `t9`.`L_ORDERKEY`, + COUNT(1) AS `bfuid_col_3831` + FROM ( + SELECT + `t5`.`L_ORDERKEY` + FROM ( + SELECT + `L_ORDERKEY` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t5` + ) AS `t9` + GROUP BY + 1 + ) AS `t17` + WHERE + ( + `t17`.`L_ORDERKEY` + ) IS NOT NULL AND `t17`.`bfuid_col_3831` > 1 + ) AS `t19` + INNER JOIN ( + SELECT + `t4`.`L_ORDERKEY` AS `bfuid_col_3839`, + `t4`.`L_SUPPKEY` AS `bfuid_col_3841` + FROM ( + SELECT + `L_ORDERKEY`, + `L_SUPPKEY`, + `L_COMMITDATE`, + `L_RECEIPTDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + WHERE + `t4`.`L_RECEIPTDATE` > `t4`.`L_COMMITDATE` + ) AS `t16` + ON `t19`.`bfuid_col_3833` = `t16`.`bfuid_col_3839` + ) AS `t21` + ) AS `t24` + ON `t26`.`bfuid_col_3833` = `t24`.`bfuid_col_3857` + ) AS `t27` + ) AS `t29` + INNER JOIN ( + SELECT + `t2`.`S_SUPPKEY`, + `t2`.`S_NAME`, + `t2`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NAME`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t12` + ON COALESCE(`t29`.`bfuid_col_3841`, 0) = COALESCE(`t12`.`S_SUPPKEY`, 0) + AND COALESCE(`t29`.`bfuid_col_3841`, 1) = COALESCE(`t12`.`S_SUPPKEY`, 1) + ) AS `t30` + ) AS `t32` + INNER JOIN ( + SELECT + `t1`.`N_NATIONKEY`, + `t1`.`N_NAME` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t11` + ON COALESCE(`t32`.`S_NATIONKEY`, 0) = COALESCE(`t11`.`N_NATIONKEY`, 0) + AND COALESCE(`t32`.`S_NATIONKEY`, 1) = COALESCE(`t11`.`N_NATIONKEY`, 1) + ) AS `t33` + ) AS `t35` + INNER JOIN ( + SELECT + `t0`.`O_ORDERKEY`, + `t0`.`O_ORDERSTATUS` + FROM ( + SELECT + `O_ORDERKEY`, + `O_ORDERSTATUS` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t10` + ON `t35`.`bfuid_col_3833` = `t10`.`O_ORDERKEY` + ) AS `t36` + WHERE + `t36`.`bfuid_col_3905` + ) AS `t37` GROUP BY - `bfcol_53` -) -SELECT - `bfcol_53` AS `S_NAME`, - `bfcol_58` AS `NUMWAIT` -FROM `bfcte_15` -ORDER BY - `bfcol_58` DESC, - `bfcol_53` ASC NULLS LAST + 1 +) AS `t38` +WHERE + ( + `t38`.`bfuid_col_3886` + ) IS NOT NULL) AS `t` +ORDER BY `NUMWAIT` DESC NULLS LAST ,`S_NAME` ASC NULLS LAST LIMIT 100 \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/22/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/22/out.sql index 87ca2d8d5e0..78d8a67db13 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/22/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/22/out.sql @@ -1,136 +1,216 @@ -WITH `bfcte_0` AS ( +SELECT `CNTRYCODE`, `NUMCUST`, `TOTACCTBAL` FROM (SELECT + `t25`.`bfuid_col_3962` AS `CNTRYCODE`, + `t25`.`bfuid_col_3980` AS `NUMCUST`, + `t25`.`bfuid_col_3981` AS `TOTACCTBAL` +FROM ( SELECT - * - FROM UNNEST(ARRAY>[STRUCT('C_ACCTBAL', 0, 0)]) -), `bfcte_1` AS ( - SELECT - `O_CUSTKEY` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `C_PHONE`, - `C_ACCTBAL`, - `C_ACCTBAL` AS `bfcol_9`, - SUBSTRING(`C_PHONE`, 1, 2) AS `bfcol_10`, - `C_ACCTBAL` AS `bfcol_19`, - COALESCE( - COALESCE(SUBSTRING(`C_PHONE`, 1, 2) IN ('13', '31', '23', '29', '30', '18', '17'), FALSE), - FALSE - ) AS `bfcol_20`, - `C_ACCTBAL` AS `bfcol_35`, - `C_ACCTBAL` > 0.0 AS `bfcol_36` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - COALESCE( - COALESCE(SUBSTRING(`C_PHONE`, 1, 2) IN ('13', '31', '23', '29', '30', '18', '17'), FALSE), - FALSE - ) - AND `C_ACCTBAL` > 0.0 -), `bfcte_3` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_32`, - `C_ACCTBAL` AS `bfcol_33`, - SUBSTRING(`C_PHONE`, 1, 2) AS `bfcol_34` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - COALESCE( - COALESCE(SUBSTRING(`C_PHONE`, 1, 2) IN ('13', '31', '23', '29', '30', '18', '17'), FALSE), - FALSE - ) -), `bfcte_4` AS ( - SELECT - `O_CUSTKEY` - FROM `bfcte_1` - GROUP BY - `O_CUSTKEY` -), `bfcte_5` AS ( - SELECT - AVG(`bfcol_35`) AS `bfcol_40` - FROM `bfcte_2` -), `bfcte_6` AS ( - SELECT - `O_CUSTKEY` AS `bfcol_0` - FROM `bfcte_4` -), `bfcte_7` AS ( - SELECT - `bfcol_40`, - 0 AS `bfcol_41` - FROM `bfcte_5` -), `bfcte_8` AS ( - SELECT - `bfcol_3`, - `bfcol_4`, - `bfcol_5`, - `bfcol_40`, - `bfcol_41`, - CASE WHEN `bfcol_5` = 0 THEN `bfcol_40` END AS `bfcol_42`, - IF(`bfcol_41` = 0, CASE WHEN `bfcol_5` = 0 THEN `bfcol_40` END, NULL) AS `bfcol_47` - FROM `bfcte_0` - CROSS JOIN `bfcte_7` -), `bfcte_9` AS ( - SELECT - `bfcol_3`, - `bfcol_4`, - ANY_VALUE(`bfcol_47`) AS `bfcol_51` - FROM `bfcte_8` - WHERE - NOT `bfcol_3` IS NULL AND NOT `bfcol_4` IS NULL - GROUP BY - `bfcol_3`, - `bfcol_4` -), `bfcte_10` AS ( - SELECT - `bfcol_51` AS `bfcol_52` - FROM `bfcte_9` -), `bfcte_11` AS ( - SELECT - `bfcol_32` AS `bfcol_61`, - `bfcol_33` AS `bfcol_62`, - `bfcol_34` AS `bfcol_63` - FROM `bfcte_3` - CROSS JOIN `bfcte_10` - WHERE - `bfcol_33` > `bfcol_52` -), `bfcte_12` AS ( - SELECT - *, - STRUCT(COALESCE(`bfcol_61`, 0) AS `bfpart1`, COALESCE(`bfcol_61`, 1) AS `bfpart2`) IN ( - ( + `t24`.`bfuid_col_3962`, + COUNT(`t24`.`bfuid_col_3954`) AS `bfuid_col_3980`, + COALESCE(SUM(`t24`.`bfuid_col_3959`), 0) AS `bfuid_col_3981` + FROM ( + SELECT + `t23`.`bfuid_col_3954`, + `t23`.`bfuid_col_3959`, + `t23`.`bfuid_col_3962` + FROM ( + SELECT + `t21`.`bfuid_col_3954`, + `t21`.`bfuid_col_3959`, + `t21`.`bfuid_col_3962`, + NOT ( + EXISTS( + SELECT + 1 + FROM ( + SELECT + `t4`.`O_CUSTKEY` + FROM ( + SELECT + `t1`.`O_CUSTKEY` + FROM ( + SELECT + `O_CUSTKEY` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t4` + GROUP BY + 1 + ) AS `t7` + WHERE + ( + COALESCE(`t21`.`bfuid_col_3954`, 0) = COALESCE(`t7`.`O_CUSTKEY`, 0) + ) + AND ( + COALESCE(`t21`.`bfuid_col_3954`, 1) = COALESCE(`t7`.`O_CUSTKEY`, 1) + ) + ) + ) AS `bfuid_col_3966` + FROM ( SELECT - STRUCT(COALESCE(`bfcol_0`, 0) AS `bfpart1`, COALESCE(`bfcol_0`, 1) AS `bfpart2`) - FROM `bfcte_6` - ) - ) AS `bfcol_64` - FROM `bfcte_11` -), `bfcte_13` AS ( - SELECT - `bfcol_61`, - `bfcol_62`, - `bfcol_63`, - `bfcol_64`, - NOT ( - `bfcol_64` - ) AS `bfcol_65` - FROM `bfcte_12` - WHERE - NOT ( - `bfcol_64` - ) -), `bfcte_14` AS ( - SELECT - `bfcol_63`, - COUNT(`bfcol_61`) AS `bfcol_73`, - COALESCE(SUM(`bfcol_62`), 0) AS `bfcol_74` - FROM `bfcte_13` - WHERE - NOT `bfcol_63` IS NULL + `t20`.`bfuid_col_3954`, + `t20`.`bfuid_col_3959`, + `t20`.`bfuid_col_3962` + FROM ( + SELECT + `t11`.`bfuid_col_3919` AS `bfuid_col_3954`, + `t11`.`bfuid_col_3924` AS `bfuid_col_3959`, + `t11`.`bfuid_col_3927` AS `bfuid_col_3962`, + `t11`.`bfuid_col_3924` > `t19`.`bfuid_col_3946` AS `bfuid_col_3964` + FROM ( + SELECT + `t8`.`bfuid_col_3919`, + `t8`.`bfuid_col_3924`, + `t8`.`bfuid_col_3927` + FROM ( + SELECT + `t0`.`C_CUSTKEY` AS `bfuid_col_3919`, + `t0`.`C_ACCTBAL` AS `bfuid_col_3924`, + SUBSTRING( + `t0`.`C_PHONE`, + IF( + ( + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + 1 + ) >= 1, + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + 1, + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + 1 + LENGTH(`t0`.`C_PHONE`) + ), + GREATEST( + 0, + IF(2 >= 0, 2, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 2)) - IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + ) + ) AS `bfuid_col_3927`, + COALESCE( + COALESCE( + SUBSTRING( + `t0`.`C_PHONE`, + IF( + ( + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + 1 + ) >= 1, + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + 1, + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + 1 + LENGTH(`t0`.`C_PHONE`) + ), + GREATEST( + 0, + IF(2 >= 0, 2, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 2)) - IF(0 >= 0, 0, GREATEST(0, LENGTH(`t0`.`C_PHONE`) + 0)) + ) + ) IN ('13', '31', '23', '29', '30', '18', '17'), + FALSE + ), + FALSE + ) AS `bfuid_col_3928` + FROM ( + SELECT + `C_CUSTKEY`, + `C_PHONE`, + `C_ACCTBAL` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t8` + WHERE + `t8`.`bfuid_col_3928` + ) AS `t11` + CROSS JOIN ( + SELECT + `t17`.`bfuid_col_3946` + FROM ( + SELECT + `t16`.`bfuid_col_3943`, + `t16`.`bfuid_col_3944`, + ANY_VALUE(`t16`.`bfuid_col_3945`) AS `bfuid_col_3946` + FROM ( + SELECT + `t6`.`col_0` AS `bfuid_col_3943`, + `t6`.`col_1` AS `bfuid_col_3944`, + CASE + WHEN `t15`.`bfuid_col_3941` = 0 + THEN CASE + WHEN `t6`.`col_2` = 0 + THEN `t15`.`bfuid_col_3935` + ELSE CAST(NULL AS FLOAT64) + END + ELSE CAST(NULL AS FLOAT64) + END AS `bfuid_col_3945` + FROM ( + SELECT + * + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT('C_ACCTBAL', 0, 0)]) AS `col_0` + ) AS `t2` + ) AS `t6` + CROSS JOIN ( + SELECT + `t13`.`bfuid_col_3935`, + 0 AS `bfuid_col_3941` + FROM ( + SELECT + AVG(`t12`.`bfuid_col_3935`) AS `bfuid_col_3935` + FROM ( + SELECT + `t9`.`bfuid_col_3924` AS `bfuid_col_3935` + FROM ( + SELECT + `t3`.`C_ACCTBAL` AS `bfuid_col_3924`, + COALESCE( + COALESCE( + SUBSTRING( + `t3`.`C_PHONE`, + IF( + ( + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t3`.`C_PHONE`) + 0)) + 1 + ) >= 1, + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t3`.`C_PHONE`) + 0)) + 1, + IF(0 >= 0, 0, GREATEST(0, LENGTH(`t3`.`C_PHONE`) + 0)) + 1 + LENGTH(`t3`.`C_PHONE`) + ), + GREATEST( + 0, + IF(2 >= 0, 2, GREATEST(0, LENGTH(`t3`.`C_PHONE`) + 2)) - IF(0 >= 0, 0, GREATEST(0, LENGTH(`t3`.`C_PHONE`) + 0)) + ) + ) IN ('13', '31', '23', '29', '30', '18', '17'), + FALSE + ), + FALSE + ) AS `bfuid_col_3928` + FROM ( + SELECT + `C_PHONE`, + `C_ACCTBAL` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t9` + WHERE + `t9`.`bfuid_col_3928` AND `t9`.`bfuid_col_3924` > 0.0 + ) AS `t12` + ) AS `t13` + ) AS `t15` + ) AS `t16` + GROUP BY + 1, + 2 + ) AS `t17` + WHERE + ( + `t17`.`bfuid_col_3943` + ) IS NOT NULL + AND ( + `t17`.`bfuid_col_3944` + ) IS NOT NULL + ) AS `t19` + ) AS `t20` + WHERE + `t20`.`bfuid_col_3964` + ) AS `t21` + ) AS `t23` + WHERE + `t23`.`bfuid_col_3966` + ) AS `t24` GROUP BY - `bfcol_63` -) -SELECT - `bfcol_63` AS `CNTRYCODE`, - `bfcol_73` AS `NUMCUST`, - `bfcol_74` AS `TOTACCTBAL` -FROM `bfcte_14` -ORDER BY - `bfcol_63` ASC NULLS LAST \ No newline at end of file + 1 +) AS `t25` +WHERE + ( + `t25`.`bfuid_col_3962` + ) IS NOT NULL) AS `t` +ORDER BY `CNTRYCODE` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/3/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/3/out.sql index 0d1365d76d1..41c003dcd5d 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/3/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/3/out.sql @@ -1,80 +1,99 @@ -WITH `bfcte_0` AS ( +SELECT `L_ORDERKEY`, `REVENUE`, `O_ORDERDATE`, `O_SHIPPRIORITY` FROM (SELECT + `t13`.`bfuid_col_2068` AS `L_ORDERKEY`, + `t13`.`bfuid_col_2078` AS `REVENUE`, + `t13`.`bfuid_col_2072` AS `O_ORDERDATE`, + `t13`.`bfuid_col_2075` AS `O_SHIPPRIORITY` +FROM ( SELECT - `O_ORDERKEY` AS `bfcol_32`, - `O_CUSTKEY` AS `bfcol_33`, - `O_ORDERDATE` AS `bfcol_34`, - `O_SHIPPRIORITY` AS `bfcol_35` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `O_ORDERDATE` < CAST('1995-03-15' AS DATE) -), `bfcte_1` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_36`, - `L_EXTENDEDPRICE` AS `bfcol_37`, - `L_DISCOUNT` AS `bfcol_38` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `L_SHIPDATE` > CAST('1995-03-15' AS DATE) -), `bfcte_2` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_39` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `C_MKTSEGMENT` = 'BUILDING' -), `bfcte_3` AS ( - SELECT - `bfcol_37` AS `bfcol_40`, - `bfcol_38` AS `bfcol_41`, - `bfcol_32` AS `bfcol_42`, - `bfcol_33` AS `bfcol_43`, - `bfcol_34` AS `bfcol_44`, - `bfcol_35` AS `bfcol_45` - FROM `bfcte_1` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_36`, 0) = COALESCE(`bfcol_32`, 0) - AND COALESCE(`bfcol_36`, 1) = COALESCE(`bfcol_32`, 1) -), `bfcte_4` AS ( - SELECT - `bfcol_39`, - `bfcol_40`, - `bfcol_41`, - `bfcol_42`, - `bfcol_43`, - `bfcol_44`, - `bfcol_45`, - `bfcol_42` AS `bfcol_51`, - `bfcol_44` AS `bfcol_52`, - `bfcol_45` AS `bfcol_53`, - `bfcol_40` * ( - 1 - `bfcol_41` - ) AS `bfcol_54` - FROM `bfcte_2` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_39`, 0) = COALESCE(`bfcol_43`, 0) - AND COALESCE(`bfcol_39`, 1) = COALESCE(`bfcol_43`, 1) -), `bfcte_5` AS ( - SELECT - `bfcol_51`, - `bfcol_52`, - `bfcol_53`, - COALESCE(SUM(`bfcol_54`), 0) AS `bfcol_59` - FROM `bfcte_4` - WHERE - NOT `bfcol_51` IS NULL AND NOT `bfcol_52` IS NULL AND NOT `bfcol_53` IS NULL + `t12`.`bfuid_col_2068`, + `t12`.`bfuid_col_2072`, + `t12`.`bfuid_col_2075`, + COALESCE(SUM(`t12`.`bfuid_col_2077`), 0) AS `bfuid_col_2078` + FROM ( + SELECT + `t11`.`bfuid_col_2012` AS `bfuid_col_2068`, + `t11`.`bfuid_col_2016` AS `bfuid_col_2072`, + `t11`.`bfuid_col_2019` AS `bfuid_col_2075`, + `t11`.`bfuid_col_2028` * ( + 1 - `t11`.`bfuid_col_2029` + ) AS `bfuid_col_2077` + FROM ( + SELECT + `t0`.`C_CUSTKEY` AS `bfuid_col_2002` + FROM ( + SELECT + `C_CUSTKEY`, + `C_MKTSEGMENT` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + WHERE + `t0`.`C_MKTSEGMENT` = 'BUILDING' + ) AS `t6` + INNER JOIN ( + SELECT + * + FROM ( + SELECT + `t7`.`bfuid_col_2028`, + `t7`.`bfuid_col_2029`, + `t8`.`bfuid_col_2012`, + `t8`.`bfuid_col_2013`, + `t8`.`bfuid_col_2016`, + `t8`.`bfuid_col_2019` + FROM ( + SELECT + `t1`.`L_ORDERKEY` AS `bfuid_col_2023`, + `t1`.`L_EXTENDEDPRICE` AS `bfuid_col_2028`, + `t1`.`L_DISCOUNT` AS `bfuid_col_2029` + FROM ( + SELECT + `L_ORDERKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + WHERE + `t1`.`L_SHIPDATE` > DATE(1995, 3, 15) + ) AS `t7` + INNER JOIN ( + SELECT + `t2`.`O_ORDERKEY` AS `bfuid_col_2012`, + `t2`.`O_CUSTKEY` AS `bfuid_col_2013`, + `t2`.`O_ORDERDATE` AS `bfuid_col_2016`, + `t2`.`O_SHIPPRIORITY` AS `bfuid_col_2019` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY`, + `O_ORDERDATE`, + `O_SHIPPRIORITY` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + WHERE + `t2`.`O_ORDERDATE` < DATE(1995, 3, 15) + ) AS `t8` + ON COALESCE(`t7`.`bfuid_col_2023`, 0) = COALESCE(`t8`.`bfuid_col_2012`, 0) + AND COALESCE(`t7`.`bfuid_col_2023`, 1) = COALESCE(`t8`.`bfuid_col_2012`, 1) + ) AS `t9` + ) AS `t11` + ON COALESCE(`t6`.`bfuid_col_2002`, 0) = COALESCE(`t11`.`bfuid_col_2013`, 0) + AND COALESCE(`t6`.`bfuid_col_2002`, 1) = COALESCE(`t11`.`bfuid_col_2013`, 1) + ) AS `t12` GROUP BY - `bfcol_51`, - `bfcol_52`, - `bfcol_53` -) -SELECT - `bfcol_51` AS `L_ORDERKEY`, - `bfcol_59` AS `REVENUE`, - `bfcol_52` AS `O_ORDERDATE`, - `bfcol_53` AS `O_SHIPPRIORITY` -FROM `bfcte_5` -ORDER BY - `bfcol_59` DESC, - `bfcol_52` ASC NULLS LAST, - `bfcol_51` ASC NULLS LAST, - `bfcol_53` ASC NULLS LAST + 1, + 2, + 3 +) AS `t13` +WHERE + ( + `t13`.`bfuid_col_2068` + ) IS NOT NULL + AND ( + `t13`.`bfuid_col_2072` + ) IS NOT NULL + AND ( + `t13`.`bfuid_col_2075` + ) IS NOT NULL) AS `t` +ORDER BY `REVENUE` DESC NULLS LAST ,`O_ORDERDATE` ASC NULLS LAST ,`L_ORDERKEY` ASC NULLS LAST ,`O_SHIPPRIORITY` ASC NULLS LAST LIMIT 10 \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/4/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/4/out.sql index 9eb0259be50..451dbe6f128 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/4/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/4/out.sql @@ -1,70 +1,80 @@ -WITH `bfcte_0` AS ( +SELECT `O_ORDERPRIORITY`, `ORDER_COUNT` FROM (SELECT + `t10`.`bfuid_col_2134` AS `O_ORDERPRIORITY`, + `t10`.`bfuid_col_2140` AS `ORDER_COUNT` +FROM ( SELECT - `O_ORDERKEY` AS `bfcol_0`, - `O_ORDERDATE` AS `bfcol_1`, - `O_ORDERPRIORITY` AS `bfcol_2` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_3`, - `L_COMMITDATE` AS `bfcol_4`, - `L_RECEIPTDATE` AS `bfcol_5` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `bfcol_3`, - `bfcol_4`, - `bfcol_5`, - `bfcol_0`, - `bfcol_1`, - `bfcol_2`, - `bfcol_3` AS `bfcol_11`, - `bfcol_4` AS `bfcol_12`, - `bfcol_5` AS `bfcol_13`, - `bfcol_2` AS `bfcol_14`, - ( - `bfcol_1` >= CAST('1993-07-01' AS DATE) - ) - AND ( - `bfcol_1` < CAST('1993-10-01' AS DATE) - ) AS `bfcol_15`, - `bfcol_3` AS `bfcol_25`, - `bfcol_2` AS `bfcol_26`, - `bfcol_4` < `bfcol_5` AS `bfcol_27` - FROM `bfcte_1` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_3`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_3`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - ( - `bfcol_1` >= CAST('1993-07-01' AS DATE) - ) - AND ( - `bfcol_1` < CAST('1993-10-01' AS DATE) - ) - AND `bfcol_4` < `bfcol_5` -), `bfcte_3` AS ( - SELECT - `bfcol_26`, - `bfcol_25`, - COUNT(1) AS `bfcol_33` - FROM `bfcte_2` - WHERE - NOT `bfcol_26` IS NULL AND NOT `bfcol_25` IS NULL - GROUP BY - `bfcol_26`, - `bfcol_25` -), `bfcte_4` AS ( - SELECT - `bfcol_26`, - COUNT(`bfcol_25`) AS `bfcol_36` - FROM `bfcte_3` + `t9`.`bfuid_col_2134`, + COUNT(`t9`.`bfuid_col_2113`) AS `bfuid_col_2140` + FROM ( + SELECT + `t8`.`bfuid_col_2134`, + `t8`.`bfuid_col_2113` + FROM ( + SELECT + `t7`.`bfuid_col_2134`, + `t7`.`bfuid_col_2113`, + COUNT(1) AS `bfuid_col_2139` + FROM ( + SELECT + `t6`.`bfuid_col_2084` AS `bfuid_col_2113`, + `t6`.`bfuid_col_2105` AS `bfuid_col_2134` + FROM ( + SELECT + `t4`.`L_ORDERKEY` AS `bfuid_col_2084`, + `t4`.`L_COMMITDATE` AS `bfuid_col_2095`, + `t4`.`L_RECEIPTDATE` AS `bfuid_col_2096`, + `t5`.`O_ORDERPRIORITY` AS `bfuid_col_2105`, + ( + `t5`.`O_ORDERDATE` >= DATE(1993, 7, 1) + ) + AND ( + `t5`.`O_ORDERDATE` < DATE(1993, 10, 1) + ) AS `bfuid_col_2109` + FROM ( + SELECT + `t0`.`L_ORDERKEY`, + `t0`.`L_COMMITDATE`, + `t0`.`L_RECEIPTDATE` + FROM ( + SELECT + `L_ORDERKEY`, + `L_COMMITDATE`, + `L_RECEIPTDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t4` + INNER JOIN ( + SELECT + `t1`.`O_ORDERKEY`, + `t1`.`O_ORDERDATE`, + `t1`.`O_ORDERPRIORITY` + FROM ( + SELECT + `O_ORDERKEY`, + `O_ORDERDATE`, + `O_ORDERPRIORITY` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t5` + ON COALESCE(`t4`.`L_ORDERKEY`, 0) = COALESCE(`t5`.`O_ORDERKEY`, 0) + AND COALESCE(`t4`.`L_ORDERKEY`, 1) = COALESCE(`t5`.`O_ORDERKEY`, 1) + ) AS `t6` + WHERE + `t6`.`bfuid_col_2109` AND `t6`.`bfuid_col_2095` < `t6`.`bfuid_col_2096` + ) AS `t7` + GROUP BY + 1, + 2 + ) AS `t8` + WHERE + ( + `t8`.`bfuid_col_2134` + ) IS NOT NULL + AND ( + `t8`.`bfuid_col_2113` + ) IS NOT NULL + ) AS `t9` GROUP BY - `bfcol_26` -) -SELECT - `bfcol_26` AS `O_ORDERPRIORITY`, - `bfcol_36` AS `ORDER_COUNT` -FROM `bfcte_4` -ORDER BY - `bfcol_26` ASC NULLS LAST \ No newline at end of file + 1 +) AS `t10`) AS `t` +ORDER BY `O_ORDERPRIORITY` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/5/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/5/out.sql index 34974b36d8f..6349933563d 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/5/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/5/out.sql @@ -1,100 +1,160 @@ -WITH `bfcte_0` AS ( +SELECT `N_NAME`, `REVENUE` FROM (SELECT + `t32`.`N_NAME`, + `t32`.`bfuid_col_2182` AS `REVENUE` +FROM ( SELECT - `S_SUPPKEY` AS `bfcol_0`, - `S_NATIONKEY` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_5` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_2`, - `C_NATIONKEY` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_4` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_4`, - `N_NAME` AS `bfcol_5`, - `N_REGIONKEY` AS `bfcol_6` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `R_REGIONKEY` AS `bfcol_32` - FROM `bigframes-dev`.`tpch`.`REGION` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - `R_NAME` = 'ASIA' -), `bfcte_4` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_33`, - `O_CUSTKEY` AS `bfcol_34` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - ( - `O_ORDERDATE` >= CAST('1994-01-01' AS DATE) - ) - AND ( - `O_ORDERDATE` < CAST('1995-01-01' AS DATE) - ) -), `bfcte_5` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_29`, - `L_SUPPKEY` AS `bfcol_30`, - `L_EXTENDEDPRICE` * ( - 1.0 - `L_DISCOUNT` - ) AS `bfcol_31` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_6` AS ( - SELECT - `bfcol_4` AS `bfcol_35`, - `bfcol_5` AS `bfcol_36` - FROM `bfcte_3` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_32`, 0) = COALESCE(`bfcol_6`, 0) - AND COALESCE(`bfcol_32`, 1) = COALESCE(`bfcol_6`, 1) -), `bfcte_7` AS ( - SELECT - `bfcol_35` AS `bfcol_37`, - `bfcol_36` AS `bfcol_38`, - `bfcol_2` AS `bfcol_39` - FROM `bfcte_6` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_35`, 0) = COALESCE(`bfcol_3`, 0) - AND COALESCE(`bfcol_35`, 1) = COALESCE(`bfcol_3`, 1) -), `bfcte_8` AS ( - SELECT - `bfcol_33` AS `bfcol_40`, - `bfcol_37` AS `bfcol_41`, - `bfcol_38` AS `bfcol_42` - FROM `bfcte_4` - INNER JOIN `bfcte_7` - ON COALESCE(`bfcol_34`, 0) = COALESCE(`bfcol_39`, 0) - AND COALESCE(`bfcol_34`, 1) = COALESCE(`bfcol_39`, 1) -), `bfcte_9` AS ( - SELECT - `bfcol_30` AS `bfcol_43`, - `bfcol_31` AS `bfcol_44`, - `bfcol_41` AS `bfcol_45`, - `bfcol_42` AS `bfcol_46` - FROM `bfcte_5` - INNER JOIN `bfcte_8` - ON COALESCE(`bfcol_29`, 0) = COALESCE(`bfcol_40`, 0) - AND COALESCE(`bfcol_29`, 1) = COALESCE(`bfcol_40`, 1) -), `bfcte_10` AS ( - SELECT - `bfcol_46`, - COALESCE(SUM(`bfcol_44`), 0) AS `bfcol_49` - FROM `bfcte_9` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_43`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_43`, 1) = COALESCE(`bfcol_0`, 1) - AND COALESCE(`bfcol_45`, 0) = COALESCE(`bfcol_1`, 0) - AND COALESCE(`bfcol_45`, 1) = COALESCE(`bfcol_1`, 1) - WHERE - NOT `bfcol_46` IS NULL + `t31`.`N_NAME`, + COALESCE(SUM(`t31`.`bfuid_col_2181`), 0) AS `bfuid_col_2182` + FROM ( + SELECT + `t30`.`bfuid_col_2181`, + `t30`.`N_NAME` + FROM ( + SELECT + * + FROM ( + SELECT + `t16`.`bfuid_col_2167`, + `t16`.`bfuid_col_2181`, + `t27`.`N_NATIONKEY`, + `t27`.`N_NAME` + FROM ( + SELECT + `t1`.`L_ORDERKEY` AS `bfuid_col_2165`, + `t1`.`L_SUPPKEY` AS `bfuid_col_2167`, + `t1`.`L_EXTENDEDPRICE` * ( + 1.0 - `t1`.`L_DISCOUNT` + ) AS `bfuid_col_2181` + FROM ( + SELECT + `L_ORDERKEY`, + `L_SUPPKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t16` + INNER JOIN ( + SELECT + * + FROM ( + SELECT + `t18`.`bfuid_col_2151`, + `t24`.`N_NATIONKEY`, + `t24`.`N_NAME` + FROM ( + SELECT + `t14`.`bfuid_col_2151`, + `t14`.`bfuid_col_2152` + FROM ( + SELECT + `t2`.`O_ORDERKEY` AS `bfuid_col_2151`, + `t2`.`O_CUSTKEY` AS `bfuid_col_2152`, + ( + `t2`.`O_ORDERDATE` >= DATE(1994, 1, 1) + ) + AND ( + `t2`.`O_ORDERDATE` < DATE(1995, 1, 1) + ) AS `bfuid_col_2160` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY`, + `O_ORDERDATE` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t14` + WHERE + `t14`.`bfuid_col_2160` + ) AS `t18` + INNER JOIN ( + SELECT + * + FROM ( + SELECT + `t21`.`N_NATIONKEY`, + `t21`.`N_NAME`, + `t10`.`C_CUSTKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t12`.`N_NATIONKEY`, + `t12`.`N_NAME` + FROM ( + SELECT + `t4`.`R_REGIONKEY` AS `bfuid_col_2142` + FROM ( + SELECT + `R_REGIONKEY`, + `R_NAME` + FROM `bigframes-dev.tpch.REGION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + WHERE + `t4`.`R_NAME` = 'ASIA' + ) AS `t15` + INNER JOIN ( + SELECT + `t5`.`N_NATIONKEY`, + `t5`.`N_NAME`, + `t5`.`N_REGIONKEY` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME`, + `N_REGIONKEY` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t5` + ) AS `t12` + ON COALESCE(`t15`.`bfuid_col_2142`, 0) = COALESCE(`t12`.`N_REGIONKEY`, 0) + AND COALESCE(`t15`.`bfuid_col_2142`, 1) = COALESCE(`t12`.`N_REGIONKEY`, 1) + ) AS `t19` + ) AS `t21` + INNER JOIN ( + SELECT + `t3`.`C_CUSTKEY`, + `t3`.`C_NATIONKEY` + FROM ( + SELECT + `C_CUSTKEY`, + `C_NATIONKEY` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t10` + ON COALESCE(`t21`.`N_NATIONKEY`, 0) = COALESCE(`t10`.`C_NATIONKEY`, 0) + AND COALESCE(`t21`.`N_NATIONKEY`, 1) = COALESCE(`t10`.`C_NATIONKEY`, 1) + ) AS `t22` + ) AS `t24` + ON COALESCE(`t18`.`bfuid_col_2152`, 0) = COALESCE(`t24`.`C_CUSTKEY`, 0) + AND COALESCE(`t18`.`bfuid_col_2152`, 1) = COALESCE(`t24`.`C_CUSTKEY`, 1) + ) AS `t25` + ) AS `t27` + ON COALESCE(`t16`.`bfuid_col_2165`, 0) = COALESCE(`t27`.`bfuid_col_2151`, 0) + AND COALESCE(`t16`.`bfuid_col_2165`, 1) = COALESCE(`t27`.`bfuid_col_2151`, 1) + ) AS `t28` + ) AS `t30` + INNER JOIN ( + SELECT + `t0`.`S_SUPPKEY`, + `t0`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t9` + ON COALESCE(`t30`.`bfuid_col_2167`, 0) = COALESCE(`t9`.`S_SUPPKEY`, 0) + AND COALESCE(`t30`.`bfuid_col_2167`, 1) = COALESCE(`t9`.`S_SUPPKEY`, 1) + AND COALESCE(`t30`.`N_NATIONKEY`, 0) = COALESCE(`t9`.`S_NATIONKEY`, 0) + AND COALESCE(`t30`.`N_NATIONKEY`, 1) = COALESCE(`t9`.`S_NATIONKEY`, 1) + ) AS `t31` GROUP BY - `bfcol_46` -) -SELECT - `bfcol_46` AS `N_NAME`, - `bfcol_49` AS `REVENUE` -FROM `bfcte_10` -ORDER BY - `bfcol_49` DESC, - `bfcol_46` ASC NULLS LAST \ No newline at end of file + 1 +) AS `t32` +WHERE + ( + `t32`.`N_NAME` + ) IS NOT NULL) AS `t` +ORDER BY `REVENUE` DESC NULLS LAST ,`N_NAME` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/6/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/6/out.sql index 110f3f9736f..7e17c01cf11 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/6/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/6/out.sql @@ -1,61 +1,62 @@ -WITH `bfcte_0` AS ( +SELECT + CASE + WHEN `t3`.`col_1` = 0 + THEN `t9`.`bfuid_col_2247-sum` + ELSE CAST(NULL AS FLOAT64) + END AS `REVENUE` +FROM ( SELECT * - FROM UNNEST(ARRAY>[STRUCT(0)]) -), `bfcte_1` AS ( - SELECT - `L_QUANTITY`, - `L_EXTENDEDPRICE`, - `L_DISCOUNT`, - `L_SHIPDATE`, - `L_QUANTITY` AS `bfcol_5`, - `L_EXTENDEDPRICE` AS `bfcol_6`, - `L_DISCOUNT` AS `bfcol_7`, - ( - `L_SHIPDATE` >= CAST('1994-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` < CAST('1995-01-01' AS DATE) - ) AS `bfcol_8`, - `L_QUANTITY` AS `bfcol_16`, - `L_EXTENDEDPRICE` AS `bfcol_17`, - `L_DISCOUNT` AS `bfcol_18`, - ( - `L_DISCOUNT` >= 0.05 - ) AND ( - `L_DISCOUNT` <= 0.07 - ) AS `bfcol_19`, - `L_EXTENDEDPRICE` AS `bfcol_27`, - `L_DISCOUNT` AS `bfcol_28`, - `L_QUANTITY` < 24 AS `bfcol_29`, - `L_EXTENDEDPRICE` AS `bfcol_35`, - `L_DISCOUNT` AS `bfcol_36`, - `L_EXTENDEDPRICE` * `L_DISCOUNT` AS `bfcol_39` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - ( - `L_SHIPDATE` >= CAST('1994-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` < CAST('1995-01-01' AS DATE) - ) - AND ( - `L_DISCOUNT` >= 0.05 - ) - AND ( - `L_DISCOUNT` <= 0.07 - ) - AND `L_QUANTITY` < 24 -), `bfcte_2` AS ( - SELECT - COALESCE(SUM(`bfcol_39`), 0) AS `bfcol_41` - FROM `bfcte_1` -), `bfcte_3` AS ( + FROM ( + SELECT + COALESCE(SUM(`t6`.`bfuid_col_2247`), 0) AS `bfuid_col_2247-sum` + FROM ( + SELECT + `t5`.`bfuid_col_2215` * `t5`.`bfuid_col_2216` AS `bfuid_col_2247` + FROM ( + SELECT + `t4`.`bfuid_col_2192` AS `bfuid_col_2214`, + `t4`.`bfuid_col_2193` AS `bfuid_col_2215`, + `t4`.`bfuid_col_2194` AS `bfuid_col_2216`, + ( + `t4`.`bfuid_col_2194` >= 0.05 + ) AND ( + `t4`.`bfuid_col_2194` <= 0.07 + ) AS `bfuid_col_2226` + FROM ( + SELECT + `t1`.`L_QUANTITY` AS `bfuid_col_2192`, + `t1`.`L_EXTENDEDPRICE` AS `bfuid_col_2193`, + `t1`.`L_DISCOUNT` AS `bfuid_col_2194`, + ( + `t1`.`L_SHIPDATE` >= DATE(1994, 1, 1) + ) + AND ( + `t1`.`L_SHIPDATE` < DATE(1995, 1, 1) + ) AS `bfuid_col_2204` + FROM ( + SELECT + `L_QUANTITY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t4` + WHERE + `t4`.`bfuid_col_2204` + ) AS `t5` + WHERE + `t5`.`bfuid_col_2226` AND `t5`.`bfuid_col_2214` < 24 + ) AS `t6` + ) AS `t7` +) AS `t9` +CROSS JOIN ( SELECT * - FROM `bfcte_2` -) -SELECT - CASE WHEN `bfcol_0` = 0 THEN `bfcol_41` END AS `REVENUE` -FROM `bfcte_3` -CROSS JOIN `bfcte_0` \ No newline at end of file + FROM ( + SELECT + * + FROM UNNEST(ARRAY>[STRUCT(0)]) AS `col_1` + ) AS `t0` +) AS `t3` \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/7/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/7/out.sql index 3d82a905e8b..3bd854aa8bb 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/7/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/7/out.sql @@ -1,143 +1,184 @@ -WITH `bfcte_0` AS ( +SELECT `SUPP_NATION`, `CUST_NATION`, `L_YEAR`, `REVENUE` FROM (WITH `t12` AS ( SELECT - `N_NATIONKEY` AS `bfcol_22`, - `N_NAME` AS `bfcol_23`, - COALESCE(COALESCE(`N_NAME` IN ('FRANCE', 'GERMANY'), FALSE), FALSE) AS `bfcol_24` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_4` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - COALESCE(COALESCE(`N_NAME` IN ('FRANCE', 'GERMANY'), FALSE), FALSE) -), `bfcte_1` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_2`, - `S_NATIONKEY` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_31`, - `L_SUPPKEY` AS `bfcol_32`, - `L_EXTENDEDPRICE` AS `bfcol_33`, - `L_DISCOUNT` AS `bfcol_34`, - `L_SHIPDATE` AS `bfcol_35` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' - WHERE - ( - `L_SHIPDATE` >= CAST('1995-01-01' AS DATE) - ) - AND ( - `L_SHIPDATE` <= CAST('1996-12-31' AS DATE) - ) -), `bfcte_3` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_9`, - `O_CUSTKEY` AS `bfcol_10` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_11`, - `C_NATIONKEY` AS `bfcol_12` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `bfcol_22` AS `bfcol_36`, - `bfcol_23` AS `bfcol_37` - FROM `bfcte_0` -), `bfcte_6` AS ( - SELECT - `bfcol_22` AS `bfcol_38`, - `bfcol_23` AS `bfcol_39` - FROM `bfcte_0` -), `bfcte_7` AS ( - SELECT - `bfcol_11` AS `bfcol_40`, - `bfcol_39` AS `bfcol_41` - FROM `bfcte_4` - INNER JOIN `bfcte_6` - ON COALESCE(`bfcol_12`, 0) = COALESCE(`bfcol_38`, 0) - AND COALESCE(`bfcol_12`, 1) = COALESCE(`bfcol_38`, 1) -), `bfcte_8` AS ( - SELECT - `bfcol_41` AS `bfcol_42`, - `bfcol_9` AS `bfcol_43` - FROM `bfcte_7` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_40`, 0) = COALESCE(`bfcol_10`, 0) - AND COALESCE(`bfcol_40`, 1) = COALESCE(`bfcol_10`, 1) -), `bfcte_9` AS ( - SELECT - `bfcol_42` AS `bfcol_44`, - `bfcol_32` AS `bfcol_45`, - `bfcol_33` AS `bfcol_46`, - `bfcol_34` AS `bfcol_47`, - `bfcol_35` AS `bfcol_48` - FROM `bfcte_8` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_43`, 0) = COALESCE(`bfcol_31`, 0) - AND COALESCE(`bfcol_43`, 1) = COALESCE(`bfcol_31`, 1) -), `bfcte_10` AS ( - SELECT - `bfcol_44` AS `bfcol_49`, - `bfcol_46` AS `bfcol_50`, - `bfcol_47` AS `bfcol_51`, - `bfcol_48` AS `bfcol_52`, - `bfcol_3` AS `bfcol_53` - FROM `bfcte_9` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_45`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_45`, 1) = COALESCE(`bfcol_2`, 1) -), `bfcte_11` AS ( - SELECT - `bfcol_49`, - `bfcol_50`, - `bfcol_51`, - `bfcol_52`, - `bfcol_53`, - `bfcol_36`, - `bfcol_37`, - `bfcol_49` AS `bfcol_59`, - `bfcol_50` AS `bfcol_60`, - `bfcol_51` AS `bfcol_61`, - `bfcol_52` AS `bfcol_62`, - `bfcol_37` AS `bfcol_63`, - `bfcol_49` <> `bfcol_37` AS `bfcol_64`, - `bfcol_49` AS `bfcol_76`, - `bfcol_52` AS `bfcol_77`, - `bfcol_37` AS `bfcol_78`, - `bfcol_50` * ( - 1.0 - `bfcol_51` - ) AS `bfcol_79`, - `bfcol_49` AS `bfcol_84`, - `bfcol_37` AS `bfcol_85`, - `bfcol_50` * ( - 1.0 - `bfcol_51` - ) AS `bfcol_86`, - EXTRACT(YEAR FROM `bfcol_52`) AS `bfcol_87` - FROM `bfcte_10` - INNER JOIN `bfcte_5` - ON COALESCE(`bfcol_53`, 0) = COALESCE(`bfcol_36`, 0) - AND COALESCE(`bfcol_53`, 1) = COALESCE(`bfcol_36`, 1) - WHERE - `bfcol_49` <> `bfcol_37` -), `bfcte_12` AS ( - SELECT - `bfcol_85`, - `bfcol_84`, - `bfcol_87`, - COALESCE(SUM(`bfcol_86`), 0) AS `bfcol_92` - FROM `bfcte_11` - WHERE - NOT `bfcol_85` IS NULL AND NOT `bfcol_84` IS NULL AND NOT `bfcol_87` IS NULL - GROUP BY - `bfcol_85`, - `bfcol_84`, - `bfcol_87` + `t0`.`N_NATIONKEY` AS `bfuid_col_2251`, + `t0`.`N_NAME` AS `bfuid_col_2252`, + COALESCE(COALESCE(`t0`.`N_NAME` IN ('FRANCE', 'GERMANY'), FALSE), FALSE) AS `bfuid_col_2255` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` ) SELECT - `bfcol_85` AS `SUPP_NATION`, - `bfcol_84` AS `CUST_NATION`, - `bfcol_87` AS `L_YEAR`, - `bfcol_92` AS `REVENUE` -FROM `bfcte_12` -ORDER BY - `bfcol_85` ASC NULLS LAST, - `bfcol_84` ASC NULLS LAST, - `bfcol_87` ASC NULLS LAST \ No newline at end of file + `t33`.`bfuid_col_2433` AS `SUPP_NATION`, + `t33`.`bfuid_col_2397` AS `CUST_NATION`, + `t33`.`bfuid_col_2437` AS `L_YEAR`, + `t33`.`bfuid_col_2438` AS `REVENUE` +FROM ( + SELECT + `t32`.`bfuid_col_2433`, + `t32`.`bfuid_col_2397`, + `t32`.`bfuid_col_2437`, + COALESCE(SUM(`t32`.`bfuid_col_2436`), 0) AS `bfuid_col_2438` + FROM ( + SELECT + `t31`.`bfuid_col_2294` AS `bfuid_col_2397`, + `t31`.`bfuid_col_2330` AS `bfuid_col_2433`, + `t31`.`bfuid_col_2311` * ( + 1.0 - `t31`.`bfuid_col_2312` + ) AS `bfuid_col_2436`, + EXTRACT(year FROM `t31`.`bfuid_col_2316`) AS `bfuid_col_2437` + FROM ( + SELECT + `t30`.`bfuid_col_2252` AS `bfuid_col_2294`, + `t30`.`bfuid_col_2266` AS `bfuid_col_2311`, + `t30`.`bfuid_col_2267` AS `bfuid_col_2312`, + `t30`.`bfuid_col_2271` AS `bfuid_col_2316`, + `t17`.`bfuid_col_2279` AS `bfuid_col_2330`, + `t30`.`bfuid_col_2252` <> `t17`.`bfuid_col_2279` AS `bfuid_col_2333` + FROM ( + SELECT + * + FROM ( + SELECT + `t27`.`bfuid_col_2252`, + `t27`.`bfuid_col_2266`, + `t27`.`bfuid_col_2267`, + `t27`.`bfuid_col_2271`, + `t8`.`S_NATIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t24`.`bfuid_col_2252`, + `t13`.`bfuid_col_2263`, + `t13`.`bfuid_col_2266`, + `t13`.`bfuid_col_2267`, + `t13`.`bfuid_col_2271` + FROM ( + SELECT + * + FROM ( + SELECT + `t21`.`bfuid_col_2252`, + `t9`.`O_ORDERKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t10`.`C_CUSTKEY`, + `t18`.`bfuid_col_2252` + FROM ( + SELECT + `t4`.`C_CUSTKEY`, + `t4`.`C_NATIONKEY` + FROM ( + SELECT + `C_CUSTKEY`, + `C_NATIONKEY` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + ) AS `t10` + INNER JOIN ( + SELECT + `t14`.`bfuid_col_2251`, + `t14`.`bfuid_col_2252` + FROM `t12` AS `t14` + WHERE + `t14`.`bfuid_col_2255` + ) AS `t18` + ON COALESCE(`t10`.`C_NATIONKEY`, 0) = COALESCE(`t18`.`bfuid_col_2251`, 0) + AND COALESCE(`t10`.`C_NATIONKEY`, 1) = COALESCE(`t18`.`bfuid_col_2251`, 1) + ) AS `t19` + ) AS `t21` + INNER JOIN ( + SELECT + `t3`.`O_ORDERKEY`, + `t3`.`O_CUSTKEY` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t9` + ON COALESCE(`t21`.`C_CUSTKEY`, 0) = COALESCE(`t9`.`O_CUSTKEY`, 0) + AND COALESCE(`t21`.`C_CUSTKEY`, 1) = COALESCE(`t9`.`O_CUSTKEY`, 1) + ) AS `t22` + ) AS `t24` + INNER JOIN ( + SELECT + `t2`.`L_ORDERKEY` AS `bfuid_col_2261`, + `t2`.`L_SUPPKEY` AS `bfuid_col_2263`, + `t2`.`L_EXTENDEDPRICE` AS `bfuid_col_2266`, + `t2`.`L_DISCOUNT` AS `bfuid_col_2267`, + `t2`.`L_SHIPDATE` AS `bfuid_col_2271` + FROM ( + SELECT + `L_ORDERKEY`, + `L_SUPPKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT`, + `L_SHIPDATE` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + WHERE + ( + `t2`.`L_SHIPDATE` >= DATE(1995, 1, 1) + ) + AND ( + `t2`.`L_SHIPDATE` <= DATE(1996, 12, 31) + ) + ) AS `t13` + ON COALESCE(`t24`.`O_ORDERKEY`, 0) = COALESCE(`t13`.`bfuid_col_2261`, 0) + AND COALESCE(`t24`.`O_ORDERKEY`, 1) = COALESCE(`t13`.`bfuid_col_2261`, 1) + ) AS `t25` + ) AS `t27` + INNER JOIN ( + SELECT + `t1`.`S_SUPPKEY`, + `t1`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t8` + ON COALESCE(`t27`.`bfuid_col_2263`, 0) = COALESCE(`t8`.`S_SUPPKEY`, 0) + AND COALESCE(`t27`.`bfuid_col_2263`, 1) = COALESCE(`t8`.`S_SUPPKEY`, 1) + ) AS `t28` + ) AS `t30` + INNER JOIN ( + SELECT + `t14`.`bfuid_col_2251` AS `bfuid_col_2278`, + `t14`.`bfuid_col_2252` AS `bfuid_col_2279` + FROM `t12` AS `t14` + WHERE + `t14`.`bfuid_col_2255` + ) AS `t17` + ON COALESCE(`t30`.`S_NATIONKEY`, 0) = COALESCE(`t17`.`bfuid_col_2278`, 0) + AND COALESCE(`t30`.`S_NATIONKEY`, 1) = COALESCE(`t17`.`bfuid_col_2278`, 1) + ) AS `t31` + WHERE + `t31`.`bfuid_col_2333` + ) AS `t32` + GROUP BY + 1, + 2, + 3 +) AS `t33` +WHERE + ( + `t33`.`bfuid_col_2433` + ) IS NOT NULL + AND ( + `t33`.`bfuid_col_2397` + ) IS NOT NULL + AND ( + `t33`.`bfuid_col_2437` + ) IS NOT NULL) AS `t` +ORDER BY `SUPP_NATION` ASC NULLS LAST ,`CUST_NATION` ASC NULLS LAST ,`L_YEAR` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/8/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/8/out.sql index b2fa2971caf..3b270a12a8c 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/8/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/8/out.sql @@ -1,193 +1,239 @@ -WITH `bfcte_0` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_0`, - `N_NAME` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_6` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `N_NATIONKEY` AS `bfcol_4`, - `N_REGIONKEY` AS `bfcol_5` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_6` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `R_REGIONKEY` AS `bfcol_2`, - `R_NAME` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`REGION` AS `bft_5` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `C_CUSTKEY` AS `bfcol_6`, - `C_NATIONKEY` AS `bfcol_7` - FROM `bigframes-dev`.`tpch`.`CUSTOMER` AS `bft_4` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_8`, - `O_CUSTKEY` AS `bfcol_9`, - `O_ORDERDATE` AS `bfcol_10` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_11`, - `S_NATIONKEY` AS `bfcol_12` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_6` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_13`, - `L_PARTKEY` AS `bfcol_14`, - `L_SUPPKEY` AS `bfcol_15`, - `L_EXTENDEDPRICE` AS `bfcol_16`, - `L_DISCOUNT` AS `bfcol_17` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_7` AS ( - SELECT - `P_PARTKEY` AS `bfcol_18`, - `P_TYPE` AS `bfcol_19` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_8` AS ( - SELECT - `bfcol_19` AS `bfcol_20`, - `bfcol_13` AS `bfcol_21`, - `bfcol_15` AS `bfcol_22`, - `bfcol_16` AS `bfcol_23`, - `bfcol_17` AS `bfcol_24` - FROM `bfcte_7` - INNER JOIN `bfcte_6` - ON COALESCE(`bfcol_18`, 0) = COALESCE(`bfcol_14`, 0) - AND COALESCE(`bfcol_18`, 1) = COALESCE(`bfcol_14`, 1) -), `bfcte_9` AS ( - SELECT - `bfcol_20` AS `bfcol_25`, - `bfcol_21` AS `bfcol_26`, - `bfcol_23` AS `bfcol_27`, - `bfcol_24` AS `bfcol_28`, - `bfcol_12` AS `bfcol_29` - FROM `bfcte_8` - INNER JOIN `bfcte_5` - ON COALESCE(`bfcol_22`, 0) = COALESCE(`bfcol_11`, 0) - AND COALESCE(`bfcol_22`, 1) = COALESCE(`bfcol_11`, 1) -), `bfcte_10` AS ( - SELECT - `bfcol_25` AS `bfcol_30`, - `bfcol_27` AS `bfcol_31`, - `bfcol_28` AS `bfcol_32`, - `bfcol_29` AS `bfcol_33`, - `bfcol_9` AS `bfcol_34`, - `bfcol_10` AS `bfcol_35` - FROM `bfcte_9` - INNER JOIN `bfcte_4` - ON COALESCE(`bfcol_26`, 0) = COALESCE(`bfcol_8`, 0) - AND COALESCE(`bfcol_26`, 1) = COALESCE(`bfcol_8`, 1) -), `bfcte_11` AS ( - SELECT - `bfcol_30` AS `bfcol_36`, - `bfcol_31` AS `bfcol_37`, - `bfcol_32` AS `bfcol_38`, - `bfcol_33` AS `bfcol_39`, - `bfcol_35` AS `bfcol_40`, - `bfcol_7` AS `bfcol_41` - FROM `bfcte_10` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_34`, 0) = COALESCE(`bfcol_6`, 0) - AND COALESCE(`bfcol_34`, 1) = COALESCE(`bfcol_6`, 1) -), `bfcte_12` AS ( - SELECT - `bfcol_36` AS `bfcol_42`, - `bfcol_37` AS `bfcol_43`, - `bfcol_38` AS `bfcol_44`, - `bfcol_39` AS `bfcol_45`, - `bfcol_40` AS `bfcol_46`, - `bfcol_5` AS `bfcol_47` - FROM `bfcte_11` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_41`, 0) = COALESCE(`bfcol_4`, 0) - AND COALESCE(`bfcol_41`, 1) = COALESCE(`bfcol_4`, 1) -), `bfcte_13` AS ( - SELECT - `bfcol_42` AS `bfcol_66`, - `bfcol_43` AS `bfcol_67`, - `bfcol_44` AS `bfcol_68`, - `bfcol_45` AS `bfcol_69`, - `bfcol_46` AS `bfcol_70` - FROM `bfcte_12` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_47`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_47`, 1) = COALESCE(`bfcol_2`, 1) - WHERE - `bfcol_3` = 'AMERICA' -), `bfcte_14` AS ( - SELECT - `bfcol_66`, - `bfcol_67`, - `bfcol_68`, - `bfcol_69`, - `bfcol_70`, - `bfcol_0`, - `bfcol_1`, - `bfcol_66` AS `bfcol_76`, - `bfcol_67` AS `bfcol_77`, - `bfcol_68` AS `bfcol_78`, - `bfcol_70` AS `bfcol_79`, - `bfcol_1` AS `bfcol_80`, - ( - `bfcol_70` >= CAST('1995-01-01' AS DATE) - ) - AND ( - `bfcol_70` <= CAST('1996-12-31' AS DATE) - ) AS `bfcol_81`, - `bfcol_67` AS `bfcol_93`, - `bfcol_68` AS `bfcol_94`, - `bfcol_70` AS `bfcol_95`, - `bfcol_1` AS `bfcol_96`, - `bfcol_66` = 'ECONOMY ANODIZED STEEL' AS `bfcol_97`, - `bfcol_67` AS `bfcol_107`, - `bfcol_68` AS `bfcol_108`, - `bfcol_1` AS `bfcol_109`, - EXTRACT(YEAR FROM `bfcol_70`) AS `bfcol_110`, - `bfcol_1` AS `bfcol_115`, - EXTRACT(YEAR FROM `bfcol_70`) AS `bfcol_116`, - `bfcol_67` * ( - 1.0 - `bfcol_68` - ) AS `bfcol_117`, - EXTRACT(YEAR FROM `bfcol_70`) AS `bfcol_121`, - `bfcol_67` * ( - 1.0 - `bfcol_68` - ) AS `bfcol_122`, - IF(`bfcol_1` = 'BRAZIL', `bfcol_67` * ( - 1.0 - `bfcol_68` - ), 0) AS `bfcol_123`, - EXTRACT(YEAR FROM `bfcol_70`) AS `bfcol_127`, - IF(`bfcol_1` = 'BRAZIL', `bfcol_67` * ( - 1.0 - `bfcol_68` - ), 0) AS `bfcol_128`, - `bfcol_67` * ( - 1.0 - `bfcol_68` - ) AS `bfcol_129` - FROM `bfcte_13` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_69`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_69`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - ( - `bfcol_70` >= CAST('1995-01-01' AS DATE) - ) - AND ( - `bfcol_70` <= CAST('1996-12-31' AS DATE) - ) - AND `bfcol_66` = 'ECONOMY ANODIZED STEEL' -), `bfcte_15` AS ( - SELECT - `bfcol_127`, - COALESCE(SUM(`bfcol_128`), 0) AS `bfcol_133`, - COALESCE(SUM(`bfcol_129`), 0) AS `bfcol_134` - FROM `bfcte_14` - WHERE - NOT `bfcol_127` IS NULL +SELECT `O_YEAR`, `MKT_SHARE` FROM (SELECT + `t44`.`bfuid_col_2854` AS `O_YEAR`, + ROUND(ieee_divide(`t44`.`bfuid_col_2858`, `t44`.`bfuid_col_2859`), 2) AS `MKT_SHARE`, + `t44`.`bfuid_col_2854` AS `bfuid_col_2870` +FROM ( + SELECT + `t43`.`bfuid_col_2854`, + COALESCE(SUM(`t43`.`bfuid_col_2856`), 0) AS `bfuid_col_2858`, + COALESCE(SUM(`t43`.`bfuid_col_2857`), 0) AS `bfuid_col_2859` + FROM ( + SELECT + EXTRACT(year FROM `t42`.`bfuid_col_2536`) AS `bfuid_col_2854`, + CASE + WHEN `t42`.`bfuid_col_2555` = 'BRAZIL' + THEN `t42`.`bfuid_col_2514` * ( + 1.0 - `t42`.`bfuid_col_2515` + ) + ELSE 0.0 + END AS `bfuid_col_2856`, + `t42`.`bfuid_col_2514` * ( + 1.0 - `t42`.`bfuid_col_2515` + ) AS `bfuid_col_2857` + FROM ( + SELECT + `t41`.`bfuid_col_2444` AS `bfuid_col_2504`, + `t41`.`bfuid_col_2454` AS `bfuid_col_2514`, + `t41`.`bfuid_col_2455` AS `bfuid_col_2515`, + `t41`.`bfuid_col_2476` AS `bfuid_col_2536`, + `t16`.`N_NAME` AS `bfuid_col_2555`, + ( + `t41`.`bfuid_col_2476` >= DATE(1995, 1, 1) + ) + AND ( + `t41`.`bfuid_col_2476` <= DATE(1996, 12, 31) + ) AS `bfuid_col_2556` + FROM ( + SELECT + `t39`.`bfuid_col_2444`, + `t39`.`bfuid_col_2454`, + `t39`.`bfuid_col_2455`, + `t39`.`bfuid_col_2468`, + `t39`.`bfuid_col_2476` + FROM ( + SELECT + `t38`.`P_TYPE` AS `bfuid_col_2444`, + `t38`.`L_EXTENDEDPRICE` AS `bfuid_col_2454`, + `t38`.`L_DISCOUNT` AS `bfuid_col_2455`, + `t38`.`S_NATIONKEY` AS `bfuid_col_2468`, + `t38`.`O_ORDERDATE` AS `bfuid_col_2476`, + `t17`.`R_NAME` = 'AMERICA' AS `bfuid_col_2494` + FROM ( + SELECT + * + FROM ( + SELECT + `t35`.`P_TYPE`, + `t35`.`L_EXTENDEDPRICE`, + `t35`.`L_DISCOUNT`, + `t35`.`S_NATIONKEY`, + `t35`.`O_ORDERDATE`, + `t18`.`N_REGIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t32`.`P_TYPE`, + `t32`.`L_EXTENDEDPRICE`, + `t32`.`L_DISCOUNT`, + `t32`.`S_NATIONKEY`, + `t32`.`O_ORDERDATE`, + `t19`.`C_NATIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t29`.`P_TYPE`, + `t29`.`L_EXTENDEDPRICE`, + `t29`.`L_DISCOUNT`, + `t29`.`S_NATIONKEY`, + `t20`.`O_CUSTKEY`, + `t20`.`O_ORDERDATE` + FROM ( + SELECT + * + FROM ( + SELECT + `t26`.`P_TYPE`, + `t26`.`L_ORDERKEY`, + `t26`.`L_EXTENDEDPRICE`, + `t26`.`L_DISCOUNT`, + `t21`.`S_NATIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t22`.`P_TYPE`, + `t23`.`L_ORDERKEY`, + `t23`.`L_SUPPKEY`, + `t23`.`L_EXTENDEDPRICE`, + `t23`.`L_DISCOUNT` + FROM ( + SELECT + `t6`.`P_PARTKEY`, + `t6`.`P_TYPE` + FROM ( + SELECT + `P_PARTKEY`, + `P_TYPE` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t6` + ) AS `t22` + INNER JOIN ( + SELECT + `t7`.`L_ORDERKEY`, + `t7`.`L_PARTKEY`, + `t7`.`L_SUPPKEY`, + `t7`.`L_EXTENDEDPRICE`, + `t7`.`L_DISCOUNT` + FROM ( + SELECT + `L_ORDERKEY`, + `L_PARTKEY`, + `L_SUPPKEY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t7` + ) AS `t23` + ON COALESCE(`t22`.`P_PARTKEY`, 0) = COALESCE(`t23`.`L_PARTKEY`, 0) + AND COALESCE(`t22`.`P_PARTKEY`, 1) = COALESCE(`t23`.`L_PARTKEY`, 1) + ) AS `t24` + ) AS `t26` + INNER JOIN ( + SELECT + `t5`.`S_SUPPKEY`, + `t5`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t5` + ) AS `t21` + ON COALESCE(`t26`.`L_SUPPKEY`, 0) = COALESCE(`t21`.`S_SUPPKEY`, 0) + AND COALESCE(`t26`.`L_SUPPKEY`, 1) = COALESCE(`t21`.`S_SUPPKEY`, 1) + ) AS `t27` + ) AS `t29` + INNER JOIN ( + SELECT + `t4`.`O_ORDERKEY`, + `t4`.`O_CUSTKEY`, + `t4`.`O_ORDERDATE` + FROM ( + SELECT + `O_ORDERKEY`, + `O_CUSTKEY`, + `O_ORDERDATE` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + ) AS `t20` + ON COALESCE(`t29`.`L_ORDERKEY`, 0) = COALESCE(`t20`.`O_ORDERKEY`, 0) + AND COALESCE(`t29`.`L_ORDERKEY`, 1) = COALESCE(`t20`.`O_ORDERKEY`, 1) + ) AS `t30` + ) AS `t32` + INNER JOIN ( + SELECT + `t3`.`C_CUSTKEY`, + `t3`.`C_NATIONKEY` + FROM ( + SELECT + `C_CUSTKEY`, + `C_NATIONKEY` + FROM `bigframes-dev.tpch.CUSTOMER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t19` + ON COALESCE(`t32`.`O_CUSTKEY`, 0) = COALESCE(`t19`.`C_CUSTKEY`, 0) + AND COALESCE(`t32`.`O_CUSTKEY`, 1) = COALESCE(`t19`.`C_CUSTKEY`, 1) + ) AS `t33` + ) AS `t35` + INNER JOIN ( + SELECT + `t2`.`N_NATIONKEY`, + `t2`.`N_REGIONKEY` + FROM ( + SELECT + `N_NATIONKEY`, + `N_REGIONKEY` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t18` + ON COALESCE(`t35`.`C_NATIONKEY`, 0) = COALESCE(`t18`.`N_NATIONKEY`, 0) + AND COALESCE(`t35`.`C_NATIONKEY`, 1) = COALESCE(`t18`.`N_NATIONKEY`, 1) + ) AS `t36` + ) AS `t38` + INNER JOIN ( + SELECT + `t1`.`R_REGIONKEY`, + `t1`.`R_NAME` + FROM ( + SELECT + `R_REGIONKEY`, + `R_NAME` + FROM `bigframes-dev.tpch.REGION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t17` + ON COALESCE(`t38`.`N_REGIONKEY`, 0) = COALESCE(`t17`.`R_REGIONKEY`, 0) + AND COALESCE(`t38`.`N_REGIONKEY`, 1) = COALESCE(`t17`.`R_REGIONKEY`, 1) + ) AS `t39` + WHERE + `t39`.`bfuid_col_2494` + ) AS `t41` + INNER JOIN ( + SELECT + `t0`.`N_NATIONKEY`, + `t0`.`N_NAME` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t16` + ON COALESCE(`t41`.`bfuid_col_2468`, 0) = COALESCE(`t16`.`N_NATIONKEY`, 0) + AND COALESCE(`t41`.`bfuid_col_2468`, 1) = COALESCE(`t16`.`N_NATIONKEY`, 1) + ) AS `t42` + WHERE + `t42`.`bfuid_col_2556` AND `t42`.`bfuid_col_2504` = 'ECONOMY ANODIZED STEEL' + ) AS `t43` GROUP BY - `bfcol_127` -) -SELECT - `bfcol_127` AS `O_YEAR`, - ROUND(IEEE_DIVIDE(`bfcol_133`, `bfcol_134`), 2) AS `MKT_SHARE` -FROM `bfcte_15` -ORDER BY - `bfcol_127` ASC NULLS LAST, - `bfcol_127` ASC NULLS LAST \ No newline at end of file + 1 +) AS `t44` +WHERE + ( + `t44`.`bfuid_col_2854` + ) IS NOT NULL) AS `t` +ORDER BY `O_YEAR` ASC NULLS LAST ,`bfuid_col_2870` ASC NULLS LAST \ No newline at end of file diff --git a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/9/out.sql b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/9/out.sql index 7f886aa7ce5..9b5b298996a 100644 --- a/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/9/out.sql +++ b/tests/unit/core/compile/sqlglot/tpch/snapshots/test_tpch/test_tpch_query/9/out.sql @@ -1,150 +1,191 @@ -WITH `bfcte_0` AS ( +SELECT `NATION`, `O_YEAR`, `SUM_PROFIT` FROM (SELECT + `t32`.`bfuid_col_3032` AS `NATION`, + `t32`.`bfuid_col_3035` AS `O_YEAR`, + ROUND(`t32`.`bfuid_col_3037`, 2) AS `SUM_PROFIT`, + `t32`.`bfuid_col_3035` AS `bfuid_col_3045`, + `t32`.`bfuid_col_3032` AS `bfuid_col_3046` +FROM ( SELECT - `N_NATIONKEY` AS `bfcol_0`, - `N_NAME` AS `bfcol_1` - FROM `bigframes-dev`.`tpch`.`NATION` AS `bft_5` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_1` AS ( - SELECT - `O_ORDERKEY` AS `bfcol_2`, - `O_ORDERDATE` AS `bfcol_3` - FROM `bigframes-dev`.`tpch`.`ORDERS` AS `bft_4` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_2` AS ( - SELECT - `S_SUPPKEY` AS `bfcol_4`, - `S_NATIONKEY` AS `bfcol_5` - FROM `bigframes-dev`.`tpch`.`SUPPLIER` AS `bft_3` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_3` AS ( - SELECT - `PS_PARTKEY` AS `bfcol_6`, - `PS_SUPPKEY` AS `bfcol_7`, - `PS_SUPPLYCOST` AS `bfcol_8` - FROM `bigframes-dev`.`tpch`.`PARTSUPP` AS `bft_2` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_4` AS ( - SELECT - `L_ORDERKEY` AS `bfcol_9`, - `L_PARTKEY` AS `bfcol_10`, - `L_SUPPKEY` AS `bfcol_11`, - `L_QUANTITY` AS `bfcol_12`, - `L_EXTENDEDPRICE` AS `bfcol_13`, - `L_DISCOUNT` AS `bfcol_14` - FROM `bigframes-dev`.`tpch`.`LINEITEM` AS `bft_1` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_5` AS ( - SELECT - `P_PARTKEY` AS `bfcol_15`, - `P_NAME` AS `bfcol_16` - FROM `bigframes-dev`.`tpch`.`PART` AS `bft_0` FOR SYSTEM_TIME AS OF '2026-03-10T18:00:00' -), `bfcte_6` AS ( - SELECT - `bfcol_16` AS `bfcol_17`, - `bfcol_9` AS `bfcol_18`, - `bfcol_10` AS `bfcol_19`, - `bfcol_11` AS `bfcol_20`, - `bfcol_12` AS `bfcol_21`, - `bfcol_13` AS `bfcol_22`, - `bfcol_14` AS `bfcol_23` - FROM `bfcte_5` - INNER JOIN `bfcte_4` - ON COALESCE(`bfcol_15`, 0) = COALESCE(`bfcol_10`, 0) - AND COALESCE(`bfcol_15`, 1) = COALESCE(`bfcol_10`, 1) -), `bfcte_7` AS ( - SELECT - `bfcol_17` AS `bfcol_24`, - `bfcol_18` AS `bfcol_25`, - `bfcol_20` AS `bfcol_26`, - `bfcol_21` AS `bfcol_27`, - `bfcol_22` AS `bfcol_28`, - `bfcol_23` AS `bfcol_29`, - `bfcol_8` AS `bfcol_30` - FROM `bfcte_6` - INNER JOIN `bfcte_3` - ON COALESCE(`bfcol_20`, 0) = COALESCE(`bfcol_7`, 0) - AND COALESCE(`bfcol_20`, 1) = COALESCE(`bfcol_7`, 1) - AND COALESCE(`bfcol_19`, 0) = COALESCE(`bfcol_6`, 0) - AND COALESCE(`bfcol_19`, 1) = COALESCE(`bfcol_6`, 1) -), `bfcte_8` AS ( - SELECT - `bfcol_24` AS `bfcol_31`, - `bfcol_25` AS `bfcol_32`, - `bfcol_27` AS `bfcol_33`, - `bfcol_28` AS `bfcol_34`, - `bfcol_29` AS `bfcol_35`, - `bfcol_30` AS `bfcol_36`, - `bfcol_5` AS `bfcol_37` - FROM `bfcte_7` - INNER JOIN `bfcte_2` - ON COALESCE(`bfcol_26`, 0) = COALESCE(`bfcol_4`, 0) - AND COALESCE(`bfcol_26`, 1) = COALESCE(`bfcol_4`, 1) -), `bfcte_9` AS ( - SELECT - `bfcol_31` AS `bfcol_38`, - `bfcol_33` AS `bfcol_39`, - `bfcol_34` AS `bfcol_40`, - `bfcol_35` AS `bfcol_41`, - `bfcol_36` AS `bfcol_42`, - `bfcol_37` AS `bfcol_43`, - `bfcol_3` AS `bfcol_44` - FROM `bfcte_8` - INNER JOIN `bfcte_1` - ON COALESCE(`bfcol_32`, 0) = COALESCE(`bfcol_2`, 0) - AND COALESCE(`bfcol_32`, 1) = COALESCE(`bfcol_2`, 1) -), `bfcte_10` AS ( - SELECT - `bfcol_38`, - `bfcol_39`, - `bfcol_40`, - `bfcol_41`, - `bfcol_42`, - `bfcol_43`, - `bfcol_44`, - `bfcol_0`, - `bfcol_1`, - `bfcol_39` AS `bfcol_52`, - `bfcol_40` AS `bfcol_53`, - `bfcol_41` AS `bfcol_54`, - `bfcol_42` AS `bfcol_55`, - `bfcol_44` AS `bfcol_56`, - `bfcol_1` AS `bfcol_57`, - REGEXP_CONTAINS(`bfcol_38`, 'green') AS `bfcol_58`, - `bfcol_39` AS `bfcol_72`, - `bfcol_40` AS `bfcol_73`, - `bfcol_41` AS `bfcol_74`, - `bfcol_42` AS `bfcol_75`, - `bfcol_1` AS `bfcol_76`, - EXTRACT(YEAR FROM `bfcol_44`) AS `bfcol_77`, - `bfcol_1` AS `bfcol_84`, - EXTRACT(YEAR FROM `bfcol_44`) AS `bfcol_85`, - ( - `bfcol_40` * ( - 1 - `bfcol_41` - ) - ) - ( - `bfcol_42` * `bfcol_39` - ) AS `bfcol_86` - FROM `bfcte_9` - INNER JOIN `bfcte_0` - ON COALESCE(`bfcol_43`, 0) = COALESCE(`bfcol_0`, 0) - AND COALESCE(`bfcol_43`, 1) = COALESCE(`bfcol_0`, 1) - WHERE - REGEXP_CONTAINS(`bfcol_38`, 'green') -), `bfcte_11` AS ( - SELECT - `bfcol_84`, - `bfcol_85`, - COALESCE(SUM(`bfcol_86`), 0) AS `bfcol_90` - FROM `bfcte_10` - WHERE - NOT `bfcol_84` IS NULL AND NOT `bfcol_85` IS NULL + `t31`.`bfuid_col_3032`, + `t31`.`bfuid_col_3035`, + COALESCE(SUM(`t31`.`bfuid_col_3036`), 0) AS `bfuid_col_3037` + FROM ( + SELECT + `t30`.`bfuid_col_2919` AS `bfuid_col_3032`, + EXTRACT(year FROM `t30`.`bfuid_col_2913`) AS `bfuid_col_3035`, + ( + `t30`.`bfuid_col_2886` * ( + 1 - `t30`.`bfuid_col_2887` + ) + ) - ( + `t30`.`bfuid_col_2900` * `t30`.`bfuid_col_2885` + ) AS `bfuid_col_3036` + FROM ( + SELECT + `t29`.`L_QUANTITY` AS `bfuid_col_2885`, + `t29`.`L_EXTENDEDPRICE` AS `bfuid_col_2886`, + `t29`.`L_DISCOUNT` AS `bfuid_col_2887`, + `t29`.`PS_SUPPLYCOST` AS `bfuid_col_2900`, + `t29`.`O_ORDERDATE` AS `bfuid_col_2913`, + `t12`.`N_NAME` AS `bfuid_col_2919`, + regexp_contains(`t29`.`P_NAME`, 'green') AS `bfuid_col_2922` + FROM ( + SELECT + * + FROM ( + SELECT + `t26`.`P_NAME`, + `t26`.`L_QUANTITY`, + `t26`.`L_EXTENDEDPRICE`, + `t26`.`L_DISCOUNT`, + `t26`.`PS_SUPPLYCOST`, + `t26`.`S_NATIONKEY`, + `t13`.`O_ORDERDATE` + FROM ( + SELECT + * + FROM ( + SELECT + `t23`.`P_NAME`, + `t23`.`L_ORDERKEY`, + `t23`.`L_QUANTITY`, + `t23`.`L_EXTENDEDPRICE`, + `t23`.`L_DISCOUNT`, + `t23`.`PS_SUPPLYCOST`, + `t14`.`S_NATIONKEY` + FROM ( + SELECT + * + FROM ( + SELECT + `t20`.`P_NAME`, + `t20`.`L_ORDERKEY`, + `t20`.`L_SUPPKEY`, + `t20`.`L_QUANTITY`, + `t20`.`L_EXTENDEDPRICE`, + `t20`.`L_DISCOUNT`, + `t15`.`PS_SUPPLYCOST` + FROM ( + SELECT + * + FROM ( + SELECT + `t16`.`P_NAME`, + `t17`.`L_ORDERKEY`, + `t17`.`L_PARTKEY`, + `t17`.`L_SUPPKEY`, + `t17`.`L_QUANTITY`, + `t17`.`L_EXTENDEDPRICE`, + `t17`.`L_DISCOUNT` + FROM ( + SELECT + `t4`.`P_PARTKEY`, + `t4`.`P_NAME` + FROM ( + SELECT + `P_PARTKEY`, + `P_NAME` + FROM `bigframes-dev.tpch.PART` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t4` + ) AS `t16` + INNER JOIN ( + SELECT + `t5`.`L_ORDERKEY`, + `t5`.`L_PARTKEY`, + `t5`.`L_SUPPKEY`, + `t5`.`L_QUANTITY`, + `t5`.`L_EXTENDEDPRICE`, + `t5`.`L_DISCOUNT` + FROM ( + SELECT + `L_ORDERKEY`, + `L_PARTKEY`, + `L_SUPPKEY`, + `L_QUANTITY`, + `L_EXTENDEDPRICE`, + `L_DISCOUNT` + FROM `bigframes-dev.tpch.LINEITEM` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t5` + ) AS `t17` + ON COALESCE(`t16`.`P_PARTKEY`, 0) = COALESCE(`t17`.`L_PARTKEY`, 0) + AND COALESCE(`t16`.`P_PARTKEY`, 1) = COALESCE(`t17`.`L_PARTKEY`, 1) + ) AS `t18` + ) AS `t20` + INNER JOIN ( + SELECT + `t3`.`PS_PARTKEY`, + `t3`.`PS_SUPPKEY`, + `t3`.`PS_SUPPLYCOST` + FROM ( + SELECT + `PS_PARTKEY`, + `PS_SUPPKEY`, + `PS_SUPPLYCOST` + FROM `bigframes-dev.tpch.PARTSUPP` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t3` + ) AS `t15` + ON COALESCE(`t20`.`L_SUPPKEY`, 0) = COALESCE(`t15`.`PS_SUPPKEY`, 0) + AND COALESCE(`t20`.`L_SUPPKEY`, 1) = COALESCE(`t15`.`PS_SUPPKEY`, 1) + AND COALESCE(`t20`.`L_PARTKEY`, 0) = COALESCE(`t15`.`PS_PARTKEY`, 0) + AND COALESCE(`t20`.`L_PARTKEY`, 1) = COALESCE(`t15`.`PS_PARTKEY`, 1) + ) AS `t21` + ) AS `t23` + INNER JOIN ( + SELECT + `t2`.`S_SUPPKEY`, + `t2`.`S_NATIONKEY` + FROM ( + SELECT + `S_SUPPKEY`, + `S_NATIONKEY` + FROM `bigframes-dev.tpch.SUPPLIER` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t2` + ) AS `t14` + ON COALESCE(`t23`.`L_SUPPKEY`, 0) = COALESCE(`t14`.`S_SUPPKEY`, 0) + AND COALESCE(`t23`.`L_SUPPKEY`, 1) = COALESCE(`t14`.`S_SUPPKEY`, 1) + ) AS `t24` + ) AS `t26` + INNER JOIN ( + SELECT + `t1`.`O_ORDERKEY`, + `t1`.`O_ORDERDATE` + FROM ( + SELECT + `O_ORDERKEY`, + `O_ORDERDATE` + FROM `bigframes-dev.tpch.ORDERS` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t1` + ) AS `t13` + ON COALESCE(`t26`.`L_ORDERKEY`, 0) = COALESCE(`t13`.`O_ORDERKEY`, 0) + AND COALESCE(`t26`.`L_ORDERKEY`, 1) = COALESCE(`t13`.`O_ORDERKEY`, 1) + ) AS `t27` + ) AS `t29` + INNER JOIN ( + SELECT + `t0`.`N_NATIONKEY`, + `t0`.`N_NAME` + FROM ( + SELECT + `N_NATIONKEY`, + `N_NAME` + FROM `bigframes-dev.tpch.NATION` FOR SYSTEM_TIME AS OF CAST('2026-03-10T18:00:00' AS DATETIME) + ) AS `t0` + ) AS `t12` + ON COALESCE(`t29`.`S_NATIONKEY`, 0) = COALESCE(`t12`.`N_NATIONKEY`, 0) + AND COALESCE(`t29`.`S_NATIONKEY`, 1) = COALESCE(`t12`.`N_NATIONKEY`, 1) + ) AS `t30` + WHERE + `t30`.`bfuid_col_2922` + ) AS `t31` GROUP BY - `bfcol_84`, - `bfcol_85` -) -SELECT - `bfcol_84` AS `NATION`, - `bfcol_85` AS `O_YEAR`, - ROUND(`bfcol_90`, 2) AS `SUM_PROFIT` -FROM `bfcte_11` -ORDER BY - `bfcol_84` ASC NULLS LAST, - `bfcol_85` DESC, - `bfcol_84` ASC NULLS LAST, - `bfcol_85` ASC NULLS LAST \ No newline at end of file + 1, + 2 +) AS `t32` +WHERE + ( + `t32`.`bfuid_col_3032` + ) IS NOT NULL + AND ( + `t32`.`bfuid_col_3035` + ) IS NOT NULL) AS `t` +ORDER BY `NATION` ASC NULLS LAST ,`O_YEAR` DESC NULLS LAST ,`bfuid_col_3046` ASC NULLS LAST ,`bfuid_col_3045` ASC NULLS LAST \ No newline at end of file