diff --git a/core/dbt/adapters/base/impl.py b/core/dbt/adapters/base/impl.py index 88ab4c5ff95..9a9fb55e562 100644 --- a/core/dbt/adapters/base/impl.py +++ b/core/dbt/adapters/base/impl.py @@ -162,6 +162,14 @@ def submit(self, compiled_code: str) -> Any: raise NotImplementedError("PythonJobHelper submit function is not implemented yet") +class AdapterFeature(str, Enum): + """Enumeration of optional adapter features which can be probed using BaseAdapter.has_feature()""" + + CatalogByRelations = "GetCatalogByRelations" + """Flags support for retrieving catalog information using a list of relations, rather than always retrieving all + the relations in a schema """ + + class BaseAdapter(metaclass=AdapterMeta): """The BaseAdapter provides an abstract base class for adapters. @@ -223,8 +231,6 @@ class BaseAdapter(metaclass=AdapterMeta): ConstraintType.foreign_key: ConstraintSupport.ENFORCED, } - CATALOG_BY_RELATION_SUPPORT = False - def __init__(self, config) -> None: self.config = config self.cache = RelationsCache() @@ -1141,7 +1147,7 @@ def get_catalog(self, manifest: Manifest) -> Tuple[agate.Table, List[Exception]] with executor(self.config) as tpe: futures: List[Future[agate.Table]] = [] relation_count = len(self._get_catalog_relations(manifest)) - if relation_count <= 100 and self.CATALOG_BY_RELATION_SUPPORT: + if relation_count <= 100 and self.has_feature(AdapterFeature.CatalogByRelations): relations_by_schema = self._get_catalog_relations_by_info_schema(manifest) for info_schema in relations_by_schema: name = ".".join([str(info_schema.database), "information_schema"]) @@ -1495,6 +1501,12 @@ def render_model_constraint(cls, constraint: ModelLevelConstraint) -> Optional[s else: return None + def has_feature(self, feature: AdapterFeature) -> bool: + # The base adapter implementation does not implement any optional + # features, so always return false. Adapters which wish to provide + # optional features will have to override this function. + return False + COLUMNS_EQUAL_SQL = """ with diff_count as ( diff --git a/plugins/postgres/dbt/adapters/postgres/impl.py b/plugins/postgres/dbt/adapters/postgres/impl.py index 6b8f1d756ca..c9a77a945de 100644 --- a/plugins/postgres/dbt/adapters/postgres/impl.py +++ b/plugins/postgres/dbt/adapters/postgres/impl.py @@ -3,7 +3,7 @@ from typing import Optional, Set, List, Any from dbt.adapters.base.meta import available -from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport +from dbt.adapters.base.impl import AdapterConfig, AdapterFeature, ConstraintSupport from dbt.adapters.sql import SQLAdapter from dbt.adapters.postgres import PostgresConnectionManager from dbt.adapters.postgres.column import PostgresColumn @@ -75,6 +75,8 @@ class PostgresAdapter(SQLAdapter): CATALOG_BY_RELATION_SUPPORT = True + SUPPORTED_FEATURES: Set[AdapterFeature] = frozenset(AdapterFeature.CatalogByRelations) + @classmethod def date_function(cls): return "now()" @@ -145,3 +147,6 @@ def valid_incremental_strategies(self): def debug_query(self): self.execute("select 1 as id") + + def has_feature(self, feature: AdapterFeature) -> bool: + return feature in self.SUPPORTED_FEATURES