Skip to content

Commit

Permalink
fix setting of default schema name in destination config
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Nov 12, 2024
1 parent 08c7d45 commit c7f44d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
1 change: 0 additions & 1 deletion dlt/common/destination/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ def _make_dataset_name(self, schema_name: str) -> str:
# if default schema is None then suffix is not added
if self.default_schema_name is not None and schema_name != self.default_schema_name:
return (self.dataset_name or "") + "_" + schema_name

return self.dataset_name


Expand Down
15 changes: 7 additions & 8 deletions dlt/destinations/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,9 @@ def dataset(
# helpers
def get_destination_client_initial_config(
destination: AnyDestination,
schema_name: str,
default_schema_name: str,
dataset_name: str,
as_staging: bool = False,
use_single_dataset: bool = False,
) -> DestinationClientConfiguration:
client_spec = destination.spec

Expand All @@ -352,7 +351,7 @@ def get_destination_client_initial_config(
else:
spec = client_spec()

spec._bind_dataset_name(dataset_name, schema_name if not use_single_dataset else None)
spec._bind_dataset_name(dataset_name, default_schema_name)
return spec

return client_spec()
Expand All @@ -366,10 +365,12 @@ def get_destination_clients(
staging: AnyDestination = None,
staging_dataset_name: str = None,
staging_initial_config: DestinationClientConfiguration = None,
use_single_dataset: bool = False,
# pipeline specific settings
default_schema_name: str = None,
) -> Tuple[JobClientBase, JobClientBase]:
destination = Destination.from_reference(destination) if destination else None
staging = Destination.from_reference(staging) if staging else None

try:
# resolve staging config in order to pass it to destination client config
staging_client = None
Expand All @@ -379,9 +380,8 @@ def get_destination_clients(
staging_initial_config = get_destination_client_initial_config(
staging,
dataset_name=staging_dataset_name,
schema_name=schema.name,
default_schema_name=default_schema_name,
as_staging=True,
use_single_dataset=use_single_dataset,
)
# create the client - that will also resolve the config
staging_client = staging.client(schema, staging_initial_config)
Expand All @@ -391,8 +391,7 @@ def get_destination_clients(
initial_config = get_destination_client_initial_config(
destination,
dataset_name=destination_dataset_name,
schema_name=schema.name,
use_single_dataset=use_single_dataset,
default_schema_name=default_schema_name,
)

# attach the staging client config to destination client config - if its type supports it
Expand Down
9 changes: 4 additions & 5 deletions dlt/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
from dlt.destinations.job_client_impl import SqlJobClientBase
from dlt.destinations.dataset import (
dataset,
get_destination_client_initial_config,
get_destination_clients,
)
from dlt.load.configuration import LoaderConfiguration
Expand Down Expand Up @@ -1266,10 +1265,11 @@ def _get_destination_clients(
" directly or via .dlt config.toml file or environment variable.",
)

schema = schema or self.default_schema

destination_client, staging_client = get_destination_clients(
schema=schema,
schema=schema or self.default_schema,
default_schema_name=(
self.default_schema_name if not self.config.use_single_dataset else None
),
destination=self._destination,
destination_dataset_name=self.dataset_name,
destination_initial_config=initial_config,
Expand All @@ -1281,7 +1281,6 @@ def _get_destination_clients(
staging_dataset_name=self.dataset_name
or self._make_dataset_name(None, self._destination),
staging_initial_config=initial_staging_config,
use_single_dataset=self.config.use_single_dataset,
)

if isinstance(destination_client.config, DestinationClientStagingConfiguration):
Expand Down

0 comments on commit c7f44d5

Please sign in to comment.