Skip to content

Commit

Permalink
Reducing Locking by using SP_Rename
Browse files Browse the repository at this point in the history
  • Loading branch information
prdpsvs committed Jul 2, 2024
1 parent d4f99e7 commit 09ff851
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dbt/adapters/fabric/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.7"
version = "1.8.8"
17 changes: 10 additions & 7 deletions dbt/include/fabric/macros/adapters/relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit 09ff851

Please sign in to comment.