Skip to content

Commit

Permalink
Remove relation_alias argument
Browse files Browse the repository at this point in the history
  • Loading branch information
judahrand committed Apr 14, 2022
1 parent 37fce43 commit 593ac80
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions integration_tests/models/sql/test_deduplicate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}}

Expand Down
22 changes: 11 additions & 11 deletions macros/sql/deduplicate.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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 -%}
Expand All @@ -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 }}
Expand All @@ -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 (
Expand All @@ -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 -%}

0 comments on commit 593ac80

Please sign in to comment.