From 001508522154fb596eadbd779143b37a35e04226 Mon Sep 17 00:00:00 2001 From: Geoff Genz Date: Thu, 23 Nov 2023 05:00:49 -0700 Subject: [PATCH] Release 0 6 21 (#274) * Clean up C exception * Tweak changelog * Test updates --- .github/workflows/on_push.yml | 2 +- CHANGELOG.md | 9 ++++++--- clickhouse_connect/__version__.py | 2 +- .../cc_sqlalchemy/datatypes/sqltypes.py | 4 ++++ clickhouse_connect/datatypes/string.py | 4 ++-- clickhouse_connect/driver/dataconv.py | 7 ++++--- clickhouse_connect/driver/errors.py | 13 +++++++++++++ clickhouse_connect/driverc/dataconv.pyx | 7 ++++--- pyproject.toml | 2 +- tests/test_requirements.txt | 4 ++-- 10 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 clickhouse_connect/driver/errors.py diff --git a/.github/workflows/on_push.yml b/.github/workflows/on_push.yml index 13fe7156..5c575ba0 100644 --- a/.github/workflows/on_push.yml +++ b/.github/workflows/on_push.yml @@ -64,9 +64,9 @@ jobs: - '3.12' clickhouse-version: - '23.3' - - '23.7' - '23.8' - '23.9' + - '23.10' - latest name: Local Tests Py=${{ matrix.python-version }} CH=${{ matrix.clickhouse-version }} diff --git a/CHANGELOG.md b/CHANGELOG.md index bdb00943..88639b4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,9 +14,12 @@ In any case, this should not affect the basic usage of Superset with ClickHouse. your Superset installation, the ClickHouse datasource will be available with either the enhanced connection dialog or a standard SqlAlchemy DSN in the form of `clickhousedb://{username}:{password}@{host}:{port}`. -## 0.6.21, 2023-11-22 -### New Feature -- Added support for Point type. Closes https://github.com/ClickHouse/clickhouse-connect/issues/151 +## 0.6.21, 2023-11-23 +### Improvements +- Added support for Point type. Closes https://github.com/ClickHouse/clickhouse-connect/issues/151. Thanks to +[Dhruvit Maniya](https://github.com/Dhruvit96) for the PR! +- Upgraded to Cython 3.0.5 +- Change exception handling in C API to stop spamming stderr ## 0.6.20, 2023-11-09 ### Bug Fix diff --git a/clickhouse_connect/__version__.py b/clickhouse_connect/__version__.py index 61f0ae17..ecb766dd 100644 --- a/clickhouse_connect/__version__.py +++ b/clickhouse_connect/__version__.py @@ -1 +1 @@ -version = '0.6.20' +version = '0.6.21' diff --git a/clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py b/clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py index d611f189..dc4fd089 100644 --- a/clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py +++ b/clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py @@ -198,6 +198,10 @@ class UUID(ChSqlaType, UserDefinedType): python_type = None +class Point(ChSqlaType, UserDefinedType): + python_type = None + + class Date(ChSqlaType, SqlaDate): pass diff --git a/clickhouse_connect/datatypes/string.py b/clickhouse_connect/datatypes/string.py index 0b5a81cb..efc04df0 100644 --- a/clickhouse_connect/datatypes/string.py +++ b/clickhouse_connect/datatypes/string.py @@ -3,6 +3,7 @@ from clickhouse_connect.driver.ctypes import data_conv from clickhouse_connect.datatypes.base import ClickHouseType, TypeDef +from clickhouse_connect.driver.errors import handle_error from clickhouse_connect.driver.exceptions import DataError from clickhouse_connect.driver.insert import InsertContext from clickhouse_connect.driver.query import QueryContext @@ -42,12 +43,11 @@ def _finalize_column(self, column: Sequence, ctx: QueryContext) -> Sequence: return np.array(column, dtype=f' Sequence[Se return tuple(zip(*data[start_row: end_row])) -def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], dest: bytearray): +def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], dest: bytearray) -> int: app = dest.append for x in column: if not x: if not nullable and x is None: - raise DataError('Invalid None value in non-Nullable column') + return NONE_IN_NULLABLE_COLUMN app(0) else: if encoding: @@ -132,3 +132,4 @@ def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], des break app(0x80 | b) dest += x + return 0 diff --git a/clickhouse_connect/driver/errors.py b/clickhouse_connect/driver/errors.py new file mode 100644 index 00000000..0d37890b --- /dev/null +++ b/clickhouse_connect/driver/errors.py @@ -0,0 +1,13 @@ +from clickhouse_connect.driver.exceptions import DataError + + +# Error codes used in the Cython API +NO_ERROR = 0 +NONE_IN_NULLABLE_COLUMN = 1 + +error_messages = {NONE_IN_NULLABLE_COLUMN: 'Invalid None value in non-Nullable column'} + + +def handle_error(error_num: int): + if error_num > 0: + raise DataError(error_messages[error_num]) diff --git a/clickhouse_connect/driverc/dataconv.pyx b/clickhouse_connect/driverc/dataconv.pyx index 0c9bbc19..da3718d1 100644 --- a/clickhouse_connect/driverc/dataconv.pyx +++ b/clickhouse_connect/driverc/dataconv.pyx @@ -19,7 +19,7 @@ from uuid import UUID, SafeUUID from libc.string cimport memcpy from datetime import tzinfo -from clickhouse_connect.driver.exceptions import DataError +from clickhouse_connect.driver.errors import NONE_IN_NULLABLE_COLUMN @cython.boundscheck(False) @cython.wraparound(False) @@ -255,7 +255,7 @@ cdef inline extend_byte_array(target: bytearray, int start, object source, Py_ss @cython.boundscheck(False) @cython.wraparound(False) -def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], dest: bytearray): +def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], dest: bytearray) -> int: cdef unsigned long long buff_size = len(column) << 5 cdef unsigned long long buff_loc = 0, sz = 0, dsz = 0 cdef unsigned long long array_size = PyByteArray_GET_SIZE(dest) @@ -268,7 +268,7 @@ def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], des for x in column: if not x: if not nullable and x is None: - raise DataError('Invalid None value in non-Nullable column') + return NONE_IN_NULLABLE_COLUMN temp_buff[buff_loc] = 0 buff_loc += 1 if buff_loc == buff_size: @@ -315,3 +315,4 @@ def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], des finally: mv.release() PyMem_Free(temp_buff) + return 0 diff --git a/pyproject.toml b/pyproject.toml index 9b175714..013f715d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools", "cython==3.0.4"] +requires = ["setuptools", "cython==3.0.5"] build-backend = "setuptools.build_meta" diff --git a/tests/test_requirements.txt b/tests/test_requirements.txt index 6c1a9e80..58d6e313 100644 --- a/tests/test_requirements.txt +++ b/tests/test_requirements.txt @@ -3,8 +3,8 @@ urllib3>=1.26 setuptools certifi sqlalchemy>1.3.21,<2.0 -cython==3.0.4 -pyarrow; python_version < '3.12' +cython==3.0.5 +pyarrow pytest pytest-mock pytest-dotenv