From ecfe173ce4671f9435a21c06859b424081704ff7 Mon Sep 17 00:00:00 2001 From: Marcel Coetzee Date: Wed, 17 Apr 2024 00:27:06 +0200 Subject: [PATCH] Set experimental session in DSN #1055 Signed-off-by: Marcel Coetzee --- .../impl/clickhouse/configuration.py | 4 ++++ dlt/destinations/impl/clickhouse/sql_client.py | 4 +--- .../test_clickhouse_configuration.py | 18 +++++------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/dlt/destinations/impl/clickhouse/configuration.py b/dlt/destinations/impl/clickhouse/configuration.py index d6352a1467..71d9d1de38 100644 --- a/dlt/destinations/impl/clickhouse/configuration.py +++ b/dlt/destinations/impl/clickhouse/configuration.py @@ -67,6 +67,10 @@ def to_url(self) -> URL: ("connect_timeout", str(self.connect_timeout)), ("send_receive_timeout", str(self.send_receive_timeout)), ("secure", str(1) if self.secure else str(0)), + # Toggle experimental settings. These are necessary for certain datatypes and not optional. + ("allow_experimental_lightweight_delete", "1"), + ("allow_experimental_object_type", "1"), + ("enable_http_compression", "1"), ] ) return url diff --git a/dlt/destinations/impl/clickhouse/sql_client.py b/dlt/destinations/impl/clickhouse/sql_client.py index 8fafa7ba74..fdddf7de3c 100644 --- a/dlt/destinations/impl/clickhouse/sql_client.py +++ b/dlt/destinations/impl/clickhouse/sql_client.py @@ -57,9 +57,7 @@ def has_dataset(self) -> bool: return len(self._list_tables()) > 0 def open_connection(self) -> clickhouse_driver.dbapi.connection.Connection: - self._conn = clickhouse_driver.dbapi.connect( - dsn=self.credentials.to_native_representation() - ) + self._conn = clickhouse_driver.connect(dsn=self.credentials.to_native_representation()) return self._conn @raise_open_connection_error diff --git a/tests/load/clickhouse/test_clickhouse_configuration.py b/tests/load/clickhouse/test_clickhouse_configuration.py index 5268c7bd22..dcbf7e0935 100644 --- a/tests/load/clickhouse/test_clickhouse_configuration.py +++ b/tests/load/clickhouse/test_clickhouse_configuration.py @@ -5,7 +5,6 @@ import dlt from dlt.common.configuration.resolve import resolve_configuration from dlt.common.libs.sql_alchemy import make_url -from dlt.common.storages import FileStorage from dlt.common.utils import digest128 from dlt.destinations.impl.clickhouse.clickhouse import ClickHouseClient from dlt.destinations.impl.clickhouse.configuration import ( @@ -18,17 +17,6 @@ ) from tests.common.configuration.utils import environment from tests.load.utils import yield_client_with_storage -from tests.utils import TEST_STORAGE_ROOT, delete_test_storage - - -@pytest.fixture -def file_storage() -> FileStorage: - return FileStorage(TEST_STORAGE_ROOT, file_type="b", makedirs=True) - - -@pytest.fixture(autouse=True) -def auto_delete_storage() -> None: - delete_test_storage() @pytest.fixture(scope="function") @@ -37,7 +25,11 @@ def client() -> Iterator[ClickHouseClient]: 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" + url = ( + "clickhouse://user1:pass1@host1:9000/testdb?allow_experimental_lightweight_delete=1&" + "allow_experimental_object_type=1&connect_timeout=230&enable_http_compression=1&secure=0" + "&send_receive_timeout=1000" + ) creds = ClickHouseCredentials() creds.parse_native_representation(url)