Skip to content

Commit

Permalink
Release 0 6 21 (#274)
Browse files Browse the repository at this point in the history
* Clean up C exception

* Tweak changelog

* Test updates
  • Loading branch information
genzgd authored Nov 23, 2023
1 parent ed14656 commit 0015085
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_connect/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.6.20'
version = '0.6.21'
4 changes: 4 additions & 0 deletions clickhouse_connect/cc_sqlalchemy/datatypes/sqltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ class UUID(ChSqlaType, UserDefinedType):
python_type = None


class Point(ChSqlaType, UserDefinedType):
python_type = None


class Date(ChSqlaType, SqlaDate):
pass

Expand Down
4 changes: 2 additions & 2 deletions clickhouse_connect/datatypes/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,12 +43,11 @@ def _finalize_column(self, column: Sequence, ctx: QueryContext) -> Sequence:
return np.array(column, dtype=f'<U{ctx.max_str_len}')
return column

# pylint: disable=duplicate-code,too-many-nested-blocks,too-many-branches
def _write_column_binary(self, column: Union[Sequence, MutableSequence], dest: bytearray, ctx: InsertContext):
encoding = None
if not isinstance(self._first_value(column), bytes):
encoding = ctx.encoding or self.encoding
data_conv.write_str_col(column, self.nullable, encoding, dest)
handle_error(data_conv.write_str_col(column, self.nullable, encoding, dest))

def _active_null(self, ctx):
if ctx.use_none:
Expand Down
7 changes: 4 additions & 3 deletions clickhouse_connect/driver/dataconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from uuid import UUID, SafeUUID

from clickhouse_connect.driver.common import int_size
from clickhouse_connect.driver.exceptions import DataError
from clickhouse_connect.driver.errors import NONE_IN_NULLABLE_COLUMN
from clickhouse_connect.driver.types import ByteSource
from clickhouse_connect.driver.options import np

Expand Down Expand Up @@ -111,12 +111,12 @@ def pivot(data: Sequence[Sequence], start_row: int, end_row: int) -> 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:
Expand All @@ -132,3 +132,4 @@ def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], des
break
app(0x80 | b)
dest += x
return 0
13 changes: 13 additions & 0 deletions clickhouse_connect/driver/errors.py
Original file line number Diff line number Diff line change
@@ -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])
7 changes: 4 additions & 3 deletions clickhouse_connect/driverc/dataconv.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -315,3 +315,4 @@ def write_str_col(column: Sequence, nullable: bool, encoding: Optional[str], des
finally:
mv.release()
PyMem_Free(<void *>temp_buff)
return 0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "cython==3.0.4"]
requires = ["setuptools", "cython==3.0.5"]

build-backend = "setuptools.build_meta"

Expand Down
4 changes: 2 additions & 2 deletions tests/test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0015085

Please sign in to comment.