Skip to content

Commit

Permalink
Add unique UUID to temp table name (#482)
Browse files Browse the repository at this point in the history
* add unique UUID to temp table name

* rename to uuid

* make private variable

* Add type annotation

* formatting

* remove dash, use only last part of uuid

* fix type hint

* remove unused import
  • Loading branch information
guenp authored Dec 4, 2024
1 parent 3650b4e commit 9f9cdb1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion dbt/adapters/duckdb/impl.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import os
from collections import defaultdict
from typing import Any
from typing import List
from typing import Optional
from typing import Sequence
from typing import TYPE_CHECKING
from uuid import uuid4

from dbt_common.contracts.constraints import ColumnLevelConstraint
from dbt_common.contracts.constraints import ConstraintType
Expand Down Expand Up @@ -50,6 +52,7 @@ class DuckDBAdapter(SQLAdapter):

# can be overridden via the model config metadata
_temp_schema_name = DEFAULT_TEMP_SCHEMA_NAME
_temp_schema_model_uuid: dict[str, str] = defaultdict(lambda: str(uuid4()).split("-")[-1])

@classmethod
def date_function(cls) -> str:
Expand Down Expand Up @@ -286,10 +289,12 @@ def get_temp_relation_path(self, model: Any):
currently doesn't support remote temporary tables. Instead we use a regular
table that is dropped at the end of the incremental macro or post-model hook.
"""
# Add a unique identifier for this model (scoped per dbt run)
_uuid = self._temp_schema_model_uuid[model.identifier]
return Path(
schema=self._temp_schema_name,
database=model.database,
identifier=model.identifier,
identifier=f"{model.identifier}__{_uuid}",
)

def post_model_hook(self, config: Any, context: Any) -> None:
Expand Down

0 comments on commit 9f9cdb1

Please sign in to comment.