diff --git a/dbt/adapters/fabric/__version__.py b/dbt/adapters/fabric/__version__.py index 9675f25..e570961 100644 --- a/dbt/adapters/fabric/__version__.py +++ b/dbt/adapters/fabric/__version__.py @@ -1 +1 @@ -version = "1.8.7" +version = "1.8.8" diff --git a/dbt/include/fabric/macros/adapters/relation.sql b/dbt/include/fabric/macros/adapters/relation.sql index 6eac9bb..0942597 100644 --- a/dbt/include/fabric/macros/adapters/relation.sql +++ b/dbt/include/fabric/macros/adapters/relation.sql @@ -51,16 +51,19 @@ -- DROP fabric__truncate_relation when TRUNCATE TABLE is supported {% macro fabric__truncate_relation(relation) -%} - - {% set tempTableName %} - {{ relation.include(database=False).identifier.replace("#", "") }}_{{ range(21000, 109000) | random }} + {% set random_int %} + {{ range(21000, 109000) | random }} {% endset %} + + {% set temp_relation = relation.incorporate(path={ "identifier": relation.identifier ~ random_int }, type='table')-%} + {# {% set tempTableName %} + {{ relation.identifier.replace("#", "") }}_{{ range(21000, 109000) | random }} + {% endset %} #} {{ log("Truncate Statement is not supported, Using random table as a temp table. - " ~ tempTableName) }} {% call statement('truncate_relation') -%} - CREATE TABLE {{ tempTableName }} AS SELECT * FROM {{ relation }} WHERE 1=2 - EXEC('DROP TABLE IF EXISTS {{ relation.include(database=False) }};'); - EXEC('CREATE TABLE {{ relation.include(database=False) }} AS SELECT * FROM {{ tempTableName }};'); - EXEC('DROP TABLE IF EXISTS {{ tempTableName }};'); + CREATE TABLE {{ temp_relation}} AS SELECT * FROM {{ relation }} WHERE 1=2 + DROP TABLE IF EXISTS {{ relation }} + EXEC sp_rename '{{temp_relation.include(database=False)}}','{{relation.identifier}}' {%- endcall %} {% endmacro %}