Skip to content

Commit

Permalink
Optimize import and type hinting in Clickhouse factory #1055
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Coetzee <[email protected]>
  • Loading branch information
Pipboyguy committed Apr 6, 2024
1 parent 9f41edd commit 584ebe7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions dlt/destinations/impl/clickhouse/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@

from dlt.common.destination import Destination, DestinationCapabilitiesContext
from dlt.destinations.impl.clickhouse import capabilities
from dlt.destinations.impl.clickhouse.clickhouse import ClickhouseClient
from dlt.destinations.impl.clickhouse.configuration import (
ClickhouseClientConfiguration,
ClickhouseCredentials,
)


if t.TYPE_CHECKING:
from dlt.destinations.impl.clickhouse.clickhouse import ClickhouseClient


# noinspection PyPep8Naming
class clickhouse(Destination[ClickhouseClientConfiguration, ClickhouseClient]):
class clickhouse(Destination[ClickhouseClientConfiguration, "ClickhouseClient"]):
spec = ClickhouseClientConfiguration

def capabilities(self) -> DestinationCapabilitiesContext:
return capabilities()

@property
def client_class(self) -> t.Type[ClickhouseClient]:
def client_class(self) -> t.Type["ClickhouseClient"]:
from dlt.destinations.impl.clickhouse.clickhouse import ClickhouseClient

return ClickhouseClient
Expand Down
2 changes: 1 addition & 1 deletion tests/load/clickhouse/test_clickhouse_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
def test_clickhouse_connection_string_with_all_params() -> None:
url = "clickhouse://user1:pass1@host1:9000/testdb?secure=0&connect_timeout=230&send_receive_timeout=1000"

creds = ClickhouseCredentials() # type: ignore
creds = ClickhouseCredentials()
creds.parse_native_representation(url)

assert creds.database == "testdb"
Expand Down
6 changes: 3 additions & 3 deletions tests/load/clickhouse/test_clickhouse_table_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@pytest.fixture
def clickhouse_client(empty_schema: Schema) -> ClickhouseClient:
# Return a client without opening connection.
creds = ClickhouseCredentials() # type: ignore
creds = ClickhouseCredentials()
return ClickhouseClient(
empty_schema,
ClickhouseClientConfiguration(dataset_name=f"test_{uniq_id()}", credentials=creds),
Expand All @@ -34,15 +34,15 @@ def test_clickhouse_configuration() -> None:
"DESTINATION__CLICKHOUSE__CREDENTIALS__PASSWORD": "fuss_do_rah",
}
):
C = resolve_configuration(ClickhouseCredentials(), sections=("destination", "clickhouse")) # type: ignore
C = resolve_configuration(ClickhouseCredentials(), sections=("destination", "clickhouse"))
assert C.database == "mydb"
assert C.password == "fuss_do_rah"

# Check fingerprint.
assert ClickhouseClientConfiguration().fingerprint() == ""
# Based on host.
c = resolve_configuration(
ClickhouseCredentials(), # type: ignore
ClickhouseCredentials(),
explicit_value="clickhouse://user1:pass@host1/db1",
)
assert ClickhouseClientConfiguration(credentials=c).fingerprint() == digest128("host1")
Expand Down

0 comments on commit 584ebe7

Please sign in to comment.