Skip to content

Commit

Permalink
allow datasets without schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Oct 4, 2024
1 parent eaf1cd8 commit 6bb7117
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions dlt/destinations/dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Generator, AnyStr
from typing import Any, Generator, AnyStr, Optional

from contextlib import contextmanager
from dlt.common.destination.reference import (
Expand Down Expand Up @@ -71,7 +71,7 @@ def _wrap(*args: Any, **kwargs: Any) -> Any:
class ReadableDBAPIDataset(SupportsReadableDataset):
"""Access to dataframes and arrowtables in the destination dataset via dbapi"""

def __init__(self, client: SqlClientBase[Any], schema: Schema) -> None:
def __init__(self, client: SqlClientBase[Any], schema: Optional[Schema]) -> None:
self.client = client
self.schema = schema

Expand All @@ -83,7 +83,9 @@ def __call__(

def table(self, table_name: str) -> SupportsReadableRelation:
# prepare query for table relation
schema_columns = self.schema.tables.get(table_name, {}).get("columns", {})
schema_columns = (
self.schema.tables.get(table_name, {}).get("columns", {}) if self.schema else {}
)
table_name = self.client.make_qualified_table_name(table_name)
query = f"SELECT * FROM {table_name}"
return self(query, schema_columns)
Expand Down
4 changes: 3 additions & 1 deletion dlt/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1720,5 +1720,7 @@ def __getstate__(self) -> Any:
def _dataset(self, dataset_type: Literal["dbapi", "ibis"] = "dbapi") -> SupportsReadableDataset:
"""Access helper to dataset"""
if dataset_type == "dbapi":
return ReadableDBAPIDataset(self.sql_client(), schema=self.default_schema)
return ReadableDBAPIDataset(
self.sql_client(), schema=self.default_schema if self.default_schema_name else None
)
raise NotImplementedError(f"Dataset of type {dataset_type} not implemented")

0 comments on commit 6bb7117

Please sign in to comment.