clickhouse-driver 0.2.9__cp38-cp38-musllinux_1_1_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clickhouse_driver/__init__.py +9 -0
- clickhouse_driver/block.py +227 -0
- clickhouse_driver/blockstreamprofileinfo.py +22 -0
- clickhouse_driver/bufferedreader.cpython-38-aarch64-linux-gnu.so +0 -0
- clickhouse_driver/bufferedwriter.cpython-38-aarch64-linux-gnu.so +0 -0
- clickhouse_driver/client.py +812 -0
- clickhouse_driver/clientinfo.py +119 -0
- clickhouse_driver/columns/__init__.py +0 -0
- clickhouse_driver/columns/arraycolumn.py +161 -0
- clickhouse_driver/columns/base.py +221 -0
- clickhouse_driver/columns/boolcolumn.py +7 -0
- clickhouse_driver/columns/datecolumn.py +108 -0
- clickhouse_driver/columns/datetimecolumn.py +203 -0
- clickhouse_driver/columns/decimalcolumn.py +116 -0
- clickhouse_driver/columns/enumcolumn.py +129 -0
- clickhouse_driver/columns/exceptions.py +12 -0
- clickhouse_driver/columns/floatcolumn.py +34 -0
- clickhouse_driver/columns/intcolumn.py +157 -0
- clickhouse_driver/columns/intervalcolumn.py +33 -0
- clickhouse_driver/columns/ipcolumn.py +118 -0
- clickhouse_driver/columns/jsoncolumn.py +37 -0
- clickhouse_driver/columns/largeint.cpython-38-aarch64-linux-gnu.so +0 -0
- clickhouse_driver/columns/lowcardinalitycolumn.py +142 -0
- clickhouse_driver/columns/mapcolumn.py +73 -0
- clickhouse_driver/columns/nestedcolumn.py +10 -0
- clickhouse_driver/columns/nothingcolumn.py +13 -0
- clickhouse_driver/columns/nullablecolumn.py +7 -0
- clickhouse_driver/columns/nullcolumn.py +15 -0
- clickhouse_driver/columns/numpy/__init__.py +0 -0
- clickhouse_driver/columns/numpy/base.py +47 -0
- clickhouse_driver/columns/numpy/boolcolumn.py +8 -0
- clickhouse_driver/columns/numpy/datecolumn.py +19 -0
- clickhouse_driver/columns/numpy/datetimecolumn.py +146 -0
- clickhouse_driver/columns/numpy/floatcolumn.py +24 -0
- clickhouse_driver/columns/numpy/intcolumn.py +43 -0
- clickhouse_driver/columns/numpy/lowcardinalitycolumn.py +96 -0
- clickhouse_driver/columns/numpy/service.py +58 -0
- clickhouse_driver/columns/numpy/stringcolumn.py +78 -0
- clickhouse_driver/columns/numpy/tuplecolumn.py +37 -0
- clickhouse_driver/columns/service.py +185 -0
- clickhouse_driver/columns/simpleaggregatefunctioncolumn.py +7 -0
- clickhouse_driver/columns/stringcolumn.py +73 -0
- clickhouse_driver/columns/tuplecolumn.py +63 -0
- clickhouse_driver/columns/util.py +61 -0
- clickhouse_driver/columns/uuidcolumn.py +64 -0
- clickhouse_driver/compression/__init__.py +28 -0
- clickhouse_driver/compression/base.py +87 -0
- clickhouse_driver/compression/lz4.py +21 -0
- clickhouse_driver/compression/lz4hc.py +9 -0
- clickhouse_driver/compression/zstd.py +20 -0
- clickhouse_driver/connection.py +793 -0
- clickhouse_driver/context.py +36 -0
- clickhouse_driver/dbapi/__init__.py +62 -0
- clickhouse_driver/dbapi/connection.py +99 -0
- clickhouse_driver/dbapi/cursor.py +370 -0
- clickhouse_driver/dbapi/errors.py +40 -0
- clickhouse_driver/dbapi/extras.py +73 -0
- clickhouse_driver/defines.py +58 -0
- clickhouse_driver/errors.py +453 -0
- clickhouse_driver/log.py +48 -0
- clickhouse_driver/numpy/__init__.py +0 -0
- clickhouse_driver/numpy/block.py +8 -0
- clickhouse_driver/numpy/helpers.py +28 -0
- clickhouse_driver/numpy/result.py +123 -0
- clickhouse_driver/opentelemetry.py +43 -0
- clickhouse_driver/progress.py +44 -0
- clickhouse_driver/protocol.py +130 -0
- clickhouse_driver/queryprocessingstage.py +8 -0
- clickhouse_driver/reader.py +69 -0
- clickhouse_driver/readhelpers.py +26 -0
- clickhouse_driver/result.py +144 -0
- clickhouse_driver/settings/__init__.py +0 -0
- clickhouse_driver/settings/available.py +405 -0
- clickhouse_driver/settings/types.py +50 -0
- clickhouse_driver/settings/writer.py +34 -0
- clickhouse_driver/streams/__init__.py +0 -0
- clickhouse_driver/streams/compressed.py +88 -0
- clickhouse_driver/streams/native.py +108 -0
- clickhouse_driver/util/__init__.py +0 -0
- clickhouse_driver/util/compat.py +39 -0
- clickhouse_driver/util/escape.py +94 -0
- clickhouse_driver/util/helpers.py +171 -0
- clickhouse_driver/varint.cpython-38-aarch64-linux-gnu.so +0 -0
- clickhouse_driver/writer.py +67 -0
- clickhouse_driver-0.2.9.dist-info/LICENSE +21 -0
- clickhouse_driver-0.2.9.dist-info/METADATA +202 -0
- clickhouse_driver-0.2.9.dist-info/RECORD +89 -0
- clickhouse_driver-0.2.9.dist-info/WHEEL +5 -0
- clickhouse_driver-0.2.9.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
from .columns.util import get_inner_spec, get_inner_columns_with_types
|
|
2
|
+
from .reader import read_varint, read_binary_uint8, read_binary_int32
|
|
3
|
+
from .varint import write_varint
|
|
4
|
+
from .writer import write_binary_uint8, write_binary_int32
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BlockInfo(object):
|
|
8
|
+
is_overflows = False
|
|
9
|
+
bucket_num = -1
|
|
10
|
+
|
|
11
|
+
def write(self, buf):
|
|
12
|
+
# Set of pairs (`FIELD_NUM`, value) in binary form. Then 0.
|
|
13
|
+
write_varint(1, buf)
|
|
14
|
+
write_binary_uint8(self.is_overflows, buf)
|
|
15
|
+
|
|
16
|
+
write_varint(2, buf)
|
|
17
|
+
write_binary_int32(self.bucket_num, buf)
|
|
18
|
+
|
|
19
|
+
write_varint(0, buf)
|
|
20
|
+
|
|
21
|
+
def read(self, buf):
|
|
22
|
+
while True:
|
|
23
|
+
field_num = read_varint(buf)
|
|
24
|
+
if not field_num:
|
|
25
|
+
break
|
|
26
|
+
|
|
27
|
+
if field_num == 1:
|
|
28
|
+
self.is_overflows = bool(read_binary_uint8(buf))
|
|
29
|
+
|
|
30
|
+
elif field_num == 2:
|
|
31
|
+
self.bucket_num = read_binary_int32(buf)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class BaseBlock(object):
|
|
35
|
+
def __init__(self, columns_with_types=None, data=None,
|
|
36
|
+
info=None, types_check=False):
|
|
37
|
+
self.columns_with_types = columns_with_types or []
|
|
38
|
+
self.types_check = types_check
|
|
39
|
+
self.info = info or BlockInfo()
|
|
40
|
+
self.data = self.normalize(data or [])
|
|
41
|
+
|
|
42
|
+
super(BaseBlock, self).__init__()
|
|
43
|
+
|
|
44
|
+
def normalize(self, data):
|
|
45
|
+
return data
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def num_columns(self):
|
|
49
|
+
raise NotImplementedError
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def num_rows(self):
|
|
53
|
+
raise NotImplementedError
|
|
54
|
+
|
|
55
|
+
def get_columns(self):
|
|
56
|
+
raise NotImplementedError
|
|
57
|
+
|
|
58
|
+
def get_rows(self):
|
|
59
|
+
raise NotImplementedError
|
|
60
|
+
|
|
61
|
+
def get_column_by_index(self, index):
|
|
62
|
+
raise NotImplementedError
|
|
63
|
+
|
|
64
|
+
def transposed(self):
|
|
65
|
+
return list(zip(*self.data))
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class ColumnOrientedBlock(BaseBlock):
|
|
69
|
+
def normalize(self, data):
|
|
70
|
+
if not data:
|
|
71
|
+
return []
|
|
72
|
+
|
|
73
|
+
self._check_number_of_columns(data)
|
|
74
|
+
self._check_all_columns_equal_length(data)
|
|
75
|
+
return data
|
|
76
|
+
|
|
77
|
+
@property
|
|
78
|
+
def num_columns(self):
|
|
79
|
+
return len(self.data)
|
|
80
|
+
|
|
81
|
+
@property
|
|
82
|
+
def num_rows(self):
|
|
83
|
+
return len(self.data[0]) if self.num_columns else 0
|
|
84
|
+
|
|
85
|
+
def get_columns(self):
|
|
86
|
+
return self.data
|
|
87
|
+
|
|
88
|
+
def get_rows(self):
|
|
89
|
+
return self.transposed()
|
|
90
|
+
|
|
91
|
+
def get_column_by_index(self, index):
|
|
92
|
+
return self.data[index]
|
|
93
|
+
|
|
94
|
+
def _check_number_of_columns(self, data):
|
|
95
|
+
expected_row_len = len(self.columns_with_types)
|
|
96
|
+
|
|
97
|
+
got = len(data)
|
|
98
|
+
if expected_row_len != got:
|
|
99
|
+
msg = 'Expected {} columns, got {}'.format(expected_row_len, got)
|
|
100
|
+
raise ValueError(msg)
|
|
101
|
+
|
|
102
|
+
def _check_all_columns_equal_length(self, data):
|
|
103
|
+
expected = len(data[0])
|
|
104
|
+
|
|
105
|
+
for column in data:
|
|
106
|
+
got = len(column)
|
|
107
|
+
if got != expected:
|
|
108
|
+
msg = 'Expected {} rows, got {}'.format(expected, got)
|
|
109
|
+
raise ValueError(msg)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class RowOrientedBlock(BaseBlock):
|
|
113
|
+
dict_row_types = (dict, )
|
|
114
|
+
tuple_row_types = (list, tuple)
|
|
115
|
+
supported_row_types = dict_row_types + tuple_row_types
|
|
116
|
+
|
|
117
|
+
def normalize(self, data):
|
|
118
|
+
if not data:
|
|
119
|
+
return []
|
|
120
|
+
|
|
121
|
+
# Guessing about whole data format by first row.
|
|
122
|
+
first_row = data[0]
|
|
123
|
+
|
|
124
|
+
if self.types_check:
|
|
125
|
+
self._check_row_type(first_row)
|
|
126
|
+
|
|
127
|
+
if isinstance(first_row, dict):
|
|
128
|
+
self._mutate_dicts_to_rows(data)
|
|
129
|
+
else:
|
|
130
|
+
self._check_rows(data)
|
|
131
|
+
|
|
132
|
+
return data
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def num_columns(self):
|
|
136
|
+
if self.columns_with_types is not None:
|
|
137
|
+
return len(self.columns_with_types)
|
|
138
|
+
|
|
139
|
+
return len(self.data[0]) if self.num_rows else 0
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def num_rows(self):
|
|
143
|
+
return len(self.data)
|
|
144
|
+
|
|
145
|
+
def get_columns(self):
|
|
146
|
+
return self.transposed()
|
|
147
|
+
|
|
148
|
+
def get_rows(self):
|
|
149
|
+
return self.data
|
|
150
|
+
|
|
151
|
+
def get_column_by_index(self, index):
|
|
152
|
+
return [row[index] for row in self.data]
|
|
153
|
+
|
|
154
|
+
def _mutate_dicts_to_rows(self, data):
|
|
155
|
+
check_row_type = False
|
|
156
|
+
if self.types_check:
|
|
157
|
+
check_row_type = self._check_dict_row_type
|
|
158
|
+
|
|
159
|
+
return self._pure_mutate_dicts_to_rows(
|
|
160
|
+
data,
|
|
161
|
+
self.columns_with_types,
|
|
162
|
+
check_row_type,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def _pure_mutate_dicts_to_rows(
|
|
166
|
+
self,
|
|
167
|
+
data,
|
|
168
|
+
columns_with_types,
|
|
169
|
+
check_row_type,
|
|
170
|
+
):
|
|
171
|
+
columns_with_cwt = []
|
|
172
|
+
for name, type_ in columns_with_types:
|
|
173
|
+
cwt = None
|
|
174
|
+
if type_.startswith('Nested'):
|
|
175
|
+
inner_spec = get_inner_spec('Nested', type_)
|
|
176
|
+
cwt = get_inner_columns_with_types(inner_spec)
|
|
177
|
+
columns_with_cwt.append((name, cwt))
|
|
178
|
+
|
|
179
|
+
for i, row in enumerate(data):
|
|
180
|
+
if check_row_type:
|
|
181
|
+
check_row_type(row)
|
|
182
|
+
|
|
183
|
+
new_data = []
|
|
184
|
+
for name, cwt in columns_with_cwt:
|
|
185
|
+
if cwt is None:
|
|
186
|
+
new_data.append(row[name])
|
|
187
|
+
else:
|
|
188
|
+
new_data.append(self._pure_mutate_dicts_to_rows(
|
|
189
|
+
row[name], cwt, check_row_type
|
|
190
|
+
))
|
|
191
|
+
data[i] = new_data
|
|
192
|
+
# return for recursion
|
|
193
|
+
return data
|
|
194
|
+
|
|
195
|
+
def _check_rows(self, data):
|
|
196
|
+
expected_row_len = len(self.columns_with_types)
|
|
197
|
+
|
|
198
|
+
got = len(data[0])
|
|
199
|
+
if expected_row_len != got:
|
|
200
|
+
msg = 'Expected {} columns, got {}'.format(expected_row_len, got)
|
|
201
|
+
raise ValueError(msg)
|
|
202
|
+
|
|
203
|
+
if self.types_check:
|
|
204
|
+
check_row_type = self._check_tuple_row_type
|
|
205
|
+
for row in data:
|
|
206
|
+
check_row_type(row)
|
|
207
|
+
|
|
208
|
+
def _check_row_type(self, row):
|
|
209
|
+
if not isinstance(row, self.supported_row_types):
|
|
210
|
+
raise TypeError(
|
|
211
|
+
'Unsupported row type: {}. dict, list or tuple is expected.'
|
|
212
|
+
.format(type(row))
|
|
213
|
+
)
|
|
214
|
+
|
|
215
|
+
def _check_tuple_row_type(self, row):
|
|
216
|
+
if not isinstance(row, self.tuple_row_types):
|
|
217
|
+
raise TypeError(
|
|
218
|
+
'Unsupported row type: {}. list or tuple is expected.'
|
|
219
|
+
.format(type(row))
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
def _check_dict_row_type(self, row):
|
|
223
|
+
if not isinstance(row, self.dict_row_types):
|
|
224
|
+
raise TypeError(
|
|
225
|
+
'Unsupported row type: {}. dict is expected.'
|
|
226
|
+
.format(type(row))
|
|
227
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .reader import read_binary_uint8
|
|
2
|
+
from .varint import read_varint
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BlockStreamProfileInfo(object):
|
|
6
|
+
def __init__(self):
|
|
7
|
+
self.rows = 0
|
|
8
|
+
self.blocks = 0
|
|
9
|
+
self.bytes = 0
|
|
10
|
+
self.applied_limit = False # bool
|
|
11
|
+
self.rows_before_limit = 0
|
|
12
|
+
self.calculated_rows_before_limit = 0 # bool
|
|
13
|
+
|
|
14
|
+
super(BlockStreamProfileInfo, self).__init__()
|
|
15
|
+
|
|
16
|
+
def read(self, fin):
|
|
17
|
+
self.rows = read_varint(fin)
|
|
18
|
+
self.blocks = read_varint(fin)
|
|
19
|
+
self.bytes = read_varint(fin)
|
|
20
|
+
self.applied_limit = bool(read_binary_uint8(fin))
|
|
21
|
+
self.rows_before_limit = read_varint(fin)
|
|
22
|
+
self.calculated_rows_before_limit = bool(read_binary_uint8(fin))
|
|
Binary file
|
|
Binary file
|