Skip to content

Commit

Permalink
Fix deserialization of containerized LowCardinality types
Browse files Browse the repository at this point in the history
  • Loading branch information
vivienm committed Apr 25, 2022
1 parent cbdba09 commit 4d77445
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion aiochclient/_types.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ cdef class LowCardinalityType:
def __cinit__(self, str name, bint container):
self.name = name
self.container = container
self.type = what_py_type(RE_LOW_CARDINALITY.findall(name)[0])
self.type = what_py_type(RE_LOW_CARDINALITY.findall(name)[0], container)

cdef _convert(self, str string):
return self.type.p_type(string)
Expand Down
6 changes: 4 additions & 2 deletions aiochclient/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,11 @@ class LowCardinalityType(BaseType):

__slots__ = ("name", "type")

def __init__(self, name: str, **kwargs):
def __init__(self, name: str, container: bool = False, **kwargs):
super().__init__(name, **kwargs)
self.type = what_py_type(RE_LOW_CARDINALITY.findall(name)[0])
self.type = what_py_type(
RE_LOW_CARDINALITY.findall(name)[0], container=container
)

def p_type(self, string: str) -> Any:
return self.type.p_type(string)
Expand Down
18 changes: 17 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def rows(uuid):
(4, "hello"),
0,
["hello", "world"],
["hello", "world"],
"'\b\f\r\n\t\\",
uuid,
[uuid, uuid, uuid],
Expand Down Expand Up @@ -85,6 +86,7 @@ def rows(uuid):
(4, "hello"),
None,
[],
[],
"'\b\f\r\n\t\\",
None,
[],
Expand Down Expand Up @@ -157,6 +159,7 @@ async def all_types_db(chclient, rows):
tuple Tuple(UInt8, String),
nullable Nullable(Int8),
array_string Array(String),
array_low_cardinality_string Array(LowCardinality(String)),
escape_string String,
uuid Nullable(UUID),
array_uuid Array(UUID),
Expand Down Expand Up @@ -202,7 +205,7 @@ async def all_types_db(chclient, rows):
def class_chclient(chclient, all_types_db, rows, request):
request.cls.ch = chclient
cls_rows = rows
cls_rows[1][38] = dt.datetime(
cls_rows[1][-1] = dt.datetime(
2019, 1, 1, 3, 0
) # DateTime64 always returns datetime type
request.cls.rows = [tuple(r) for r in cls_rows]
Expand Down Expand Up @@ -502,6 +505,19 @@ async def test_array_string(self):
assert record[0] == result
assert record["array_string"] == result

async def test_array_low_cardinality_string(self):
result = ["hello", "world"]
assert await self.select_field("array_low_cardinality_string") == result
record = await self.select_record("array_low_cardinality_string")
assert record[0] == result
assert record["array_low_cardinality_string"] == result

result = b"['hello','world']"
assert await self.select_field_bytes("array_low_cardinality_string") == result
record = await self.select_record_bytes("array_low_cardinality_string")
assert record[0] == result
assert record["array_low_cardinality_string"] == result

async def test_escape_string(self):
result = "'\b\f\r\n\t\\"
assert await self.select_field("escape_string") == result
Expand Down

0 comments on commit 4d77445

Please sign in to comment.