Skip to content

Commit

Permalink
Merge pull request #250 from ScalefreeCOM/create-ghost-records-only-w…
Browse files Browse the repository at this point in the history
…hen-not-incremental

only create ghost records when it is not an incremental run
  • Loading branch information
tkirschke authored Sep 5, 2024
2 parents edceed4 + 34098fd commit 846a926
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions macros/staging/bigquery/stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ hashed_columns AS (
{%- endif -%}
{%- endif -%}

{% if enable_ghost_records %}
{%- if enable_ghost_records and not is_incremental() %}
{# Creating Ghost Record for unknown case, based on datatype #}
unknown_values AS (

Expand Down Expand Up @@ -597,7 +597,7 @@ columns_to_select AS (

FROM {{ last_cte }}

{%- if enable_ghost_records %}
{%- if enable_ghost_records and not is_incremental() %}
UNION ALL

SELECT
Expand Down
4 changes: 2 additions & 2 deletions macros/staging/exasol/stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ hashed_columns AS (
{%- endif -%}
{%- endif -%}

{% if enable_ghost_records %}
{%- if enable_ghost_records and not is_incremental() %}
{# Creating Ghost Record for unknown case, based on datatype #}
unknown_values AS (
SELECT
Expand Down Expand Up @@ -580,7 +580,7 @@ columns_to_select AS (

FROM {{ last_cte }}

{%- if enable_ghost_records %}
{%- if enable_ghost_records and not is_incremental() %}
UNION ALL
SELECT

Expand Down
4 changes: 2 additions & 2 deletions macros/staging/postgres/stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ hashed_columns AS (
{%- endif -%}
{%- endif -%}

{%- if enable_ghost_records -%}
{%- if enable_ghost_records and not is_incremental() %}
{# Creating Ghost Record for unknown case, based on datatype #}
unknown_values AS (

Expand Down Expand Up @@ -597,7 +597,7 @@ columns_to_select AS (

FROM {{ last_cte }}

{% if enable_ghost_records %}
{%- if enable_ghost_records and not is_incremental() %}
UNION ALL

SELECT
Expand Down
4 changes: 2 additions & 2 deletions macros/staging/redshift/stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ hashed_columns AS (
{%- endif -%}
{%- endif -%}

{%- if enable_ghost_records -%}
{%- if enable_ghost_records and not is_incremental() %}
{# Creating Ghost Record for unknown case, based on datatype #}
unknown_values AS (

Expand Down Expand Up @@ -606,7 +606,7 @@ columns_to_select AS (

FROM {{ last_cte }}

{%- if enable_ghost_records %}
{%- if enable_ghost_records and not is_incremental() %}
UNION ALL

SELECT
Expand Down
8 changes: 2 additions & 6 deletions macros/staging/snowflake/stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,7 @@ hashed_columns AS (
{%- endif -%}
{%- endif -%}

{% if enable_ghost_records %}
{% if not is_incremental() %}
{%- if enable_ghost_records and not is_incremental() %}
{# Creating Ghost Record for unknown case, based on datatype #}
unknown_values AS (

Expand Down Expand Up @@ -535,7 +534,6 @@ ghost_records AS (
SELECT * FROM error_values
),
{%- endif %}
{%- endif %}

{%- if not include_source_columns -%}
{% set source_columns_to_select = datavault4dbt.process_columns_to_select(columns_list=source_columns_to_select, exclude_columns_list=derived_column_names) %}
Expand All @@ -551,16 +549,14 @@ columns_to_select AS (

FROM {{ last_cte }}

{% if enable_ghost_records %}
{% if not is_incremental() %}
{%- if enable_ghost_records and not is_incremental() %}
UNION ALL

SELECT

{{ datavault4dbt.print_list(datavault4dbt.escape_column_names(final_columns_to_select)) }}

FROM ghost_records
{% endif %}
{% endif %}
)

Expand Down
8 changes: 2 additions & 6 deletions macros/staging/synapse/stage.sql
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ hashed_columns AS (
{% set processed_hash_columns = datavault4dbt.process_hash_column_excludes(hashed_columns) -%}
{%- endif -%}

{% if enable_ghost_records %}
{% if not is_incremental() %}
{%- if enable_ghost_records and not is_incremental() %}
{# Creating Ghost Record for unknown case, based on datatype #}
unknown_values AS (

Expand Down Expand Up @@ -585,7 +584,6 @@ ghost_records AS (
SELECT * FROM error_values
),
{%- endif %}
{%- endif %}

{%- if not include_source_columns -%}
{% set final_columns_to_select = datavault4dbt.process_columns_to_select(columns_list=final_columns_to_select, exclude_columns_list=source_columns_to_select) %}
Expand All @@ -600,16 +598,14 @@ columns_to_select AS (

FROM {{ last_cte }}

{% if enable_ghost_records %}
{% if not is_incremental() %}
{%- if enable_ghost_records and not is_incremental() %}
UNION ALL

SELECT

{{ datavault4dbt.print_list(datavault4dbt.escape_column_names(final_columns_to_select)) }}

FROM ghost_records
{% endif %}
{% endif %}
)

Expand Down

0 comments on commit 846a926

Please sign in to comment.