Skip to content

Commit

Permalink
[DOP-13855] - fix Version.min_digits() method
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-lixakov committed Apr 12, 2024
1 parent 50c05bf commit 8a8fea7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/changelog/next_release/249.breaking.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Updated the Clickhouse JDBC driver from ``ru.yandex.clickhouse:clickhouse-jdbc:0.3.2`` to `com.clickhouse:clickhouse-jdbc:0.6.0 <https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc/0.6.0>`_. Added support for dynamic package versioning and dependencies on the `Apache HTTP client <https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5/5.3.1>`_ as needed.
Updated the Clickhouse JDBC driver from ``ru.yandex.clickhouse:clickhouse-jdbc:0.3.2`` to `com.clickhouse:clickhouse-jdbc:0.6.0 <https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc/0.6.0>`_.
1 change: 1 addition & 0 deletions docs/changelog/next_release/249.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow passing custom JDBC driver version to ``Clickhouse.get_packages(package_version=...)``.
4 changes: 1 addition & 3 deletions onetl/_util/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ def min_digits(self, num_parts: int) -> Version:
"""
if len(self._numeric_parts) < num_parts:
raise ValueError(f"Version '{self}' does not have enough numeric components for requested format.")
truncated_parts = self._numeric_parts[:num_parts]
truncated_str = ".".join(str(part) for part in truncated_parts)
return Version(truncated_str)
return self

def format(self, format_string: str) -> str:
"""
Expand Down
6 changes: 2 additions & 4 deletions onetl/connection/db_connection/clickhouse/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,10 @@ def get_packages(
``com.clickhouse:clickhouse-jdbc:0.6.0:all`` to install all required packages.
"""
package_version_obj = Version(package_version) if package_version else Version("0.6.0")
package_version_obj = Version(package_version).min_digits(3) if package_version else Version("0.6.0")
apache_http_client_version_obj = (
Version(apache_http_client_version) if apache_http_client_version else Version("5.3.1")
Version(apache_http_client_version).min_digits(3) if apache_http_client_version else Version("5.3.1")
)
if len(package_version_obj) != 3 or len(apache_http_client_version_obj) != 3:
raise ValueError("Version should consist of exactly three numeric_parts (major.minor.patch)")

result = [
f"com.clickhouse:clickhouse-jdbc:{package_version_obj}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_clickhouse_get_packages(package_version, apache_http_client_version, ex
def test_invalid_versions_raise_error(package_version, apache_http_client_version):
with pytest.raises(
ValueError,
match=r"Version should consist of exactly three numeric_parts \(major\.minor\.patch\)",
match=rf"Version '{package_version}' does not have enough numeric components for requested format.",
):
Clickhouse.get_packages(package_version=package_version, apache_http_client_version=apache_http_client_version)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_greenplum_get_packages_scala_version_not_supported(scala_version):
("2.3", "2.11", "io.pivotal:greenplum-spark_2.11:2.2.0"),
("2.4", "2.12", "io.pivotal:greenplum-spark_2.12:2.2.0"),
# Scala version contain three digits when only two needed
("3.2.4", "2.12.1", "io.pivotal:greenplum-spark_2.12:2.2.0"),
("3.2.4", "2.11.1", "io.pivotal:greenplum-spark_2.11:2.2.0"),
],
)
def test_greenplum_get_packages(spark_version, scala_version, package):
Expand Down

0 comments on commit 8a8fea7

Please sign in to comment.