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

Switch from environment variable to behavior flag for gating microbatch functionality #323

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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: 7 additions & 0 deletions .changes/unreleased/Features-20241001-165406.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Use a behavior flag to gate microbatch functionality (instead of an environment
variable)
time: 2024-10-01T16:54:06.121016-05:00
custom:
Author: QMalcolm
Issue: "327"
2 changes: 1 addition & 1 deletion dbt-tests-adapter/dbt/tests/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.10.2"
version = "1.10.3"
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import os
from pprint import pformat
from unittest import mock

import pytest

Expand Down Expand Up @@ -63,7 +61,16 @@ def assert_row_count(self, project, relation_name: str, expected_row_count: int)

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

@mock.patch.dict(os.environ, {"DBT_EXPERIMENTAL_MICROBATCH": "True"})

class BaseTestMicrobatchOn(BaseMicrobatch):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
"flags": {
"require_builtin_microbatch_strategy": True,
}
}

def test_run_with_event_time(self, project, insert_two_rows_sql):
# initial run -- backfills all data
with patch_microbatch_end_time("2020-01-03 13:57:00"):
Expand Down Expand Up @@ -94,3 +101,17 @@ def test_run_with_event_time(self, project, insert_two_rows_sql):
with patch_microbatch_end_time("2020-01-05 14:57:00"):
run_dbt(["run", "--select", "microbatch_model"])
self.assert_row_count(project, "microbatch_model", 5)


class BaseTestMicrobatchOff(BaseMicrobatch):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
"flags": {
"require_builtin_microbatch_strategy": False,
}
}

def test_run_with_event_time(self, project):
with patch_microbatch_end_time("2020-01-03 13:57:00"):
run_dbt(["run"], expect_pass=False)
11 changes: 8 additions & 3 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Union,
TYPE_CHECKING,
)
import os
import pytz
from dbt_common.behavior_flags import Behavior, BehaviorFlag
from dbt_common.clients.jinja import CallableMacroGenerator
Expand Down Expand Up @@ -312,7 +311,13 @@ def _behavior_flags(self) -> List[BehaviorFlag]:
"""
This method should be overwritten by adapter maintainers to provide platform-specific flags
"""
return []
return [
{
"name": "require_builtin_microbatch_strategy",
"default": False,
"docs_url": "https://docs.getdbt.com/docs/build/incremental-microbatch",
}
]

###
# Methods that pass through to the connection manager
Expand Down Expand Up @@ -1570,7 +1575,7 @@ def valid_incremental_strategies(self):

def builtin_incremental_strategies(self):
builtin_strategies = ["append", "delete+insert", "merge", "insert_overwrite"]
if os.environ.get("DBT_EXPERIMENTAL_MICROBATCH"):
if self.behavior.require_builtin_microbatch_strategy:
builtin_strategies.append("microbatch")

return builtin_strategies
Expand Down
Loading