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

Methods to achieve null safety for deduplicate #815

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion macros/sql/deduplicate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ path: {}
{% set row_alias = kwargs.get('row_alias') %}
{% set columns = kwargs.get('columns') %}

{% if row_alias != None or columns != None %}
{% if relation.is_cte is defined and not relation.is_cte %}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a simplified alternative to this and this to determine if a Relation is backed by a real database object whose columns can be fetched via the star macro.

i.e., the columns for tables and views can be retrieved via information_schema.columns (or an equivalent), but can't for CTE.

{% set columns = dbt_utils.get_filtered_columns_in_relation(relation) %}
{{ dbt_utils._safe_deduplicate(relation, partition_by, order_by, columns=columns) }}
{% elif row_alias != None or columns != None %}
{{ dbt_utils._safe_deduplicate(relation, partition_by, order_by, row_alias=row_alias, columns=columns) }}
{% else %}
{{ dbt_utils._unsafe_deduplicate(relation, partition_by, order_by) }}
Expand Down