Skip to content

Commit

Permalink
updated for ignore case changes for infer schema
Browse files Browse the repository at this point in the history
  • Loading branch information
cakkinep committed Jul 19, 2024
1 parent cebfcf4 commit 093f967
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
32 changes: 20 additions & 12 deletions integration_tests/models/plugins/snowflake/snowflake_external.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,24 +202,32 @@ sources:
- email
- email_domain

- name: people_ignore_case

- name: people_parquet_infer_schema_ignore_case_unpartitioned
external:
<<: *csv-people
<<: *parquet-people
infer_schema: true
ignore_case: true
columns:
- name: id
data_type: int
- name: first_name
data_type: varchar(64)
- name: last_name
data_type: varchar(64)
- name: email
data_type: varchar(64)
tests:
- dbt_utils.equality:
compare_model: ref('people_ignore_case')
compare_columns:
- id
- first_name
- last_name
- email
- 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
6 changes: 5 additions & 1 deletion macros/plugins/snowflake/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% 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 @@ -55,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 093f967

Please sign in to comment.