clickhouse-driver 0.2.1__cp39-cp39-win_amd64.whl → 0.2.10__cp39-cp39-win_amd64.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.
Files changed (85) hide show
  1. clickhouse_driver/__init__.py +9 -9
  2. clickhouse_driver/block.py +227 -195
  3. clickhouse_driver/blockstreamprofileinfo.py +22 -22
  4. clickhouse_driver/bufferedreader.cp39-win_amd64.pyd +0 -0
  5. clickhouse_driver/bufferedwriter.cp39-win_amd64.pyd +0 -0
  6. clickhouse_driver/client.py +812 -666
  7. clickhouse_driver/clientinfo.py +119 -80
  8. clickhouse_driver/columns/arraycolumn.py +161 -150
  9. clickhouse_driver/columns/base.py +221 -147
  10. clickhouse_driver/columns/boolcolumn.py +7 -0
  11. clickhouse_driver/columns/datecolumn.py +108 -49
  12. clickhouse_driver/columns/datetimecolumn.py +203 -207
  13. clickhouse_driver/columns/decimalcolumn.py +116 -118
  14. clickhouse_driver/columns/enumcolumn.py +129 -119
  15. clickhouse_driver/columns/exceptions.py +12 -12
  16. clickhouse_driver/columns/floatcolumn.py +34 -34
  17. clickhouse_driver/columns/intcolumn.py +157 -157
  18. clickhouse_driver/columns/intervalcolumn.py +33 -33
  19. clickhouse_driver/columns/ipcolumn.py +118 -118
  20. clickhouse_driver/columns/jsoncolumn.py +37 -0
  21. clickhouse_driver/columns/largeint.cp39-win_amd64.pyd +0 -0
  22. clickhouse_driver/columns/lowcardinalitycolumn.py +142 -123
  23. clickhouse_driver/columns/mapcolumn.py +73 -58
  24. clickhouse_driver/columns/nestedcolumn.py +10 -0
  25. clickhouse_driver/columns/nothingcolumn.py +13 -13
  26. clickhouse_driver/columns/nullablecolumn.py +7 -7
  27. clickhouse_driver/columns/nullcolumn.py +15 -15
  28. clickhouse_driver/columns/numpy/base.py +47 -14
  29. clickhouse_driver/columns/numpy/boolcolumn.py +8 -0
  30. clickhouse_driver/columns/numpy/datecolumn.py +19 -12
  31. clickhouse_driver/columns/numpy/datetimecolumn.py +146 -145
  32. clickhouse_driver/columns/numpy/floatcolumn.py +24 -13
  33. clickhouse_driver/columns/numpy/intcolumn.py +43 -43
  34. clickhouse_driver/columns/numpy/lowcardinalitycolumn.py +96 -83
  35. clickhouse_driver/columns/numpy/service.py +58 -80
  36. clickhouse_driver/columns/numpy/stringcolumn.py +78 -76
  37. clickhouse_driver/columns/numpy/tuplecolumn.py +37 -0
  38. clickhouse_driver/columns/service.py +185 -131
  39. clickhouse_driver/columns/simpleaggregatefunctioncolumn.py +7 -7
  40. clickhouse_driver/columns/stringcolumn.py +73 -73
  41. clickhouse_driver/columns/tuplecolumn.py +63 -65
  42. clickhouse_driver/columns/util.py +61 -0
  43. clickhouse_driver/columns/uuidcolumn.py +64 -64
  44. clickhouse_driver/compression/__init__.py +32 -28
  45. clickhouse_driver/compression/base.py +87 -52
  46. clickhouse_driver/compression/lz4.py +21 -55
  47. clickhouse_driver/compression/lz4hc.py +9 -9
  48. clickhouse_driver/compression/zstd.py +20 -51
  49. clickhouse_driver/connection.py +825 -632
  50. clickhouse_driver/context.py +36 -36
  51. clickhouse_driver/dbapi/__init__.py +62 -62
  52. clickhouse_driver/dbapi/connection.py +99 -96
  53. clickhouse_driver/dbapi/cursor.py +370 -368
  54. clickhouse_driver/dbapi/errors.py +40 -40
  55. clickhouse_driver/dbapi/extras.py +73 -0
  56. clickhouse_driver/defines.py +58 -42
  57. clickhouse_driver/errors.py +453 -446
  58. clickhouse_driver/log.py +48 -44
  59. clickhouse_driver/numpy/block.py +8 -8
  60. clickhouse_driver/numpy/helpers.py +28 -25
  61. clickhouse_driver/numpy/result.py +123 -123
  62. clickhouse_driver/opentelemetry.py +43 -0
  63. clickhouse_driver/progress.py +44 -32
  64. clickhouse_driver/protocol.py +130 -105
  65. clickhouse_driver/queryprocessingstage.py +8 -8
  66. clickhouse_driver/reader.py +69 -69
  67. clickhouse_driver/readhelpers.py +26 -26
  68. clickhouse_driver/result.py +144 -144
  69. clickhouse_driver/settings/available.py +405 -405
  70. clickhouse_driver/settings/types.py +50 -50
  71. clickhouse_driver/settings/writer.py +34 -29
  72. clickhouse_driver/streams/compressed.py +88 -88
  73. clickhouse_driver/streams/native.py +108 -90
  74. clickhouse_driver/util/compat.py +39 -0
  75. clickhouse_driver/util/escape.py +94 -55
  76. clickhouse_driver/util/helpers.py +173 -57
  77. clickhouse_driver/varint.cp39-win_amd64.pyd +0 -0
  78. clickhouse_driver/writer.py +67 -67
  79. clickhouse_driver-0.2.10.dist-info/METADATA +215 -0
  80. clickhouse_driver-0.2.10.dist-info/RECORD +89 -0
  81. {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.10.dist-info}/WHEEL +1 -1
  82. {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.10.dist-info/licenses}/LICENSE +21 -21
  83. clickhouse_driver-0.2.1.dist-info/METADATA +0 -24
  84. clickhouse_driver-0.2.1.dist-info/RECORD +0 -80
  85. {clickhouse_driver-0.2.1.dist-info → clickhouse_driver-0.2.10.dist-info}/top_level.txt +0 -0
@@ -1,368 +1,370 @@
1
- from collections import namedtuple
2
- from itertools import islice
3
-
4
- from ..errors import Error as DriverError
5
- from .errors import InterfaceError, OperationalError, ProgrammingError
6
-
7
-
8
- Column = namedtuple(
9
- 'Column',
10
- 'name type_code display_size internal_size precision scale null_ok'
11
- )
12
-
13
-
14
- class Cursor(object):
15
-
16
- class States(object):
17
- (
18
- NONE,
19
- RUNNING,
20
- FINISHED,
21
- CURSOR_CLOSED
22
- ) = range(4)
23
-
24
- _states = States()
25
-
26
- def __init__(self, client, connection):
27
- self._client = client
28
- self._connection = connection
29
- self._reset_state()
30
-
31
- self.arraysize = 1
32
-
33
- # Begin non-PEP attributes
34
- self._columns_with_types = None
35
- # End non-PEP attributes
36
-
37
- super(Cursor, self).__init__()
38
-
39
- def __repr__(self):
40
- is_closed = self._state == self._states.CURSOR_CLOSED
41
- return '<cursor object at 0x{0:x}; closed: {1:}>'.format(
42
- id(self), is_closed
43
- )
44
-
45
- # Iteration support.
46
- def __iter__(self):
47
- while True:
48
- one = self.fetchone()
49
- if one is None:
50
- return
51
- yield one
52
-
53
- # Context manager integrations.
54
- def __enter__(self):
55
- return self
56
-
57
- def __exit__(self, exc_type, exc_val, exc_tb):
58
- self.close()
59
-
60
- @property
61
- def description(self):
62
- if self._state == self._states.NONE:
63
- return None
64
-
65
- columns = self._columns or []
66
- types = self._types or []
67
-
68
- return [
69
- Column(name, type_code, None, None, None, None, True)
70
- for name, type_code in zip(columns, types)
71
- ]
72
-
73
- @property
74
- def rowcount(self):
75
- """
76
- :return: the number of rows that the last .execute*() produced.
77
- """
78
- return self._rowcount
79
-
80
- def close(self):
81
- """
82
- Close the cursor now. The cursor will be unusable from this point
83
- forward; an :data:`~clickhouse_driver.dbapi.Error` (or subclass)
84
- exception will be raised if any operation is attempted with the
85
- cursor.
86
- """
87
- self._client.disconnect()
88
- self._state = self._states.CURSOR_CLOSED
89
-
90
- try:
91
- # cursor can be already closed
92
- self._connection.cursors.remove(self)
93
- except ValueError:
94
- pass
95
-
96
- def execute(self, operation, parameters=None):
97
- """
98
- Prepare and execute a database operation (query or command).
99
-
100
- :param operation: query or command to execute.
101
- :param parameters: sequence or mapping that will be bound to
102
- variables in the operation.
103
- :return: None
104
- """
105
- self._check_cursor_closed()
106
- self._begin_query()
107
-
108
- try:
109
- execute, execute_kwargs = self._prepare()
110
-
111
- response = execute(
112
- operation, params=parameters, with_column_types=True,
113
- **execute_kwargs
114
- )
115
-
116
- except DriverError as orig:
117
- raise OperationalError(orig)
118
-
119
- self._process_response(response)
120
- self._end_query()
121
-
122
- def executemany(self, operation, seq_of_parameters):
123
- """
124
- Prepare a database operation (query or command) and then execute it
125
- against all parameter sequences found in the sequence
126
- `seq_of_parameters`.
127
-
128
- :param operation: query or command to execute.
129
- :param seq_of_parameters: sequences or mappings for execution.
130
- :return: None
131
- """
132
- self._check_cursor_closed()
133
- self._begin_query()
134
-
135
- try:
136
- execute, execute_kwargs = self._prepare()
137
-
138
- response = execute(
139
- operation, params=seq_of_parameters, **execute_kwargs
140
- )
141
-
142
- except DriverError as orig:
143
- raise OperationalError(orig)
144
-
145
- self._process_response(response, executemany=True)
146
- self._end_query()
147
-
148
- def fetchone(self):
149
- """
150
- Fetch the next row of a query result set, returning a single sequence,
151
- or None when no more data is available.
152
-
153
- :return: the next row of a query result set or None.
154
- """
155
- self._check_query_started()
156
-
157
- if self._stream_results:
158
- return next(self._rows, None)
159
-
160
- else:
161
- if not self._rows:
162
- return None
163
-
164
- return self._rows.pop(0)
165
-
166
- def fetchmany(self, size=None):
167
- """
168
- Fetch the next set of rows of a query result, returning a sequence of
169
- sequences (e.g. a list of tuples). An empty sequence is returned when
170
- no more rows are available.
171
-
172
- :param size: amount of rows to return.
173
- :return: list of fetched rows or empty list.
174
- """
175
- self._check_query_started()
176
-
177
- if size is None:
178
- size = self.arraysize
179
-
180
- if self._stream_results:
181
- if size == -1:
182
- return list(self._rows)
183
- else:
184
- return list(islice(self._rows, size))
185
-
186
- if size < 0:
187
- rv = self._rows
188
- self._rows = []
189
- else:
190
- rv = self._rows[:size]
191
- self._rows = self._rows[size:]
192
-
193
- return rv
194
-
195
- def fetchall(self):
196
- """
197
- Fetch all (remaining) rows of a query result, returning them as a
198
- sequence of sequences (e.g. a list of tuples).
199
-
200
- :return: list of fetched rows.
201
- """
202
- self._check_query_started()
203
-
204
- if self._stream_results:
205
- return list(self._rows)
206
-
207
- rv = self._rows
208
- self._rows = []
209
- return rv
210
-
211
- def setinputsizes(self, sizes):
212
- # Do nothing.
213
- pass
214
-
215
- def setoutputsize(self, size, column=None):
216
- # Do nothing.
217
- pass
218
-
219
- # Begin non-PEP methods
220
- @property
221
- def columns_with_types(self):
222
- """
223
- :return: list of column names with corresponding types of the last
224
- .execute*(). E.g. [('x', 'UInt64')].
225
- """
226
- return self._columns_with_types
227
-
228
- def set_stream_results(self, stream_results, max_row_buffer):
229
- """
230
- Toggles results streaming from server. Driver will consume
231
- block-by-block of `max_row_buffer` size and yield row-by-row from each
232
- block.
233
-
234
- :param stream_results: enable or disable results streaming.
235
- :param max_row_buffer: specifies the maximum number of rows to buffer
236
- at a time.
237
- :return: None
238
- """
239
- self._stream_results = stream_results
240
- self._max_row_buffer = max_row_buffer
241
-
242
- def set_settings(self, settings):
243
- """
244
- Specifies settings for cursor.
245
-
246
- :param settings: dictionary of query settings
247
- :return: None
248
- """
249
- self._settings = settings
250
-
251
- def set_types_check(self, types_check):
252
- """
253
- Toggles type checking for sequence of INSERT parameters.
254
- Disabled by default.
255
-
256
- :param types_check: new types check value.
257
- :return: None
258
- """
259
- self._types_check = types_check
260
-
261
- def set_external_table(self, name, structure, data):
262
- """
263
- Adds external table to cursor context.
264
-
265
- If the same table is specified more than once the last one is used.
266
-
267
- :param name: name of external table
268
- :param structure: list of tuples (name, type) that defines table
269
- structure. Example [(x, 'Int32')].
270
- :param data: sequence of rows of tuples or dicts for transmission.
271
- :return: None
272
- """
273
- self._external_tables[name] = (structure, data)
274
-
275
- def set_query_id(self, query_id):
276
- """
277
- Specifies the query identifier for cursor.
278
-
279
- :param query_id: the query identifier.
280
- :return: None
281
- """
282
- self._query_id = query_id
283
- # End non-PEP methods
284
-
285
- # Private methods.
286
- def _prepare(self):
287
- external_tables = [
288
- {'name': name, 'structure': structure, 'data': data}
289
- for name, (structure, data) in self._external_tables.items()
290
- ] or None
291
-
292
- execute = self._client.execute
293
-
294
- if self._stream_results:
295
- execute = self._client.execute_iter
296
- self._settings = self._settings or {}
297
- self._settings['max_block_size'] = self._max_row_buffer
298
-
299
- execute_kwargs = {
300
- 'settings': self._settings,
301
- 'external_tables': external_tables,
302
- 'types_check': self._types_check,
303
- 'query_id': self._query_id
304
- }
305
-
306
- return execute, execute_kwargs
307
-
308
- def _process_response(self, response, executemany=False):
309
- if executemany:
310
- self._rowcount = response
311
- response = None
312
-
313
- if not response:
314
- self._columns = self._types = self._rows = []
315
- return
316
-
317
- if self._stream_results:
318
- columns_with_types = next(response)
319
- rows = response
320
-
321
- else:
322
- rows, columns_with_types = response
323
-
324
- self._columns_with_types = columns_with_types
325
-
326
- # Only SELECT queries have columns_with_types.
327
- # DDL and INSERT INTO ... SELECT queries have empty columns header.
328
- # We need to obtain rows count only during non-streaming SELECTs.
329
- if columns_with_types:
330
- self._columns, self._types = zip(*columns_with_types)
331
- if not self._stream_results:
332
- self._rowcount = len(rows)
333
- else:
334
- self._columns = self._types = []
335
-
336
- self._rows = rows
337
-
338
- def _reset_state(self):
339
- """
340
- Resets query state and get ready for another query.
341
- """
342
- self._state = self._states.NONE
343
-
344
- self._columns = None
345
- self._types = None
346
- self._rows = None
347
- self._rowcount = -1
348
-
349
- self._stream_results = False
350
- self._max_row_buffer = 0
351
- self._settings = None
352
- self._query_id = None
353
- self._external_tables = {}
354
- self._types_check = False
355
-
356
- def _begin_query(self):
357
- self._state = self._states.RUNNING
358
-
359
- def _end_query(self):
360
- self._state = self._states.FINISHED
361
-
362
- def _check_cursor_closed(self):
363
- if self._state == self._states.CURSOR_CLOSED:
364
- raise InterfaceError('cursor already closed')
365
-
366
- def _check_query_started(self):
367
- if self._state == self._states.NONE:
368
- raise ProgrammingError('no results to fetch')
1
+ from collections import namedtuple
2
+ from itertools import islice
3
+
4
+ from ..errors import Error as DriverError
5
+ from .errors import InterfaceError, OperationalError, ProgrammingError
6
+
7
+
8
+ Column = namedtuple(
9
+ 'Column',
10
+ 'name type_code display_size internal_size precision scale null_ok'
11
+ )
12
+
13
+
14
+ class Cursor(object):
15
+
16
+ class States(object):
17
+ (
18
+ NONE,
19
+ RUNNING,
20
+ FINISHED,
21
+ CURSOR_CLOSED
22
+ ) = range(4)
23
+
24
+ _states = States()
25
+
26
+ def __init__(self, client, connection):
27
+ self._client = client
28
+ self._connection = connection
29
+ self._reset_state()
30
+
31
+ self.arraysize = 1
32
+
33
+ # Begin non-PEP attributes
34
+ self._columns_with_types = None
35
+ # End non-PEP attributes
36
+
37
+ super(Cursor, self).__init__()
38
+
39
+ def __repr__(self):
40
+ is_closed = self._state == self._states.CURSOR_CLOSED
41
+ return '<cursor object at 0x{0:x}; closed: {1:}>'.format(
42
+ id(self), is_closed
43
+ )
44
+
45
+ # Iteration support.
46
+ def __iter__(self):
47
+ while True:
48
+ one = self.fetchone()
49
+ if one is None:
50
+ return
51
+ yield one
52
+
53
+ # Context manager integrations.
54
+ def __enter__(self):
55
+ return self
56
+
57
+ def __exit__(self, exc_type, exc_val, exc_tb):
58
+ self.close()
59
+
60
+ @property
61
+ def description(self):
62
+ if self._state == self._states.NONE:
63
+ return None
64
+
65
+ columns = self._columns or []
66
+ types = self._types or []
67
+
68
+ return [
69
+ Column(name, type_code, None, None, None, None, True)
70
+ for name, type_code in zip(columns, types)
71
+ ]
72
+
73
+ @property
74
+ def rowcount(self):
75
+ """
76
+ :return: the number of rows that the last .execute*() produced.
77
+ """
78
+ return self._rowcount
79
+
80
+ def close(self):
81
+ """
82
+ Close the cursor now. The cursor will be unusable from this point
83
+ forward; an :data:`~clickhouse_driver.dbapi.Error` (or subclass)
84
+ exception will be raised if any operation is attempted with the
85
+ cursor.
86
+ """
87
+ self._client.disconnect()
88
+ self._state = self._states.CURSOR_CLOSED
89
+
90
+ try:
91
+ # cursor can be already closed
92
+ self._connection.cursors.remove(self)
93
+ except ValueError:
94
+ pass
95
+
96
+ def execute(self, operation, parameters=None):
97
+ """
98
+ Prepare and execute a database operation (query or command).
99
+
100
+ :param operation: query or command to execute.
101
+ :param parameters: sequence or mapping that will be bound to
102
+ variables in the operation.
103
+ :return: None
104
+ """
105
+ self._check_cursor_closed()
106
+ self._begin_query()
107
+
108
+ try:
109
+ execute, execute_kwargs = self._prepare()
110
+
111
+ response = execute(
112
+ operation, params=parameters, with_column_types=True,
113
+ **execute_kwargs
114
+ )
115
+
116
+ except DriverError as orig:
117
+ raise OperationalError(orig)
118
+
119
+ self._process_response(response)
120
+ self._end_query()
121
+
122
+ def executemany(self, operation, seq_of_parameters):
123
+ """
124
+ Prepare a database operation (query or command) and then execute it
125
+ against all parameter sequences found in the sequence
126
+ `seq_of_parameters`.
127
+
128
+ :param operation: query or command to execute.
129
+ :param seq_of_parameters: sequences or mappings for execution.
130
+ :return: None
131
+ """
132
+ self._check_cursor_closed()
133
+ self._begin_query()
134
+
135
+ try:
136
+ execute, execute_kwargs = self._prepare()
137
+
138
+ response = execute(
139
+ operation, params=seq_of_parameters, **execute_kwargs
140
+ )
141
+
142
+ except DriverError as orig:
143
+ raise OperationalError(orig)
144
+
145
+ self._process_response(response, executemany=True)
146
+ self._end_query()
147
+
148
+ def fetchone(self):
149
+ """
150
+ Fetch the next row of a query result set, returning a single sequence,
151
+ or None when no more data is available.
152
+
153
+ :return: the next row of a query result set or None.
154
+ """
155
+ self._check_query_started()
156
+
157
+ if self._stream_results:
158
+ return next(self._rows, None)
159
+
160
+ else:
161
+ if not self._rows:
162
+ return None
163
+
164
+ return self._rows.pop(0)
165
+
166
+ def fetchmany(self, size=None):
167
+ """
168
+ Fetch the next set of rows of a query result, returning a sequence of
169
+ sequences (e.g. a list of tuples). An empty sequence is returned when
170
+ no more rows are available.
171
+
172
+ :param size: amount of rows to return.
173
+ :return: list of fetched rows or empty list.
174
+ """
175
+ self._check_query_started()
176
+
177
+ if size is None:
178
+ size = self.arraysize
179
+
180
+ if self._stream_results:
181
+ if size == -1:
182
+ return list(self._rows)
183
+ else:
184
+ return list(islice(self._rows, size))
185
+
186
+ if size < 0:
187
+ rv = self._rows
188
+ self._rows = []
189
+ else:
190
+ rv = self._rows[:size]
191
+ self._rows = self._rows[size:]
192
+
193
+ return rv
194
+
195
+ def fetchall(self):
196
+ """
197
+ Fetch all (remaining) rows of a query result, returning them as a
198
+ sequence of sequences (e.g. a list of tuples).
199
+
200
+ :return: list of fetched rows.
201
+ """
202
+ self._check_query_started()
203
+
204
+ if self._stream_results:
205
+ return list(self._rows)
206
+
207
+ rv = self._rows
208
+ self._rows = []
209
+ return rv
210
+
211
+ def setinputsizes(self, sizes):
212
+ # Do nothing.
213
+ pass
214
+
215
+ def setoutputsize(self, size, column=None):
216
+ # Do nothing.
217
+ pass
218
+
219
+ # Begin non-PEP methods
220
+ @property
221
+ def columns_with_types(self):
222
+ """
223
+ :return: list of column names with corresponding types of the last
224
+ .execute*(). E.g. [('x', 'UInt64')].
225
+ """
226
+ return self._columns_with_types
227
+
228
+ def set_stream_results(self, stream_results, max_row_buffer):
229
+ """
230
+ Toggles results streaming from server. Driver will consume
231
+ block-by-block of `max_row_buffer` size and yield row-by-row from each
232
+ block.
233
+
234
+ :param stream_results: enable or disable results streaming.
235
+ :param max_row_buffer: specifies the maximum number of rows to buffer
236
+ at a time.
237
+ :return: None
238
+ """
239
+ self._stream_results = stream_results
240
+ self._max_row_buffer = max_row_buffer
241
+
242
+ def set_settings(self, settings):
243
+ """
244
+ Specifies settings for cursor.
245
+
246
+ :param settings: dictionary of query settings
247
+ :return: None
248
+ """
249
+ self._settings = settings
250
+
251
+ def set_types_check(self, types_check):
252
+ """
253
+ Toggles type checking for sequence of INSERT parameters.
254
+ Disabled by default.
255
+
256
+ :param types_check: new types check value.
257
+ :return: None
258
+ """
259
+ self._types_check = types_check
260
+
261
+ def set_external_table(self, name, structure, data):
262
+ """
263
+ Adds external table to cursor context.
264
+
265
+ If the same table is specified more than once the last one is used.
266
+
267
+ :param name: name of external table
268
+ :param structure: list of tuples (name, type) that defines table
269
+ structure. Example [(x, 'Int32')].
270
+ :param data: sequence of rows of tuples or dicts for transmission.
271
+ :return: None
272
+ """
273
+ self._external_tables[name] = (structure, data)
274
+
275
+ def set_query_id(self, query_id):
276
+ """
277
+ Specifies the query identifier for cursor.
278
+
279
+ :param query_id: the query identifier.
280
+ :return: None
281
+ """
282
+ self._query_id = query_id
283
+ # End non-PEP methods
284
+
285
+ # Private methods.
286
+ def _prepare(self):
287
+ external_tables = [
288
+ {'name': name, 'structure': structure, 'data': data}
289
+ for name, (structure, data) in self._external_tables.items()
290
+ ] or None
291
+
292
+ execute = self._client.execute
293
+
294
+ if self._stream_results:
295
+ execute = self._client.execute_iter
296
+ self._settings = self._settings or {}
297
+ self._settings['max_block_size'] = self._max_row_buffer
298
+
299
+ execute_kwargs = {
300
+ 'settings': self._settings,
301
+ 'external_tables': external_tables,
302
+ 'types_check': self._types_check,
303
+ 'query_id': self._query_id
304
+ }
305
+
306
+ return execute, execute_kwargs
307
+
308
+ def _process_response(self, response, executemany=False):
309
+ if executemany:
310
+ self._rowcount = response
311
+ response = None
312
+
313
+ if not response or isinstance(response, int):
314
+ self._columns = self._types = self._rows = []
315
+ if isinstance(response, int):
316
+ self._rowcount = response
317
+ return
318
+
319
+ if self._stream_results:
320
+ columns_with_types = next(response)
321
+ rows = response
322
+
323
+ else:
324
+ rows, columns_with_types = response
325
+
326
+ self._columns_with_types = columns_with_types
327
+
328
+ # Only SELECT queries have columns_with_types.
329
+ # DDL and INSERT INTO ... SELECT queries have empty columns header.
330
+ # We need to obtain rows count only during non-streaming SELECTs.
331
+ if columns_with_types:
332
+ self._columns, self._types = zip(*columns_with_types)
333
+ if not self._stream_results:
334
+ self._rowcount = len(rows)
335
+ else:
336
+ self._columns = self._types = []
337
+
338
+ self._rows = rows
339
+
340
+ def _reset_state(self):
341
+ """
342
+ Resets query state and get ready for another query.
343
+ """
344
+ self._state = self._states.NONE
345
+
346
+ self._columns = None
347
+ self._types = None
348
+ self._rows = None
349
+ self._rowcount = -1
350
+
351
+ self._stream_results = False
352
+ self._max_row_buffer = 0
353
+ self._settings = None
354
+ self._query_id = None
355
+ self._external_tables = {}
356
+ self._types_check = False
357
+
358
+ def _begin_query(self):
359
+ self._state = self._states.RUNNING
360
+
361
+ def _end_query(self):
362
+ self._state = self._states.FINISHED
363
+
364
+ def _check_cursor_closed(self):
365
+ if self._state == self._states.CURSOR_CLOSED:
366
+ raise InterfaceError('cursor already closed')
367
+
368
+ def _check_query_started(self):
369
+ if self._state == self._states.NONE:
370
+ raise ProgrammingError('no results to fetch')