From 8e5cc3b635732812285089adedcd8cd9544f5370 Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Fri, 10 May 2024 17:47:02 -0400 Subject: [PATCH] fix(bigquery): strip whitespace from bigquery field names (#9160) Removes extra whitespace from the generated field name. xref #9112 but doesn't strictly solve the issue --- ibis/backends/bigquery/compiler.py | 2 +- .../test_approx/filter-approx_median/out.sql | 2 +- .../test_approx/filter-approx_nunique/out.sql | 2 +- .../snapshots/test_compiler/test_binary/out.sql | 2 +- .../test_compiler/test_bit/filter-bit_and/out.sql | 2 +- .../test_compiler/test_bit/filter-bit_or/out.sql | 2 +- .../test_compiler/test_bit/filter-bit_xor/out.sql | 2 +- .../test_bool_reducers_where_conj/out.sql | 2 +- .../test_bool_reducers_where_simple/out.sql | 2 +- .../test_compiler/test_cast_float_to_int/out.sql | 2 +- .../snapshots/test_compiler/test_cov/pop/out.sql | 2 +- .../snapshots/test_compiler/test_cov/sample/out.sql | 2 +- .../test_compiler/test_day_of_week/date/index.sql | 2 +- .../test_compiler/test_day_of_week/date/name.sql | 2 +- .../test_day_of_week/datetime/index.sql | 2 +- .../test_day_of_week/datetime/name.sql | 2 +- .../test_day_of_week/string_date/index.sql | 2 +- .../test_day_of_week/string_date/name.sql | 2 +- .../test_day_of_week/string_timestamp/index.sql | 2 +- .../test_day_of_week/string_timestamp/name.sql | 2 +- .../test_day_of_week/timestamp/index.sql | 2 +- .../test_day_of_week/timestamp/name.sql | 2 +- .../test_day_of_week/timestamp_date/index.sql | 2 +- .../test_day_of_week/timestamp_date/name.sql | 2 +- .../test_divide_by_zero/floordiv/out.sql | 2 +- .../test_divide_by_zero/truediv/out.sql | 2 +- .../test_compiler/test_literal_year/date/out.sql | 2 +- .../test_literal_year/datetime/out.sql | 2 +- .../test_literal_year/string_date/out.sql | 2 +- .../test_literal_year/string_timestamp/out.sql | 2 +- .../test_literal_year/timestamp/out.sql | 2 +- .../test_literal_year/timestamp_date/out.sql | 2 +- .../test_to_timestamp_no_timezone/out.sql | 2 +- .../test_to_timestamp_timezone/out.sql | 2 +- ibis/backends/bigquery/tests/unit/test_compiler.py | 13 +++++++++++++ .../test_builtin/test_farm_fingerprint/out.sql | 2 +- 36 files changed, 48 insertions(+), 35 deletions(-) diff --git a/ibis/backends/bigquery/compiler.py b/ibis/backends/bigquery/compiler.py index 633d12708861..2f4160ae05cc 100644 --- a/ibis/backends/bigquery/compiler.py +++ b/ibis/backends/bigquery/compiler.py @@ -673,7 +673,7 @@ def visit_HashBytes(self, op, *, arg, how): @staticmethod def _gen_valid_name(name: str) -> str: - return "_".join(_NAME_REGEX.findall(name)) or "tmp" + return "_".join(map(str.strip, _NAME_REGEX.findall(name))) or "tmp" def visit_CountStar(self, op, *, arg, where): if where is not None: diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_median/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_median/out.sql index 8c5a9fb3f8dc..96f8187cf3f0 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_median/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_median/out.sql @@ -1,3 +1,3 @@ SELECT - approx_quantiles(IF(`t0`.`month` > 0, `t0`.`double_col`, NULL), IF(`t0`.`month` > 0, 2, NULL))[offset(1)] AS `ApproxMedian_double_col_ Greater_month_ 0` + approx_quantiles(IF(`t0`.`month` > 0, `t0`.`double_col`, NULL), IF(`t0`.`month` > 0, 2, NULL))[offset(1)] AS `ApproxMedian_double_col_Greater_month_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_nunique/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_nunique/out.sql index 68d924daea71..922db1fd246d 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_nunique/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_approx/filter-approx_nunique/out.sql @@ -1,3 +1,3 @@ SELECT - APPROX_COUNT_DISTINCT(IF(`t0`.`month` > 0, `t0`.`double_col`, NULL)) AS `ApproxCountDistinct_double_col_ Greater_month_ 0` + APPROX_COUNT_DISTINCT(IF(`t0`.`month` > 0, `t0`.`double_col`, NULL)) AS `ApproxCountDistinct_double_col_Greater_month_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_binary/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_binary/out.sql index f385d2b9a02f..88ae6929eb21 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_binary/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_binary/out.sql @@ -1,3 +1,3 @@ SELECT - CAST(`t0`.`value` AS BYTES) AS `Cast_value_ binary` + CAST(`t0`.`value` AS BYTES) AS `Cast_value_binary` FROM `t` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_and/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_and/out.sql index b416c9f9136b..6e42e7e72ef2 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_and/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_and/out.sql @@ -1,3 +1,3 @@ SELECT - bit_and(IF(`t0`.`bigint_col` > 0, `t0`.`int_col`, NULL)) AS `BitAnd_int_col_ Greater_bigint_col_ 0` + bit_and(IF(`t0`.`bigint_col` > 0, `t0`.`int_col`, NULL)) AS `BitAnd_int_col_Greater_bigint_col_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_or/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_or/out.sql index 533efe55deab..bd09e6029a05 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_or/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_or/out.sql @@ -1,3 +1,3 @@ SELECT - bit_or(IF(`t0`.`bigint_col` > 0, `t0`.`int_col`, NULL)) AS `BitOr_int_col_ Greater_bigint_col_ 0` + bit_or(IF(`t0`.`bigint_col` > 0, `t0`.`int_col`, NULL)) AS `BitOr_int_col_Greater_bigint_col_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_xor/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_xor/out.sql index 6e8799e46de4..92c8d1d9d3db 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_xor/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bit/filter-bit_xor/out.sql @@ -1,3 +1,3 @@ SELECT - bit_xor(IF(`t0`.`bigint_col` > 0, `t0`.`int_col`, NULL)) AS `BitXor_int_col_ Greater_bigint_col_ 0` + bit_xor(IF(`t0`.`bigint_col` > 0, `t0`.`int_col`, NULL)) AS `BitXor_int_col_Greater_bigint_col_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_conj/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_conj/out.sql index 3dcdc77c2b16..04f02e1c03b4 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_conj/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_conj/out.sql @@ -9,5 +9,5 @@ SELECT CAST(`t0`.`bool_col` AS INT64), NULL ) - ) AS `Sum_bool_col_ And_Greater_month_ 6_ Less_month_ 10` + ) AS `Sum_bool_col_And_Greater_month_6_Less_month_10` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_simple/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_simple/out.sql index 6bc6dd23ed12..213a3b9e5dbb 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_simple/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_bool_reducers_where_simple/out.sql @@ -1,3 +1,3 @@ SELECT - AVG(IF(`t0`.`month` > 6, CAST(`t0`.`bool_col` AS INT64), NULL)) AS `Mean_bool_col_ Greater_month_ 6` + AVG(IF(`t0`.`month` > 6, CAST(`t0`.`bool_col` AS INT64), NULL)) AS `Mean_bool_col_Greater_month_6` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cast_float_to_int/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cast_float_to_int/out.sql index 3ebdfd612e9d..e76ef1f2e63e 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cast_float_to_int/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cast_float_to_int/out.sql @@ -1,3 +1,3 @@ SELECT - CAST(trunc(`t0`.`double_col`) AS INT64) AS `Cast_double_col_ int64` + CAST(trunc(`t0`.`double_col`) AS INT64) AS `Cast_double_col_int64` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/pop/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/pop/out.sql index e9c15dc26bb2..919a4c78d61e 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/pop/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/pop/out.sql @@ -1,3 +1,3 @@ SELECT - COVAR_POP(`t0`.`double_col`, `t0`.`double_col`) AS `Covariance_double_col_ double_col` + COVAR_POP(`t0`.`double_col`, `t0`.`double_col`) AS `Covariance_double_col_double_col` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/sample/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/sample/out.sql index 795180ad2157..d43e0f8eefed 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/sample/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_cov/sample/out.sql @@ -1,3 +1,3 @@ SELECT - COVAR_SAMP(`t0`.`double_col`, `t0`.`double_col`) AS `Covariance_double_col_ double_col` + COVAR_SAMP(`t0`.`double_col`, `t0`.`double_col`) AS `Covariance_double_col_double_col` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/index.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/index.sql index 06f99572d914..9732be5c8eea 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/index.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/index.sql @@ -1,2 +1,2 @@ SELECT - MOD(EXTRACT(dayofweek FROM DATE(2017, 1, 1)) + 5, 7) AS `DayOfWeekIndex_datetime_date_2017_ 1_ 1` \ No newline at end of file + MOD(EXTRACT(dayofweek FROM DATE(2017, 1, 1)) + 5, 7) AS `DayOfWeekIndex_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/name.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/name.sql index f207aa60fec7..25523cea7b39 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/name.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/date/name.sql @@ -1,2 +1,2 @@ SELECT - INITCAP(CAST(DATE(2017, 1, 1) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_date_2017_ 1_ 1` \ No newline at end of file + INITCAP(CAST(DATE(2017, 1, 1) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/index.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/index.sql index 3bc9fc10069f..2c01d43964b6 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/index.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/index.sql @@ -1,2 +1,2 @@ SELECT - MOD(EXTRACT(dayofweek FROM datetime('2017-01-01T04:55:59')) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + MOD(EXTRACT(dayofweek FROM datetime('2017-01-01T04:55:59')) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/name.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/name.sql index fed76c0c815d..ed2e29f823ca 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/name.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/datetime/name.sql @@ -1,2 +1,2 @@ SELECT - INITCAP(CAST(datetime('2017-01-01T04:55:59') AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + INITCAP(CAST(datetime('2017-01-01T04:55:59') AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/index.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/index.sql index 06f99572d914..9732be5c8eea 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/index.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/index.sql @@ -1,2 +1,2 @@ SELECT - MOD(EXTRACT(dayofweek FROM DATE(2017, 1, 1)) + 5, 7) AS `DayOfWeekIndex_datetime_date_2017_ 1_ 1` \ No newline at end of file + MOD(EXTRACT(dayofweek FROM DATE(2017, 1, 1)) + 5, 7) AS `DayOfWeekIndex_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/name.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/name.sql index f207aa60fec7..25523cea7b39 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/name.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_date/name.sql @@ -1,2 +1,2 @@ SELECT - INITCAP(CAST(DATE(2017, 1, 1) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_date_2017_ 1_ 1` \ No newline at end of file + INITCAP(CAST(DATE(2017, 1, 1) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/index.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/index.sql index 3bc9fc10069f..2c01d43964b6 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/index.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/index.sql @@ -1,2 +1,2 @@ SELECT - MOD(EXTRACT(dayofweek FROM datetime('2017-01-01T04:55:59')) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + MOD(EXTRACT(dayofweek FROM datetime('2017-01-01T04:55:59')) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/name.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/name.sql index fed76c0c815d..ed2e29f823ca 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/name.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/string_timestamp/name.sql @@ -1,2 +1,2 @@ SELECT - INITCAP(CAST(datetime('2017-01-01T04:55:59') AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + INITCAP(CAST(datetime('2017-01-01T04:55:59') AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/index.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/index.sql index 3bc9fc10069f..2c01d43964b6 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/index.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/index.sql @@ -1,2 +1,2 @@ SELECT - MOD(EXTRACT(dayofweek FROM datetime('2017-01-01T04:55:59')) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + MOD(EXTRACT(dayofweek FROM datetime('2017-01-01T04:55:59')) + 5, 7) AS `DayOfWeekIndex_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/name.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/name.sql index fed76c0c815d..ed2e29f823ca 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/name.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp/name.sql @@ -1,2 +1,2 @@ SELECT - INITCAP(CAST(datetime('2017-01-01T04:55:59') AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + INITCAP(CAST(datetime('2017-01-01T04:55:59') AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/index.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/index.sql index 06f99572d914..9732be5c8eea 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/index.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/index.sql @@ -1,2 +1,2 @@ SELECT - MOD(EXTRACT(dayofweek FROM DATE(2017, 1, 1)) + 5, 7) AS `DayOfWeekIndex_datetime_date_2017_ 1_ 1` \ No newline at end of file + MOD(EXTRACT(dayofweek FROM DATE(2017, 1, 1)) + 5, 7) AS `DayOfWeekIndex_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/name.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/name.sql index f207aa60fec7..25523cea7b39 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/name.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_day_of_week/timestamp_date/name.sql @@ -1,2 +1,2 @@ SELECT - INITCAP(CAST(DATE(2017, 1, 1) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_date_2017_ 1_ 1` \ No newline at end of file + INITCAP(CAST(DATE(2017, 1, 1) AS STRING FORMAT 'DAY')) AS `DayOfWeekName_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/floordiv/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/floordiv/out.sql index 545d71968181..89ff23c572b6 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/floordiv/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/floordiv/out.sql @@ -1,3 +1,3 @@ SELECT - CAST(FLOOR(ieee_divide(`t0`.`double_col`, 0)) AS INT64) AS `FloorDivide_double_col_ 0` + CAST(FLOOR(ieee_divide(`t0`.`double_col`, 0)) AS INT64) AS `FloorDivide_double_col_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/truediv/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/truediv/out.sql index fd497dabba49..5f1b526fbf75 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/truediv/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_divide_by_zero/truediv/out.sql @@ -1,3 +1,3 @@ SELECT - ieee_divide(`t0`.`double_col`, 0) AS `Divide_double_col_ 0` + ieee_divide(`t0`.`double_col`, 0) AS `Divide_double_col_0` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/date/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/date/out.sql index df8033bc163e..24801fd14720 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/date/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/date/out.sql @@ -1,2 +1,2 @@ SELECT - EXTRACT(year FROM DATE(2017, 1, 1)) AS `ExtractYear_datetime_date_2017_ 1_ 1` \ No newline at end of file + EXTRACT(year FROM DATE(2017, 1, 1)) AS `ExtractYear_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/datetime/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/datetime/out.sql index afa341282049..f0e626ce7758 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/datetime/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/datetime/out.sql @@ -1,2 +1,2 @@ SELECT - EXTRACT(year FROM datetime('2017-01-01T04:55:59')) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + EXTRACT(year FROM datetime('2017-01-01T04:55:59')) AS `ExtractYear_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_date/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_date/out.sql index df8033bc163e..24801fd14720 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_date/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_date/out.sql @@ -1,2 +1,2 @@ SELECT - EXTRACT(year FROM DATE(2017, 1, 1)) AS `ExtractYear_datetime_date_2017_ 1_ 1` \ No newline at end of file + EXTRACT(year FROM DATE(2017, 1, 1)) AS `ExtractYear_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_timestamp/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_timestamp/out.sql index afa341282049..f0e626ce7758 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_timestamp/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/string_timestamp/out.sql @@ -1,2 +1,2 @@ SELECT - EXTRACT(year FROM datetime('2017-01-01T04:55:59')) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + EXTRACT(year FROM datetime('2017-01-01T04:55:59')) AS `ExtractYear_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp/out.sql index afa341282049..f0e626ce7758 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp/out.sql @@ -1,2 +1,2 @@ SELECT - EXTRACT(year FROM datetime('2017-01-01T04:55:59')) AS `ExtractYear_datetime_datetime_2017_ 1_ 1_ 4_ 55_ 59` \ No newline at end of file + EXTRACT(year FROM datetime('2017-01-01T04:55:59')) AS `ExtractYear_datetime_datetime_2017_1_1_4_55_59` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp_date/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp_date/out.sql index df8033bc163e..24801fd14720 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp_date/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_literal_year/timestamp_date/out.sql @@ -1,2 +1,2 @@ SELECT - EXTRACT(year FROM DATE(2017, 1, 1)) AS `ExtractYear_datetime_date_2017_ 1_ 1` \ No newline at end of file + EXTRACT(year FROM DATE(2017, 1, 1)) AS `ExtractYear_datetime_date_2017_1_1` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_no_timezone/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_no_timezone/out.sql index 78b8c273dbcf..04b417384f0a 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_no_timezone/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_no_timezone/out.sql @@ -1,3 +1,3 @@ SELECT - parse_timestamp('%F', `t0`.`date_string_col`, 'UTC') AS `StringToTimestamp_date_string_col_ '%F'` + parse_timestamp('%F', `t0`.`date_string_col`, 'UTC') AS `StringToTimestamp_date_string_col_'%F'` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_timezone/out.sql b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_timezone/out.sql index 01ed85e47093..3e79c2e21179 100644 --- a/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_timezone/out.sql +++ b/ibis/backends/bigquery/tests/unit/snapshots/test_compiler/test_to_timestamp_timezone/out.sql @@ -1,3 +1,3 @@ SELECT - parse_timestamp('%F %Z', CONCAT(`t0`.`date_string_col`, ' America/New_York'), 'UTC') AS `StringToTimestamp_StringConcat_ '%F %Z'` + parse_timestamp('%F %Z', CONCAT(`t0`.`date_string_col`, ' America/New_York'), 'UTC') AS `StringToTimestamp_StringConcat_'%F %Z'` FROM `functional_alltypes` AS `t0` \ No newline at end of file diff --git a/ibis/backends/bigquery/tests/unit/test_compiler.py b/ibis/backends/bigquery/tests/unit/test_compiler.py index 42df4c2c708d..bc231269ef06 100644 --- a/ibis/backends/bigquery/tests/unit/test_compiler.py +++ b/ibis/backends/bigquery/tests/unit/test_compiler.py @@ -13,6 +13,7 @@ import ibis.expr.datatypes as dt import ibis.expr.operations as ops from ibis import _ +from ibis.backends.bigquery.compiler import BigQueryCompiler from ibis.common.annotations import ValidationError to_sql = ibis.bigquery.compile @@ -633,3 +634,15 @@ def test_unnest(snapshot): ).select(level_two=lambda t: t.level_one.unnest()) ) snapshot.assert_match(result, "out_two_unnests.sql") + + +@pytest.mark.parametrize( + "fieldname, expected", + [ + ("TryCast(b, Float64)", "TryCast_b_Float64"), + ("Cast(b, Int64)", "Cast_b_Int64"), + ("that, is, a, lot, of, spaces", "that_is_a_lot_of_spaces"), + ], +) +def test_field_names_strip_whitespace(fieldname, expected): + assert BigQueryCompiler._gen_valid_name(fieldname) == expected diff --git a/ibis/backends/bigquery/tests/unit/udf/snapshots/test_builtin/test_farm_fingerprint/out.sql b/ibis/backends/bigquery/tests/unit/udf/snapshots/test_builtin/test_farm_fingerprint/out.sql index 49c49900b198..f82a18767bb6 100644 --- a/ibis/backends/bigquery/tests/unit/udf/snapshots/test_builtin/test_farm_fingerprint/out.sql +++ b/ibis/backends/bigquery/tests/unit/udf/snapshots/test_builtin/test_farm_fingerprint/out.sql @@ -1,2 +1,2 @@ SELECT - farm_fingerprint(CAST('48656c6c6f2c20576f726c6421' AS BYTES FORMAT 'HEX')) AS `farm_fingerprint_0_b'Hello_ World_'` \ No newline at end of file + farm_fingerprint(CAST('48656c6c6f2c20576f726c6421' AS BYTES FORMAT 'HEX')) AS `farm_fingerprint_0_b'Hello_World_'` \ No newline at end of file