apache-iotdb 2.0.2__py3-none-any.whl → 2.0.4.dev0__py3-none-any.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 (35) hide show
  1. {apache_iotdb-2.0.2.dist-info → apache_iotdb-2.0.4.dev0.dist-info}/METADATA +6 -6
  2. {apache_iotdb-2.0.2.dist-info → apache_iotdb-2.0.4.dev0.dist-info}/RECORD +34 -22
  3. {apache_iotdb-2.0.2.dist-info → apache_iotdb-2.0.4.dev0.dist-info}/WHEEL +1 -1
  4. iotdb/Session.py +158 -184
  5. iotdb/SessionPool.py +3 -1
  6. iotdb/template/MeasurementNode.py +1 -1
  7. iotdb/template/Template.py +3 -3
  8. iotdb/thrift/common/ttypes.py +18 -1
  9. iotdb/thrift/confignode/IConfigNodeRPCService.py +28290 -0
  10. iotdb/thrift/confignode/__init__.py +1 -0
  11. iotdb/thrift/confignode/constants.py +14 -0
  12. iotdb/thrift/confignode/ttypes.py +17249 -0
  13. iotdb/thrift/datanode/IDataNodeRPCService.py +17960 -0
  14. iotdb/thrift/datanode/MPPDataExchangeService.py +1071 -0
  15. iotdb/thrift/datanode/__init__.py +1 -0
  16. iotdb/thrift/datanode/constants.py +14 -0
  17. iotdb/thrift/datanode/ttypes.py +10920 -0
  18. iotdb/tsfile/utils/tsblock_serde.py +266 -0
  19. iotdb/utils/Field.py +30 -5
  20. iotdb/utils/NumpyTablet.py +1 -1
  21. iotdb/utils/SessionDataSet.py +43 -24
  22. iotdb/utils/Tablet.py +1 -1
  23. iotdb/utils/{IoTDBConnectionException.py → exception.py} +20 -0
  24. iotdb/utils/iotdb_rpc_dataset.py +406 -0
  25. iotdb/utils/rpc_utils.py +110 -0
  26. tests/integration/tablet_performance_comparison.py +3 -1
  27. tests/integration/test_new_data_types.py +6 -6
  28. tests/integration/test_tablemodel_query.py +476 -0
  29. iotdb/utils/IoTDBRpcDataSet.py +0 -463
  30. {apache_iotdb-2.0.2.dist-info → apache_iotdb-2.0.4.dev0.dist-info}/entry_points.txt +0 -0
  31. {apache_iotdb-2.0.2.dist-info → apache_iotdb-2.0.4.dev0.dist-info}/top_level.txt +0 -0
  32. /iotdb/tsfile/common/constant/{TsFileConstant.py → tsfile_constant.py} +0 -0
  33. /iotdb/tsfile/utils/{DateUtils.py → date_utils.py} +0 -0
  34. /iotdb/tsfile/utils/{Pair.py → pair.py} +0 -0
  35. /iotdb/tsfile/utils/{ReadWriteIOUtils.py → read_write_io_utils.py} +0 -0
@@ -1,463 +0,0 @@
1
- # Licensed to the Apache Software Foundation (ASF) under one
2
- # or more contributor license agreements. See the NOTICE file
3
- # distributed with this work for additional information
4
- # regarding copyright ownership. The ASF licenses this file
5
- # to you under the Apache License, Version 2.0 (the
6
- # "License"); you may not use this file except in compliance
7
- # with the License. You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing,
12
- # software distributed under the License is distributed on an
13
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
- # KIND, either express or implied. See the License for the
15
- # specific language governing permissions and limitations
16
- # under the License.
17
- #
18
-
19
- # for package
20
- import binascii
21
- import logging
22
-
23
- import numpy as np
24
- import pandas as pd
25
- from thrift.transport import TTransport
26
- from iotdb.thrift.rpc.IClientRPCService import TSFetchResultsReq, TSCloseOperationReq
27
- from iotdb.tsfile.utils.DateUtils import parse_int_to_date
28
- from iotdb.utils.IoTDBConnectionException import IoTDBConnectionException
29
- from iotdb.utils.IoTDBConstants import TSDataType
30
-
31
- logger = logging.getLogger("IoTDB")
32
-
33
-
34
- def _to_bitbuffer(b):
35
- return bytes("{:0{}b}".format(int(binascii.hexlify(b), 16), 8 * len(b)), "utf-8")
36
-
37
-
38
- class IoTDBRpcDataSet(object):
39
- TIMESTAMP_STR = "Time"
40
- # VALUE_IS_NULL = "The value got by %s (column name) is NULL."
41
- START_INDEX = 2
42
-
43
- def __init__(
44
- self,
45
- sql,
46
- column_name_list,
47
- column_type_list,
48
- column_name_index,
49
- ignore_timestamp,
50
- query_id,
51
- client,
52
- statement_id,
53
- session_id,
54
- query_data_set,
55
- fetch_size,
56
- ):
57
- self.__statement_id = statement_id
58
- self.__session_id = session_id
59
- self.ignore_timestamp = ignore_timestamp
60
- self.__sql = sql
61
- self.__query_id = query_id
62
- self.__client = client
63
- self.__fetch_size = fetch_size
64
- self.column_size = len(column_name_list)
65
- self.__default_time_out = 1000
66
-
67
- self.__column_name_list = []
68
- self.__column_type_list = []
69
- self.column_ordinal_dict = {}
70
- if not ignore_timestamp:
71
- self.__column_name_list.append(IoTDBRpcDataSet.TIMESTAMP_STR)
72
- self.__column_type_list.append(TSDataType.INT64)
73
- self.column_ordinal_dict[IoTDBRpcDataSet.TIMESTAMP_STR] = 1
74
-
75
- if column_name_index is not None:
76
- self.column_type_deduplicated_list = [
77
- None for _ in range(len(column_name_index))
78
- ]
79
- for i in range(self.column_size):
80
- name = column_name_list[i]
81
- self.__column_name_list.append(name)
82
- self.__column_type_list.append(TSDataType[column_type_list[i]])
83
- if name not in self.column_ordinal_dict:
84
- index = column_name_index[name]
85
- self.column_ordinal_dict[name] = index + IoTDBRpcDataSet.START_INDEX
86
- self.column_type_deduplicated_list[index] = TSDataType[
87
- column_type_list[i]
88
- ]
89
- else:
90
- index = IoTDBRpcDataSet.START_INDEX
91
- self.column_type_deduplicated_list = []
92
- for i in range(len(column_name_list)):
93
- name = column_name_list[i]
94
- self.__column_name_list.append(name)
95
- self.__column_type_list.append(TSDataType[column_type_list[i]])
96
- if name not in self.column_ordinal_dict:
97
- self.column_ordinal_dict[name] = index
98
- index += 1
99
- self.column_type_deduplicated_list.append(
100
- TSDataType[column_type_list[i]]
101
- )
102
- self.__query_data_set = query_data_set
103
- self.__is_closed = False
104
- self.__empty_resultSet = False
105
- self.__rows_index = 0
106
- self.has_cached_data_frame = False
107
- self.data_frame = None
108
-
109
- def close(self):
110
- if self.__is_closed:
111
- return
112
- if self.__client is not None:
113
- try:
114
- status = self.__client.closeOperation(
115
- TSCloseOperationReq(
116
- self.__session_id, self.__query_id, self.__statement_id
117
- )
118
- )
119
- logger.debug(
120
- "close session {}, message: {}".format(
121
- self.__session_id, status.message
122
- )
123
- )
124
- except TTransport.TException as e:
125
- raise RuntimeError(
126
- "close session {} failed because: ".format(self.__session_id), e
127
- )
128
-
129
- self.__is_closed = True
130
- self.__client = None
131
-
132
- def next(self):
133
- if not self.has_cached_data_frame:
134
- self.construct_one_data_frame()
135
- if self.has_cached_data_frame:
136
- return True
137
- if self.__empty_resultSet:
138
- return False
139
- if self.fetch_results():
140
- self.construct_one_data_frame()
141
- return True
142
- return False
143
-
144
- def construct_one_data_frame(self):
145
- if (
146
- self.has_cached_data_frame
147
- or self.__query_data_set is None
148
- or len(self.__query_data_set.time) == 0
149
- ):
150
- return
151
- result = {}
152
- time_array = np.frombuffer(
153
- self.__query_data_set.time, np.dtype(np.longlong).newbyteorder(">")
154
- )
155
- if time_array.dtype.byteorder == ">":
156
- time_array = time_array.byteswap().view(time_array.dtype.newbyteorder("<"))
157
- result[0] = time_array
158
- total_length = len(time_array)
159
- for i in range(self.column_size):
160
- if self.ignore_timestamp is True:
161
- column_name = self.__column_name_list[i]
162
- else:
163
- column_name = self.__column_name_list[i + 1]
164
-
165
- location = (
166
- self.column_ordinal_dict[column_name] - IoTDBRpcDataSet.START_INDEX
167
- )
168
- if location < 0:
169
- continue
170
- data_type = self.column_type_deduplicated_list[location]
171
- value_buffer = self.__query_data_set.valueList[location]
172
- value_buffer_len = len(value_buffer)
173
- # DOUBLE
174
- if data_type == 4:
175
- data_array = np.frombuffer(
176
- value_buffer, np.dtype(np.double).newbyteorder(">")
177
- )
178
- # FLOAT
179
- elif data_type == 3:
180
- data_array = np.frombuffer(
181
- value_buffer, np.dtype(np.float32).newbyteorder(">")
182
- )
183
- # BOOLEAN
184
- elif data_type == 0:
185
- data_array = np.frombuffer(value_buffer, np.dtype("?"))
186
- # INT32, DATE
187
- elif data_type == 1 or data_type == 9:
188
- data_array = np.frombuffer(
189
- value_buffer, np.dtype(np.int32).newbyteorder(">")
190
- )
191
- # INT64, TIMESTAMP
192
- elif data_type == 2 or data_type == 8:
193
- data_array = np.frombuffer(
194
- value_buffer, np.dtype(np.int64).newbyteorder(">")
195
- )
196
- # TEXT, STRING, BLOB
197
- elif data_type == 5 or data_type == 11 or data_type == 10:
198
- j = 0
199
- offset = 0
200
- data_array = []
201
- while offset < value_buffer_len:
202
- length = int.from_bytes(
203
- value_buffer[offset : offset + 4],
204
- byteorder="big",
205
- signed=False,
206
- )
207
- offset += 4
208
- value = bytes(value_buffer[offset : offset + length])
209
- data_array.append(value)
210
- j += 1
211
- offset += length
212
- data_array = np.array(data_array, dtype=object)
213
- else:
214
- raise RuntimeError("unsupported data type {}.".format(data_type))
215
- if data_array.dtype.byteorder == ">":
216
- data_array = data_array.byteswap().view(
217
- data_array.dtype.newbyteorder("<")
218
- )
219
- if len(data_array) < total_length:
220
- tmp_array = np.full(total_length, None, dtype=object)
221
-
222
- bitmap_buffer = self.__query_data_set.bitmapList[location]
223
- buffer = _to_bitbuffer(bitmap_buffer)
224
- bit_mask = (np.frombuffer(buffer, "u1") - ord("0")).astype(bool)
225
- if len(bit_mask) != total_length:
226
- bit_mask = bit_mask[:total_length]
227
- tmp_array[bit_mask] = data_array
228
-
229
- # INT32, DATE
230
- if data_type == 1 or data_type == 9:
231
- tmp_array = pd.Series(tmp_array, dtype="Int32")
232
- # INT64, TIMESTAMP
233
- elif data_type == 2 or data_type == 8:
234
- tmp_array = pd.Series(tmp_array, dtype="Int64")
235
- # BOOLEAN
236
- elif data_type == 0:
237
- tmp_array = pd.Series(tmp_array, dtype="boolean")
238
- data_array = tmp_array
239
-
240
- result[i + 1] = data_array
241
- self.__query_data_set = None
242
- self.data_frame = pd.DataFrame(result, dtype=object)
243
- if not self.data_frame.empty:
244
- self.has_cached_data_frame = True
245
-
246
- def has_cached_result(self):
247
- return self.has_cached_data_frame
248
-
249
- def _has_next_result_set(self):
250
- if (self.__query_data_set is not None) and (
251
- len(self.__query_data_set.time) != 0
252
- ):
253
- return True
254
- if self.__empty_resultSet:
255
- return False
256
- if self.fetch_results():
257
- return True
258
- return False
259
-
260
- def result_set_to_pandas(self):
261
- result = {}
262
- for column_name in self.__column_name_list:
263
- result[column_name] = []
264
- while self._has_next_result_set():
265
- time_array = np.frombuffer(
266
- self.__query_data_set.time, np.dtype(np.longlong).newbyteorder(">")
267
- )
268
- if time_array.dtype.byteorder == ">":
269
- time_array = time_array.byteswap().view(
270
- time_array.dtype.newbyteorder("<")
271
- )
272
- if self.ignore_timestamp is None or self.ignore_timestamp is False:
273
- result[IoTDBRpcDataSet.TIMESTAMP_STR].append(time_array)
274
-
275
- self.__query_data_set.time = []
276
- total_length = len(time_array)
277
-
278
- for i in range(len(self.__query_data_set.bitmapList)):
279
- if self.ignore_timestamp is True:
280
- column_name = self.__column_name_list[i]
281
- else:
282
- column_name = self.__column_name_list[i + 1]
283
-
284
- location = (
285
- self.column_ordinal_dict[column_name] - IoTDBRpcDataSet.START_INDEX
286
- )
287
- if location < 0:
288
- continue
289
- data_type = self.column_type_deduplicated_list[location]
290
- value_buffer = self.__query_data_set.valueList[location]
291
- value_buffer_len = len(value_buffer)
292
- # DOUBLE
293
- if data_type == 4:
294
- data_array = np.frombuffer(
295
- value_buffer, np.dtype(np.double).newbyteorder(">")
296
- )
297
- # FLOAT
298
- elif data_type == 3:
299
- data_array = np.frombuffer(
300
- value_buffer, np.dtype(np.float32).newbyteorder(">")
301
- )
302
- # BOOLEAN
303
- elif data_type == 0:
304
- data_array = np.frombuffer(value_buffer, np.dtype("?"))
305
- # INT32
306
- elif data_type == 1:
307
- data_array = np.frombuffer(
308
- value_buffer, np.dtype(np.int32).newbyteorder(">")
309
- )
310
- # INT64, TIMESTAMP
311
- elif data_type == 2 or data_type == 8:
312
- data_array = np.frombuffer(
313
- value_buffer, np.dtype(np.int64).newbyteorder(">")
314
- )
315
- # TEXT, STRING
316
- elif data_type == 5 or data_type == 11:
317
- j = 0
318
- offset = 0
319
- data_array = []
320
- while offset < value_buffer_len:
321
- length = int.from_bytes(
322
- value_buffer[offset : offset + 4],
323
- byteorder="big",
324
- signed=False,
325
- )
326
- offset += 4
327
- value_bytes = bytes(value_buffer[offset : offset + length])
328
- value = value_bytes.decode("utf-8")
329
- data_array.append(value)
330
- j += 1
331
- offset += length
332
- data_array = pd.Series(data_array).astype(str)
333
- # BLOB
334
- elif data_type == 10:
335
- j = 0
336
- offset = 0
337
- data_array = []
338
- while offset < value_buffer_len:
339
- length = int.from_bytes(
340
- value_buffer[offset : offset + 4],
341
- byteorder="big",
342
- signed=False,
343
- )
344
- offset += 4
345
- value = value_buffer[offset : offset + length]
346
- data_array.append(value)
347
- j += 1
348
- offset += length
349
- data_array = pd.Series(data_array)
350
- # DATE
351
- elif data_type == 9:
352
- data_array = np.frombuffer(
353
- value_buffer, np.dtype(np.int32).newbyteorder(">")
354
- )
355
- data_array = pd.Series(data_array).apply(parse_int_to_date)
356
- else:
357
- raise RuntimeError("unsupported data type {}.".format(data_type))
358
- if data_array.dtype.byteorder == ">":
359
- data_array = data_array.byteswap().view(
360
- data_array.dtype.newbyteorder("<")
361
- )
362
- self.__query_data_set.valueList[location] = None
363
- tmp_array = []
364
- if len(data_array) < total_length:
365
- # BOOLEAN, INT32, INT64, TIMESTAMP
366
- if (
367
- data_type == 0
368
- or data_type == 1
369
- or data_type == 2
370
- or data_type == 8
371
- ):
372
- tmp_array = np.full(total_length, np.nan, dtype=np.float32)
373
- # FLOAT, DOUBLE
374
- elif data_type == 3 or data_type == 4:
375
- tmp_array = np.full(
376
- total_length, np.nan, dtype=data_array.dtype
377
- )
378
- # TEXT, STRING, BLOB, DATE
379
- elif (
380
- data_type == 5
381
- or data_type == 11
382
- or data_type == 10
383
- or data_type == 9
384
- ):
385
- tmp_array = np.full(total_length, None, dtype=data_array.dtype)
386
-
387
- bitmap_buffer = self.__query_data_set.bitmapList[location]
388
- buffer = _to_bitbuffer(bitmap_buffer)
389
- bit_mask = (np.frombuffer(buffer, "u1") - ord("0")).astype(bool)
390
- if len(bit_mask) != total_length:
391
- bit_mask = bit_mask[:total_length]
392
- tmp_array[bit_mask] = data_array
393
-
394
- if data_type == 1:
395
- tmp_array = pd.Series(tmp_array).astype("Int32")
396
- elif data_type == 2 or data_type == 8:
397
- tmp_array = pd.Series(tmp_array).astype("Int64")
398
- elif data_type == 0:
399
- tmp_array = pd.Series(tmp_array).astype("boolean")
400
-
401
- data_array = tmp_array
402
-
403
- result[column_name].append(data_array)
404
-
405
- for k, v in result.items():
406
- if v is None or len(v) < 1 or v[0] is None:
407
- result[k] = []
408
- elif v[0].dtype == "Int32":
409
- result[k] = pd.Series(np.concatenate(v, axis=0)).astype("Int32")
410
- elif v[0].dtype == "Int64":
411
- result[k] = pd.Series(np.concatenate(v, axis=0)).astype("Int64")
412
- elif v[0].dtype == bool:
413
- result[k] = pd.Series(np.concatenate(v, axis=0)).astype("boolean")
414
- else:
415
- result[k] = np.concatenate(v, axis=0)
416
-
417
- df = pd.DataFrame(result)
418
- return df
419
-
420
- def fetch_results(self):
421
- if self.__is_closed:
422
- raise IoTDBConnectionException("This DataSet is already closed")
423
- self.__rows_index = 0
424
- request = TSFetchResultsReq(
425
- self.__session_id,
426
- self.__sql,
427
- self.__fetch_size,
428
- self.__query_id,
429
- True,
430
- self.__default_time_out,
431
- )
432
- try:
433
- resp = self.__client.fetchResults(request)
434
- if not resp.hasResultSet:
435
- self.__empty_resultSet = True
436
- else:
437
- self.__query_data_set = resp.queryDataSet
438
- return resp.hasResultSet
439
- except TTransport.TException as e:
440
- raise RuntimeError(
441
- "Cannot fetch result from server, because of network connection: ", e
442
- )
443
-
444
- def find_column_name_by_index(self, column_index):
445
- if column_index <= 0:
446
- raise Exception("Column index should start from 1")
447
- if column_index > len(self.__column_name_list):
448
- raise Exception(
449
- "column index {} out of range {}".format(column_index, self.column_size)
450
- )
451
- return self.__column_name_list[column_index - 1]
452
-
453
- def get_fetch_size(self):
454
- return self.__fetch_size
455
-
456
- def set_fetch_size(self, fetch_size):
457
- self.__fetch_size = fetch_size
458
-
459
- def get_column_names(self):
460
- return self.__column_name_list
461
-
462
- def get_column_types(self):
463
- return self.__column_type_list
File without changes
File without changes