@@ -66,6 +66,12 @@ RE_MAP = re.compile(r"^Map\((.*)\)$")
66
66
RE_REPLACE_QUOTE = re.compile(r " (?<! \\ ) '" )
67
67
68
68
69
+ cdef str remove_single_quotes(str string):
70
+ if string[0 ] == string[- 1 ] == " '" :
71
+ return string[1 :- 1 ]
72
+ return string
73
+
74
+
69
75
cdef str decode(char * val):
70
76
"""
71
77
Converting bytes from clickhouse with
@@ -168,7 +174,7 @@ cdef class StrType:
168
174
169
175
cdef str _convert(self , str string):
170
176
if self .container:
171
- return string.strip( " ' " )
177
+ return remove_single_quotes(string )
172
178
return string
173
179
174
180
cpdef str p_type(self , str string):
@@ -528,7 +534,7 @@ cdef class TupleType:
528
534
return self ._convert(value.decode())
529
535
530
536
531
- cdef class MapType:
537
+ cdef class MapType:
532
538
533
539
cdef:
534
540
str name
@@ -544,19 +550,10 @@ cdef class MapType:
544
550
self .key_type = what_py_type(tps[:comma_index], container = True )
545
551
self .value_type = what_py_type(tps[comma_index + 1 :], container = True )
546
552
547
- cdef dict _convert(self , string):
548
- if isinstance (string, str ):
549
- string = RE_REPLACE_QUOTE.sub(' "' , string)
550
- string = string.replace(' \\ ' , ' \\\\ ' )
551
- dict_from_string = json.loads(string)
552
- else :
553
- dict_from_string = string
553
+ cdef dict _convert(self , str string):
554
+ key, value = string[1 :- 1 ].split(' :' , 1 )
554
555
return {
555
- self .key_type.p_type(
556
- decode(key.encode()) if isinstance (key, str ) else key
557
- ): self .value_type.p_type(
558
- decode(val.encode()) if isinstance (val, str ) else val
559
- ) for key, val in dict_from_string.items()
556
+ self .key_type.p_type(decode(key.encode())): self .value_type.p_type(decode(value.encode()))
560
557
}
561
558
562
559
cpdef dict p_type(self , string):
0 commit comments