Skip to content

Commit bfd2d0b

Browse files
Merge pull request #105 from Maksim-Burtsev/nested-speedups
NestedType for _types.pyx
2 parents a29f496 + 605431c commit bfd2d0b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

aiochclient/_types.pyx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ DEF ARR_CLS = ']'
6060

6161
RE_TUPLE = re.compile(r"^Tuple\((.*)\)$")
6262
RE_ARRAY = re.compile(r"^Array\((.*)\)$")
63+
RE_NESTED = re.compile(r"^Nested\((.*)\)$")
6364
RE_NULLABLE = re.compile(r"^Nullable\((.*)\)$")
6465
RE_LOW_CARDINALITY = re.compile(r"^LowCardinality\((.*)\)$")
6566
RE_MAP = re.compile(r"^Map\((.*)\)$")
@@ -590,6 +591,36 @@ cdef class ArrayType:
590591
return self.p_type(value.decode())
591592

592593

594+
cdef class NestedType:
595+
596+
cdef:
597+
str name
598+
bint container
599+
tuple types
600+
601+
def __cinit__(self, str name, bint container):
602+
self.name = name
603+
self.container = container
604+
self.types = tuple(
605+
what_py_type(i.split()[1], container=True)
606+
for i in RE_NESTED.findall(name)[0].split(',')
607+
)
608+
609+
cdef list _convert(self, str string):
610+
return self.p_type(string)
611+
612+
cpdef list p_type(self, str string):
613+
result = []
614+
for val in seq_parser(string[1:-1]):
615+
temp = []
616+
for tp, elem in zip(self.types, seq_parser(val.strip("()"))):
617+
temp.append(tp.p_type(decode(elem.encode())))
618+
result.append(tuple(temp))
619+
return result
620+
621+
cpdef list convert(self, bytes value):
622+
return self._convert(value.decode())
623+
593624
cdef class NullableType:
594625

595626
cdef:
@@ -766,6 +797,7 @@ cdef dict CH_TYPES_MAPPING = {
766797
"Decimal128": DecimalType,
767798
"IPv4": IPv4Type,
768799
"IPv6": IPv6Type,
800+
"Nested": NestedType,
769801
}
770802

771803

0 commit comments

Comments
 (0)