diff --git a/integration_tests/models/plugins/snowflake/snowflake_external.yml b/integration_tests/models/plugins/snowflake/snowflake_external.yml index ad62cec..922ca68 100644 --- a/integration_tests/models/plugins/snowflake/snowflake_external.yml +++ b/integration_tests/models/plugins/snowflake/snowflake_external.yml @@ -202,19 +202,12 @@ 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') @@ -222,4 +215,19 @@ sources: - id - first_name - last_name - - email \ No newline at end of file + - 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 \ No newline at end of file diff --git a/macros/plugins/snowflake/create_external_table.sql b/macros/plugins/snowflake/create_external_table.sql index d671e8d..9045ced 100644 --- a/macros/plugins/snowflake/create_external_table.sql +++ b/macros/plugins/snowflake/create_external_table.sql @@ -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) %} @@ -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]}})