Skip to content

Commit 9c08dea

Browse files
authored
Switch from environment variable to behavior flag for gating microbatch functionality (#323)
1 parent da2a380 commit 9c08dea

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: Features
2+
body: Use a behavior flag to gate microbatch functionality (instead of an environment
3+
variable)
4+
time: 2024-10-01T16:54:06.121016-05:00
5+
custom:
6+
Author: QMalcolm
7+
Issue: "327"

dbt-tests-adapter/dbt/tests/adapter/incremental/test_incremental_microbatch.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
from pprint import pformat
3-
from unittest import mock
42

53
import pytest
64

@@ -63,7 +61,6 @@ def assert_row_count(self, project, relation_name: str, expected_row_count: int)
6361

6462
assert len(result) == expected_row_count, f"{relation_name}:{pformat(result)}"
6563

66-
@mock.patch.dict(os.environ, {"DBT_EXPERIMENTAL_MICROBATCH": "True"})
6764
def test_run_with_event_time(self, project, insert_two_rows_sql):
6865
# initial run -- backfills all data
6966
with patch_microbatch_end_time("2020-01-03 13:57:00"):

dbt/adapters/base/impl.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
Union,
2424
TYPE_CHECKING,
2525
)
26-
import os
2726
import pytz
2827
from dbt_common.behavior_flags import Behavior, BehaviorFlag
2928
from dbt_common.clients.jinja import CallableMacroGenerator
@@ -316,7 +315,13 @@ def _behavior_flags(self) -> List[BehaviorFlag]:
316315
"""
317316
This method should be overwritten by adapter maintainers to provide platform-specific flags
318317
"""
319-
return []
318+
return [
319+
{
320+
"name": "require_batched_execution_for_custom_microbatch_strategy",
321+
"default": False,
322+
"docs_url": "https://docs.getdbt.com/docs/build/incremental-microbatch",
323+
}
324+
]
320325

321326
###
322327
# Methods that pass through to the connection manager
@@ -1574,13 +1579,24 @@ def valid_incremental_strategies(self):
15741579

15751580
def builtin_incremental_strategies(self):
15761581
builtin_strategies = ["append", "delete+insert", "merge", "insert_overwrite"]
1577-
if os.environ.get("DBT_EXPERIMENTAL_MICROBATCH"):
1582+
if self.behavior.require_batched_execution_for_custom_microbatch_strategy.no_warn:
15781583
builtin_strategies.append("microbatch")
15791584

15801585
return builtin_strategies
15811586

15821587
@available.parse_none
15831588
def get_incremental_strategy_macro(self, model_context, strategy: str):
1589+
"""Gets the macro for the given incremental strategy.
1590+
1591+
Additionally some validations are done:
1592+
1. Assert that if the given strategy is a "builtin" strategy, then it must
1593+
also be defined as a "valid" strategy for the associated adapter
1594+
2. Assert that the incremental strategy exists in the model context
1595+
1596+
Notably, something be defined by the adapter as "valid" without it being
1597+
a "builtin", and nothing will break (and that is desirable).
1598+
"""
1599+
15841600
# Construct macro_name from strategy name
15851601
if strategy is None:
15861602
strategy = "default"

0 commit comments

Comments
 (0)