Skip to content

Commit

Permalink
implement DuckDbRelation.create_from, fix TestExternalSources::test_e…
Browse files Browse the repository at this point in the history
…xternal_sources
  • Loading branch information
MichelleArk committed Feb 29, 2024
1 parent 10034b3 commit 5712711
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 3 additions & 2 deletions dbt/adapters/duckdb/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 18 additions & 3 deletions dbt/adapters/duckdb/relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions dbt/adapters/duckdb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5712711

Please sign in to comment.