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 5 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"
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,6 @@ 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"})
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
2 changes: 1 addition & 1 deletion dbt/adapters/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "1.8.0"
version = "1.8.1"
22 changes: 19 additions & 3 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 @@ -316,7 +315,13 @@ def _behavior_flags(self) -> List[BehaviorFlag]:
"""
This method should be overwritten by adapter maintainers to provide platform-specific flags
"""
return []
return [
{
"name": "require_batched_execution_for_custom_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 @@ -1574,13 +1579,24 @@ 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_batched_execution_for_custom_microbatch_strategy:
builtin_strategies.append("microbatch")

return builtin_strategies

@available.parse_none
def get_incremental_strategy_macro(self, model_context, strategy: str):
"""Gets the macro for the given incremental strategy.

Additionally some validations are done:
1. Assert that if the given strategy is a "builtin" strategy, then it must
also be defined as a "valid" strategy for the associated adapter
2. Assert that the incremental strategy exists in the model context

Notably, something be defined by the adapter as "valid" without it being
a "builtin", and nothing will break (and that is desirable).
"""

# Construct macro_name from strategy name
if strategy is None:
strategy = "default"
Expand Down
Loading