Skip to content

Commit a80a51b

Browse files
authored
Merge pull request #279 from ScalefreeCOM/improve-snowflake-ghostrecords
improve handling of the various timestamp formats in snowflake ghost records
2 parents 30ae0c7 + f5eee3d commit a80a51b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

macros/supporting/ghost_record_per_datatype.sql

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@
170170
{%- set alias = datavault4dbt.escape_column_names(alias) -%}
171171

172172
{%- if ghost_record_type == 'unknown' -%}
173-
{%- if datatype in ['TIMESTAMP_NTZ','TIMESTAMP'] %}{{ datavault4dbt.string_to_timestamp(timestamp_format, beginning_of_all_times) }} AS {{ alias }}
173+
{%- if datatype in ['TIMESTAMP_NTZ'] %} TO_TIMESTAMP_NTZ( '{{ beginning_of_all_times}}', '{{ timestamp_format}}') AS {{ alias }}
174+
{%- elif datatype in ['TIMESTAMP_TZ'] %} TO_TIMESTAMP_TZ( '{{ beginning_of_all_times}}', '{{ timestamp_format}}') AS {{ alias }}
175+
{%- elif datatype in ['TIMESTAMP_LTZ'] %} TO_TIMESTAMP_LTZ( '{{ beginning_of_all_times}}', '{{ timestamp_format}}') AS {{ alias }}
174176
{%- elif datatype == 'DATE'-%} TO_DATE('{{ beginning_of_all_times_date }}', '{{ date_format }}' ) as {{ alias }}
175177
{%- elif datatype in ['STRING', 'VARCHAR','TEXT'] %}'{{ unknown_value__STRING }}' AS {{ alias }}
176178
{%- elif datatype == 'CHAR' %}CAST('{{ unknown_value_alt__STRING }}' as {{ datatype }} ) as {{ alias }}
@@ -190,13 +192,18 @@
190192
{%- else -%}
191193
CAST('{{ unknown_value__STRING }}' as {{ datatype }} ) as {{ alias }}
192194
{%- endif -%}
193-
{%- elif datatype in ['NUMBER','INT','FLOAT','DECIMAL'] %}{{unknown_value__numeric}} AS {{ alias }}
195+
{%- elif datatype in ['INT','FLOAT', 'INTEGER', 'BIGINT', 'SMALLINT', 'TINYINT', 'BYTEINT'] %}{{unknown_value__numeric}} AS {{ alias }}
196+
{%- elif datatype.startswith('NUMBER') %} {{unknown_value__numeric}} AS {{ alias }}
197+
{%- elif datatype.startswith('NUMERIC') %} {{unknown_value__numeric}} AS {{ alias }}
198+
{%- elif datatype.startswith('DECIMAL') %} {{unknown_value__numeric}} AS {{ alias }}
194199
{%- elif datatype == 'BOOLEAN' %}CAST('FALSE' AS BOOLEAN) AS {{ alias }}
195200
{%- elif datatype in ['ARRAY', 'VARIANT'] %} CAST('{{ unknown_value__STRING }}' as {{ datatype }} ) AS {{ alias }}
196201
{%- else %}NULL AS {{ alias }}
197202
{% endif %}
198203
{%- elif ghost_record_type == 'error' -%}
199-
{%- if datatype in ['TIMESTAMP_NTZ','TIMESTAMP'] %}{{ datavault4dbt.string_to_timestamp(timestamp_format, end_of_all_times) }} AS {{ alias }}
204+
{%- if datatype in ['TIMESTAMP_NTZ'] %} TO_TIMESTAMP_NTZ( '{{ end_of_all_times}}', '{{ timestamp_format}}') AS {{ alias }}
205+
{%- elif datatype in ['TIMESTAMP_TZ'] %} TO_TIMESTAMP_TZ( '{{ end_of_all_times}}', '{{ timestamp_format}}') AS {{ alias }}
206+
{%- elif datatype in ['TIMESTAMP_LTZ'] %} TO_TIMESTAMP_LTZ( '{{ end_of_all_times}}', '{{ timestamp_format}}') AS {{ alias }}
200207
{%- elif datatype == 'DATE'-%} TO_DATE('{{ end_of_all_times_date }}', '{{ date_format }}' ) as {{ alias }}
201208
{%- elif datatype in ['STRING','VARCHAR','TEXT'] %}'{{ error_value__STRING }}' AS {{ alias }}
202209
{%- elif datatype == 'CHAR' %}CAST('{{ error_value_alt__STRING }}' as {{ datatype }} ) as {{ alias }}
@@ -216,11 +223,14 @@
216223
{%- else -%}
217224
CAST('{{ error_value__STRING }}' as {{ datatype }} ) as {{ alias }}
218225
{%- endif -%}
219-
{% elif datatype in ['NUMBER','INT','FLOAT','DECIMAL'] %}{{error_value__numeric}} AS {{ alias }}
226+
{%- elif datatype in ['INT','FLOAT', 'INTEGER', 'BIGINT', 'SMALLINT', 'TINYINT', 'BYTEINT'] %}{{error_value__numeric}} AS {{ alias }}
227+
{%- elif datatype.startswith('NUMBER') %} {{error_value__numeric}} AS {{ alias }}
228+
{%- elif datatype.startswith('NUMERIC') %} {{error_value__numeric}} AS {{ alias }}
229+
{%- elif datatype.startswith('DECIMAL') %} {{error_value__numeric}} AS {{ alias }}
220230
{% elif datatype == 'BOOLEAN' %}CAST('FALSE' AS BOOLEAN) AS {{ alias }}
221231
{%- elif datatype in ['ARRAY', 'VARIANT'] %} CAST('{{ error_value__STRING }}' as {{ datatype }} ) AS {{ alias }}
222232
{% else %}NULL AS {{ alias }}
223-
{% endif %}
233+
{% endif %}
224234
{%- else -%}
225235
{%- if execute -%}
226236
{{ exceptions.raise_compiler_error("Invalid Ghost Record Type. Accepted are 'unknown' and 'error'.") }}

0 commit comments

Comments
 (0)