Skip to content

Commit

Permalink
Merge pull request #47 from fishtown-analytics/fix/snowpipe-copy-commit
Browse files Browse the repository at this point in the history
Commit transactions on Snowflake
  • Loading branch information
jtcohen6 authored May 25, 2021
2 parents a3b5619 + 5fdca89 commit 662b5a0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions integration_tests/macros/common/cleanup_external.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% macro cleanup_external() %}
{{ return(adapter.dispatch('cleanup_external', dbt_external_tables._get_dbt_external_tables_namespaces())()) }}
{% endmacro %}

{% macro default__cleanup_external() %}
{% do log('No cleanup necessary, skipping', info = true) %}
{# noop #}
{% endmacro %}
10 changes: 10 additions & 0 deletions integration_tests/macros/plugins/snowflake/cleanup_external.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% macro snowflake__cleanup_external() %}

{% set unset_autocommit %}
alter user {{ target.user }} unset autocommit;
{% endset %}

{% do log('Unsetting autocommit parameter for user ' ~ target.user, info = true) %}
{% do run_query(unset_autocommit) %}

{% endmacro %}
7 changes: 7 additions & 0 deletions integration_tests/macros/plugins/snowflake/prep_external.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
{% do log('Creating external stage ' ~ external_stage, info = true) %}
{% do run_query(create_external_stage) %}

{% set set_autocommit_false %}
alter user {{ target.user }} set autocommit = false;
{% endset %}

{% do log('Turning off autocommit for user ' ~ target.user, info = true) %}
{% do run_query(set_autocommit_false) %}

{% endmacro %}
3 changes: 3 additions & 0 deletions macros/plugins/snowflake/helpers/transaction.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro snowflake__exit_transaction() %}
{{ return('begin; commit;') }}
{% endmacro %}
1 change: 1 addition & 0 deletions run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ dbt run-operation prep_external --target $1
dbt run-operation stage_external_sources --var 'ext_full_refresh: true' --target $1
dbt run-operation stage_external_sources --target $1
dbt test --target $1
dbt run-operation cleanup_external --target $1

0 comments on commit 662b5a0

Please sign in to comment.