diff --git a/integration_tests/macros/common/cleanup_external.sql b/integration_tests/macros/common/cleanup_external.sql new file mode 100644 index 00000000..5ddcaf19 --- /dev/null +++ b/integration_tests/macros/common/cleanup_external.sql @@ -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 %} diff --git a/integration_tests/macros/plugins/snowflake/cleanup_external.sql b/integration_tests/macros/plugins/snowflake/cleanup_external.sql new file mode 100644 index 00000000..305b9f48 --- /dev/null +++ b/integration_tests/macros/plugins/snowflake/cleanup_external.sql @@ -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 %} diff --git a/integration_tests/macros/plugins/snowflake/prep_external.sql b/integration_tests/macros/plugins/snowflake/prep_external.sql index 5dd4dca9..6d33ca0b 100644 --- a/integration_tests/macros/plugins/snowflake/prep_external.sql +++ b/integration_tests/macros/plugins/snowflake/prep_external.sql @@ -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 %} diff --git a/macros/plugins/snowflake/helpers/transaction.sql b/macros/plugins/snowflake/helpers/transaction.sql new file mode 100644 index 00000000..15b3e003 --- /dev/null +++ b/macros/plugins/snowflake/helpers/transaction.sql @@ -0,0 +1,3 @@ +{% macro snowflake__exit_transaction() %} + {{ return('begin; commit;') }} +{% endmacro %} diff --git a/run_test.sh b/run_test.sh index a4faf193..b9f61de6 100755 --- a/run_test.sh +++ b/run_test.sh @@ -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