Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore dbt. prefix for all migrated cross-db macros #701

Merged
merged 6 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions integration_tests/models/sql/test_safe_divide.sql
Original file line number Diff line number Diff line change
@@ -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') }}
)
Expand All @@ -26,11 +26,13 @@ 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

select
{{ dbt_utils.safe_divide('numerator', 'denominator_1 * denominator_2') }} as actual,
output as expected

from data_safe_divide_denominator_expressions
4 changes: 2 additions & 2 deletions macros/generic_tests/cardinality_equality.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ group by {{ field }}
except_a as (
select *
from table_a
{{ except() }}
{{ dbt.except() }}
select *
from table_b
),

except_b as (
select *
from table_b
{{ except() }}
{{ dbt.except() }}
select *
from table_a
),
Expand Down
4 changes: 2 additions & 2 deletions macros/generic_tests/equality.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ b as (
a_minus_b as (

select {{compare_cols_csv}} from a
{{ except() }}
{{ dbt.except() }}
select {{compare_cols_csv}} from b

),

b_minus_a as (

select {{compare_cols_csv}} from b
{{ except() }}
{{ dbt.except() }}
select {{compare_cols_csv}} from a

),
Expand Down
3 changes: 2 additions & 1 deletion macros/generic_tests/recency.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

{% macro default__test_recency(model, field, datepart, interval, group_by_columns) %}

{% set threshold = dateadd(datepart, interval * -1, current_timestamp_backcompat()) %}
{% set threshold = dbt.dateadd(datepart, interval * -1, current_timestamp_backcompat()) %}

{% if group_by_columns|length() > 0 %}
{% set select_gb_cols = group_by_columns|join(' ,') + ', ' %}
{% set groupby_gb_cols = 'group by ' + group_by_columns|join(',') %}
Expand Down
2 changes: 1 addition & 1 deletion macros/generic_tests/sequential_values.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
6 changes: 3 additions & 3 deletions macros/sql/date_spine.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}

Expand Down Expand Up @@ -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)"
) #}


Expand All @@ -51,7 +51,7 @@ all_periods as (

select (
{{
dateadd(
dbt.dateadd(
datepart,
"row_number() over (order by 1) - 1",
start_date
Expand Down
4 changes: 2 additions & 2 deletions macros/sql/generate_surrogate_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -24,6 +24,6 @@

{%- endfor -%}

{{ hash(concat(fields)) }}
{{ dbt.hash(dbt.concat(fields)) }}

{%- endmacro -%}
2 changes: 1 addition & 1 deletion macros/sql/pivot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion macros/sql/union.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%}
Expand Down
4 changes: 2 additions & 2 deletions macros/sql/unpivot.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
8 changes: 4 additions & 4 deletions macros/sql/width_bucket.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions macros/web/get_url_host.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@

{{ dbt.safe_cast(
parsed,
type_string()
dbt.type_string()
)}}

{%- endmacro %}
2 changes: 1 addition & 1 deletion macros/web/get_url_parameter.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 }},'')

Expand Down
18 changes: 9 additions & 9 deletions macros/web/get_url_path.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}