diff --git a/integration_tests/models/plugins/snowflake/snowflake_external.yml b/integration_tests/models/plugins/snowflake/snowflake_external.yml index 195cca9d..4e8c24b6 100644 --- a/integration_tests/models/plugins/snowflake/snowflake_external.yml +++ b/integration_tests/models/plugins/snowflake/snowflake_external.yml @@ -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') @@ -28,6 +31,7 @@ sources: - first_name - last_name - email + - email_alias - name: people_csv_partitioned external: diff --git a/macros/plugins/snowflake/create_external_table.sql b/macros/plugins/snowflake/create_external_table.sql index bdfcd9f4..7db5749f 100644 --- a/macros/plugins/snowflake/create_external_table.sql +++ b/macros/plugins/snowflake/create_external_table.sql @@ -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 %}