-
Notifications
You must be signed in to change notification settings - Fork 140
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Support safe concurrent dbt runs
Description
There have been multiple issues related to concurrent dbt runs in ClickHouse, where one run attempts to query an intermediate/temp table that has already been dropped by a previous run.
Several PRs have attempted to fix this by appending invocation_id
or UUIDs to table names or by implementing conditional drops based on specific criteria. However, each change was applied to different parts of the codebase based on individual use cases, resulting in an inconsistent and partial solution.
Proposed Solution
Introduce dedicated macros, clickhouse__make_intermediate_relation
and clickhouse__make_temp_relation
, that would:
- Include a
prefix
parameter with a default value usinginvocation_id
, ensuring unique table names for each dbt run. - Introduce a feature flag (disabled by default) that allows users to opt into this behavior. When enabled,
invocation_id
will be automatically appended to intermediate and temp table names. - Standardize the handling of temp and intermediate relations across the dbt-clickhouse adapter, avoiding ad-hoc solutions in different parts of the code.
✅ Benefits
- Prevents table name collisions in parallel dbt runs.
- Ensures a consistent approach to naming intermediate and temp tables.
- Provides an opt-in feature flag for backward compatibility.
- Reduces the need for future patches addressing the same issue in different ways.
❌ Potential Downsides
- Increased risk of hanging tables:
- Currently, if a temp/intermediate table is not dropped, it is often cleaned up in the next run. With this change, the risk of orphaned tables may increase.
- Potential solution: Implement a cleanup mechanism that drops stale intermediate/temp tables based on their creation time or last usage.
This is not a heavy lift, but I Would love to get the community's opinion on it.
mshustov, stephen-up, Shlomixg and canbekley
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working