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
@@ -0,0 +1,476 @@
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
+ import math
19
+
20
+ import pandas as pd
21
+ from tzlocal import get_localzone_name
22
+
23
+ from iotdb.table_session import TableSession, TableSessionConfig
24
+ from iotdb.utils.IoTDBConstants import TSDataType
25
+ from iotdb.utils.Tablet import Tablet, ColumnType
26
+ from datetime import date
27
+
28
+ from iotdb.utils.rpc_utils import convert_to_timestamp
29
+ from .iotdb_container import IoTDBContainer
30
+
31
+
32
+ # Test query data
33
+ def test_query_data():
34
+ with IoTDBContainer("iotdb:dev") as db:
35
+ db: IoTDBContainer
36
+ config = TableSessionConfig(
37
+ node_urls=[f"{db.get_container_host_ip()}:{db.get_exposed_port(6667)}"]
38
+ )
39
+ session = TableSession(config)
40
+
41
+ # Preparation before testing
42
+ session.execute_non_query_statement(
43
+ "create database test_insert_relational_tablet_tablet"
44
+ )
45
+ session.execute_non_query_statement("use test_insert_relational_tablet_tablet")
46
+ session.execute_non_query_statement(
47
+ "create table table_b("
48
+ "tag1 STRING TAG, tag2 STRING TAG, tag3 STRING TAG, "
49
+ "attr1 string attribute, attr2 string attribute, attr3 string attribute,"
50
+ "BOOLEAN BOOLEAN FIELD, INT32 INT32 FIELD, INT64 INT64 FIELD, FLOAT FLOAT FIELD, DOUBLE DOUBLE FIELD,"
51
+ "TEXT TEXT FIELD, TIMESTAMP TIMESTAMP FIELD, DATE DATE FIELD, BLOB BLOB FIELD, STRING STRING FIELD)"
52
+ )
53
+
54
+ # 1、General scenario
55
+ expect = 10
56
+ table_name = "table_b"
57
+ column_names = [
58
+ "tag1",
59
+ "tag2",
60
+ "tag3",
61
+ "attr1",
62
+ "attr2",
63
+ "attr3",
64
+ "BOOLEAN",
65
+ "INT32",
66
+ "INT64",
67
+ "FLOAT",
68
+ "DOUBLE",
69
+ "TEXT",
70
+ "TIMESTAMP",
71
+ "DATE",
72
+ "BLOB",
73
+ "STRING",
74
+ ]
75
+ data_types = [
76
+ TSDataType.STRING,
77
+ TSDataType.STRING,
78
+ TSDataType.STRING,
79
+ TSDataType.STRING,
80
+ TSDataType.STRING,
81
+ TSDataType.STRING,
82
+ TSDataType.BOOLEAN,
83
+ TSDataType.INT32,
84
+ TSDataType.INT64,
85
+ TSDataType.FLOAT,
86
+ TSDataType.DOUBLE,
87
+ TSDataType.TEXT,
88
+ TSDataType.TIMESTAMP,
89
+ TSDataType.DATE,
90
+ TSDataType.BLOB,
91
+ TSDataType.STRING,
92
+ ]
93
+ column_types = [
94
+ ColumnType.TAG,
95
+ ColumnType.TAG,
96
+ ColumnType.TAG,
97
+ ColumnType.ATTRIBUTE,
98
+ ColumnType.ATTRIBUTE,
99
+ ColumnType.ATTRIBUTE,
100
+ ColumnType.FIELD,
101
+ ColumnType.FIELD,
102
+ ColumnType.FIELD,
103
+ ColumnType.FIELD,
104
+ ColumnType.FIELD,
105
+ ColumnType.FIELD,
106
+ ColumnType.FIELD,
107
+ ColumnType.FIELD,
108
+ ColumnType.FIELD,
109
+ ColumnType.FIELD,
110
+ ]
111
+ timestamps = []
112
+ values = []
113
+ for row_b in range(10):
114
+ timestamps.append(row_b)
115
+ values.append(
116
+ [
117
+ "tag1:" + str(row_b),
118
+ "tag2:" + str(row_b),
119
+ "tag3:" + str(row_b),
120
+ "attr1:" + str(row_b),
121
+ "attr2:" + str(row_b),
122
+ "attr3:" + str(row_b),
123
+ False,
124
+ 0,
125
+ 0,
126
+ 0.0,
127
+ 0.0,
128
+ "1234567890",
129
+ 0,
130
+ date(1970, 1, 1),
131
+ "1234567890".encode("utf-8"),
132
+ "1234567890",
133
+ ]
134
+ )
135
+ values.append(
136
+ [
137
+ "tag1:" + str(row_b),
138
+ "tag2:" + str(row_b),
139
+ "tag3:" + str(row_b),
140
+ "attr1:" + str(row_b),
141
+ "attr2:" + str(row_b),
142
+ "attr3:" + str(row_b),
143
+ True,
144
+ -2147483648,
145
+ -9223372036854775808,
146
+ -0.12345678,
147
+ -0.12345678901234567,
148
+ "abcdefghijklmnopqrstuvwsyz",
149
+ -9223372036854775808,
150
+ date(1000, 1, 1),
151
+ "abcdefghijklmnopqrstuvwsyz".encode("utf-8"),
152
+ "abcdefghijklmnopqrstuvwsyz",
153
+ ]
154
+ )
155
+ values.append(
156
+ [
157
+ "tag1:" + str(row_b),
158
+ "tag2:" + str(row_b),
159
+ "tag3:" + str(row_b),
160
+ "attr1:" + str(row_b),
161
+ "attr2:" + str(row_b),
162
+ "attr3:" + str(row_b),
163
+ True,
164
+ 2147483647,
165
+ 9223372036854775807,
166
+ 0.123456789,
167
+ 0.12345678901234567,
168
+ "!@#$%^&*()_+}{|:'`~-=[];,./<>?~",
169
+ 9223372036854775807,
170
+ date(9999, 12, 31),
171
+ "!@#$%^&*()_+}{|:`~-=[];,./<>?~".encode("utf-8"),
172
+ "!@#$%^&*()_+}{|:`~-=[];,./<>?~",
173
+ ]
174
+ )
175
+ values.append(
176
+ [
177
+ "tag1:" + str(row_b),
178
+ "tag2:" + str(row_b),
179
+ "tag3:" + str(row_b),
180
+ "attr1:" + str(row_b),
181
+ "attr2:" + str(row_b),
182
+ "attr3:" + str(row_b),
183
+ True,
184
+ 1,
185
+ 1,
186
+ 1.0,
187
+ 1.0,
188
+ "没问题",
189
+ 1,
190
+ date(1970, 1, 1),
191
+ "没问题".encode("utf-8"),
192
+ "没问题",
193
+ ]
194
+ )
195
+ values.append(
196
+ [
197
+ "tag1:" + str(row_b),
198
+ "tag2:" + str(row_b),
199
+ "tag3:" + str(row_b),
200
+ "attr1:" + str(row_b),
201
+ "attr2:" + str(row_b),
202
+ "attr3:" + str(row_b),
203
+ True,
204
+ -1,
205
+ -1,
206
+ 1.1234567,
207
+ 1.1234567890123456,
208
+ "!@#¥%……&*()——|:“《》?·【】、;‘,。/",
209
+ 11,
210
+ date(1970, 1, 1),
211
+ "!@#¥%……&*()——|:“《》?·【】、;‘,。/".encode("utf-8"),
212
+ "!@#¥%……&*()——|:“《》?·【】、;‘,。/",
213
+ ]
214
+ )
215
+ values.append(
216
+ [
217
+ "tag1:" + str(row_b),
218
+ "tag2:" + str(row_b),
219
+ "tag3:" + str(row_b),
220
+ "attr1:" + str(row_b),
221
+ "attr2:" + str(row_b),
222
+ "attr3:" + str(row_b),
223
+ True,
224
+ 10,
225
+ 11,
226
+ 4.123456,
227
+ 4.123456789012345,
228
+ "1234567890abcdefghijklmnopqrstuvwsyz!@#$%^&*()_+}{|:'`~-=[];,./<>?~!@#¥%……&*()——|:“《》?·【】、;‘,。/没问题",
229
+ 11,
230
+ date(1970, 1, 1),
231
+ "1234567890abcdefghijklmnopqrstuvwsyz!@#$%^&*()_+}{|:`~-=[];,./<>?~!@#¥%……&*()——|:“《》?·【】、;‘,。/没问题".encode(
232
+ "utf-8"
233
+ ),
234
+ "1234567890abcdefghijklmnopqrstuvwsyz!@#$%^&*()_+}{|:`~-=[];,./<>?~!@#¥%……&*()——|:“《》?·【】、;‘,。/没问题",
235
+ ]
236
+ )
237
+ values.append(
238
+ [
239
+ "tag1:" + str(row_b),
240
+ "tag2:" + str(row_b),
241
+ "tag3:" + str(row_b),
242
+ "attr1:" + str(row_b),
243
+ "attr2:" + str(row_b),
244
+ "attr3:" + str(row_b),
245
+ True,
246
+ -10,
247
+ -11,
248
+ 12.12345,
249
+ 12.12345678901234,
250
+ "test01",
251
+ 11,
252
+ date(1970, 1, 1),
253
+ "Hello, World!".encode("utf-8"),
254
+ "string01",
255
+ ]
256
+ )
257
+ values.append(
258
+ [
259
+ "tag1:" + str(row_b),
260
+ "tag2:" + str(row_b),
261
+ "tag3:" + str(row_b),
262
+ "attr1:" + str(row_b),
263
+ "attr2:" + str(row_b),
264
+ "attr3:" + str(row_b),
265
+ None,
266
+ None,
267
+ None,
268
+ None,
269
+ None,
270
+ "",
271
+ None,
272
+ date(1970, 1, 1),
273
+ "".encode("utf-8"),
274
+ "",
275
+ ]
276
+ )
277
+ values.append(
278
+ [
279
+ "tag1:" + str(row_b),
280
+ "tag2:" + str(row_b),
281
+ "tag3:" + str(row_b),
282
+ "attr1:" + str(row_b),
283
+ "attr2:" + str(row_b),
284
+ "attr3:" + str(row_b),
285
+ True,
286
+ -0,
287
+ -0,
288
+ -0.0,
289
+ -0.0,
290
+ " ",
291
+ 11,
292
+ date(1970, 1, 1),
293
+ " ".encode("utf-8"),
294
+ " ",
295
+ ]
296
+ )
297
+ values.append(
298
+ [
299
+ "tag1:" + str(row_b),
300
+ "tag2:" + str(row_b),
301
+ "tag3:" + str(row_b),
302
+ "attr1:" + str(row_b),
303
+ "attr2:" + str(row_b),
304
+ "attr3:" + str(row_b),
305
+ True,
306
+ 10,
307
+ 11,
308
+ 1.1,
309
+ 10011.1,
310
+ "test01",
311
+ 11,
312
+ date(1970, 1, 1),
313
+ "Hello, World!".encode("utf-8"),
314
+ "string01",
315
+ ]
316
+ )
317
+ tablet = Tablet(
318
+ table_name, column_names, data_types, values, timestamps, column_types
319
+ )
320
+ session.insert(tablet)
321
+ row = 0
322
+ with session.execute_query_statement(
323
+ "select * from table_b"
324
+ ) as session_data_set:
325
+ print(session_data_set.get_column_names())
326
+ while session_data_set.has_next():
327
+ print(session_data_set.next())
328
+ row += 1
329
+ # Determine whether it meets expectations
330
+ assert expect == row
331
+
332
+ with session.execute_query_statement(
333
+ "select * from table_b"
334
+ ) as session_data_set:
335
+ df = session_data_set.todf()
336
+ rows, columns = df.shape
337
+ assert rows == expect
338
+ assert columns == len(column_names) + 1
339
+
340
+ row = 0
341
+ with session.execute_query_statement(
342
+ "select " + ",".join(column_names) + " from table_b"
343
+ ) as session_data_set:
344
+ assert session_data_set.get_column_names() == column_names
345
+ while session_data_set.has_next():
346
+ row_record = session_data_set.next()
347
+ assert row_record.get_timestamp() == 0
348
+ for i in range(len(column_names)):
349
+ if values[row][i] is not None and (
350
+ data_types[i] == TSDataType.FLOAT
351
+ or data_types[i] == TSDataType.DOUBLE
352
+ ):
353
+ assert math.isclose(
354
+ row_record.get_fields()[i].get_object_value(data_types[i]),
355
+ values[row][i],
356
+ rel_tol=1e-6,
357
+ )
358
+ elif data_types[i] == TSDataType.TIMESTAMP:
359
+ actual = row_record.get_fields()[i].get_timestamp_value()
360
+ expected = convert_to_timestamp(
361
+ values[row][i], "ms", get_localzone_name()
362
+ )
363
+ if pd.isnull(actual):
364
+ assert pd.isnull(expected)
365
+ else:
366
+ assert actual == expected
367
+ else:
368
+ assert (
369
+ row_record.get_fields()[i].get_object_value(data_types[i])
370
+ == values[row][i]
371
+ )
372
+ row += 1
373
+ # Determine whether it meets expectations
374
+ assert expect == row
375
+
376
+ with session.execute_query_statement(
377
+ "select " + ",".join(column_names) + " from table_b"
378
+ ) as session_data_set:
379
+ df = session_data_set.todf()
380
+ assert list(df.columns) == column_names
381
+ rows, columns = df.shape
382
+ assert rows == expect
383
+ assert columns == len(column_names)
384
+ for i in range(rows):
385
+ for j in range(columns):
386
+ if pd.isna(df.iloc[i, j]):
387
+ continue
388
+ elif isinstance(values[i][j], float):
389
+ assert math.isclose(
390
+ df.iloc[i, j],
391
+ values[i][j],
392
+ rel_tol=1e-6,
393
+ )
394
+ elif isinstance(df.iloc[i, j], pd.Timestamp):
395
+ actual = df.iloc[i, j]
396
+ expected = pd.Series(
397
+ convert_to_timestamp(
398
+ values[i][j], "ms", get_localzone_name()
399
+ )
400
+ )[0]
401
+ assert actual == expected
402
+ else:
403
+ assert df.iloc[i, j] == values[i][j]
404
+
405
+ row = 0
406
+ with session.execute_query_statement(
407
+ "select tag1, tag1 from table_b"
408
+ ) as session_data_set:
409
+ assert session_data_set.get_column_names() == ["tag1", "tag1"]
410
+ while session_data_set.has_next():
411
+ row_record = session_data_set.next()
412
+ assert row_record.get_timestamp() == 0
413
+ for i in range(len(["tag1", "tag1"])):
414
+ assert (
415
+ row_record.get_fields()[i].get_object_value(
416
+ row_record.get_fields()[i].get_data_type()
417
+ )
418
+ == values[row][0]
419
+ )
420
+ row += 1
421
+ # Determine whether it meets expectations
422
+ assert expect == row
423
+
424
+ with session.execute_query_statement(
425
+ "select tag1, tag1 from table_b"
426
+ ) as session_data_set:
427
+ df = session_data_set.todf()
428
+ assert list(df.columns) == ["tag1", "tag1"]
429
+ rows, columns = df.shape
430
+ assert rows == expect
431
+ assert columns == 2
432
+ for i in range(rows):
433
+ for j in range(columns):
434
+ if pd.isna(df.iloc[i, j]):
435
+ assert values[i][j] is None
436
+ else:
437
+ assert df.iloc[i, j] == values[i][0]
438
+
439
+ row = 0
440
+ with session.execute_query_statement(
441
+ "select tag1, attr1 as tag1 from table_b"
442
+ ) as session_data_set:
443
+ assert session_data_set.get_column_names() == ["tag1", "tag1"]
444
+ while session_data_set.has_next():
445
+ row_record = session_data_set.next()
446
+ print(row_record)
447
+ assert row_record.get_timestamp() == 0
448
+ assert (
449
+ row_record.get_fields()[0].get_object_value(
450
+ row_record.get_fields()[0].get_data_type()
451
+ )
452
+ == values[row][0]
453
+ )
454
+ assert (
455
+ row_record.get_fields()[1].get_object_value(
456
+ row_record.get_fields()[1].get_data_type()
457
+ )
458
+ == values[row][3]
459
+ )
460
+ row += 1
461
+ # Determine whether it meets expectations
462
+ assert expect == row
463
+
464
+ with session.execute_query_statement(
465
+ "select tag1, attr1 as tag1 from table_b"
466
+ ) as session_data_set:
467
+ df = session_data_set.todf()
468
+ assert list(df.columns) == ["tag1", "tag1"]
469
+ rows, columns = df.shape
470
+ assert rows == expect
471
+ assert columns == 2
472
+ for i in range(rows):
473
+ assert df.iloc[i, 0] == values[i][0]
474
+ assert df.iloc[i, 1] == values[i][3]
475
+
476
+ session.close()