Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unique UUID to temp table name #482

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading