From 360f165f0aa77f1b766bf3ac272c1ab3d7e0d9f1 Mon Sep 17 00:00:00 2001 From: Steinthor Palsson Date: Wed, 1 Nov 2023 12:49:47 -0400 Subject: [PATCH 1/2] Set port correctly in mssql connection string --- dlt/destinations/mssql/configuration.py | 3 +-- tests/load/mssql/test_mssql_credentials.py | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/load/mssql/test_mssql_credentials.py diff --git a/dlt/destinations/mssql/configuration.py b/dlt/destinations/mssql/configuration.py index 581da0f782..17f10ddff0 100644 --- a/dlt/destinations/mssql/configuration.py +++ b/dlt/destinations/mssql/configuration.py @@ -60,8 +60,7 @@ def _get_odbc_driver(self) -> str: def to_odbc_dsn(self) -> str: params = { "DRIVER": self.odbc_driver, - "SERVER": self.host, - "PORT": self.port, + "SERVER": f"{self.host},{self.port}", "DATABASE": self.database, "UID": self.username, "PWD": self.password, diff --git a/tests/load/mssql/test_mssql_credentials.py b/tests/load/mssql/test_mssql_credentials.py new file mode 100644 index 0000000000..9b57692bb2 --- /dev/null +++ b/tests/load/mssql/test_mssql_credentials.py @@ -0,0 +1,24 @@ +from dlt.common.configuration import resolve_configuration + +from dlt.destinations.mssql.configuration import MsSqlCredentials + + + +def test_to_odbc_dsn() -> None: + creds = resolve_configuration( + MsSqlCredentials("mssql://test_user:test_password@sql.example.com:12345/test_db?FOO=a&BAR=b") + ) + + dsn = creds.to_odbc_dsn() + + result = {k: v for k, v in (param.split('=') for param in dsn.split(";"))} + + assert result == { + 'DRIVER': 'ODBC Driver 18 for SQL Server', + 'SERVER': 'sql.example.com,12345', + 'DATABASE': 'test_db', + 'UID': 'test_user', + 'PWD': 'test_password', + 'FOO': 'a', + 'BAR': 'b' + } From 835c49c1119fff08dc4a6063a855627bc27fcc6e Mon Sep 17 00:00:00 2001 From: Steinthor Palsson Date: Mon, 6 Nov 2023 13:03:57 -0500 Subject: [PATCH 2/2] Fix flaky sorting in arrow loading test --- tests/load/pipeline/test_arrow_loading.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/load/pipeline/test_arrow_loading.py b/tests/load/pipeline/test_arrow_loading.py index b69ac5d2be..bd709e764d 100644 --- a/tests/load/pipeline/test_arrow_loading.py +++ b/tests/load/pipeline/test_arrow_loading.py @@ -46,7 +46,7 @@ def some_data(): assert some_table_columns["time"]["data_type"] == "time" qual_name = pipeline.sql_client().make_qualified_table_name("some_data") - rows = [list(row) for row in select_data(pipeline, f"SELECT * FROM {qual_name} ORDER BY 1")] + rows = [list(row) for row in select_data(pipeline, f"SELECT * FROM {qual_name}")] for row in rows: for i in range(len(row)): @@ -66,7 +66,7 @@ def some_data(): if isinstance(row[i], datetime): row[i] = pendulum.instance(row[i]) - expected = sorted([list(r.values()) for r in records], key=lambda x: x[0]) + expected = sorted([list(r.values()) for r in records]) for row in expected: for i in range(len(row)): @@ -75,6 +75,10 @@ def some_data(): load_id = load_info.loads_ids[0] + # Sort rows by all columns except _dlt_id/_dlt_load_id for deterministic comparison + rows = sorted(rows, key=lambda row: row[:-2]) + expected = sorted(expected) + for row, expected_row in zip(rows, expected): # Compare without _dlt_id/_dlt_load_id columns assert row[:-2] == expected_row