Skip to content

Commit

Permalink
Merge pull request #257 from cakkinep/snowflake_column_alias
Browse files Browse the repository at this point in the history
alias column for snowflake external table
  • Loading branch information
dataders authored Apr 11, 2024
2 parents 38417dd + 954733a commit a56a255
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ sources:
data_type: varchar(64)
- name: email
data_type: varchar(64)
- name: email
alias: email_alias
data_type: varchar(64)
tests: &equal-to-the-people
- dbt_utils.equality:
compare_model: ref('people')
Expand All @@ -28,6 +31,7 @@ sources:
- first_name
- last_name
- email
- email_alias

- name: people_csv_partitioned
external:
Expand Down
4 changes: 3 additions & 1 deletion macros/plugins/snowflake/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
{%- endfor -%}{%- endif -%}
{%- if not infer_schema -%}
{%- for column in columns %}
{%- set column_alias = column.alias if column.alias else column.name %}
{%- set column_alias_quoted = adapter.quote(column_alias) if column.quote else column_alias %}
{%- set column_quoted = adapter.quote(column.name) if column.quote else column.name %}
{%- set col_expression -%}
{%- set col_id = 'value:c' ~ loop.index if is_csv else 'value:' ~ column_quoted -%}
(case when is_null_value({{col_id}}) or lower({{col_id}}) = 'null' then null else {{col_id}} end)
{%- endset %}
{{column_quoted}} {{column.data_type}} as ({{col_expression}}::{{column.data_type}})
{{column_alias_quoted}} {{column.data_type}} as ({{col_expression}}::{{column.data_type}})
{{- ',' if not loop.last -}}
{% endfor %}
{% else %}
Expand Down

0 comments on commit a56a255

Please sign in to comment.