Skip to content

Commit

Permalink
Use QUALIFY clause in deduplicate macro for Redshift (#811)
Browse files Browse the repository at this point in the history
* refactor: Use QUALIFY syntax in deduplicate() macro for Redshift

* chore: Update changelog

---------

Co-authored-by: Yauhen Sobaleu <[email protected]>
  • Loading branch information
yauhen-sobaleu and Yauhen Sobaleu authored Jul 25, 2023
1 parent 9cd5988 commit a17d66f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
# Unreleased
## Fixes
- deduplicate macro for Databricks now uses the QUALIFY clause, which fixes NULL columns issues from the default natural join logic
- deduplicate macro for Redshift now uses the QUALIFY clause, which fixes NULL columns issues from the default natural join logic

## Contributors:
[@graciegoheen](https://github.com/graciegoheen)
[@yauhen-sobaleu](https://github.com/yauhen-sobaleu)

# dbt utils v1.1.1
## New features
Expand Down
11 changes: 9 additions & 2 deletions macros/sql/deduplicate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@

{%- endmacro -%}

{# Redshift should use default instead of Postgres #}
-- Redshift has the `QUALIFY` syntax:
-- https://docs.aws.amazon.com/redshift/latest/dg/r_QUALIFY_clause.html
{% macro redshift__deduplicate(relation, partition_by, order_by) -%}

{{ return(dbt_utils.default__deduplicate(relation, partition_by, order_by=order_by)) }}
select *
from {{ relation }} as tt
qualify
row_number() over (
partition by {{ partition_by }}
order by {{ order_by }}
) = 1

{% endmacro %}

Expand Down

0 comments on commit a17d66f

Please sign in to comment.