Skip to content

Commit

Permalink
Set experimental session in DSN #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 16, 2024
1 parent 027d52a commit ecfe173
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 4 additions & 0 deletions dlt/destinations/impl/clickhouse/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions dlt/destinations/impl/clickhouse/sql_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 5 additions & 13 deletions tests/load/clickhouse/test_clickhouse_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit ecfe173

Please sign in to comment.