Skip to content

Commit

Permalink
Merge pull request ClickHouse#11 from ClickHouse/deprecation_fix
Browse files Browse the repository at this point in the history
Deprecation fix
  • Loading branch information
genzgd authored Jun 6, 2022
2 parents b717afb + f9a286f commit 8637d1b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
16 changes: 9 additions & 7 deletions clickhouse_connect/datatypes/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,21 +198,23 @@ def write_native_data(self, column: Sequence, dest: MutableSequence):
self.value_type.write_native_data(values, dest)


class Object(UnsupportedType):
python_type = dict
class Nested(UnsupportedType):
__slots__ = ('elements',)
python_type = list

def __init__(self, type_def):
super().__init__(type_def)
self.elements = [get_from_name(x) for x in type_def.values]
self._name_suffix = type_def.arg_str


class JSON(UnsupportedType):
class Object(UnsupportedType):
python_type = dict


class Nested(UnsupportedType):
python_type = list

def __init__(self, type_def):
super().__init__(type_def)
self._name_suffix = type_def.arg_str


class JSON(UnsupportedType):
python_type = dict
5 changes: 5 additions & 0 deletions clickhouse_connect/driver/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ def write_array(code: str, column: Sequence, dest: MutableSequence):
:param column: Column of native Python values
:param dest: Destination byte buffer
"""
if 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]
buff = array.array(code, column)
if must_swap:
buff.byteswap()
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_connect/driver/httpclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# the client as thread safe as possible while sharing a single connection pool. For the same reason we
# don't call the Session.close() method from the client so the connection pool remains available
retry = Retry(total=2, status_forcelist=[429, 503, 504],
method_whitelist=['HEAD', 'GET', 'OPTIONS', 'POST'],
allowed_methods=['HEAD', 'GET', 'OPTIONS', 'POST'],
backoff_factor=1.5)
http_adapter = HTTPAdapter(pool_connections=4, pool_maxsize=8, max_retries=retry)
atexit.register(http_adapter.close)
Expand Down
12 changes: 12 additions & 0 deletions tests/integration_tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from decimal import Decimal

from clickhouse_connect.driver.client import Client
from clickhouse_connect.driver.options import HAS_NUMPY, HAS_PANDAS
from clickhouse_connect.driver.query import QueryResult
Expand All @@ -20,6 +22,16 @@ def test_insert(test_client: Client, test_table_engine: str):
test_client.insert(table='test_system_insert', column_names='*', data=tables_result.result_set)


def test_decimal_conv(test_client: Client, test_table_engine: str):
test_client.command('DROP TABLE IF EXISTS test_number_conv')
test_client.command('CREATE TABLE test_num_conv (col1 UInt64, col2 Int32, f1 Float64)' +
f' Engine {test_table_engine} ORDER BY col1')
data = [[Decimal(5), Decimal(-182), Decimal(55.2)], [Decimal(57238478234), Decimal(77), Decimal(-29.5773)]]
test_client.insert('test_num_conv', data)
result = test_client.query('SELECT * FROM test_num_conv').result_set
assert result == [(5, -182, 55.2), (57238478234, 77, -29.5773)]


def test_numpy(test_client: Client):
if HAS_NUMPY:
np_array = test_client.query_np('SELECT * FROM system.tables')
Expand Down

0 comments on commit 8637d1b

Please sign in to comment.