Skip to content

Commit

Permalink
Merge pull request #67 from fishtown-analytics/fix/snowflake-column-q…
Browse files Browse the repository at this point in the history
…uoting

Account for col quoting on Snowflake
  • Loading branch information
jtcohen6 authored Jan 28, 2021
2 parents 9d895a1 + 222cd50 commit 74bb971
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions integration_tests/models/plugins/snowflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@ sources:

- name: people_csv_partitioned_no_columns
external:
<<: *json-people
<<: *csv-people
partitions: *parts-of-the-people
tests: *same-rowcount

- name: people_csv_with_keyword_colname
external: *csv-people
columns:
- name: UNION
quote: true
data_type: varchar(64)
tests: *same-rowcount

- name: people_json_unpartitioned_no_columns
external: *csv-people
external: *json-people
tests: *same-rowcount

- name: people_json_partitioned_no_columns
Expand Down
3 changes: 2 additions & 1 deletion macros/plugins/snowflake/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
{{partition.name}} {{partition.data_type}} as {{partition.expression}}{{- ',' if not loop.last or columns|length > 0 -}}
{%- endfor -%}{%- endif -%}
{%- for column in columns %}
{%- set column_quoted = adapter.quote(column.name) if column.quote else column.name %}
{%- set col_expression -%}
{%- if is_csv -%}nullif(value:c{{loop.index}},''){# special case: get columns by ordinal position #}
{%- else -%}nullif(value:{{column.name}},''){# standard behavior: get columns by name #}
{%- endif -%}
{%- endset %}
{{column.name}} {{column.data_type}} as ({{col_expression}}::{{column.data_type}})
{{column_quoted}} {{column.data_type}} as ({{col_expression}}::{{column.data_type}})
{{- ',' if not loop.last -}}
{% endfor %}
)
Expand Down

0 comments on commit 74bb971

Please sign in to comment.