From 1057d0cbe8c36bb556634e629289c86c6b5432f7 Mon Sep 17 00:00:00 2001 From: Miles Liu Date: Thu, 15 Sep 2022 13:36:35 +0800 Subject: [PATCH] Remove deprecated table argument from unpivot() resolves #670 --- CHANGELOG.md | 4 +++ .../models/sql/test_unpivot_original_api.sql | 32 ------------------- macros/sql/unpivot.sql | 21 +++--------- 3 files changed, 8 insertions(+), 49 deletions(-) delete mode 100644 integration_tests/models/sql/test_unpivot_original_api.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 4359fb09..57744da3 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 +- Remove deprecated table argument from unpivot ([#671](https://github.com/dbt-labs/dbt-utils/pull/671)) + ## 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) (#671) # dbt-utils v0.8.6 diff --git a/integration_tests/models/sql/test_unpivot_original_api.sql b/integration_tests/models/sql/test_unpivot_original_api.sql deleted file mode 100644 index f6b9395a..00000000 --- a/integration_tests/models/sql/test_unpivot_original_api.sql +++ /dev/null @@ -1,32 +0,0 @@ - --- unpivot() was enhanced with 3 new parameters --- This test targets the original API. - --- snowflake messes with these tests pretty badly since the --- output of the macro considers the casing of the source --- table columns. Using some hacks here to get this to work, --- but we should consider lowercasing the unpivot macro output --- at some point in the future for consistency - -{% if target.name == 'snowflake' %} - {% set exclude = ['CUSTOMER_ID', 'CREATED_AT'] %} -{% else %} - {% set exclude = ['customer_id', 'created_at'] %} -{% endif %} - -select - customer_id, - created_at, - case - when '{{ target.name }}' = 'snowflake' then lower(FIELD_NAME) - else field_name - end as field_name, - value - -from ( - {{ dbt_utils.unpivot( - table=ref('data_unpivot'), - cast_to=dbt_utils.type_string(), - exclude=exclude - ) }} -) as sbq diff --git a/macros/sql/unpivot.sql b/macros/sql/unpivot.sql index 4db2f8af..b88a6191 100644 --- a/macros/sql/unpivot.sql +++ b/macros/sql/unpivot.sql @@ -12,26 +12,13 @@ Arguments: value_name: Destination table column name for the pivoted values #} -{% macro unpivot(relation=none, cast_to='varchar', exclude=none, remove=none, field_name='field_name', value_name='value', table=none) -%} - {{ return(adapter.dispatch('unpivot', 'dbt_utils')(relation, cast_to, exclude, remove, field_name, value_name, table)) }} +{% macro unpivot(relation=none, cast_to='varchar', exclude=none, remove=none, field_name='field_name', value_name='value') -%} + {{ return(adapter.dispatch('unpivot', 'dbt_utils')(relation, cast_to, exclude, remove, field_name, value_name)) }} {% endmacro %} -{% macro default__unpivot(relation=none, cast_to='varchar', exclude=none, remove=none, field_name='field_name', value_name='value', table=none) -%} +{% macro default__unpivot(relation=none, cast_to='varchar', exclude=none, remove=none, field_name='field_name', value_name='value') -%} - {% if table %} - {%- set error_message = ' - Warning: the `unpivot` macro no longer accepts a `table` parameter. \ - This parameter will be deprecated in a future release of dbt-utils. Use the `relation` parameter instead. \ - The {}.{} model triggered this warning. \ - '.format(model.package_name, model.name) -%} - {%- do exceptions.warn(error_message) -%} - {% endif %} - - {% if relation and table %} - {{ exceptions.raise_compiler_error("Error: both the `relation` and `table` parameters were provided to `unpivot` macro. Choose one only (we recommend `relation`).") }} - {% elif not relation and table %} - {% set relation=table %} - {% elif not relation and not table %} + {% if not relation %} {{ exceptions.raise_compiler_error("Error: argument `relation` is required for `unpivot` macro.") }} {% endif %}