Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add point type #273

Merged
merged 5 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ 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.20, 2023-11-09
### Bug Fix
- Fixed an issue where client side binding of datetimes with timezones would produce the incorrect time string if
Expand Down
7 changes: 7 additions & 0 deletions clickhouse_connect/datatypes/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ def convert_dict_insert(self, column: Sequence) -> Sequence:
return col


class Point(Tuple):

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


class Map(ClickHouseType):
_slots = 'key_type', 'value_type'
python_type = dict
Expand Down
2 changes: 2 additions & 0 deletions clickhouse_connect/datatypes/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def parse_name(name: str) -> Tuple[str, str, TypeDef]:
elif base.startswith('Tuple'):
keys, values = parse_columns(base[5:])
base = 'Tuple'
elif base == 'Point':
values = ['Float64', 'Float64']
else:
try:
base, values, _ = parse_callable(base)
Expand Down
11 changes: 11 additions & 0 deletions tests/integration_tests/test_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ def test_tuple_inserts(test_client: Client, table_context: Callable):
assert query_result[2] == query_result[3]


def test_point_inserts(test_client: Client, table_context: Callable):
with table_context('insert_point_test', ['key Int32', 'point Point']):
data = [[1, (3.55, 3.55)], [2, (4.55, 4.55)]]
result = test_client.insert('insert_point_test', data)
assert 2 == result.written_rows

query_result = test_client.query('SELECT * FROM insert_point_test ORDER BY key').result_rows
assert query_result[0] == (1, (3.55, 3.55))
assert query_result[1] == (2, (4.55, 4.55))


def test_agg_function(test_client: Client, table_context: Callable):
with table_context('agg_func_test', ['key Int32',
'str SimpleAggregateFunction(any, String)',
Expand Down
9 changes: 9 additions & 0 deletions tests/unit_tests/test_driver/test_native_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ def test_ip():
assert tuple(python) == tuple(IPv4Address(ip) for ip in ips)


def test_point():
points = ((3.22, 3.22),(5.22, 5.22),(4.22, 4.22))
point_type = registry.get_from_name('Point')
dest = bytearray()
point_type.write_column(points, dest, BaseQueryContext())
python = point_type.read_column(bytes_source(bytes(dest)), 3, QueryContext())
assert tuple(python) == tuple(point for point in points)


def test_nested():
result = parse_response (bytes_source(NESTED_BINARY))
check_result(result, [{'str1': 'one', 'int32': 5}, {'str1': 'two', 'int32': 55}], 2, 0)
13 changes: 13 additions & 0 deletions tests/unit_tests/test_driver/test_native_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
7472 696e 6732 0773 7472 696e 6733
"""

POINT_OUTPUT = """
0101 0576 616c 7565 0550 6f69 6e74 c3f5
285c 8fc2 0940 c3f5 285c 8fc2 0940
"""

STRING_ACCEPTS_BYTES_OUTPUT = """
0101 0576 616c 7565 0653 7472 696e 6701
ff
Expand Down Expand Up @@ -77,6 +82,14 @@ def test_tuple_three():
assert bytes(output) == bytes.fromhex(TUPLE_THREE_OUTPUT)


def test_point():
data = [[(3.22, 3.22)]]
names = ['value']
types = [get_from_name('Point')]
output = native_insert_block(data, names, types)
assert bytes(output) == bytes.fromhex(POINT_OUTPUT)


def test_nested():
data = [([],),
([{'str1': 'three', 'int32': 5}, {'str1': 'five', 'int32': 77}],),
Expand Down
Loading