diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-11-08 09:59:41 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-11-08 10:08:42 +0300 |
commit | d70137a7b530ccaa52834274913bbb5a3d1ca06e (patch) | |
tree | 1fefbe374d1154a52cb9f9b36b1e956d8f8d4aaf | |
parent | 3065c87f146e17787c53369001cfe6fe557f4d6f (diff) | |
download | ydb-d70137a7b530ccaa52834274913bbb5a3d1ca06e.tar.gz |
Intermediate changes
commit_hash:b029461eab3edbc697836a436c182ef54d9048a9
5 files changed, 44 insertions, 17 deletions
diff --git a/contrib/python/clickhouse-connect/.dist-info/METADATA b/contrib/python/clickhouse-connect/.dist-info/METADATA index 66c4f4ba69..21a0525563 100644 --- a/contrib/python/clickhouse-connect/.dist-info/METADATA +++ b/contrib/python/clickhouse-connect/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: clickhouse-connect -Version: 0.8.4 +Version: 0.8.5 Summary: ClickHouse Database Core Driver for Python, Pandas, and Superset Home-page: https://github.com/ClickHouse/clickhouse-connect Author: ClickHouse Inc. diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py b/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py index 63fa052550..ef88a314d6 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/__version__.py @@ -1 +1 @@ -version = '0.8.4' +version = '0.8.5' diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/datatypes/numeric.py b/contrib/python/clickhouse-connect/clickhouse_connect/datatypes/numeric.py index 0ff62b1dc2..a9629dd3e0 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/datatypes/numeric.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/datatypes/numeric.py @@ -1,7 +1,7 @@ import decimal from typing import Union, Type, Sequence, MutableSequence -from math import nan +from math import nan, isnan, isinf from clickhouse_connect.datatypes.base import TypeDef, ArrayType, ClickHouseType from clickhouse_connect.driver.common import array_type, write_array, decimal_size, decimal_prec, first_value @@ -12,42 +12,61 @@ from clickhouse_connect.driver.query import QueryContext from clickhouse_connect.driver.types import ByteSource -class Int8(ArrayType): +class IntBase(ArrayType, registered=False): + def _write_column_binary(self, column: Union[Sequence, MutableSequence], dest: bytearray, ctx: InsertContext): + if len(column) == 0: + return + if self.nullable: + first = next((x for x in column if x is not None), None) + if isinstance(first, int): + column = [0 if x is None else x for x in column] + elif isinstance(first, float): + column = [0 if x is None or isnan(x) or isinf(x) else int(x) for x in column] + else: + column = [int(x) if x else 0 for x in column] + elif isinstance(column[0], float): + column = [0 if x is None or isnan(x) or isinf(x) else int(x) for x in column] + elif not isinstance(column[0], int): + column = [int(x) for x in column] + write_array(self._array_type, column, dest) + + +class Int8(IntBase): _array_type = 'b' np_type = 'b' -class UInt8(ArrayType): +class UInt8(IntBase): _array_type = 'B' np_type = 'B' -class Int16(ArrayType): +class Int16(IntBase): _array_type = 'h' np_type = '<i2' -class UInt16(ArrayType): +class UInt16(IntBase): _array_type = 'H' np_type = '<u2' -class Int32(ArrayType): +class Int32(IntBase): _array_type = 'i' np_type = '<i4' -class UInt32(ArrayType): +class UInt32(IntBase): _array_type = 'I' np_type = '<u4' -class Int64(ArrayType): +class Int64(IntBase): _array_type = 'q' np_type = '<i8' -class UInt64(ArrayType): +class UInt64(IntBase): valid_formats = 'signed', 'native' _array_type = 'Q' np_type = '<u8' @@ -165,6 +184,19 @@ class Float(ArrayType, registered=False): return nan return 0.0 + def _write_column_binary(self, column: Union[Sequence, MutableSequence], dest: bytearray, ctx: InsertContext): + if len(column) == 0: + return + if self.nullable: + first = next((x for x in column if x is not None), None) + if not isinstance(first, float): + column = [0 if x is None else float(x) for x in column] + else: + column = [0 if x is None else x for x in column] + elif not isinstance(column[0], float): + column = [float(x) for x in column] + write_array(self._array_type, column, dest) + class Float32(Float): np_type = '<f4' diff --git a/contrib/python/clickhouse-connect/clickhouse_connect/driver/common.py b/contrib/python/clickhouse-connect/clickhouse_connect/driver/common.py index 404a09e867..38bbd52783 100644 --- a/contrib/python/clickhouse-connect/clickhouse_connect/driver/common.py +++ b/contrib/python/clickhouse-connect/clickhouse_connect/driver/common.py @@ -47,11 +47,6 @@ def write_array(code: str, column: Sequence, dest: MutableSequence, col_name: Op :param dest: Destination byte buffer :param col_name: Optional column name for error tracking """ - if len(column) and not isinstance(column[0], (int, float)): - if code in ('f', 'F', 'd', 'D'): - column = [float(x) for x in column] - else: - column = [int(x) for x in column] try: buff = struct.Struct(f'<{len(column)}{code}') dest += buff.pack(*column) diff --git a/contrib/python/clickhouse-connect/ya.make b/contrib/python/clickhouse-connect/ya.make index 78e990a925..c9e611a5f4 100644 --- a/contrib/python/clickhouse-connect/ya.make +++ b/contrib/python/clickhouse-connect/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(0.8.4) +VERSION(0.8.5) LICENSE(Apache-2.0) |