Skip to content

Commit

Permalink
Merge branch 'main' into jtmcn/external-tables/snf-copied-at
Browse files Browse the repository at this point in the history
  • Loading branch information
dataders authored Apr 11, 2024
2 parents f627222 + a56a255 commit 09835ce
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ sources:
columns: &cols-of-the-people
- name: id
data_type: int64
description: id_of_the_person
- name: first_name
data_type: string
- name: last_name
Expand Down
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
3 changes: 3 additions & 0 deletions macros/common/stage_external_sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@

{% endfor %}

{% set update_columns = dbt_external_tables.update_external_table_columns(node) %}
{{ update_columns }}

{% endfor %}

{% endmacro %}
7 changes: 7 additions & 0 deletions macros/common/update_external_table_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% macro update_external_table_columns(source_node) %}
{{ return(adapter.dispatch('update_external_table_columns', 'dbt_external_tables')(source_node)) }}
{% endmacro %}

{% macro default__update_external_table_columns(source_node) %}

{% endmacro %}
1 change: 0 additions & 1 deletion macros/plugins/bigquery/create_external_table.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% macro bigquery__create_external_table(source_node) %}

{%- set columns = source_node.columns.values() -%}
{%- set external = source_node.external -%}
{%- set partitions = external.partitions -%}
Expand Down
5 changes: 5 additions & 0 deletions macros/plugins/bigquery/update_external_table_columns.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro bigquery__update_external_table_columns(source_node) %}
{%- set columns = source_node.columns -%}
{%- set relation = source(source_node.source_name, source_node.name) -%}
{%- do adapter.update_columns(relation, columns) -%}
{% endmacro %}
7 changes: 6 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 All @@ -51,6 +53,9 @@
{% if external.auto_refresh in (true, false) -%}
auto_refresh = {{external.auto_refresh}}
{%- endif %}
{% if external.aws_sns_topic -%}
aws_sns_topic = '{{external.aws_sns_topic}}'
{%- endif %}
{% if external.table_format | lower == "delta" %}
refresh_on_create = false
{% endif %}
Expand Down
10 changes: 9 additions & 1 deletion sample_sources/snowflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ sources:
- name: id
description: this is an id
- name: name
description: and this is a name
description: and this is a name

- name: aws_sns_refresh_tbl
description: "External table using AWS SNS for auto-refresh"
external:
location: "@stage" # reference an existing external stage
file_format: "( type = csv )"
# auto_refresh is assumed, setting to false is not supported
aws_sns_topic: "arn:aws:sns:us-east-1:123456789012:my_topic" # SNS topic ARN

0 comments on commit 09835ce

Please sign in to comment.