Skip to content

Commit b819a87

Browse files
committed
Gate MicrobatchConcurrency behind use_concurrent_microbatch behavior flag
Makes concurrent microbatch opt-in (default=False) so it can ship safely in a patch release. Users enable it via `flags: {use_concurrent_microbatch: true}` in dbt_project.yml. The default can be flipped to True in 1.12. Overrides supports() as an instance method rather than adding to the class-level _capabilities dict, ensuring the behavior flag is always checked regardless of how supports() is called.
1 parent 9d46080 commit b819a87

3 files changed

Lines changed: 52 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Features
44
- Add `query_id` to `SQLQueryStatus` events to improve query tracing and debugging
55
- Add support for Row Filters ([#1294](https://github.com/databricks/dbt-databricks/pull/1294))
6+
- Enable concurrent microbatch execution via `use_concurrent_microbatch` behavior flag ([#914](https://github.com/databricks/dbt-databricks/issues/914))
67

78
### Fixes
89
- Fix `hard_deletes: invalidate` incorrectly invalidating active records in snapshots (thanks @Zurbste!) ([#1281](https://github.com/databricks/dbt-databricks/issues/1281))

dbt/adapters/databricks/impl.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@
141141
),
142142
) # type: ignore[typeddict-item]
143143

144+
USE_CONCURRENT_MICROBATCH = BehaviorFlag(
145+
name="use_concurrent_microbatch",
146+
default=False,
147+
description=(
148+
"Enable concurrent execution of microbatch incremental batches. "
149+
"When enabled, dbt will run microbatch batches in parallel threads "
150+
"instead of sequentially. Requires dbt-core 1.9+."
151+
),
152+
) # type: ignore[typeddict-item]
153+
144154

145155
class DatabricksRelationInfo(NamedTuple):
146156
table_name: str
@@ -246,8 +256,14 @@ def _behavior_flags(self) -> list[BehaviorFlag]:
246256
USE_MATERIALIZATION_V2,
247257
USE_REPLACE_ON_FOR_INSERT_OVERWRITE,
248258
USE_MANAGED_ICEBERG,
259+
USE_CONCURRENT_MICROBATCH,
249260
]
250261

262+
def supports(self, capability: Capability) -> bool:
263+
if capability == Capability.MicrobatchConcurrency:
264+
return bool(self.behavior.use_concurrent_microbatch)
265+
return super().supports(capability)
266+
251267
def quote(self, identifier): # type: ignore[override,no-untyped-def]
252268
"""Override base adapter's quote method to prevent double quoting."""
253269
return quote(identifier)

tests/unit/test_adapter_capabilities.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,41 @@ def test_capability_caching_in_adapter(self, adapter):
136136
# Connection should have been asked twice (adapter doesn't cache)
137137
assert mock_conn.has_capability.call_count == 2
138138

139+
def test_microbatch_concurrency_disabled_by_default(self, adapter):
140+
"""Test that MicrobatchConcurrency is disabled by default (behavior flag off)."""
141+
from dbt.adapters.capability import Capability
142+
143+
assert not adapter.supports(Capability.MicrobatchConcurrency)
144+
145+
def test_microbatch_concurrency_enabled_with_flag(self):
146+
"""Test that MicrobatchConcurrency is enabled when behavior flag is on."""
147+
from dbt.adapters.capability import Capability
148+
149+
project_cfg = {
150+
"name": "test_project",
151+
"version": "0.1",
152+
"profile": "test",
153+
"project-root": "/tmp/dbt/does-not-exist",
154+
"config-version": 2,
155+
"flags": {"use_concurrent_microbatch": True},
156+
}
157+
profile_cfg = {
158+
"outputs": {
159+
"test": {
160+
"type": "databricks",
161+
"catalog": "main",
162+
"schema": "analytics",
163+
"host": "test.databricks.com",
164+
"http_path": "sql/protocolv1/o/1234567890123456/1234-567890-test123",
165+
"token": "dapi" + "X" * 32,
166+
}
167+
},
168+
"target": "test",
169+
}
170+
config = config_from_parts_or_dicts(project_cfg, profile_cfg)
171+
adapter = DatabricksAdapter(config, get_context("spawn"))
172+
assert adapter.supports(Capability.MicrobatchConcurrency)
173+
139174
def test_insert_by_name_capability_spec(self):
140175
"""Test INSERT_BY_NAME capability specification and requirements."""
141176
# Verify the capability exists

0 commit comments

Comments
 (0)