From b2a27c8cb2862d2f427761bb77a16383512b5fa4 Mon Sep 17 00:00:00 2001 From: Miles Liu Date: Thu, 15 Sep 2022 14:30:27 +0800 Subject: [PATCH] Handle deprecations in deduplicate macro resolves #668 --- CHANGELOG.md | 4 ++ integration_tests/models/sql/schema.yml | 7 +--- .../sql/test_deduplicate_deprecated.sql | 22 ----------- macros/sql/deduplicate.sql | 37 +------------------ 4 files changed, 6 insertions(+), 64 deletions(-) delete mode 100644 integration_tests/models/sql/test_deduplicate_deprecated.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 4359fb099..6ae97581f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ ## New features - 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)) +## Under the hood +- Handle deprecations in deduplicate macro ([#673](https://github.com/dbt-labs/dbt-utils/pull/673)) + ## Fixes - 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)) @@ -21,6 +24,7 @@ - [@christineberger](https://github.com/christineberger) (#624) - [@courentin](https://github.com/courentin) (#651) - [@sfc-gh-ancoleman](https://github.com/sfc-gh-ancoleman) (#660) +- [@miles170](https://github.com/miles170) (#673) # dbt-utils v0.8.6 diff --git a/integration_tests/models/sql/schema.yml b/integration_tests/models/sql/schema.yml index 7463edc44..a1e74b896 100644 --- a/integration_tests/models/sql/schema.yml +++ b/integration_tests/models/sql/schema.yml @@ -178,13 +178,8 @@ models: - dbt_utils.equality: compare_model: ref('data_deduplicate_expected') - - name: test_deduplicate_deprecated - tests: - - dbt_utils.equality: - compare_model: ref('data_deduplicate_expected') - - name: test_width_bucket tests: - assert_equal: actual: actual - expected: expected \ No newline at end of file + expected: expected diff --git a/integration_tests/models/sql/test_deduplicate_deprecated.sql b/integration_tests/models/sql/test_deduplicate_deprecated.sql deleted file mode 100644 index b80db2cb2..000000000 --- a/integration_tests/models/sql/test_deduplicate_deprecated.sql +++ /dev/null @@ -1,22 +0,0 @@ -with - -source as ( - select * - from {{ ref('data_deduplicate') }} - where user_id = 1 -), - -deduped as ( - - {{ - dbt_utils.deduplicate( - ref('data_deduplicate'), - group_by='user_id', - order_by='version desc', - relation_alias='source', - ) | indent - }} - -) - -select * from deduped diff --git a/macros/sql/deduplicate.sql b/macros/sql/deduplicate.sql index 64501740f..34d87425e 100644 --- a/macros/sql/deduplicate.sql +++ b/macros/sql/deduplicate.sql @@ -1,39 +1,4 @@ -{%- macro deduplicate(relation, partition_by, order_by=none, relation_alias=none) -%} - - {%- set error_message_group_by -%} -Warning: the `group_by` parameter of the `deduplicate` macro is no longer supported and will be deprecated in a future release of dbt-utils. -Use `partition_by` instead. -The {{ model.package_name }}.{{ model.name }} model triggered this warning. - {%- endset -%} - - {% if kwargs.get('group_by') %} - {%- do exceptions.warn(error_message_group_by) -%} - {%- endif -%} - - {%- set error_message_order_by -%} -Warning: `order_by` as an optional parameter of the `deduplicate` macro is no longer supported and will be deprecated in a future release of dbt-utils. -Supply a non-null value for `order_by` instead. -The {{ model.package_name }}.{{ model.name }} model triggered this warning. - {%- endset -%} - - {% if not order_by %} - {%- do exceptions.warn(error_message_order_by) -%} - {%- endif -%} - - {%- set error_message_alias -%} -Warning: the `relation_alias` parameter of the `deduplicate` macro is no longer supported and will be deprecated in a future release of dbt-utils. -If you were using `relation_alias` to point to a CTE previously then you can now pass the alias directly to `relation` instead. -The {{ model.package_name }}.{{ model.name }} model triggered this warning. - {%- endset -%} - - {% if relation_alias %} - {%- do exceptions.warn(error_message_alias) -%} - {%- endif -%} - - {% set partition_by = partition_by or kwargs.get('group_by') %} - {% set relation = relation_alias or relation %} - {% set order_by = order_by or "'1'" %} - +{%- macro deduplicate(relation, partition_by, order_by) -%} {{ return(adapter.dispatch('deduplicate', 'dbt_utils')(relation, partition_by, order_by)) }} {% endmacro %}