Skip to content

Commit

Permalink
Merge pull request #184 from ScalefreeCOM/tkirschke-patch-5
Browse files Browse the repository at this point in the history
Removed double comma for Multi Active Hashkey calculation, added alias column escaping to snowflake ghost records, added upper mapping to columns_list
  • Loading branch information
tkiehn authored Jun 11, 2024
2 parents 4d1d779 + 3112c41 commit 555d102
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions macros/internal/helpers/stage_processing_macros.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{%- macro process_columns_to_select(columns_list=none, exclude_columns_list=none) -%}
{% set exclude_columns_list = exclude_columns_list | map('upper') | list %}
{% set columns_list = columns_list | map('upper') | list %}
{% set columns_to_select = [] %}

{% if not datavault4dbt.is_list(columns_list) or not datavault4dbt.is_list(exclude_columns_list) %}
Expand Down
2 changes: 0 additions & 2 deletions macros/staging/hash_columns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
is_hashdiff=columns[col]['is_hashdiff'],
multi_active_key=multi_active_key,
main_hashkey_column=main_hashkey_column) -}}

{{- ", \n" if not loop.last -}}

{#- Apply standard hashing for hash key attributes. -#}
{%- elif columns[col] is not mapping -%}
Expand Down
18 changes: 10 additions & 8 deletions macros/supporting/ghost_record_per_datatype.sql
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@
{%- set unknown_value_alt__STRING = var('datavault4dbt.unknown_value_alt__STRING', 'u') -%}
{%- set error_value_alt__STRING = var('datavault4dbt.error_value_alt__STRING', 'e') -%}
{%- set datatype = datatype | string | upper | trim -%}

{%- set alias = datavault4dbt.escape_column_names(alias) -%}

{%- if ghost_record_type == 'unknown' -%}
{%- if datatype in ['TIMESTAMP_NTZ','TIMESTAMP'] %}{{ datavault4dbt.string_to_timestamp(timestamp_format, beginning_of_all_times) }} AS {{ alias }}
{%- elif datatype == 'DATE'-%} TO_DATE('{{ beginning_of_all_times_date }}', '{{ date_format }}' ) as "{{ alias }}"
{%- elif datatype == 'DATE'-%} TO_DATE('{{ beginning_of_all_times_date }}', '{{ date_format }}' ) as {{ alias }}
{%- elif datatype in ['STRING', 'VARCHAR'] %}'{{ unknown_value__STRING }}' AS {{ alias }}
{%- elif datatype == 'CHAR' %}CAST('{{ unknown_value_alt__STRING }}' as {{ datatype }} ) as "{{ alias }}"
{%- elif datatype == 'CHAR' %}CAST('{{ unknown_value_alt__STRING }}' as {{ datatype }} ) as {{ alias }}
{%- elif datatype.upper().startswith('VARCHAR(') or datatype.upper().startswith('CHAR(') -%}
{%- if col_size is not none -%}
{%- set unknown_dtype_length = col_size | int -%}
Expand All @@ -174,19 +176,19 @@
{%- set unknown_dtype_length = inside_parenthesis | int -%}
{%- endif -%}
{%- if unknown_dtype_length < unknown_value__STRING|length -%}
CAST('{{ unknown_value_alt__STRING }}' as {{ datatype }} ) as "{{ alias }}"
CAST('{{ unknown_value_alt__STRING }}' as {{ datatype }} ) as {{ alias }}
{%- else -%}
CAST('{{ unknown_value__STRING }}' as {{ datatype }} ) as "{{ alias }}"
CAST('{{ unknown_value__STRING }}' as {{ datatype }} ) as {{ alias }}
{%- endif -%}
{%- elif datatype in ['NUMBER','INT','FLOAT','DECIMAL'] %}0 AS {{ alias }}
{%- elif datatype == 'BOOLEAN' %}CAST('FALSE' AS BOOLEAN) AS {{ alias }}
{%- else %}NULL AS {{ alias }}
{% endif %}
{%- elif ghost_record_type == 'error' -%}
{%- if datatype in ['TIMESTAMP_NTZ','TIMESTAMP'] %}{{ datavault4dbt.string_to_timestamp(timestamp_format, end_of_all_times) }} AS {{ alias }}
{%- elif datatype == 'DATE'-%} TO_DATE('{{ end_of_all_times_date }}', '{{ date_format }}' ) as "{{ alias }}"
{%- elif datatype == 'DATE'-%} TO_DATE('{{ end_of_all_times_date }}', '{{ date_format }}' ) as {{ alias }}
{%- elif datatype in ['STRING','VARCHAR'] %}'{{ error_value__STRING }}' AS {{ alias }}
{%- elif datatype == 'CHAR' %}CAST('{{ error_value_alt__STRING }}' as {{ datatype }} ) as "{{ alias }}"
{%- elif datatype == 'CHAR' %}CAST('{{ error_value_alt__STRING }}' as {{ datatype }} ) as {{ alias }}
{%- elif datatype.upper().startswith('VARCHAR(') or datatype.upper().startswith('CHAR(') -%}
{%- if col_size is not none -%}
{%- set error_dtype_length = col_size | int -%}
Expand All @@ -199,9 +201,9 @@
{%- set error_dtype_length = inside_parenthesis | int -%}
{%- endif -%}
{%- if error_dtype_length < error_value__STRING|length -%}
CAST('{{ error_value_alt__STRING }}' as {{ datatype }} ) as "{{ alias }}"
CAST('{{ error_value_alt__STRING }}' as {{ datatype }} ) as {{ alias }}
{%- else -%}
CAST('{{ error_value__STRING }}' as {{ datatype }} ) as "{{ alias }}"
CAST('{{ error_value__STRING }}' as {{ datatype }} ) as {{ alias }}
{%- endif -%}
{% elif datatype in ['NUMBER','INT','FLOAT','DECIMAL'] %}-1 AS {{ alias }}
{% elif datatype == 'BOOLEAN' %}CAST('FALSE' AS BOOLEAN) AS {{ alias }}
Expand Down

0 comments on commit 555d102

Please sign in to comment.