From 5712711939d39daace0ec505c7d7753ed6370193 Mon Sep 17 00:00:00 2001 From: Michelle Ark Date: Thu, 29 Feb 2024 18:09:43 -0500 Subject: [PATCH] implement DuckDbRelation.create_from, fix TestExternalSources::test_external_sources --- dbt/adapters/duckdb/impl.py | 5 +++-- dbt/adapters/duckdb/relation.py | 21 ++++++++++++++++++--- dbt/adapters/duckdb/utils.py | 4 ++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dbt/adapters/duckdb/impl.py b/dbt/adapters/duckdb/impl.py index c35d9ef9..a778fe28 100644 --- a/dbt/adapters/duckdb/impl.py +++ b/dbt/adapters/duckdb/impl.py @@ -23,7 +23,8 @@ from dbt.adapters.duckdb.utils import TargetConfig from dbt.adapters.duckdb.utils import TargetLocation from dbt.adapters.sql import SQLAdapter -from dbt.context.providers import RuntimeConfigObject +# TODO +# from dbt.context.providers import RuntimeConfigObject TEMP_SCHEMA_NAME = "temp_schema_name" DEFAULT_TEMP_SCHEMA_NAME = "dbt_temp" @@ -99,7 +100,7 @@ def store_relation( column_list: Sequence[BaseColumn], path: str, format: str, - config: RuntimeConfigObject, + config: Any, ) -> None: target_config = TargetConfig( relation=relation, diff --git a/dbt/adapters/duckdb/relation.py b/dbt/adapters/duckdb/relation.py index 1eed82da..492ad6a2 100644 --- a/dbt/adapters/duckdb/relation.py +++ b/dbt/adapters/duckdb/relation.py @@ -8,15 +8,30 @@ from .utils import SourceConfig from dbt.adapters.base.relation import BaseRelation from dbt.adapters.base.relation import Self -from dbt.contracts.graph.nodes import SourceDefinition +from dbt.adapters.contracts.relation import ( + HasQuoting, + RelationConfig, +) @dataclass(frozen=True, eq=False, repr=False) class DuckDBRelation(BaseRelation): external: Optional[str] = None @classmethod - def create_from_source(cls: Type[Self], source: SourceDefinition, **kwargs: Any) -> Self: + def create_from( + cls: Type[Self], + quoting: HasQuoting, + relation_config: RelationConfig, + **kwargs: Any, + ) -> Self: + if relation_config.resource_type == 'source': + return cls.create_from_source(quoting, relation_config, **kwargs) + else: + return super().create_from(quoting, relation_config, **kwargs) + + @classmethod + def create_from_source(cls: Type[Self], quoting: HasQuoting, source: RelationConfig, **kwargs: Any) -> Self: """ This method creates a new DuckDBRelation instance from a source definition. It first checks if a 'plugin' is defined in the meta argument for the source or its parent configuration. @@ -59,7 +74,7 @@ def create_from_source(cls: Type[Self], source: SourceDefinition, **kwargs: Any) ext_location = f"'{ext_location}'" kwargs["external"] = ext_location - return super().create_from_source(source, **kwargs) # type: ignore + return super().create_from(quoting, source, **kwargs) # type: ignore def render(self) -> str: if self.external: diff --git a/dbt/adapters/duckdb/utils.py b/dbt/adapters/duckdb/utils.py index c6a31c87..2d7deaf7 100644 --- a/dbt/adapters/duckdb/utils.py +++ b/dbt/adapters/duckdb/utils.py @@ -7,9 +7,9 @@ from dbt.adapters.base.column import Column from dbt.adapters.base.relation import BaseRelation +from dbt.adapters.contracts.relation import RelationConfig # TODO # from dbt.context.providers import RuntimeConfigObject -# from dbt_common.contracts.graph.nodes import SourceDefinition @dataclass @@ -48,7 +48,7 @@ def as_dict(self) -> Dict[str, Any]: return base @classmethod - def create_from_source(cls, source: Any) -> "SourceConfig": + def create_from_source(cls, source: RelationConfig) -> "SourceConfig": meta = source.source_meta.copy() meta.update(source.meta) # Use the config properties as well if they are present