Skip to content

Commit

Permalink
Restore dbt. prefix for all migrated cross-db macros (#701)
Browse files Browse the repository at this point in the history
* added prefix dbt. on cross db macros

* Also prefix for new macro

* Adding changelog change

* Squashed commit of the following:

commit 5eba82b
Author: Deanna Minnick <[email protected]>
Date:   Wed Oct 12 10:30:42 2022 -0400

    remove whitespace in seed file

commit 7a2a5e3
Author: Deanna Minnick <[email protected]>
Date:   Wed Oct 12 10:22:07 2022 -0400

    fix syntax errors

Co-authored-by: Joel Labes <[email protected]>
  • Loading branch information
SimonQuvang and joellabes authored Oct 13, 2022
1 parent 38df969 commit df08128
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 36 deletions.
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
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 %}

0 comments on commit df08128

Please sign in to comment.