From 23634be5e5aded191b97e8a389c103db4d820405 Mon Sep 17 00:00:00 2001 From: SimonQuvang Date: Mon, 10 Oct 2022 01:55:19 +0200 Subject: [PATCH 1/4] added prefix dbt. on cross db macros --- macros/generic_tests/cardinality_equality.sql | 4 ++-- macros/generic_tests/equality.sql | 4 ++-- macros/generic_tests/recency.sql | 2 +- macros/generic_tests/sequential_values.sql | 2 +- macros/sql/date_spine.sql | 6 +++--- macros/sql/pivot.sql | 2 +- macros/sql/union.sql | 2 +- macros/sql/unpivot.sql | 4 ++-- macros/sql/width_bucket.sql | 8 ++++---- macros/web/get_url_host.sql | 12 ++++++------ macros/web/get_url_parameter.sql | 2 +- macros/web/get_url_path.sql | 18 +++++++++--------- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/macros/generic_tests/cardinality_equality.sql b/macros/generic_tests/cardinality_equality.sql index 5aa95efd..824f0e51 100644 --- a/macros/generic_tests/cardinality_equality.sql +++ b/macros/generic_tests/cardinality_equality.sql @@ -26,7 +26,7 @@ group by {{ field }} except_a as ( select * from table_a - {{ except() }} + {{ dbt.except() }} select * from table_b ), @@ -34,7 +34,7 @@ except_a as ( except_b as ( select * from table_b - {{ except() }} + {{ dbt.except() }} select * from table_a ), diff --git a/macros/generic_tests/equality.sql b/macros/generic_tests/equality.sql index f2128af5..ffc6a2b8 100644 --- a/macros/generic_tests/equality.sql +++ b/macros/generic_tests/equality.sql @@ -49,7 +49,7 @@ b as ( a_minus_b as ( select {{compare_cols_csv}} from a - {{ except() }} + {{ dbt.except() }} select {{compare_cols_csv}} from b ), @@ -57,7 +57,7 @@ a_minus_b as ( b_minus_a as ( select {{compare_cols_csv}} from b - {{ except() }} + {{ dbt.except() }} select {{compare_cols_csv}} from a ), diff --git a/macros/generic_tests/recency.sql b/macros/generic_tests/recency.sql index 98ed2ad5..3fb540cf 100644 --- a/macros/generic_tests/recency.sql +++ b/macros/generic_tests/recency.sql @@ -4,7 +4,7 @@ {% macro default__test_recency(model, field, datepart, interval, group_by_columns) %} -{% set threshold = dateadd(datepart, interval * -1, current_timestamp()) %} +{% set threshold = dbt.dateadd(datepart, interval * -1, current_timestamp()) %} {% if group_by_columns|length() > 0 %} {% set select_gb_cols = group_by_columns|join(' ,') + ', ' %} {% set groupby_gb_cols = 'group by ' + group_by_columns|join(',') %} diff --git a/macros/generic_tests/sequential_values.sql b/macros/generic_tests/sequential_values.sql index 619ee10e..736ccbd8 100644 --- a/macros/generic_tests/sequential_values.sql +++ b/macros/generic_tests/sequential_values.sql @@ -30,7 +30,7 @@ validation_errors as ( * from windowed {% if datepart %} - where not(cast({{ column_name }} as {{ type_timestamp() }})= cast({{ dateadd(datepart, interval, previous_column_name) }} as {{ type_timestamp() }})) + where not(cast({{ column_name }} as {{ dbt.type_timestamp() }})= cast({{ dbt.dateadd(datepart, interval, previous_column_name) }} as {{ dbt.type_timestamp() }})) {% else %} where not({{ column_name }} = {{ previous_column_name }} + {{ interval }}) {% endif %} diff --git a/macros/sql/date_spine.sql b/macros/sql/date_spine.sql index 5b4e8be0..43dfafa9 100644 --- a/macros/sql/date_spine.sql +++ b/macros/sql/date_spine.sql @@ -5,7 +5,7 @@ {% macro default__get_intervals_between(start_date, end_date, datepart) -%} {%- call statement('get_intervals_between', fetch_result=True) %} - select {{ datediff(start_date, end_date, datepart) }} + select {{ dbt.datediff(start_date, end_date, datepart) }} {%- endcall -%} @@ -35,7 +35,7 @@ date_spine( "day", "to_date('01/01/2016', 'mm/dd/yyyy')", - "dateadd(week, 1, current_date)" + "dbt.dateadd(week, 1, current_date)" ) #} @@ -51,7 +51,7 @@ all_periods as ( select ( {{ - dateadd( + dbt.dateadd( datepart, "row_number() over (order by 1) - 1", start_date diff --git a/macros/sql/pivot.sql b/macros/sql/pivot.sql index 4233ba9d..3eabc727 100644 --- a/macros/sql/pivot.sql +++ b/macros/sql/pivot.sql @@ -69,7 +69,7 @@ Arguments: {{ agg }}( {% if distinct %} distinct {% endif %} case - when {{ column }} {{ cmp }} '{{ escape_single_quotes(value) }}' + when {{ column }} {{ cmp }} '{{ dbt.escape_single_quotes(value) }}' then {{ then_value }} else {{ else_value }} end diff --git a/macros/sql/union.sql b/macros/sql/union.sql index 3a906e1c..ac289e2f 100644 --- a/macros/sql/union.sql +++ b/macros/sql/union.sql @@ -100,7 +100,7 @@ select {%- if source_column_name is not none %} - cast({{ string_literal(relation) }} as {{ type_string() }}) as {{ source_column_name }}, + cast({{ dbt.string_literal(relation) }} as {{ dbt.type_string() }}) as {{ source_column_name }}, {%- endif %} {% for col_name in ordered_column_names -%} diff --git a/macros/sql/unpivot.sql b/macros/sql/unpivot.sql index b88a6191..371b314b 100644 --- a/macros/sql/unpivot.sql +++ b/macros/sql/unpivot.sql @@ -48,9 +48,9 @@ Arguments: {{ exclude_col }}, {%- endfor %} - cast('{{ col.column }}' as {{ type_string() }}) as {{ field_name }}, + cast('{{ col.column }}' as {{ dbt.type_string() }}) as {{ field_name }}, cast( {% if col.data_type == 'boolean' %} - {{ cast_bool_to_text(col.column) }} + {{ dbt.cast_bool_to_text(col.column) }} {% else %} {{ col.column }} {% endif %} diff --git a/macros/sql/width_bucket.sql b/macros/sql/width_bucket.sql index 9a3b3d11..324e8594 100644 --- a/macros/sql/width_bucket.sql +++ b/macros/sql/width_bucket.sql @@ -13,8 +13,8 @@ case when mod( - {{ dbt.safe_cast(expr, type_numeric() ) }}, - {{ dbt.safe_cast(bin_size, type_numeric() ) }} + {{ dbt.safe_cast(expr, dbt.type_numeric() ) }}, + {{ dbt.safe_cast(bin_size, dbt.type_numeric() ) }} ) = 0 then 1 else 0 @@ -38,8 +38,8 @@ -- to break ties when the amount is exactly at the bucket edge case when - {{ dbt.safe_cast(expr, type_numeric() ) }} % - {{ dbt.safe_cast(bin_size, type_numeric() ) }} + {{ dbt.safe_cast(expr, dbt.type_numeric() ) }} % + {{ dbt.safe_cast(bin_size, dbt.type_numeric() ) }} = 0 then 1 else 0 diff --git a/macros/web/get_url_host.sql b/macros/web/get_url_host.sql index d78dff1a..ddd01974 100644 --- a/macros/web/get_url_host.sql +++ b/macros/web/get_url_host.sql @@ -5,11 +5,11 @@ {% macro default__get_url_host(field) -%} {%- set parsed = - split_part( - split_part( - replace( - replace( - replace(field, "'android-app://'", "''" + dbt.split_part( + dbt.split_part( + dbt.replace( + dbt.replace( + dbt.replace(field, "'android-app://'", "''" ), "'http://'", "''" ), "'https://'", "''" ), "'/'", 1 @@ -21,7 +21,7 @@ {{ dbt.safe_cast( parsed, - type_string() + dbt.type_string() )}} {%- endmacro %} diff --git a/macros/web/get_url_parameter.sql b/macros/web/get_url_parameter.sql index fb92ad97..8147b41f 100644 --- a/macros/web/get_url_parameter.sql +++ b/macros/web/get_url_parameter.sql @@ -6,7 +6,7 @@ {%- set formatted_url_parameter = "'" + url_parameter + "='" -%} -{%- set split = split_part(split_part(field, formatted_url_parameter, 2), "'&'", 1) -%} +{%- set split = dbt.split_part(dbt.split_part(field, formatted_url_parameter, 2), "'&'", 1) -%} nullif({{ split }},'') diff --git a/macros/web/get_url_path.sql b/macros/web/get_url_path.sql index cf18f386..b59401df 100644 --- a/macros/web/get_url_path.sql +++ b/macros/web/get_url_path.sql @@ -5,30 +5,30 @@ {% macro default__get_url_path(field) -%} {%- set stripped_url = - replace( - replace(field, "'http://'", "''"), "'https://'", "''") + dbt.replace( + dbt.replace(field, "'http://'", "''"), "'https://'", "''") -%} {%- set first_slash_pos -%} coalesce( - nullif({{ position("'/'", stripped_url) }}, 0), - {{ position("'?'", stripped_url) }} - 1 + nullif({{ dbt.position("'/'", stripped_url) }}, 0), + {{ dbt.position("'?'", stripped_url) }} - 1 ) {%- endset -%} {%- set parsed_path = - split_part( - right( + dbt.split_part( + dbt.right( stripped_url, - length(stripped_url) ~ "-" ~ first_slash_pos + dbt.length(stripped_url) ~ "-" ~ first_slash_pos ), "'?'", 1 ) -%} - {{ safe_cast( + {{ dbt.safe_cast( parsed_path, - type_string() + dbt.type_string() )}} {%- endmacro %} From 8d8200d537eedfbf6ae1a287cfb3900a6e2f6e6c Mon Sep 17 00:00:00 2001 From: SimonQuvang Date: Mon, 10 Oct 2022 02:02:31 +0200 Subject: [PATCH 2/4] Also prefix for new macro --- macros/sql/generate_surrogate_key.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/macros/sql/generate_surrogate_key.sql b/macros/sql/generate_surrogate_key.sql index 52165f6f..4de857e2 100644 --- a/macros/sql/generate_surrogate_key.sql +++ b/macros/sql/generate_surrogate_key.sql @@ -15,7 +15,7 @@ {%- for field in field_list -%} {%- do fields.append( - "coalesce(cast(" ~ field ~ " as " ~ type_string() ~ "), '" ~ default_null_value ~"')" + "coalesce(cast(" ~ field ~ " as " ~ dbt.type_string() ~ "), '" ~ default_null_value ~"')" ) -%} {%- if not loop.last %} @@ -24,6 +24,6 @@ {%- endfor -%} -{{ hash(concat(fields)) }} +{{ dbt.hash(dbt.concat(fields)) }} {%- endmacro -%} From deedf27cbfa2d018406ca5620ec9594c8e15d835 Mon Sep 17 00:00:00 2001 From: SimonQuvang Date: Mon, 10 Oct 2022 02:20:17 +0200 Subject: [PATCH 3/4] Adding changelog change --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1f6a5a9..c54afa7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,18 +23,20 @@ - Fully remove varargs usage in surrogate_key and safe_add ([#674](https://github.com/dbt-labs/dbt-utils/pull/674)) ## Fixes +- Explicitly stating the namespace for cross-db macros so that the dispatch logic works correctly by restoring the dbt. prefix for all migrated cross-db macros ([#701](https://github.com/dbt-labs/dbt-utils/pull/701)) - Better handling of whitespaces in the star macro ([#651](https://github.com/dbt-labs/dbt-utils/pull/651)) - Fix to correct behavior in `mutually_exclusive_ranges` test in certain situations when `zero_length_range_allowed: true` and multiple ranges in a partition have the same value for `lower_bound_column`. ([[#659](https://github.com/dbt-labs/dbt-utils/issues/659)], [#660](https://github.com/dbt-labs/dbt-utils/pull/660)) - Fix to utilize dbt Core version of `escape_single_quotes` instead of version from dbt Utils ([[#689](https://github.com/dbt-labs/dbt-utils/issues/689)], [#692](https://github.com/dbt-labs/dbt-utils/pull/692)) ## Contributors: +- [@SimonQuvang](https://github.com/SimonQuvang) (#701) - [@christineberger](https://github.com/christineberger) (#624) - [@epapineau](https://github.com/epapineau) (#634) - [@courentin](https://github.com/courentin) (#651) - [@sfc-gh-ancoleman](https://github.com/sfc-gh-ancoleman) (#660) - [@zachoj10](https://github.com/zachoj10) (#692) - [@miles170](https://github.com/miles170) -- [@emilyriederer](https://github.com/emilyriederer) +- [@emilyriederer](https://github.com/emilyriederer) # dbt-utils v0.8.6 From 7ea6d63579d5c9af021431e258b62263060d94ed Mon Sep 17 00:00:00 2001 From: Joel Labes Date: Thu, 13 Oct 2022 22:07:00 +1300 Subject: [PATCH 4/4] Squashed commit of the following: commit 5eba82b7ac3256d3b8789206fb717ee9377ee342 Author: Deanna Minnick Date: Wed Oct 12 10:30:42 2022 -0400 remove whitespace in seed file commit 7a2a5e3bc0a725b7f642140168becf4e71bc0d98 Author: Deanna Minnick Date: Wed Oct 12 10:22:07 2022 -0400 fix syntax errors --- .../data/sql/data_safe_divide_numerator_expressions.csv | 3 +-- integration_tests/models/sql/test_safe_divide.sql | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/integration_tests/data/sql/data_safe_divide_numerator_expressions.csv b/integration_tests/data/sql/data_safe_divide_numerator_expressions.csv index 4cb2a788..2673d9b2 100644 --- a/integration_tests/data/sql/data_safe_divide_numerator_expressions.csv +++ b/integration_tests/data/sql/data_safe_divide_numerator_expressions.csv @@ -4,5 +4,4 @@ numerator_1,numerator_2,denominator,output 0,0,0, 3,4,, ,6,14, -2,5,2,5 - +2,5,2,5 \ No newline at end of file diff --git a/integration_tests/models/sql/test_safe_divide.sql b/integration_tests/models/sql/test_safe_divide.sql index ceaf62e6..34624787 100644 --- a/integration_tests/models/sql/test_safe_divide.sql +++ b/integration_tests/models/sql/test_safe_divide.sql @@ -1,16 +1,16 @@ - + with data_safe_divide as ( select * from {{ ref('data_safe_divide') }} ), -data_safe_divide_numerator_expressions ( +data_safe_divide_numerator_expressions as ( select * from {{ ref('data_safe_divide_numerator_expressions') }} ), -data_safe_divide_denominator_expressions ( +data_safe_divide_denominator_expressions as ( select * from {{ ref('data_safe_divide_denominator_expressions') }} ) @@ -26,6 +26,7 @@ union all select {{ dbt_utils.safe_divide('numerator_1 * numerator_2', 'denominator') }} as actual, output as expected + from data_safe_divide_numerator_expressions union all @@ -33,4 +34,5 @@ union all select {{ dbt_utils.safe_divide('numerator', 'denominator_1 * denominator_2') }} as actual, output as expected + from data_safe_divide_denominator_expressions \ No newline at end of file