From 3c27a18dde34afefb1b47d92241f38ca4ca12216 Mon Sep 17 00:00:00 2001 From: Judah Rand <17158624+judahrand@users.noreply.github.com> Date: Thu, 14 Apr 2022 09:57:36 +0100 Subject: [PATCH] Remove `relation_alias` argument --- .../models/sql/test_deduplicate.sql | 3 +-- macros/sql/deduplicate.sql | 22 +++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/integration_tests/models/sql/test_deduplicate.sql b/integration_tests/models/sql/test_deduplicate.sql index 81fe81e76..3ce979101 100644 --- a/integration_tests/models/sql/test_deduplicate.sql +++ b/integration_tests/models/sql/test_deduplicate.sql @@ -10,10 +10,9 @@ deduped as ( {{ dbt_utils.deduplicate( - ref('data_deduplicate'), + 'source', group_by='user_id', order_by='version desc', - relation_alias="source" ) | indent }} diff --git a/macros/sql/deduplicate.sql b/macros/sql/deduplicate.sql index a83f7194a..eb635b101 100644 --- a/macros/sql/deduplicate.sql +++ b/macros/sql/deduplicate.sql @@ -1,8 +1,8 @@ -{%- macro deduplicate(relation, group_by, order_by=none, relation_alias=none) -%} - {{ return(adapter.dispatch('deduplicate', 'dbt_utils')(relation, group_by, order_by=order_by, relation_alias=relation_alias)) }} +{%- macro deduplicate(relation, group_by, order_by=none) -%} + {{ return(adapter.dispatch('deduplicate', 'dbt_utils')(relation, group_by, order_by=order_by)) }} {% endmacro %} -{%- macro default__deduplicate(relation, group_by, order_by=none, relation_alias=none) -%} +{%- macro default__deduplicate(relation, group_by, order_by=none) -%} with row_numbered as ( select @@ -13,12 +13,12 @@ order by {{ order_by }} {%- endif %} ) as rn - from {{ relation if relation_alias is none else relation_alias }} as _inner + from {{ relation }} as _inner ) select data.* - from {{ relation if relation_alias is none else relation_alias }} as data + from {{ relation }} as data join row_numbered using ({{ group_by }}{{ ',' ~ order_by if order_by is not none else '' }}) where row_numbered.rn = 1 @@ -28,11 +28,11 @@ -- Postgres has the `DISTINCT ON` syntax: -- https://www.postgresql.org/docs/current/sql-select.html#SQL-DISTINCT #} -{%- macro postgres__deduplicate(relation, group_by, order_by=none, relation_alias=none) -%} +{%- macro postgres__deduplicate(relation, group_by, order_by=none) -%} select distinct on ({{ group_by }}) * - from {{ relation if relation_alias is none else relation_alias }} + from {{ relation }} order by {{ group_by }}{{ ',' ~ order_by if order_by is not none else '' }} {%- endmacro -%} @@ -41,10 +41,10 @@ -- Snowflake has the `QUALIFY` syntax: -- https://docs.snowflake.com/en/sql-reference/constructs/qualify.html #} -{%- macro snowflake__deduplicate(relation, group_by, order_by=none, relation_alias=none) -%} +{%- macro snowflake__deduplicate(relation, group_by, order_by=none) -%} select * - from {{ relation if relation_alias is none else relation_alias }} + from {{ relation }} qualify row_number() over ( partition by {{ group_by }} @@ -60,7 +60,7 @@ -- clause in BigQuery: -- https://github.com/dbt-labs/dbt-utils/issues/335#issuecomment-788157572 #} -{%- macro bigquery__deduplicate(relation, group_by, order_by=none, relation_alias=none) -%} +{%- macro bigquery__deduplicate(relation, group_by, order_by=none) -%} select array_agg ( @@ -70,7 +70,7 @@ {%- endif %} limit 1 )[offset(0)].* - from {{ relation if relation_alias is none else relation_alias }} as original + from {{ relation }} as original group by {{ group_by }} {%- endmacro -%}