Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add ignore case option to snowflake #289

9 changes: 7 additions & 2 deletions 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}}'{%- if ignore_case -%}, ignore_case=>{{ignore_case}} {%- endif %} ) )
{% endset %}
{% if execute %}
{% set columns_infer = run_query(query_infer_schema) %}
Expand Down Expand Up @@ -50,7 +51,11 @@
{% else %}
{%- for column in columns_infer %}
{%- set col_expression -%}
{%- set col_id = 'value:' ~ column[0] -%}
{%- if not ignore_case -%}
{%- set col_id = 'value:' ~ column[0] -%}
{%- else -%}
{%- set col_id = "get_ignore_case(value, '{}')".format(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
17 changes: 17 additions & 0 deletions sample_sources/snowflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,23 @@ sources:
- name: name
description: and this is a name

- name: parquet_with_inferred_schema_and_mixed_column_case
description: "External table using Parquet and inferring the schema with mixed column case"
external:
location: "@stage" # reference an existing external stage
file_format: "my_file_format" # we need a named file format for infer to work
infer_schema: true # parameter to tell Snowflake we want to infer the table schema
ignore_case: true # parameter to tell Snowflake we want to ignore column case differences
partitions:
- name: section # we can define partitions on top of the schema columns
data_type: varchar(64)
expression: "substr(split_part(metadata$filename, 'section=', 2), 1, 1)"
columns: # columns can still be listed for documentation/testing purpose
- name: id
description: this is an id
- name: name
description: and this is a name

- name: aws_sns_refresh_tbl
description: "External table using AWS SNS for auto-refresh"
external:
Expand Down
Loading