Skip to content

Commit

Permalink
Merge branch 'main' into microbatch-behavior-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk authored Nov 5, 2024
2 parents a20bf51 + b12c987 commit b089416
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 27 deletions.
1 change: 1 addition & 0 deletions .changes/1.10.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## dbt-adapters 1.10.3 - October 29, 2024
16 changes: 16 additions & 0 deletions .changes/1.7.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## dbt-adapters 1.7.2 - October 21, 2024

### Breaking Changes

- Drop support for Python 3.8 ([#332](https://github.com/dbt-labs/dbt-adapters/issues/332))

### Features

- Allows unique_key for snapshots to take a list ([#181](https://github.com/dbt-labs/dbt-adapters/issues/181))

### Fixes

- Always validate an incremental model's `incremental_strategy` ([#330](https://github.com/dbt-labs/dbt-adapters/issues/330))

### Contributors
- [@agpapa](https://github.com/agpapa) ([#181](https://github.com/dbt-labs/dbt-adapters/issues/181))
9 changes: 9 additions & 0 deletions .changes/1.8.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## dbt-adapters 1.8.0 - October 29, 2024

### Fixes

- Always make behavior flags available for evaluation ([#338](https://github.com/dbt-labs/dbt-adapters/issues/338))

### Under the Hood

- Add adapter telemetry. ([#301](https://github.com/dbt-labs/dbt-adapters/issues/301))
6 changes: 0 additions & 6 deletions .changes/unreleased/Breaking Changes-20241016-180629.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .changes/unreleased/Features-20240422-081302.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .changes/unreleased/Fixes-20241016-160412.yaml

This file was deleted.

33 changes: 31 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html),
and is generated by [Changie](https://github.com/miniscruff/changie).

## dbt-adapters 1.10.3 - October 29, 2024



## dbt-adapters 1.10.2 - October 01, 2024

### Under the Hood
Expand All @@ -15,13 +19,38 @@ and is generated by [Changie](https://github.com/miniscruff/changie).

## dbt-adapters 1.10.0 - September 12, 2024

## dbt-adapters 1.7.1 - October 15, 2024
## dbt-adapters 1.8.0 - October 29, 2024

### Fixes

- Always make behavior flags available for evaluation ([#338](https://github.com/dbt-labs/dbt-adapters/issues/338))

### Under the Hood

- Add adapter telemetry. ([#301](https://github.com/dbt-labs/dbt-adapters/issues/301))

## dbt-adapters 1.7.2 - October 21, 2024

### Breaking Changes

- Drop support for Python 3.8 ([#332](https://github.com/dbt-labs/dbt-adapters/issues/332))

### Features

- Enable setting current value of dbt_valid_to ([#320](https://github.com/dbt-labs/dbt-adapters/issues/320))
- Allows unique_key for snapshots to take a list ([#181](https://github.com/dbt-labs/dbt-adapters/issues/181))

### Fixes

- Always validate an incremental model's `incremental_strategy` ([#330](https://github.com/dbt-labs/dbt-adapters/issues/330))

### Contributors
- [@agpapa](https://github.com/agpapa) ([#181](https://github.com/dbt-labs/dbt-adapters/issues/181))

## dbt-adapters 1.7.1 - October 15, 2024

### Features

- Enable setting current value of dbt_valid_to ([#320](https://github.com/dbt-labs/dbt-adapters/issues/320))

## dbt-adapters 1.7.0 - September 19, 2024

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.7.1"
version = "1.8.0"
1 change: 1 addition & 0 deletions dbt/adapters/base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
BaseRelation,
RelationType,
SchemaSearchMap,
AdapterTrackingRelationInfo,
)
40 changes: 34 additions & 6 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from contextlib import contextmanager
from datetime import datetime
from enum import Enum
from importlib import import_module
from multiprocessing.context import SpawnContext
from typing import (
Any,
Expand Down Expand Up @@ -60,12 +61,14 @@
ComponentName,
InformationSchema,
SchemaSearchMap,
AdapterTrackingRelationInfo,
)
from dbt.adapters.cache import RelationsCache, _make_ref_key_dict
from dbt.adapters.capability import Capability, CapabilityDict
from dbt.adapters.contracts.connection import Credentials
from dbt.adapters.contracts.macros import MacroResolverProtocol
from dbt.adapters.contracts.relation import RelationConfig

from dbt.adapters.events.types import (
CacheMiss,
CatalogGenerationError,
Expand Down Expand Up @@ -299,12 +302,13 @@ def behavior(self) -> Behavior:
@behavior.setter # type: ignore
def behavior(self, flags: List[BehaviorFlag]) -> None:
flags.extend(self._behavior_flags)
try:
# we don't always get project flags, for example during `dbt debug`
self._behavior = Behavior(flags, self.config.flags)
except AttributeError:
# in that case, don't load any behavior to avoid unexpected defaults
self._behavior = Behavior([], {})

# we don't always get project flags, for example, the project file is not loaded during `dbt debug`
# in that case, load the default values for behavior flags to avoid compilation errors
# this mimics not loading a project file, or not specifying flags in a project file
user_overrides = getattr(self.config, "flags", {})

self._behavior = Behavior(flags, user_overrides)

@property
def _behavior_flags(self) -> List[BehaviorFlag]:
Expand Down Expand Up @@ -1748,6 +1752,30 @@ def capabilities(cls) -> CapabilityDict:
def supports(cls, capability: Capability) -> bool:
return bool(cls.capabilities()[capability])

@classmethod
def get_adapter_run_info(cls, config: RelationConfig) -> AdapterTrackingRelationInfo:
adapter_class_name, *_ = cls.__name__.split("Adapter")
adapter_name = adapter_class_name.lower()

if adapter_name == "base":
adapter_version = ""
else:
adapter_version = import_module(f"dbt.adapters.{adapter_name}.__version__").version

return AdapterTrackingRelationInfo(
adapter_name=adapter_name,
base_adapter_version=import_module("dbt.adapters.__about__").version,
adapter_version=adapter_version,
model_adapter_details=cls._get_adapter_specific_run_info(config),
)

@classmethod
def _get_adapter_specific_run_info(cls, config) -> Dict[str, Any]:
"""
Adapter maintainers should overwrite this method to return any run metadata that should be captured during a run.
"""
return {}


COLUMNS_EQUAL_SQL = """
with diff_count as (
Expand Down
8 changes: 8 additions & 0 deletions dbt/adapters/base/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,3 +542,11 @@ def flatten(self, allow_multiple_databases: bool = False) -> "SchemaSearchMap":
)

return new


@dataclass(frozen=True, eq=False, repr=False)
class AdapterTrackingRelationInfo(FakeAPIObject, Hashable):
adapter_name: str
base_adapter_version: str
adapter_version: str
model_adapter_details: Any
Empty file.
File renamed without changes.
87 changes: 87 additions & 0 deletions tests/unit/behavior_flag_tests/test_empty_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from types import SimpleNamespace
from typing import Any, Dict, List

from dbt_common.behavior_flags import BehaviorFlag
from dbt_common.exceptions import DbtBaseException
import pytest

from dbt.adapters.contracts.connection import AdapterRequiredConfig, QueryComment

from tests.unit.fixtures.credentials import CredentialsStub


@pytest.fixture
def flags() -> Dict[str, Any]:
return {
"unregistered_flag": True,
"default_false_user_false_flag": False,
"default_false_user_true_flag": True,
"default_true_user_false_flag": False,
"default_true_user_true_flag": True,
}


@pytest.fixture
def config(flags) -> AdapterRequiredConfig:
raw_config = {
"credentials": CredentialsStub("test_database", "test_schema"),
"profile_name": "test_profile",
"target_name": "test_target",
"threads": 4,
"project_name": "test_project",
"query_comment": QueryComment(),
"cli_vars": {},
"target_path": "path/to/nowhere",
"log_cache_events": False,
}
return SimpleNamespace(**raw_config)


@pytest.fixture
def behavior_flags() -> List[BehaviorFlag]:
return [
{
"name": "default_false_user_false_flag",
"default": False,
"docs_url": "https://docs.com",
},
{
"name": "default_false_user_true_flag",
"default": False,
"description": "This is a false flag.",
},
{
"name": "default_false_user_skip_flag",
"default": False,
"description": "This is a true flag.",
},
{
"name": "default_true_user_false_flag",
"default": True,
"description": "This is fake news.",
},
{
"name": "default_true_user_true_flag",
"default": True,
"docs_url": "https://moar.docs.com",
},
{
"name": "default_true_user_skip_flag",
"default": True,
"description": "This is a true flag.",
},
]


def test_register_behavior_flags(adapter):
# make sure that users cannot add arbitrary flags to this collection
with pytest.raises(DbtBaseException):
assert adapter.behavior.unregistered_flag

# check the values of the valid behavior flags
assert not adapter.behavior.default_false_user_false_flag
assert not adapter.behavior.default_false_user_true_flag
assert not adapter.behavior.default_false_user_skip_flag
assert adapter.behavior.default_true_user_false_flag
assert adapter.behavior.default_true_user_true_flag
assert adapter.behavior.default_true_user_skip_flag
15 changes: 15 additions & 0 deletions tests/unit/test_adapter_telemetry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dbt.adapters.__about__

from dbt.adapters.base.impl import BaseAdapter
from dbt.adapters.base.relation import AdapterTrackingRelationInfo


def test_telemetry_returns():
res = BaseAdapter.get_adapter_run_info({})

assert res.adapter_name == "base"
assert res.base_adapter_version == dbt.adapters.__about__.version
assert res.adapter_version == ""
assert res.model_adapter_details == {}

assert type(res) is AdapterTrackingRelationInfo

0 comments on commit b089416

Please sign in to comment.