-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update preliminary Clickhouse configurations #1055
Signed-off-by: Marcel Coetzee <[email protected]>
- Loading branch information
Showing
4 changed files
with
81 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,88 @@ | ||
from typing import TYPE_CHECKING, ClassVar, List, Optional, Final | ||
from typing import ClassVar, List, Any, Final, TYPE_CHECKING | ||
|
||
from dlt.common.configuration import configspec | ||
from dlt.common.destination.reference import DestinationClientDwhWithStagingConfiguration | ||
from dlt.common.configuration.specs import ConnectionStringCredentials | ||
from dlt.common.destination.reference import ( | ||
DestinationClientDwhWithStagingConfiguration, | ||
) | ||
from dlt.common.libs.sql_alchemy import URL | ||
from dlt.common.utils import digest128 | ||
|
||
|
||
@configspec | ||
class ClickhouseCredentials(ConnectionStringCredentials): | ||
drivername: str = "clickhouse" | ||
host: str | ||
"""Host with running ClickHouse server.""" | ||
port: int = 9000 | ||
"""Port ClickHouse server is bound to. Defaults to 9000.""" | ||
user: str = "default" | ||
"""Database user. Defaults to 'default'.""" | ||
database: str = "default" | ||
"""database connect to. Defaults to 'default'.""" | ||
connect_timeout: int = 10 | ||
"""Timeout for establishing connection. Defaults to 10 seconds.""" | ||
send_receive_timeout: int = 300 | ||
"""Timeout for sending and receiving data. Defaults to 300 seconds.""" | ||
|
||
__config_gen_annotations__: ClassVar[List[str]] = [ | ||
"host", | ||
"port", | ||
"user", | ||
"database", | ||
"connect_timeout", | ||
"send_receive_timeout", | ||
] | ||
|
||
def parse_native_representation(self, native_value: Any) -> None: | ||
super().parse_native_representation(native_value) | ||
self.connect_timeout = int(self.query.get("connect_timeout", self.connect_timeout)) | ||
self.send_receive_timeout = int( | ||
self.query.get("send_receive_timeout", self.send_receive_timeout) | ||
) | ||
if not self.is_partial(): | ||
self.resolve() | ||
|
||
def to_url(self) -> URL: | ||
url = super().to_url() | ||
url.update_query_pairs( | ||
[ | ||
("connect_timeout", str(self.connect_timeout)), | ||
("send_receive_timeout", str(self.send_receive_timeout)), | ||
] | ||
) | ||
return url | ||
|
||
|
||
@configspec | ||
class ClickhouseClientConfiguration(DestinationClientDwhWithStagingConfiguration): | ||
destination_type: Final[str] = "clickhouse" # type: ignore | ||
destination_type: Final[str] = "clickhouse" # type: ignore[misc] | ||
credentials: ClickhouseCredentials | ||
|
||
http_timeout: float = 15.0 | ||
file_upload_timeout: float = 30 * 60.0 | ||
retry_deadline: float = 60.0 | ||
create_indexes: bool = True | ||
|
||
__config_gen_annotations__: ClassVar[List[str]] = [] | ||
def fingerprint(self) -> str: | ||
"""Returns a fingerprint of host part of a connection string.""" | ||
if self.credentials and self.credentials.host: | ||
return digest128(self.credentials.host) | ||
return "" | ||
|
||
if TYPE_CHECKING: | ||
|
||
def __init__( | ||
self, | ||
*, | ||
credentials: ClickhouseCredentials = None, | ||
dataset_name: str = None, | ||
default_schema_name: Optional[str], | ||
http_timeout: float = 15.0, | ||
file_upload_timeout: float = 30 * 60.0, | ||
retry_deadline: float = 60.0, | ||
default_schema_name: str = None, | ||
destination_name: str = None, | ||
environment: str = None | ||
) -> None: | ||
super().__init__( | ||
credentials=credentials, | ||
dataset_name=dataset_name, | ||
default_schema_name=default_schema_name, | ||
destination_name=destination_name, | ||
environment=environment, | ||
) | ||
self.retry_deadline = retry_deadline | ||
self.file_upload_timeout = file_upload_timeout | ||
self.http_timeout = http_timeout | ||
... |