-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add RelationConfig Protocol for use in Relation.create_from #9210
Changes from 6 commits
7f777f8
2cee865
160d0db
d7d5e23
b8de881
ba53f05
6796edd
7ad6aa1
7ad1acc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Remove usage of dbt.contracts in dbt/adapters | ||
time: 2023-12-05T12:05:59.936775+09:00 | ||
custom: | ||
Author: michelleark | ||
Issue: "9208" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: Under the Hood | ||
body: Introduce RelationConfig Protocol, consolidate Relation.create_from | ||
time: 2023-12-05T17:07:25.33861+09:00 | ||
custom: | ||
Author: michelleark | ||
Issue: "9215" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,7 +429,7 @@ def _get_cache_schemas(self, manifest: Manifest) -> Set[BaseRelation]: | |
""" | ||
# the cache only cares about executable nodes | ||
return { | ||
self.Relation.create_from(self.config, node).without_identifier() | ||
self.Relation.create_from(self.config, node).without_identifier() # type: ignore[arg-type] | ||
for node in manifest.nodes.values() | ||
if (node.is_relational and not node.is_ephemeral_model and not node.is_external_node) | ||
} | ||
|
@@ -476,7 +476,7 @@ def _get_catalog_relations(self, manifest: Manifest) -> List[BaseRelation]: | |
manifest.sources.values(), | ||
) | ||
|
||
relations = [self.Relation.create_from(self.config, n) for n in nodes] | ||
relations = [self.Relation.create_from(self.config, n) for n in nodes] # type: ignore[arg-type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this gets cleaned up in: #9212 |
||
return relations | ||
|
||
def _relations_cache_for_schemas( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,8 @@ | |
|
||
from dbt.common.dataclass_schema import dbtClassMixin, StrEnum | ||
|
||
from dbt.contracts.util import Replaceable | ||
from dbt.common.exceptions import CompilationError | ||
from dbt.exceptions import DataclassNotDictError | ||
from dbt.common.contracts.util import Replaceable | ||
from dbt.common.exceptions import CompilationError, DataclassNotDictError | ||
from dbt.common.utils import deep_merge | ||
|
||
|
||
|
@@ -23,6 +22,14 @@ class RelationType(StrEnum): | |
Ephemeral = "ephemeral" | ||
|
||
|
||
class RelationConfig(Protocol): | ||
name: str | ||
database: str | ||
schema: str | ||
identifier: str | ||
quoting_dict: Dict[str, bool] | ||
Comment on lines
+25
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we may want to include meta or tags to accommodate adapter-specific implementations, for example in dbt-duckdb: https://github.com/duckdb/dbt-duckdb/blob/master/dbt/adapters/duckdb/relation.py#L11 But these are the attributes necessary for core <> adapters + postgres. Have carved out an issue to add additional fields later on: https://github.com/dbt-labs/dbt-core/issues/9216 |
||
|
||
|
||
class ComponentName(StrEnum): | ||
Database = "database" | ||
Schema = "schema" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from dbt.common.exceptions.base import * # noqa | ||
from dbt.common.exceptions.events import * # noqa | ||
from dbt.common.exceptions.macros import * # noqa | ||
from dbt.common.exceptions.contracts import * # noqa |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Any | ||
from dbt.common.exceptions import CompilationError | ||
|
||
|
||
# this is part of the context and also raised in dbt.contracts.relation.py | ||
class DataclassNotDictError(CompilationError): | ||
def __init__(self, obj: Any): | ||
self.obj = obj | ||
super().__init__(msg=self.get_message()) | ||
|
||
def get_message(self) -> str: | ||
msg = ( | ||
f'The object ("{self.obj}") was used as a dictionary. This ' | ||
"capability has been removed from objects of this type." | ||
) | ||
|
||
return msg | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this gets cleaned up in: #9213