Skip to content

Commit

Permalink
fix args and protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-rogers-dbt committed Jan 7, 2025
1 parent ebfdb92 commit 7e24326
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
9 changes: 5 additions & 4 deletions dbt/adapters/base/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
SnapshotTargetNotSnapshotTableError,
UnexpectedNonTimestampError,
)
from dbt.adapters.protocol import AdapterConfig, MacroContextGeneratorCallable, CatalogIntegrationConfig
from dbt.adapters.protocol import AdapterConfig, MacroContextGeneratorCallable, CatalogIntegrationConfigProtocol

if TYPE_CHECKING:
import agate
Expand Down Expand Up @@ -268,7 +268,7 @@ class BaseAdapter(metaclass=AdapterMeta):
Relation: Type[BaseRelation] = BaseRelation
Column: Type[BaseColumn] = BaseColumn
ConnectionManager: Type[BaseConnectionManager]
CatalogIntegrations: Dict[str, Type[CatalogIntegration]]
CatalogIntegrations: Dict[str, Type[CatalogIntegrationConfigProtocol]]

# A set of clobber config fields accepted by this adapter
# for use in materializations
Expand Down Expand Up @@ -296,7 +296,7 @@ def __init__(self, config, mp_context: SpawnContext) -> None:
self._macro_context_generator: Optional[MacroContextGeneratorCallable] = None
self.behavior = DEFAULT_BASE_BEHAVIOR_FLAGS # type: ignore

def add_catalog_integrations(self, catalog_integrations: Optional[List[CatalogIntegrationConfig]]) -> None:
def add_catalog_integrations(self, catalog_integrations: Optional[List[CatalogIntegrationConfigProtocol]]) -> None:
if catalog_integrations:
for integration_config in catalog_integrations:
catalog_type = integration_config.catalog_type
Expand All @@ -306,8 +306,9 @@ def add_catalog_integrations(self, catalog_integrations: Optional[List[CatalogIn
catalogs_client.add_catalog(integration, integration_config.catalog_name)

@available
def get_catalog_integration(self, integration_name) -> CatalogIntegration:
def get_catalog_integration(self, integration_name: str) -> CatalogIntegration:
return catalogs_client.get_catalog(integration_name)

###
# Methods to set / access a macro resolver
###
Expand Down
7 changes: 5 additions & 2 deletions dbt/adapters/clients/catalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@


class CatalogIntegrations:
def __init__(self):
self._integrations = None

def get(self, name: str) -> CatalogIntegration:
return self.integrations[name]

@property
def integrations(self) -> dict[str, CatalogIntegration]:
return self.integrations
return self._integrations

def add_integration(self, integration: CatalogIntegration, catalog_name: str):
self.integrations[catalog_name] = integration
self._integrations[catalog_name] = integration


_CATALOG_CLIENT = CatalogIntegrations()
Expand Down
8 changes: 5 additions & 3 deletions dbt/adapters/contracts/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class CatalogIntegrationConfig:
integration_name: str
table_format: str
catalog_type: str
external_volume: Optional[str]
namespace: Optional[str]
adapter_configs: Optional[Dict]
external_volume: Optional[str] = None
namespace: Optional[str] = None
adapter_configs: Optional[Dict] = None


class CatalogIntegration(abc.ABC):
Expand All @@ -31,6 +31,8 @@ class CatalogIntegration(abc.ABC):
interact with the catalog. This class is an abstract base class that should be subclassed by
specific integrations in the adapters.
Implements the CatalogIntegrationProtocol.
"""
catalog_name: str
integration_name: str
Expand Down
17 changes: 15 additions & 2 deletions dbt/adapters/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ class CatalogIntegrationConfigProtocol(Protocol):
adapter_configs: Optional[Dict]


class CatalogIntegrationProtocol(Protocol):
catalog_name: str
integration_name: str
table_format: str
integration_type: str
external_volume: Optional[str]
namespace: Optional[str]

def __init__(
self, integration_config: CatalogIntegrationConfigProtocol
) -> None: ...


Self = TypeVar("Self", bound="RelationProtocol")


Expand All @@ -72,7 +85,7 @@ def create_from(
ConnectionManager_T = TypeVar("ConnectionManager_T", bound=ConnectionManagerProtocol)
Relation_T = TypeVar("Relation_T", bound=RelationProtocol)
Column_T = TypeVar("Column_T", bound=ColumnProtocol)
ExtCatInteg_T = TypeVar("ExtCatInteg_T", bound=CatalogIntegrationProtocol)
CatalogIntegration_T = TypeVar("CatalogIntegration_T", bound=CatalogIntegrationProtocol)


class MacroContextGeneratorCallable(Protocol):
Expand All @@ -93,7 +106,6 @@ class AdapterProtocol( # type: ignore[misc]
ConnectionManager_T,
Relation_T,
Column_T,
ExtCatInteg_T,
],
):
# N.B. Technically these are ClassVars, but mypy doesn't support putting type vars in a
Expand All @@ -103,6 +115,7 @@ class AdapterProtocol( # type: ignore[misc]
Column: Type[Column_T]
Relation: Type[Relation_T]
ConnectionManager: Type[ConnectionManager_T]
CatalogIntegrations: Dict[str, Type[CatalogIntegration_T]]
connections: ConnectionManager_T

def __init__(self, config: AdapterRequiredConfig) -> None: ...
Expand Down

0 comments on commit 7e24326

Please sign in to comment.