Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use QUALIFY clause in deduplicate macro for Redshift #811

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
dbeatty10 marked this conversation as resolved.
Show resolved Hide resolved
qualify
row_number() over (
partition by {{ partition_by }}
order by {{ order_by }}
) = 1

{% endmacro %}

Expand Down