Skip to content

Commit

Permalink
Merge pull request #308 from cakkinep/snowflake_ignore_case
Browse files Browse the repository at this point in the history
added ignore_case for Snowflake
  • Loading branch information
dataders authored Oct 25, 2024
2 parents b95d4e3 + 59d3174 commit 5f344e6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT
{{ dbt_utils.star(from=ref('people'), except=['email']) }},
email as Email
FROM {{ ref('people') }}
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,34 @@ sources:
- first_name
- last_name
- email
- email_domain
- email_domain


- name: people_parquet_infer_schema_ignore_case_unpartitioned
external:
<<: *parquet-people
infer_schema: true
ignore_case: true
tests:
- dbt_utils.equality:
compare_model: ref('people_ignore_case')
compare_columns:
- id
- first_name
- last_name
- email

- name: people_parquet_column_list_ignore_case_partitioned
external:
<<: *parquet-people
partitions: *parts-of-the-people
ignore_case: true
columns: *cols-of-the-people
tests:
- dbt_utils.equality:
compare_model: ref('people_ignore_case')
compare_columns:
- id
- first_name
- last_name
- email
11 changes: 10 additions & 1 deletion macros/plugins/snowflake/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
{%- set external = source_node.external -%}
{%- set partitions = external.partitions -%}
{%- set infer_schema = external.infer_schema -%}
{%- set ignore_case = external.ignore_case -%}

{% if infer_schema %}
{% set query_infer_schema %}
select * from table( infer_schema( location=>'{{external.location}}', file_format=>'{{external.file_format}}') )
select * from table( infer_schema( location=>'{{external.location}}', file_format=>'{{external.file_format}}', ignore_case=>true) )
{% endset %}
{% if execute %}
{% set columns_infer = run_query(query_infer_schema) %}
Expand Down Expand Up @@ -40,7 +41,11 @@
{%- if column.expression -%}
{{column.expression}}
{%- else -%}
{%- if ignore_case -%}
{%- set col_id = 'value:c' ~ loop.index if is_csv else 'GET_IGNORE_CASE($1, ' ~ "'"~ column_quoted ~"'"~ ')' -%}
{%- else -%}
{%- set col_id = 'value:c' ~ loop.index if is_csv else 'value:' ~ column_quoted -%}
{%- endif -%}
(case when is_null_value({{col_id}}) or lower({{col_id}}) = 'null' then null else {{col_id}} end)
{%- endif -%}
{%- endset %}
Expand All @@ -50,7 +55,11 @@
{% else %}
{%- for column in columns_infer %}
{%- set col_expression -%}
{%- if ignore_case -%}
{%- set col_id = 'GET_IGNORE_CASE($1, ' ~ "'"~ column[0] ~"'"~ ')' -%}
{%- else -%}
{%- set col_id = 'value:' ~ column[0] -%}
{%- endif -%}
(case when is_null_value({{col_id}}) or lower({{col_id}}) = 'null' then null else {{col_id}} end)
{%- endset %}
{{column[0]}} {{column[1]}} as ({{col_expression}}::{{column[1]}})
Expand Down

0 comments on commit 5f344e6

Please sign in to comment.