Feature description
When several dlt runs load into the same Databricks table concurrently and the table doesn't exist yet, each run independently decides the table is new and emits a plain CREATE TABLE. The first run wins; the others fail with "table already exists". dlt should create user tables with CREATE TABLE IF NOT EXISTS on Databricks and reconcile columns so concurrent runs converge.
Are you a dlt user?
Yes, I run dlt in production.
Use case
Parallel orchestration (multiple Airflow tasks, parallel pipeline processes, partitioned backfills) regularly lands several runs on the same not-yet-existing table at once. The DDL phase races:
- Every run calls
get_storage_tables() → table missing → generate_alter = False (dlt/destinations/job_client_impl.py:688).
- Every run emits
CREATE TABLE foo (...).
- First commit wins; the rest raise "table already exists" and the load fails.
A subtler second bug hides behind the crash: a run carrying an extra column c would see its create become a no-op against the table another run already made, then fail when its load job writes c — a column that was never added.
Proposed solution
Scoped to the Databricks destination:
- Emit
CREATE TABLE IF NOT EXISTS for user tables. Today IF NOT EXISTS is applied only to dlt internal tables in _make_create_table (dlt/destinations/job_client_impl.py:715), gated by the existing supports_create_table_if_not_exists capability.
- Reconcile columns: after the (possibly no-op) create, re-read the actual table columns and emit
ALTER TABLE … ADD COLUMN for any missing ones. Databricks has no ADD COLUMN IF NOT EXISTS, so reconciliation must re-read storage and tolerate the "column already exists" error two runs can hit when adding the same column concurrently.
This keeps the common identical-schema case race-free and lets divergent-schema runs converge.
Related issues
None known.
Feature description
When several dlt runs load into the same Databricks table concurrently and the table doesn't exist yet, each run independently decides the table is new and emits a plain
CREATE TABLE. The first run wins; the others fail with "table already exists". dlt should create user tables withCREATE TABLE IF NOT EXISTSon Databricks and reconcile columns so concurrent runs converge.Are you a dlt user?
Yes, I run dlt in production.
Use case
Parallel orchestration (multiple Airflow tasks, parallel pipeline processes, partitioned backfills) regularly lands several runs on the same not-yet-existing table at once. The DDL phase races:
get_storage_tables()→ table missing →generate_alter = False(dlt/destinations/job_client_impl.py:688).CREATE TABLE foo (...).A subtler second bug hides behind the crash: a run carrying an extra column
cwould see its create become a no-op against the table another run already made, then fail when its load job writesc— a column that was never added.Proposed solution
Scoped to the Databricks destination:
CREATE TABLE IF NOT EXISTSfor user tables. TodayIF NOT EXISTSis applied only to dlt internal tables in_make_create_table(dlt/destinations/job_client_impl.py:715), gated by the existingsupports_create_table_if_not_existscapability.ALTER TABLE … ADD COLUMNfor any missing ones. Databricks has noADD COLUMN IF NOT EXISTS, so reconciliation must re-read storage and tolerate the "column already exists" error two runs can hit when adding the same column concurrently.This keeps the common identical-schema case race-free and lets divergent-schema runs converge.
Related issues
None known.