Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
a37da9c
Added in the ability to create columns on external tables by defining…
jasonzondor Oct 6, 2020
7c6a935
updated readme and sample source
jasonzondor Oct 6, 2020
2280546
Fixing commit issue for snowflake on refreshes.
jasonzondor Nov 9, 2020
38e669d
Merge pull request #1 from jasonzondor/feature/snowflake-ext-calc-column
jasonzondor Nov 9, 2020
14c4d8c
oops, forgot to set ddl for external refresh.
jasonzondor Nov 9, 2020
02a2316
Merge pull request #2 from jasonzondor/feature/snowflake-ext-calc-column
jasonzondor Nov 9, 2020
6a65d4e
Commit transactions on Snowflake
jtcohen6 Nov 14, 2020
ebe0498
Merge branch 'master' of github.com:fishtown-analytics/dbt-external-t…
jtcohen6 Nov 16, 2020
0d01b30
Try replicating via autocommit
jtcohen6 Nov 16, 2020
de571e5
Circle hates tabs
jtcohen6 Nov 16, 2020
44220ce
Merge master
jtcohen6 Jan 25, 2021
557bf47
Add back code lost in merge
jtcohen6 Jan 25, 2021
970452b
Readd cleanup step
jtcohen6 Jan 25, 2021
62e60eb
Snowflake Azure: auto refresh external tables
Apr 21, 2021
ed05c70
Quote notification integration parameter
Apr 21, 2021
64b4714
Merge pull request #87 from bbossy/notification-integration-azure
jtcohen6 Apr 29, 2021
4f1c7d2
Try reverting test changes, upgrading python in ci
jtcohen6 May 17, 2021
0526c77
Merge pull request #90 from fishtown-analytics/fix-integration-tests-…
jtcohen6 May 17, 2021
deb9fe9
Update README.md: link to dbt PR for `external`
vergenzt May 20, 2021
85c12c3
Fix if whitespace triming
clegendre May 23, 2021
87adc64
Merge pull request #92 from datahawk-technologies/fix/spark-external-…
jtcohen6 May 25, 2021
a3b5619
Merge pull request #91 from vergenzt/patch-1
jtcohen6 May 25, 2021
5fdca89
Merge branch 'master' of github.com:fishtown-analytics/dbt-external-t…
jtcohen6 May 25, 2021
662b5a0
Merge pull request #47 from fishtown-analytics/fix/snowpipe-copy-commit
jtcohen6 May 25, 2021
4869caf
wrap options.items() values in single quotes
davesgonechina May 27, 2021
e3dea14
single quote value if string
davesgonechina May 27, 2021
f582066
Merge remote-tracking branch 'upstream/master'
jasonzondor Jun 7, 2021
289db8d
Adding begin and commit statements to refresh macro.
jasonzondor Jun 7, 2021
a4e48e6
Adding readme and snowflake sample files back in...
jasonzondor Jun 7, 2021
b0f0663
Merge pull request #93 from davesgonechina/patch-1
jtcohen6 Jun 25, 2021
6715a0f
Merge pull request #98 from jasonzondor/fix/snowflake-refresh-commit
jtcohen6 Jun 25, 2021
c09fc3f
Wrap Snowflake DML in explicit transactions
jtcohen6 Jun 25, 2021
9e7e07b
Merge pull request #101 from fishtown-analytics/snowflake-explicit-tr…
jtcohen6 Jun 25, 2021
6a05dc9
Revert previous attempt at committing Snowflake DML via implicit tran…
jtcohen6 Jul 7, 2021
850d531
Upgrade dbt v0.20, dbt-utils v0.7 (#99)
jtcohen6 Jul 7, 2021
29ff5f4
Explicitly set auto_refresh if populated
barberscott Aug 14, 2021
4cf72ba
Merge pull request #105 from dbt-labs/make-auto_refresh-explicit
barberscott Aug 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:

integration-redshift:
docker:
- image: circleci/python:3.6.3-stretch
- image: circleci/python:3.6.13-stretch
steps:
- checkout
- run:
Expand All @@ -19,7 +19,7 @@ jobs:

integration-snowflake:
docker:
- image: circleci/python:3.6.3-stretch
- image: circleci/python:3.6.13-stretch
steps:
- checkout
- run:
Expand All @@ -32,7 +32,7 @@ jobs:
environment:
BIGQUERY_SERVICE_KEY_PATH: "/home/circleci/bigquery-service-key.json"
docker:
- image: circleci/python:3.6.3-stretch
- image: circleci/python:3.6.13-stretch
steps:
- checkout
- run:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# External sources in dbt

dbt v0.15.0 added support for an `external` property within `sources` that can include information about `location`, `partitions`, and other database-specific properties.
dbt v0.15.0 [added support](https://github.com/dbt-labs/dbt/pull/1784) for an `external` property within `sources` that can include information about `location`, `partitions`, and other database-specific properties.

This package provides:
* Macros to create/replace external tables and refresh their partitions, using the metadata provided in your `.yml` file source definitions
Expand All @@ -19,7 +19,7 @@ This package provides:

## Installation

Follow the instructions at [hub.getdbt.com](https://hub.getdbt.com/fishtown-analytics/dbt_external_tables/latest/) on how to modify your `packages.yml` and run `dbt deps`.
Follow the instructions at [hub.getdbt.com](https://hub.getdbt.com/dbt-labs/dbt_external_tables/latest/) on how to modify your `packages.yml` and run `dbt deps`.

## Syntax

Expand Down Expand Up @@ -115,9 +115,9 @@ execute the appropriate `create`, `refresh`, and/or `drop` commands:
`stage_external_sources` runs as an operation
* [`tested specs`](integration_tests/models/plugins): source spec variations that are confirmed to work on each database, via integration tests

If you encounter issues using this package or have questions, please check the [open issues](https://github.com/fishtown-analytics/dbt-external-tables/issues), as there's a chance it's a known limitation or work in progress. If not, you can:
If you encounter issues using this package or have questions, please check the [open issues](https://github.com/dbt-labs/dbt-external-tables/issues), as there's a chance it's a known limitation or work in progress. If not, you can:
- open a new issue to report a bug or suggest an enhancement
- post a technical question to [StackOverflow](https://stackoverflow.com/questions/tagged/dbt)
- post a conceptual question to the relevant database channel (#db-redshift, #dbt-snowflake, etc) in the [dbt Slack community](https://community.getdbt.com/)

Additional contributions to this package are very welcome! Please create issues or open PRs against `master`. Check out [this post](https://discourse.getdbt.com/t/contributing-to-an-external-dbt-package/657) on the best workflow for contributing to a package.
Additional contributions to this package are very welcome! Please create issues or open PRs against `master`. Check out [this post](https://discourse.getdbt.com/t/contributing-to-an-external-dbt-package/657) on the best workflow for contributing to a package.
4 changes: 2 additions & 2 deletions dbt_project.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'dbt_external_tables'
version: '0.3.0'
version: '0.7.0'

config-version: 2

require-dbt-version: ">=0.18.0"
require-dbt-version: ">=0.20.0"

source-paths: ["models"]
analysis-paths: ["analysis"]
Expand Down
26 changes: 20 additions & 6 deletions integration_tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ profile: 'integration_tests'

config-version: 2

source-paths:
- "sources/common"
- "sources/plugins/{{ target.type }}"

source-paths: ["models"]
analysis-paths: ["analysis"]
test-paths: ["tests"]
data-paths: ["data"]
Expand All @@ -20,8 +17,25 @@ clean-targets:
- "target"
- "dbt_modules"

vars:
dbt_external_tables_dispatch_list: ['dbt_external_tables_integration_tests']
dispatch:
- macro_namespace: dbt_external_tables
search_order: ['dbt_external_tables_integration_tests', 'dbt_external_tables']

seeds:
+quote_columns: false

sources:
dbt_external_tables_integration_tests:
plugins:
redshift_external:
+enabled: "{{ target.type == 'redshift' }}"
snowflake_external:
+enabled: "{{ target.type == 'snowflake' }}"
bigquery_external:
+enabled: "{{ target.type == 'bigquery' }}"
spark_external:
+enabled: "{{ target.type == 'spark' }}"
synapse_external:
+enabled: "{{ target.type == 'synapse' }}"
azuresql_external:
+enabled: "{{ target.type == 'sqlserver' }}"
2 changes: 1 addition & 1 deletion integration_tests/macros/common/prep_external.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro prep_external() %}
{{ return(adapter.dispatch('prep_external', dbt_external_tables._get_dbt_external_tables_namespaces())()) }}
{{ return(adapter.dispatch('prep_external', 'dbt_external_tables')()) }}
{% endmacro %}

{% macro default__prep_external() %}
Expand Down
4 changes: 1 addition & 3 deletions macros/common/create_external_table.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% macro create_external_table(source_node) %}
{{ adapter.dispatch('create_external_table',
packages = dbt_external_tables._get_dbt_external_tables_namespaces())
(source_node) }}
{{ adapter.dispatch('create_external_table', 'dbt_external_tables')(source_node) }}
{% endmacro %}

{% macro default__create_external_table(source_node) %}
Expand Down
4 changes: 1 addition & 3 deletions macros/common/get_external_build_plan.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% macro get_external_build_plan(source_node) %}
{{ return(adapter.dispatch('get_external_build_plan',
packages = dbt_external_tables._get_dbt_external_tables_namespaces())
(source_node)) }}
{{ return(adapter.dispatch('get_external_build_plan', 'dbt_external_tables')(source_node)) }}
{% endmacro %}

{% macro default__get_external_build_plan(source_node) %}
Expand Down
4 changes: 1 addition & 3 deletions macros/common/helpers/dropif.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% macro dropif(node) %}
{{ adapter.dispatch('dropif',
packages = dbt_external_tables._get_dbt_external_tables_namespaces())
(node) }}
{{ adapter.dispatch('dropif', 'dbt_external_tables')(node) }}
{% endmacro %}

{% macro default__dropif() %}
Expand Down
4 changes: 0 additions & 4 deletions macros/common/helpers/get_external_tables_namespace.sql

This file was deleted.

2 changes: 1 addition & 1 deletion macros/common/helpers/transaction.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro exit_transaction() %}
{{ return(adapter.dispatch('exit_transaction', dbt_external_tables._get_dbt_external_tables_namespaces())()) }}
{{ return(adapter.dispatch('exit_transaction', 'dbt_external_tables')()) }}
{% endmacro %}

{% macro default__exit_transaction() %}
Expand Down
4 changes: 1 addition & 3 deletions macros/common/refresh_external_table.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% macro refresh_external_table(source_node) %}
{{ return(adapter.dispatch('refresh_external_table',
packages = dbt_external_tables._get_dbt_external_tables_namespaces())
(source_node)) }}
{{ return(adapter.dispatch('refresh_external_table', 'dbt_external_tables')(source_node)) }}
{% endmacro %}

{% macro default__refresh_external_table(source_node) %}
Expand Down
2 changes: 1 addition & 1 deletion macros/common/stage_external_sources.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

{% for q in run_queue %}

{% set q_msg = q|trim %}
{% set q_msg = q|replace('\n','')|replace('begin;','')|trim %}
{% set q_log = q_msg[:50] ~ '... ' if q_msg|length > 50 else q_msg %}

{% do dbt_utils.log_info(loop_label ~ ' (' ~ loop.index ~ ') ' ~ q_log) %}
Expand Down
4 changes: 4 additions & 0 deletions macros/plugins/bigquery/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@
uris = [{%- for uri in uris -%} '{{uri}}' {{- "," if not loop.last}} {%- endfor -%}]
{%- if options is mapping -%}
{%- for key, value in options.items() if key != 'uris' %}
{%- if value is string -%}
, {{key}} = '{{value}}'
{%- else -%}
, {{key}} = {{value}}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
)
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 @@ -27,7 +27,8 @@
{%- endif -%}
{% if partitions %} partition by ({{partitions|map(attribute='name')|join(', ')}}) {% endif %}
location = {{external.location}} {# stage #}
{% if external.auto_refresh -%} auto_refresh = {{external.auto_refresh}} {%- endif %}
{% if external.auto_refresh is not none -%} auto_refresh = {{external.auto_refresh}} {%- endif %}
{% if external.pattern -%} pattern = '{{external.pattern}}' {%- endif %}
{% if external.integration -%} integration = '{{external.integration}}' {%- endif %}
file_format = {{external.file_format}}
{% endmacro %}
2 changes: 1 addition & 1 deletion macros/plugins/snowflake/get_external_build_plan.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% if create_or_replace %}
{% set build_plan = build_plan + [
dbt_external_tables.snowflake_create_empty_table(source_node),
dbt_external_tables.snowflake_get_copy_sql(source_node),
dbt_external_tables.snowflake_get_copy_sql(source_node, explicit_transaction=true),
dbt_external_tables.snowflake_create_snowpipe(source_node)
] %}
{% else %}
Expand Down
4 changes: 3 additions & 1 deletion macros/plugins/snowflake/refresh_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
{% if manual_refresh %}

{% set ddl %}
alter external table {{source(source_node.source_name, source_node.name)}} refresh
begin;
alter external table {{source(source_node.source_name, source_node.name)}} refresh;
commit;
{% endset %}

{% do return([ddl]) %}
Expand Down
8 changes: 6 additions & 2 deletions macros/plugins/snowflake/snowpipe/get_copy_sql.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{% macro snowflake_get_copy_sql(source_node) %}
{% macro snowflake_get_copy_sql(source_node, explicit_transaction=false) %}
{# This assumes you have already created an external stage #}

{%- set columns = source_node.columns.values() -%}
{%- set external = source_node.external -%}
{%- set is_csv = dbt_external_tables.is_csv(external.file_format) %}
{%- set copy_options = external.snowpipe.get('copy_options', none) -%}

{%- if explicit_transaction -%} begin; {%- endif %}

copy into {{source(source_node.source_name, source_node.name)}}
from (
select
Expand All @@ -27,6 +29,8 @@
from {{external.location}} {# stage #}
)
file_format = {{external.file_format}}
{% if copy_options %} {{copy_options}} {% endif %}
{% if copy_options %} {{copy_options}} {% endif %};

{% if explicit_transaction -%} commit; {%- endif -%}

{% endmacro %}
2 changes: 1 addition & 1 deletion macros/plugins/spark/create_external_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{{- ',' if not loop.last -}}
{% endfor %}
) {% endif -%}
{% if external.using -%} using {{external.using}} {%- endif %}
{% if external.using %} using {{external.using}} {%- endif %}
{% if options -%} options (
{%- for key, value in options.items() -%}
'{{ key }}' = '{{value}}' {{- ', \n' if not loop.last -}}
Expand Down
4 changes: 2 additions & 2 deletions packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
packages:
- package: fishtown-analytics/dbt_utils
version: [">=0.6.0", "<0.7.0"]
- package: dbt-labs/dbt_utils
version: [">=0.7.0", "<0.8.0"]
6 changes: 3 additions & 3 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ if [[ ! -f $VENV ]]; then
if [ $1 == 'databricks' ]
then
echo "Installing dbt-spark"
pip install dbt-spark[ODBC] --upgrade
pip install dbt-spark[ODBC] --upgrade --pre
elif [ $1 == 'azuresql' ]
then
echo "Installing dbt-sqlserver"
pip install dbt-sqlserver --upgrade
pip install dbt-sqlserver --upgrade --pre
else
echo "Installing dbt-$1"
pip install dbt-$1 --upgrade
pip install dbt-$1 --upgrade --pre
fi
fi

Expand Down