Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 04536a1
Author: Joel Labes <[email protected]>
Date:   Wed Nov 23 08:30:34 2022 +1300

    Merge main into utils-v1 (dbt-labs#726)

    * Feature/safe divide (dbt-labs#697)

    * add safe_divide documentation

    * add safe_divide macro

    * add integration test for safe_divide macro

    * moved macro and documentation to new SQL generator section

    Co-authored-by: Grace Goheen <[email protected]>

    * Revert "Feature/safe divide (dbt-labs#697)" (dbt-labs#702)

    This reverts commit f368cec.

    * Quick nitpicks (dbt-labs#718)

    I was doing some studying on these and spotted some stuff. One verb conjugation and a consistency in macro description

    Co-authored-by: deanna-minnick <[email protected]>
    Co-authored-by: Grace Goheen <[email protected]>
    Co-authored-by: ian-fahey-dbt <[email protected]>

commit 2703459
Author: fivetran-catfritz <[email protected]>
Date:   Tue Nov 1 20:26:17 2022 -0500

    Slugify for snowflake (dbt-labs#707)

commit 17b017d
Merge: 31c503d b08f7bb
Author: Joel Labes <[email protected]>
Date:   Thu Oct 27 16:51:56 2022 +1300

    Merge branch 'heads/0.9.3' into utils-v1

commit b08f7bb
Author: Joel Labes <[email protected]>
Date:   Thu Oct 27 15:28:55 2022 +1300

    Wrap xdb warnings in if execute block

commit 586f278
Author: Joel Labes <[email protected]>
Date:   Thu Oct 27 15:27:57 2022 +1300

    Change deprecation resolution advice

commit 4fae6c5
Author: Joel Labes <[email protected]>
Date:   Thu Oct 27 15:19:27 2022 +1300

    Switch to dbt.escape_single_quotes
  • Loading branch information
joellabes committed Nov 23, 2022
1 parent 2be849e commit e96dc94
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fixed the `recency` test, truncating it appropriately when datepart is day or greater. Also allows tests on TIMESTAMP type columns to work (was failing before since it required a comparison of TIMESTAMP to DATETIME). [#414]

## New features
- Updated the `slugify` macro to prepend "_" to column names beginning with a number since most databases do not allow names to begin with numbers.
- Implemented an optional `group_by_columns` argument across many of the generic testing macros to test for properties that only pertain to group-level or are can be more rigorously conducted at the group level. Property available in `recency`, `at_least_one`, `equal_row_count`, `fewer_rows_than`, `not_constant`, `not_null_proportion`, and `sequential` tests [#633](https://github.com/dbt-labs/dbt-utils/pull/633)
- New feature to omit the `source_column_name` column on the `union_relations` macro ([#331](https://github.com/dbt-labs/dbt-utils/issues/331), [#624](https://github.com/dbt-labs/dbt-utils/pull/624))
- New feature to select fewer columns in `expression_is_true` ([#683](https://github.com/dbt-labs/dbt-utils/issues/683), [#686](https://github.com/dbt-labs/dbt-utils/pull/686))
Expand Down Expand Up @@ -59,6 +60,8 @@ models:
- 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:
- [@fivetran-catfritz](https://github.com/fivetran-catfritz)
- [@crowemi](https://github.com/crowemi)
- [@CR-Lough] (https://github.com/CR-Lough) (#706)
- [@SimonQuvang](https://github.com/SimonQuvang) (#701)
- [@christineberger](https://github.com/christineberger) (#624)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ Optionally takes a `unit` string argument ('km' or 'mi') which defaults to miles

#### group_by ([source](macros/sql/groupby.sql))

This macro build a group by statement for fields 1...N
This macro builds a group by statement for fields 1...N

**Usage:**

Expand Down Expand Up @@ -1016,7 +1016,7 @@ This macro implements a cross-database mechanism to generate an arbitrarily long

#### surrogate_key ([source](macros/sql/surrogate_key.sql))

Implements a cross-database way to generate a hashed surrogate key using the fields specified.
This macro implements a cross-database way to generate a hashed surrogate key using the fields specified.

**Usage:**

Expand All @@ -1026,7 +1026,7 @@ Implements a cross-database way to generate a hashed surrogate key using the fie

#### safe_add ([source](macros/sql/safe_add.sql))

Implements a cross-database way to sum nullable fields using the fields specified.
This macro implements a cross-database way to sum nullable fields using the fields specified.

**Usage:**

Expand Down
16 changes: 9 additions & 7 deletions integration_tests/tests/jinja_helpers/test_slugify.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% if dbt_utils.slugify('!Hell0 world-hi') == 'hell0_world_hi' %}
{# Return 0 rows for the test to pass #}
select 1 as col_name {{ limit_zero() }}
{% else %}
{# Return >0 rows for the test to fail #}
select 1 as col_name
{% endif %}
with comparisons as (
select '{{ dbt_utils.slugify("!Hell0 world-hi") }}' as output, 'hell0_world_hi' as expected
union all
select '{{ dbt_utils.slugify("0Hell0 world-hi") }}' as output, '_0hell0_world_hi' as expected
)

select *
from comparisons
where output != expected
6 changes: 4 additions & 2 deletions macros/cross_db_utils/deprecated/xdb_deprecation_warning.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% macro xdb_deprecation_warning_without_replacement(macro, package, model) %}
{%- set error_message = "Warning: the `" ~ macro ~"` macro is deprecated and will be removed in a future version of the package, once equivalent functionality is implemented in dbt Core. The " ~ package ~ "." ~ model ~ " model triggered this warning." -%}
{%- do exceptions.warn(error_message) -%}
{% if execute %}
{%- set error_message = "Warning: the `" ~ macro ~"` macro is deprecated and will be removed in a future version of the package, once equivalent functionality is implemented in dbt Core. The " ~ package ~ "." ~ model ~ " model triggered this warning." -%}
{%- do exceptions.warn(error_message) -%}
{% endif %}
{% endmacro %}
4 changes: 3 additions & 1 deletion macros/jinja_helpers/slugify.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
{% set string = modules.re.sub('[ -]+', '_', string) %}
{#- Only take letters, numbers, and underscores -#}
{% set string = modules.re.sub('[^a-z0-9_]+', '', string) %}
{#- Prepends "_" if string begins with a number -#}
{% set string = modules.re.sub('^[0-9]', '_' + string[0], string) %}

{{ return(string) }}

{% endmacro %}
{% endmacro %}

0 comments on commit e96dc94

Please sign in to comment.