diff --git a/dbt/include/synapse/macros/adapters/columns.sql b/dbt/include/synapse/macros/adapters/columns.sql index 37ecb9d..4487ddf 100644 --- a/dbt/include/synapse/macros/adapters/columns.sql +++ b/dbt/include/synapse/macros/adapters/columns.sql @@ -7,7 +7,7 @@ path={"identifier": relation.identifier.replace("#", "") ~ '_tmp_tbl_hack'}, type='table')-%} - {% do drop_relation(tmp_tbl_hack) %} + {% do adapter.drop_relation(tmp_tbl_hack) %} {% set sql_create %} CREATE TABLE {{ tmp_tbl_hack }} WITH( @@ -23,7 +23,7 @@ {% call statement() -%} {{ sql_create }} {%- endcall %} {% set output = get_columns_in_relation(tmp_tbl_hack) %} - {% do drop_relation(tmp_tbl_hack) %} + {% do adapter.drop_relation(tmp_tbl_hack) %} {{ return(output) }} {% endif %} diff --git a/dbt/include/synapse/macros/adapters/relation.sql b/dbt/include/synapse/macros/adapters/relation.sql index 93360a6..55cae69 100644 --- a/dbt/include/synapse/macros/adapters/relation.sql +++ b/dbt/include/synapse/macros/adapters/relation.sql @@ -7,7 +7,6 @@ {% endif %} if object_id ('{{ relation }}','{{ object_id_type }}') is not null drop {{ relation.type }} {{ relation }} - {% endif %} {% endmacro %} {% macro synapse__rename_relation(from_relation, to_relation) -%} diff --git a/dbt/include/synapse/macros/adapters/replace.sql b/dbt/include/synapse/macros/adapters/replace.sql index ec7bedf..307d95e 100644 --- a/dbt/include/synapse/macros/adapters/replace.sql +++ b/dbt/include/synapse/macros/adapters/replace.sql @@ -26,23 +26,24 @@ {{ get_create_intermediate_sql(target_relation, sql) }}; {{ get_create_backup_sql(existing_relation) }}; {{ get_rename_intermediate_sql(target_relation) }}; - {{ synapse__drop_relation(existing_relation) }} + {% do adapter.drop_relation(existing_relation) %} {# /* create target_relation as an intermediate relation, then swap it out with the existing one without using a backup */ #} {%- elif target_relation.can_be_renamed -%} {{ get_create_intermediate_sql(target_relation, sql) }}; - {{ synapse__drop_relation(existing_relation) }}; + {% do adapter.drop_relation(existing_relation) %} {{ get_rename_intermediate_sql(target_relation) }} {# /* create target_relation in place by first backing up the existing relation */ #} {%- elif existing_relation.can_be_renamed -%} {{ get_create_backup_sql(existing_relation) }}; {{ get_create_sql(target_relation, sql) }}; - {{ synapse__drop_relation(existing_relation) }} + {% do adapter.drop_relation(existing_relation) %} {# /* no renaming is allowed, so just drop and create */ #} {%- else -%} {{ synapse__drop_relation(existing_relation) }}; + {% do adapter.drop_relation(existing_relation) %} {{ get_create_sql(target_relation, sql) }} {%- endif -%} diff --git a/dbt/include/synapse/macros/adapters/schema.sql b/dbt/include/synapse/macros/adapters/schema.sql index 212c4b6..db07638 100644 --- a/dbt/include/synapse/macros/adapters/schema.sql +++ b/dbt/include/synapse/macros/adapters/schema.sql @@ -26,7 +26,7 @@ identifier=row[1], type=row[3] ) -%} - {% do drop_relation(schema_relation) %} + {% do adapter.drop_relation(schema_relation) %} {%- endfor %} {% call statement('drop_schema') -%} diff --git a/dbt/include/synapse/macros/materializations/models/materialized_view/materialized_view.sql b/dbt/include/synapse/macros/materializations/models/materialized_view/materialized_view.sql index f7251d9..352eac7 100644 --- a/dbt/include/synapse/macros/materializations/models/materialized_view/materialized_view.sql +++ b/dbt/include/synapse/macros/materializations/models/materialized_view/materialized_view.sql @@ -32,8 +32,9 @@ they return none -- drop the temp relations if they exist already in the database - {{ synapse__drop_relation(preexisting_backup_relation) }} - {{ synapse__drop_relation(preexisting_intermediate_relation) }} + {% do adapter.drop_relation(preexisting_backup_relation) %} + {% do adapter.drop_relation(preexisting_intermediate_relation) %} + {{ run_hooks(pre_hooks, inside_transaction=False) }} @@ -43,8 +44,9 @@ {% macro materialized_view_teardown(backup_relation, intermediate_relation, post_hooks) %} -- drop the temp relations if they exist to leave the database clean for the next run - {{ synapse__drop_relation_script(backup_relation) }} - {{ synapse__drop_relation_script(intermediate_relation) }} + + {% do adapter.drop_relation(backup_relation) %} + {% do adapter.drop_relation(intermediate_relation) %} {{ run_hooks(post_hooks, inside_transaction=False) }} diff --git a/dbt/include/synapse/macros/materializations/models/table/create_table_as.sql b/dbt/include/synapse/macros/materializations/models/table/create_table_as.sql index ac27d7c..b3ee31c 100644 --- a/dbt/include/synapse/macros/materializations/models/table/create_table_as.sql +++ b/dbt/include/synapse/macros/materializations/models/table/create_table_as.sql @@ -6,9 +6,8 @@ type='view')-%} {%- set temp_view_sql = sql.replace("'", "''") -%} - {{ synapse__drop_relation_script(tmp_relation) }} - - {{ synapse__drop_relation_script(relation) }} + {% do adapter.drop_relation(tmp_relation) %} + {% do adapter.drop_relation(relation) %} {{ synapse__create_view_as(tmp_relation, sql) }} @@ -39,6 +38,6 @@ EXEC('CREATE TABLE [{{relation.database}}].[{{relation.schema}}].[{{relation.identifier}}]WITH(DISTRIBUTION = {{dist}},{{index}}) AS (SELECT * FROM [{{tmp_relation.database}}].[{{tmp_relation.schema}}].[{{tmp_relation.identifier}}]);'); {% endif %} - {{ synapse__drop_relation_script(tmp_relation) }} + {% do adapter.drop_relation(tmp_relation) %} {% endmacro %} diff --git a/test.env copy.sample b/test.env copy.sample new file mode 100644 index 0000000..f30946e --- /dev/null +++ b/test.env copy.sample @@ -0,0 +1,11 @@ +SYNAPSE_TEST_DRIVER=ODBC Driver 18 for SQL Server +SYNAPSE_TEST_HOST=pvenkat-test-ws.sql.azuresynapse.net +SYNAPSE_TEST_USER= +SYNAPSE_TEST_PASS= +SYNAPSE_TEST_PORT=1433 +SYNAPSE_TEST_DWH_NAME=testsqlpool +DBT_TEST_USER_1=DBT_TEST_USER_1 +DBT_TEST_USER_2=DBT_TEST_USER_2 +DBT_TEST_USER_3=DBT_TEST_USER_3 +DBT_TEST_AAD_PRINCIPAL_1=DBT_TEST_AAD_PRINCIPAL_1 +DBT_TEST_AAD_PRINCIPAL_2=DBT_TEST_AAD_PRINCIPAL_2