apache-iotdb 1.3.4__py3-none-any.whl → 2.0.2__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-1.3.4.dist-info → apache_iotdb-2.0.2.dist-info}/METADATA +4 -4
  2. {apache_iotdb-1.3.4.dist-info → apache_iotdb-2.0.2.dist-info}/RECORD +35 -30
  3. iotdb/Session.py +214 -21
  4. iotdb/SessionPool.py +14 -0
  5. iotdb/sqlalchemy/IoTDBDialect.py +11 -4
  6. iotdb/table_session.py +156 -0
  7. iotdb/table_session_pool.py +122 -0
  8. iotdb/thrift/common/ttypes.py +57 -0
  9. iotdb/thrift/rpc/IClientRPCService.py +12 -12
  10. iotdb/thrift/rpc/ttypes.py +615 -507
  11. iotdb/utils/Field.py +0 -1
  12. iotdb/utils/IoTDBRpcDataSet.py +1 -1
  13. iotdb/utils/NumpyTablet.py +39 -14
  14. iotdb/utils/Tablet.py +50 -14
  15. {iotdb/dbapi/tests → tests/integration/dbapi}/test_connection.py +1 -1
  16. {iotdb/dbapi/tests → tests/integration/dbapi}/test_cursor.py +1 -1
  17. {iotdb/sqlalchemy/tests → tests/integration/sqlalchemy}/test_dialect.py +28 -15
  18. tests/integration/test_aligned_timeseries.py +1 -1
  19. tests/integration/test_dataframe.py +1 -1
  20. tests/integration/test_delete_data.py +1 -1
  21. tests/integration/test_new_data_types.py +1 -1
  22. tests/integration/test_one_device.py +1 -1
  23. tests/integration/test_relational_session.py +128 -0
  24. tests/integration/test_session.py +82 -20
  25. tests/integration/test_session_pool.py +1 -1
  26. tests/integration/test_tablemodel_insert.py +1592 -0
  27. tests/integration/test_tablet.py +1 -1
  28. tests/integration/test_todf.py +1 -1
  29. tests/integration/test_treemodel_insert.py +6027 -0
  30. {apache_iotdb-1.3.4.dist-info → apache_iotdb-2.0.2.dist-info}/WHEEL +0 -0
  31. {apache_iotdb-1.3.4.dist-info → apache_iotdb-2.0.2.dist-info}/entry_points.txt +0 -0
  32. {apache_iotdb-1.3.4.dist-info → apache_iotdb-2.0.2.dist-info}/top_level.txt +0 -0
  33. {iotdb/dbapi/tests → tests/integration/dbapi}/__init__.py +0 -0
  34. /iotdb/IoTDBContainer.py → /tests/integration/iotdb_container.py +0 -0
  35. {iotdb/sqlalchemy/tests → tests/integration/sqlalchemy}/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: apache-iotdb
3
- Version: 1.3.4
3
+ Version: 2.0.2
4
4
  Summary: Apache IoTDB client API
5
5
  Author-email: Apache IoTDB <dev@iotdb.apache.org>
6
6
  License: Apache License, Version 2.0
@@ -17,7 +17,7 @@ Description-Content-Type: text/markdown
17
17
  Requires-Dist: thrift>=0.14.1
18
18
  Requires-Dist: pandas>=1.0.0
19
19
  Requires-Dist: numpy>=1.0.0
20
- Requires-Dist: sqlalchemy<1.5,>=1.4
20
+ Requires-Dist: sqlalchemy>=1.4
21
21
  Requires-Dist: sqlalchemy-utils>=0.37.8
22
22
 
23
23
  <!--
@@ -69,9 +69,9 @@ You have to install thrift (>=0.14.1) before using the package.
69
69
 
70
70
  First, download the latest package: `pip3 install apache-iotdb`
71
71
 
72
- You can get an example of using the package to read and write data at here: [Example](https://github.com/apache/iotdb/blob/master/client-py/SessionExample.py)
72
+ You can get an example of using the package to read and write data at here: [Example](https://github.com/apache/iotdb/blob/master/iotdb-client/client-py/SessionExample.py)
73
73
 
74
- An example of aligned timeseries: [Aligned Timeseries Session Example](https://github.com/apache/iotdb/blob/master/client-py/SessionAlignedTimeseriesExample.py)
74
+ An example of aligned timeseries: [Aligned Timeseries Session Example](https://github.com/apache/iotdb/blob/master/iotdb-client/client-py/SessionAlignedTimeseriesExample.py)
75
75
 
76
76
  (you need to add `import iotdb` in the head of the file)
77
77
 
@@ -1,21 +1,17 @@
1
- iotdb/IoTDBContainer.py,sha256=gmGMEzacytqvrpCXGn0xrm3ab4LDyToNCHPEFg82Mwg,2514
2
- iotdb/Session.py,sha256=kPT3lyLNP5AoJMVzHUlcOqsFQc9rkQb9MvTVP2Jn-gg,95232
3
- iotdb/SessionPool.py,sha256=SSB6ohCI-8cpXYneSByuckLQQGNig3ERVaABsMgFay0,6095
1
+ iotdb/Session.py,sha256=x0vSwainD_xtL4uvYOBSEFcY5LofMaHH-HT57blCQTA,102965
2
+ iotdb/SessionPool.py,sha256=-XXWDJ2Fpo1rceyc_Q-uv7XD5p69YdR1drD9tyBqUwQ,6621
4
3
  iotdb/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
4
+ iotdb/table_session.py,sha256=Jav4TuvRl4PxOhNBaBqTvMGFWemu5YkAwRU_KXUy9wk,6173
5
+ iotdb/table_session_pool.py,sha256=sqhceeGbr1bsLjYj6aEF_p3qzqiVhtXKAEjV9CY4pWI,5329
5
6
  iotdb/dbapi/Connection.py,sha256=t5CuwOTrMJxJ2YVxaEKi2fdaH9Vob-u7nQRCD_9vLcg,2569
6
7
  iotdb/dbapi/Cursor.py,sha256=CBFyHsk7cOxLJEwCWMJK0r4guXQ-OkNh39H54cyyH5k,9110
7
8
  iotdb/dbapi/Exceptions.py,sha256=X3qhGXQ_rNL7998DQwFeQc9cG5ByXlfhIQx2sBHOiuw,1278
8
9
  iotdb/dbapi/__init__.py,sha256=98jGNzw_AI1iqbYbUxGRg4Yd92Uo63S1v143_NnKKCs,953
9
- iotdb/dbapi/tests/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
10
- iotdb/dbapi/tests/test_connection.py,sha256=cq4NlkwUMEi22e2vpNuNZKwFPNC6mTc0y84qdBXAbac,1689
11
- iotdb/dbapi/tests/test_cursor.py,sha256=etg9sOpBLL6iIBZIoOnfPMGzMn__kwDZFnHT6ugpxRU,3943
12
- iotdb/sqlalchemy/IoTDBDialect.py,sha256=Pt8O-TjGN3DzO63szD6iYA73A7g3OhYSxf7SPqvp9WQ,4557
10
+ iotdb/sqlalchemy/IoTDBDialect.py,sha256=047PV15HtnTej_cXkfwmzwp5IIOYyMco6bSeqHWDItI,4695
13
11
  iotdb/sqlalchemy/IoTDBIdentifierPreparer.py,sha256=NxOf58CXp6QYeifyF9KAZfEgPbNW0jIRZ6CwRvWcV-8,1089
14
12
  iotdb/sqlalchemy/IoTDBSQLCompiler.py,sha256=UuLRB7sEuy3YVVVU7oBeEKcJ9-OdLsbP7eiyIlja9kY,11790
15
13
  iotdb/sqlalchemy/IoTDBTypeCompiler.py,sha256=1ZrQvMt3lieN-HUjJLlmSVGy1DwBCWZMwC8zZjX6FOI,1416
16
14
  iotdb/sqlalchemy/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
17
- iotdb/sqlalchemy/tests/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
18
- iotdb/sqlalchemy/tests/test_dialect.py,sha256=MdrJXqVpwRznppYvqC3OfVUOjR0sbMU5ubpJacDxOAU,3083
19
15
  iotdb/template/MeasurementNode.py,sha256=O0-MVLN9a-Sap8uPriQxlmkh_NyUsiWGEoNQgmyBQ28,2315
20
16
  iotdb/template/Template.py,sha256=9zSaBsTwT_hWj-qf8Y_r9cIdd4WhdIrhxAl31Ejmo5E,3649
21
17
  iotdb/template/TemplateNode.py,sha256=6dR84yg7QV5A4nmGqws8cfV3GygfrR5HErQS5t2ORNw,1556
@@ -24,11 +20,11 @@ iotdb/template/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,78
24
20
  iotdb/thrift/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
21
  iotdb/thrift/common/__init__.py,sha256=YFcZTT8Cm-6Y4oTiCaqq0DT1lw2W09WqoEc5_pTAwW0,34
26
22
  iotdb/thrift/common/constants.py,sha256=IKRM8SpfhYWXERWBgUbUhbdFpn363hmZjXDhEYnVRbw,366
27
- iotdb/thrift/common/ttypes.py,sha256=CsmVig5NMdix7D2yddwdWj7ItBcmsM--8l_sVTXcOwA,115657
28
- iotdb/thrift/rpc/IClientRPCService.py,sha256=C9CZxONUf14jJgAjrgOXfxwK3rfwfVrnCDnucwpDkwI,416186
23
+ iotdb/thrift/common/ttypes.py,sha256=L8cZ-biq0G2528LSKWNteVgFkWYTBMttyr6da_JXiIM,116582
24
+ iotdb/thrift/rpc/IClientRPCService.py,sha256=gHrJArjwcFMkcKIR46CFiz_D5rhR-WetjQSI8jRLXeY,416186
29
25
  iotdb/thrift/rpc/__init__.py,sha256=69gRO2XxQu71SDeCRxiZFjK6Xw_61hdl5MdWceI-e1A,55
30
26
  iotdb/thrift/rpc/constants.py,sha256=IKRM8SpfhYWXERWBgUbUhbdFpn363hmZjXDhEYnVRbw,366
31
- iotdb/thrift/rpc/ttypes.py,sha256=hfsy0X7gLIizHVAqqMphbcgWwZPZNoHWaAvuCDwArak,295853
27
+ iotdb/thrift/rpc/ttypes.py,sha256=SBn1WHuSwmEoZrO6Ke2Ddcty6z52Hu1lGJp0uDJ1z8Y,301147
32
28
  iotdb/tsfile/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
33
29
  iotdb/tsfile/common/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
34
30
  iotdb/tsfile/common/constant/TsFileConstant.py,sha256=uLSw9vnQZ6objfyhO3b9bHTip8yUW5aapPHEsXC0e7s,1165
@@ -38,31 +34,40 @@ iotdb/tsfile/utils/Pair.py,sha256=91ecijUAlEiMRLlH2hjRi_mT_xWp6Vm-R3n4Z4USFqQ,95
38
34
  iotdb/tsfile/utils/ReadWriteIOUtils.py,sha256=31CKH_1XWz8xc7DyInKaD-avkY-hVqNQILDb5PMucm4,2977
39
35
  iotdb/tsfile/utils/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
40
36
  iotdb/utils/BitMap.py,sha256=dGvruuvDJlT4KH7pIrkprZWsY_AG-P8HXe6JHBKDOpI,1436
41
- iotdb/utils/Field.py,sha256=zc4oJBcib8BPnVpLTq_3sbPfmGRAO7SmQiWeuPgaiGc,7303
37
+ iotdb/utils/Field.py,sha256=gn2p7RBbn_Kr0r2jAGNK4TkHDOF5SrwxmeW4UgptRVQ,7302
42
38
  iotdb/utils/IoTDBConnectionException.py,sha256=D38r5MicwIdVsliCwtipICjx19wbvRI4ye0doAX7DPM,1179
43
39
  iotdb/utils/IoTDBConstants.py,sha256=mOXYQvaOccFS0cOUEqSXgZ3qSjhe6K8_sIjTT9S6qaI,1950
44
- iotdb/utils/IoTDBRpcDataSet.py,sha256=mYqfeQQQijr25mjarmPXyWhnyinBL9NNL3nSWKVo4yA,18411
45
- iotdb/utils/NumpyTablet.py,sha256=VQiuRb2vJSVgqpzod4OocehXh7JdUNBGH-MTV4lzg0g,6919
40
+ iotdb/utils/IoTDBRpcDataSet.py,sha256=aFG1BGaXFYlivTmkx2exZh5lfCPWc7JDD0PC72SR5FQ,18429
41
+ iotdb/utils/NumpyTablet.py,sha256=ImJ2y4QOQ36skWnfqVVxQHLmFh6kkik19EIAyyiQtWo,7950
46
42
  iotdb/utils/RowRecord.py,sha256=TIfQzMdi84GhGGIfVcZ-kvmm7aQwsDWge2kY00sf1lo,1690
47
43
  iotdb/utils/SessionDataSet.py,sha256=uS06ceDkhb8TocGM8MzdefofauoOrC4GWYi1TjWQS1w,5359
48
- iotdb/utils/Tablet.py,sha256=VM0Prem8xqLqV3YF9lbtGQ4N4pqQ1KvdbqrvczB6A2g,9035
44
+ iotdb/utils/Tablet.py,sha256=WguKP2_Gu3UzaaKVt9wPR8kpib3Yd5iMONAzyAoIxbI,10197
49
45
  iotdb/utils/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
50
46
  tests/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
51
47
  tests/integration/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
48
+ tests/integration/iotdb_container.py,sha256=gmGMEzacytqvrpCXGn0xrm3ab4LDyToNCHPEFg82Mwg,2514
52
49
  tests/integration/tablet_performance_comparison.py,sha256=cjWV-RGhp73JjzITyKwC7Abx5IRGg00cLrS3cH3BkOo,10724
53
- tests/integration/test_aligned_timeseries.py,sha256=hig7q7UEBEdYiQnCmW2uOUiVopBW9_WpUBWE8sWP8lk,9906
54
- tests/integration/test_dataframe.py,sha256=c3ATEbljj6NKFhbOOAFZX-WC4saoNUFNVfLfic9ogf8,2808
55
- tests/integration/test_delete_data.py,sha256=vDDNWJ_WUZihLOMdwRMyS4r9F6nm-SalVSx1hPXrDlE,5121
56
- tests/integration/test_new_data_types.py,sha256=qi1VKybP9S-KNRpXlnzgKYGoMEdRUayrr_WiXy7IN4A,6367
57
- tests/integration/test_one_device.py,sha256=QW6t8GfH4FnYxZODYztpHEt8m3NAC-AUcs18KKK4q0w,4734
58
- tests/integration/test_session.py,sha256=aLhjUxZJ1IX2DBPuh3h7E4vfJs2jTnBa4dSIDgnMLIo,14343
59
- tests/integration/test_session_pool.py,sha256=v4cbLLwob8JTG0vEV1zhr_YCHM7649JacBOg2Svcemo,3891
60
- tests/integration/test_tablet.py,sha256=m0jLWJPQpy0K8sgOMS-91MaIL8QnwI3u4SWHjcEWbDI,4438
61
- tests/integration/test_todf.py,sha256=MlntH0pnz9xXx7CJMNlb5Dm3MijKh6tpcQrr7jYTM9Q,8128
50
+ tests/integration/test_aligned_timeseries.py,sha256=W6GG08YzYDfmF5rlvKmF_iAHxNoZIc9ETaAslUTAWu4,9902
51
+ tests/integration/test_dataframe.py,sha256=6jnCqpvw-3uYLzCli9x9hnXTX8llnrLWdOzgOZ41OFA,2804
52
+ tests/integration/test_delete_data.py,sha256=7ZSVZYLFChM4V7oeBKWyZeilr_HBaLgQ8hk6H7TpwEY,5117
53
+ tests/integration/test_new_data_types.py,sha256=fjUccRuSGKHTQr03NBI3kVSqZ4IAgGZ3U_vJCoBiWIA,6363
54
+ tests/integration/test_one_device.py,sha256=6Wab6CzHvoLdlCHgYBdBD7woZqOqQ57j4AWcVFd2q4M,4730
55
+ tests/integration/test_relational_session.py,sha256=sZLZZj9IZSLVkGEPJGj2L_dmLmasm-kKwANERTPsnq8,4448
56
+ tests/integration/test_session.py,sha256=7ewSmo7eMte8J7WX7t7cu70DOv644rbwzJjC9ElDwFo,16510
57
+ tests/integration/test_session_pool.py,sha256=cldbmfO5NSK9XQipwiDgjjixpxuSoBTVYObhlFm-WRo,3887
58
+ tests/integration/test_tablemodel_insert.py,sha256=NMF4f-FzhAIDc8qLBxI8rZEtQjfs0pDPykMWx19cjwI,54634
59
+ tests/integration/test_tablet.py,sha256=j6LQJKVAZ9elZdHrv8O-yeb3q9yNIXOdjCexJqlLE24,4434
60
+ tests/integration/test_todf.py,sha256=v4aF9SwU0gcKgIms161zFbMCCWzwGACfwZ16QPQLPb0,8124
61
+ tests/integration/test_treemodel_insert.py,sha256=Td1pThwzjxg2JKSKKeMXsi9WYibDGa_eY9GlPRGajJo,195607
62
+ tests/integration/dbapi/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
63
+ tests/integration/dbapi/test_connection.py,sha256=FgM9Ama-YHcuZ-IaukAjoFcqnff9YEkAvVnXg9Y7AXg,1702
64
+ tests/integration/dbapi/test_cursor.py,sha256=5pmvTMTfsBDn9hVbBEnbrB4Obknbx3zDHm2VA19yheQ,3956
65
+ tests/integration/sqlalchemy/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
66
+ tests/integration/sqlalchemy/test_dialect.py,sha256=QvhZ3h-gbXQHRLQglbIeBM-YaJxWjd8NFwCCtRZDCQg,3478
62
67
  tests/unit/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
63
68
  tests/unit/test_numpy_tablet.py,sha256=w3lLK8Cft7lGsCj_6Z1Y7kDshltN0osSDJb-EESi6_Y,7235
64
- apache_iotdb-1.3.4.dist-info/METADATA,sha256=zL2_FMt-GbC9YkgWdAnj4vY0wWXJWS89EusBfyhuSnI,18771
65
- apache_iotdb-1.3.4.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
66
- apache_iotdb-1.3.4.dist-info/entry_points.txt,sha256=BmQWy6NHyWXorQcVm8-VWpt9MSqe46UFyV2hnsl4yok,73
67
- apache_iotdb-1.3.4.dist-info/top_level.txt,sha256=B9jGGOaAAqF1WrWw2jX2K-naWAZn2nhyrL-6hM1qwyM,12
68
- apache_iotdb-1.3.4.dist-info/RECORD,,
69
+ apache_iotdb-2.0.2.dist-info/METADATA,sha256=FRHjfXTDRW5l9tzgjeGCXdnkpxuuzk_3dUwfahHxA6E,18792
70
+ apache_iotdb-2.0.2.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
71
+ apache_iotdb-2.0.2.dist-info/entry_points.txt,sha256=BmQWy6NHyWXorQcVm8-VWpt9MSqe46UFyV2hnsl4yok,73
72
+ apache_iotdb-2.0.2.dist-info/top_level.txt,sha256=B9jGGOaAAqF1WrWw2jX2K-naWAZn2nhyrL-6hM1qwyM,12
73
+ apache_iotdb-2.0.2.dist-info/RECORD,,
iotdb/Session.py CHANGED
@@ -70,11 +70,12 @@ class Session(object):
70
70
  SUCCESS_STATUS = 200
71
71
  MULTIPLE_ERROR = 302
72
72
  REDIRECTION_RECOMMEND = 400
73
- DEFAULT_FETCH_SIZE = 10000
73
+ DEFAULT_FETCH_SIZE = 5000
74
74
  DEFAULT_USER = "root"
75
75
  DEFAULT_PASSWORD = "root"
76
76
  DEFAULT_ZONE_ID = time.strftime("%z")
77
77
  RETRY_NUM = 3
78
+ SQL_DIALECT = "tree"
78
79
 
79
80
  def __init__(
80
81
  self,
@@ -108,6 +109,8 @@ class Session(object):
108
109
  self.__enable_redirection = enable_redirection
109
110
  self.__device_id_to_endpoint = None
110
111
  self.__endpoint_to_connection = None
112
+ self.sql_dialect = self.SQL_DIALECT
113
+ self.database = None
111
114
  self.__use_ssl = use_ssl
112
115
  self.__ca_certs = ca_certs
113
116
  self.__connection_timeout_in_ms = connection_timeout_in_ms
@@ -191,12 +194,15 @@ class Session(object):
191
194
  else:
192
195
  client = Client(TBinaryProtocol.TBinaryProtocolAccelerated(transport))
193
196
 
197
+ configuration = {"version": "V_1_0", "sql_dialect": self.sql_dialect}
198
+ if self.database is not None:
199
+ configuration["db"] = self.database
194
200
  open_req = TSOpenSessionReq(
195
201
  client_protocol=self.protocol_version,
196
202
  username=self.__user,
197
203
  password=self.__password,
198
204
  zoneId=self.__zone_id,
199
- configuration={"version": "V_1_0"},
205
+ configuration=configuration,
200
206
  )
201
207
 
202
208
  try:
@@ -535,6 +541,15 @@ class Session(object):
535
541
  string_values = [string_values]
536
542
  if type(measurements) == str:
537
543
  measurements = [measurements]
544
+ if self.__has_none_value(string_values):
545
+ filtered_measurements, filtered_values = zip(
546
+ *[(m, v) for m, v in zip(measurements, string_values) if v is not None]
547
+ )
548
+ measurements = list(filtered_measurements)
549
+ values = list(filtered_values)
550
+ if len(measurements) == 0 or len(values) == 0:
551
+ logger.info("All inserting values are none!")
552
+ return
538
553
  request = self.gen_insert_str_record_req(
539
554
  device_id, timestamp, measurements, string_values
540
555
  )
@@ -566,6 +581,15 @@ class Session(object):
566
581
  string_values = [string_values]
567
582
  if type(measurements) == str:
568
583
  measurements = [measurements]
584
+ if self.__has_none_value(string_values):
585
+ filtered_measurements, filtered_values = zip(
586
+ *[(m, v) for m, v in zip(measurements, string_values) if v is not None]
587
+ )
588
+ measurements = list(filtered_measurements)
589
+ values = list(filtered_values)
590
+ if len(measurements) == 0 or len(values) == 0:
591
+ logger.info("All inserting values are none!")
592
+ return
569
593
  request = self.gen_insert_str_record_req(
570
594
  device_id, timestamp, measurements, string_values, True
571
595
  )
@@ -601,6 +625,20 @@ class Session(object):
601
625
  :param data_types: List of TSDataType, indicate the data type for each sensor
602
626
  :param values: List, values to be inserted, for each sensor
603
627
  """
628
+ if self.__has_none_value(values):
629
+ filtered_measurements, filtered_data_types, filtered_values = zip(
630
+ *[
631
+ (m, d, v)
632
+ for m, d, v in zip(measurements, data_types, values)
633
+ if v is not None
634
+ ]
635
+ )
636
+ measurements = list(filtered_measurements)
637
+ data_types = list(filtered_data_types)
638
+ values = list(filtered_values)
639
+ if len(measurements) == 0 or len(data_types) == 0 or len(values) == 0:
640
+ logger.info("All inserting values are none!")
641
+ return
604
642
  request = self.gen_insert_record_req(
605
643
  device_id, timestamp, measurements, data_types, values
606
644
  )
@@ -634,6 +672,19 @@ class Session(object):
634
672
  :param types_lst: 2-D List of TSDataType, each element of outer list indicates sensor data types of a device
635
673
  :param values_lst: 2-D List, values to be inserted, for each device
636
674
  """
675
+ if self.__has_none_value(values_lst):
676
+ (
677
+ device_ids,
678
+ times,
679
+ measurements_lst,
680
+ types_lst,
681
+ values_lst,
682
+ ) = self.__filter_lists_by_values(
683
+ device_ids, times, measurements_lst, types_lst, values_lst
684
+ )
685
+ if len(device_ids) == 0:
686
+ logger.info("All inserting values are none!")
687
+ return
637
688
  if self.__enable_redirection:
638
689
  request_group = {}
639
690
  for i in range(len(device_ids)):
@@ -703,6 +754,20 @@ class Session(object):
703
754
  :param data_types: List of TSDataType, indicate the data type for each sensor
704
755
  :param values: List, values to be inserted, for each sensor
705
756
  """
757
+ if self.__has_none_value(values):
758
+ filtered_measurements, filtered_data_types, filtered_values = zip(
759
+ *[
760
+ (m, d, v)
761
+ for m, d, v in zip(measurements, data_types, values)
762
+ if v is not None
763
+ ]
764
+ )
765
+ measurements = list(filtered_measurements)
766
+ data_types = list(filtered_data_types)
767
+ values = list(filtered_values)
768
+ if len(measurements) == 0 or len(data_types) == 0 or len(values) == 0:
769
+ logger.info("All inserting values are none!")
770
+ return
706
771
  request = self.gen_insert_record_req(
707
772
  device_id, timestamp, measurements, data_types, values, True
708
773
  )
@@ -736,6 +801,19 @@ class Session(object):
736
801
  :param types_lst: 2-D List of TSDataType, each element of outer list indicates sensor data types of a device
737
802
  :param values_lst: 2-D List, values to be inserted, for each device
738
803
  """
804
+ if self.__has_none_value(values_lst):
805
+ (
806
+ device_ids,
807
+ times,
808
+ measurements_lst,
809
+ types_lst,
810
+ values_lst,
811
+ ) = self.__filter_lists_by_values(
812
+ device_ids, times, measurements_lst, types_lst, values_lst
813
+ )
814
+ if len(device_ids) == 0:
815
+ logger.info("All inserting values are none!")
816
+ return
739
817
  if self.__enable_redirection:
740
818
  request_group = {}
741
819
  for i in range(len(device_ids)):
@@ -928,13 +1006,15 @@ class Session(object):
928
1006
  """
929
1007
  request = self.gen_insert_tablet_req(tablet)
930
1008
  try:
931
- connection = self.get_connection(tablet.get_device_id())
1009
+ connection = self.get_connection(tablet.get_insert_target_name())
932
1010
  request.sessionId = connection.session_id
933
1011
  return Session.verify_success_with_redirection(
934
1012
  connection.client.insertTablet(request)
935
1013
  )
936
1014
  except RedirectException as e:
937
- return self.handle_redirection(tablet.get_device_id(), e.redirect_node)
1015
+ return self.handle_redirection(
1016
+ tablet.get_insert_target_name(), e.redirect_node
1017
+ )
938
1018
  except TTransport.TException as e:
939
1019
  if self.reconnect():
940
1020
  try:
@@ -953,14 +1033,14 @@ class Session(object):
953
1033
  if self.__enable_redirection:
954
1034
  request_group = {}
955
1035
  for i in range(len(tablet_lst)):
956
- connection = self.get_connection(tablet_lst[i].get_device_id())
1036
+ connection = self.get_connection(tablet_lst[i].get_insert_target_name())
957
1037
  request = request_group.setdefault(
958
1038
  connection.client,
959
1039
  TSInsertTabletsReq(
960
1040
  connection.session_id, [], [], [], [], [], [], False
961
1041
  ),
962
1042
  )
963
- request.prefixPaths.append(tablet_lst[i].get_device_id())
1043
+ request.prefixPaths.append(tablet_lst[i].get_insert_target_name())
964
1044
  request.timestampsList.append(tablet_lst[i].get_binary_timestamps())
965
1045
  request.measurementsList.append(tablet_lst[i].get_measurements())
966
1046
  request.valuesList.append(tablet_lst[i].get_binary_values())
@@ -1019,13 +1099,15 @@ class Session(object):
1019
1099
  """
1020
1100
  request = self.gen_insert_tablet_req(tablet, True)
1021
1101
  try:
1022
- connection = self.get_connection(tablet.get_device_id())
1102
+ connection = self.get_connection(tablet.get_insert_target_name())
1023
1103
  request.sessionId = connection.session_id
1024
1104
  return Session.verify_success_with_redirection(
1025
1105
  connection.client.insertTablet(request)
1026
1106
  )
1027
1107
  except RedirectException as e:
1028
- return self.handle_redirection(tablet.get_device_id(), e.redirect_node)
1108
+ return self.handle_redirection(
1109
+ tablet.get_insert_target_name(), e.redirect_node
1110
+ )
1029
1111
  except TTransport.TException as e:
1030
1112
  if self.reconnect():
1031
1113
  try:
@@ -1044,14 +1126,14 @@ class Session(object):
1044
1126
  if self.__enable_redirection:
1045
1127
  request_group = {}
1046
1128
  for i in range(len(tablet_lst)):
1047
- connection = self.get_connection(tablet_lst[i].get_device_id())
1129
+ connection = self.get_connection(tablet_lst[i].get_insert_target_name())
1048
1130
  request = request_group.setdefault(
1049
1131
  connection.client,
1050
1132
  TSInsertTabletsReq(
1051
1133
  connection.session_id, [], [], [], [], [], [], True
1052
1134
  ),
1053
1135
  )
1054
- request.prefixPaths.append(tablet_lst[i].get_device_id())
1136
+ request.prefixPaths.append(tablet_lst[i].get_insert_target_name())
1055
1137
  request.timestampsList.append(tablet_lst[i].get_binary_timestamps())
1056
1138
  request.measurementsList.append(tablet_lst[i].get_measurements())
1057
1139
  request.valuesList.append(tablet_lst[i].get_binary_values())
@@ -1096,6 +1178,36 @@ class Session(object):
1096
1178
  self.connection_error_msg()
1097
1179
  ) from None
1098
1180
 
1181
+ def insert_relational_tablet(self, tablet):
1182
+ """
1183
+ insert one tablet, for example three column in the table1 can form a tablet:
1184
+ timestamps, id1, attr1, m1
1185
+ 1, id:1, attr:1, 1.0
1186
+ 2, id:1, attr:1, 2.0
1187
+ 3, id:2, attr:2, 3.0
1188
+ :param tablet: a tablet specified above
1189
+ """
1190
+ request = self.gen_insert_relational_tablet_req(tablet)
1191
+ try:
1192
+ connection = self.get_connection(tablet.get_insert_target_name())
1193
+ request.sessionId = connection.session_id
1194
+ return Session.verify_success_with_redirection(
1195
+ connection.client.insertTablet(request)
1196
+ )
1197
+ except RedirectException as e:
1198
+ return self.handle_redirection(
1199
+ tablet.get_insert_target_name(), e.redirect_node
1200
+ )
1201
+ except TTransport.TException as e:
1202
+ if self.reconnect():
1203
+ try:
1204
+ request.sessionId = self.__session_id
1205
+ return Session.verify_success(self.__client.insertTablet(request))
1206
+ except TTransport.TException as e1:
1207
+ raise IoTDBConnectionException(e1) from None
1208
+ else:
1209
+ raise IoTDBConnectionException(self.connection_error_msg()) from None
1210
+
1099
1211
  def insert_records_of_one_device(
1100
1212
  self, device_id, times_list, measurements_list, types_list, values_list
1101
1213
  ):
@@ -1312,13 +1424,27 @@ class Session(object):
1312
1424
  def gen_insert_tablet_req(self, tablet, is_aligned=False):
1313
1425
  return TSInsertTabletReq(
1314
1426
  self.__session_id,
1315
- tablet.get_device_id(),
1427
+ tablet.get_insert_target_name(),
1428
+ tablet.get_measurements(),
1429
+ tablet.get_binary_values(),
1430
+ tablet.get_binary_timestamps(),
1431
+ tablet.get_data_types(),
1432
+ tablet.get_row_number(),
1433
+ is_aligned,
1434
+ )
1435
+
1436
+ def gen_insert_relational_tablet_req(self, tablet, is_aligned=False):
1437
+ return TSInsertTabletReq(
1438
+ self.__session_id,
1439
+ tablet.get_insert_target_name(),
1316
1440
  tablet.get_measurements(),
1317
1441
  tablet.get_binary_values(),
1318
1442
  tablet.get_binary_timestamps(),
1319
1443
  tablet.get_data_types(),
1320
1444
  tablet.get_row_number(),
1321
1445
  is_aligned,
1446
+ True,
1447
+ tablet.get_column_categories(),
1322
1448
  )
1323
1449
 
1324
1450
  def gen_insert_tablets_req(self, tablet_lst, is_aligned=False):
@@ -1329,7 +1455,7 @@ class Session(object):
1329
1455
  type_lst = []
1330
1456
  size_lst = []
1331
1457
  for tablet in tablet_lst:
1332
- device_id_lst.append(tablet.get_device_id())
1458
+ device_id_lst.append(tablet.get_insert_target_name())
1333
1459
  measurements_lst.append(tablet.get_measurements())
1334
1460
  values_lst.append(tablet.get_binary_values())
1335
1461
  timestamps_lst.append(tablet.get_binary_timestamps())
@@ -1402,6 +1528,18 @@ class Session(object):
1402
1528
  else:
1403
1529
  raise IoTDBConnectionException(self.connection_error_msg()) from None
1404
1530
 
1531
+ previous_db = self.database
1532
+ if resp.database is not None:
1533
+ self.database = resp.database
1534
+ if previous_db != self.database and self.__endpoint_to_connection is not None:
1535
+ iterator = iter(self.__endpoint_to_connection.items())
1536
+ for entry in list(iterator):
1537
+ endpoint, connection = entry
1538
+ if connection != self.__default_connection:
1539
+ try:
1540
+ connection.change_database(sql)
1541
+ except Exception as e:
1542
+ self.__endpoint_to_connection.pop(endpoint)
1405
1543
  return Session.verify_success(resp.status)
1406
1544
 
1407
1545
  def execute_statement(self, sql: str, timeout=0):
@@ -1563,7 +1701,7 @@ class Session(object):
1563
1701
  ):
1564
1702
  return 0
1565
1703
 
1566
- raise RuntimeError(str(status.code) + ": " + status.message)
1704
+ raise RuntimeError(f"{status.code}: {status.message}")
1567
1705
 
1568
1706
  @staticmethod
1569
1707
  def verify_success_by_list(status_list: list):
@@ -1571,14 +1709,15 @@ class Session(object):
1571
1709
  verify success of operation
1572
1710
  :param status_list: execution result status
1573
1711
  """
1574
- message = str(Session.MULTIPLE_ERROR) + ": "
1575
- for status in status_list:
1576
- if (
1577
- status.code != Session.SUCCESS_STATUS
1578
- and status.code != Session.REDIRECTION_RECOMMEND
1579
- ):
1580
- message += status.message + "; "
1581
- raise RuntimeError(message)
1712
+ error_messages = [
1713
+ status.message
1714
+ for status in status_list
1715
+ if status.code
1716
+ not in {Session.SUCCESS_STATUS, Session.REDIRECTION_RECOMMEND}
1717
+ ]
1718
+ if error_messages:
1719
+ message = f"{Session.MULTIPLE_ERROR}: {'; '.join(error_messages)}"
1720
+ raise RuntimeError(message)
1582
1721
 
1583
1722
  @staticmethod
1584
1723
  def verify_success_with_redirection(status: TSStatus):
@@ -1879,6 +2018,49 @@ class Session(object):
1879
2018
  )
1880
2019
  return request
1881
2020
 
2021
+ def __has_none_value(self, values_list) -> bool:
2022
+ for item in values_list:
2023
+ if isinstance(item, list):
2024
+ if self.__has_none_value(item):
2025
+ return True
2026
+ elif item is None:
2027
+ return True
2028
+ return False
2029
+
2030
+ @staticmethod
2031
+ def __filter_lists_by_values(
2032
+ device_lst, time_lst, measurements_lst, types_lst, values_lst
2033
+ ):
2034
+ filtered_devices = []
2035
+ filtered_times = []
2036
+ filtered_measurements = []
2037
+ filtered_types = []
2038
+ filtered_values = []
2039
+
2040
+ for device, time_, measurements, types, values in zip(
2041
+ device_lst, time_lst, measurements_lst, types_lst, values_lst
2042
+ ):
2043
+ filtered_row = [
2044
+ (m, t, v)
2045
+ for m, t, v in zip(measurements, types, values)
2046
+ if v is not None
2047
+ ]
2048
+ if filtered_row:
2049
+ f_measurements, f_types, f_values = zip(*filtered_row)
2050
+ filtered_measurements.append(list(f_measurements))
2051
+ filtered_types.append(list(f_types))
2052
+ filtered_values.append(list(f_values))
2053
+ filtered_devices.append(device)
2054
+ filtered_times.append(time_)
2055
+
2056
+ return (
2057
+ filtered_devices,
2058
+ filtered_times,
2059
+ filtered_measurements,
2060
+ filtered_types,
2061
+ filtered_values,
2062
+ )
2063
+
1882
2064
  def create_schema_template(self, template: Template):
1883
2065
  warnings.warn(
1884
2066
  "The APIs about template are deprecated and will be removed in future versions. Use sql instead.",
@@ -2290,6 +2472,17 @@ class SessionConnection(object):
2290
2472
  self.session_id = session_id
2291
2473
  self.statement_id = statement_id
2292
2474
 
2475
+ def change_database(self, sql):
2476
+ try:
2477
+ self.client.executeUpdateStatement(
2478
+ TSExecuteStatementReq(self.session_id, sql, self.statement_id)
2479
+ )
2480
+ except TTransport.TException as e:
2481
+ raise IoTDBConnectionException(
2482
+ "failed to change database",
2483
+ e,
2484
+ ) from None
2485
+
2293
2486
  def close_connection(self, req):
2294
2487
  try:
2295
2488
  self.client.closeSession(req)
iotdb/SessionPool.py CHANGED
@@ -27,6 +27,7 @@ DEFAULT_MULTIPIE = 5
27
27
  DEFAULT_FETCH_SIZE = 5000
28
28
  DEFAULT_MAX_RETRY = 3
29
29
  DEFAULT_TIME_ZONE = "UTC+8"
30
+ SQL_DIALECT = "tree"
30
31
  logger = logging.getLogger("IoTDB")
31
32
 
32
33
 
@@ -42,6 +43,7 @@ class PoolConfig(object):
42
43
  time_zone: str = DEFAULT_TIME_ZONE,
43
44
  max_retry: int = DEFAULT_MAX_RETRY,
44
45
  enable_compression: bool = False,
46
+ enable_redirection: bool = True,
45
47
  use_ssl: bool = False,
46
48
  ca_certs: str = None,
47
49
  connection_timeout_in_ms: int = None,
@@ -61,6 +63,7 @@ class PoolConfig(object):
61
63
  self.time_zone = time_zone
62
64
  self.max_retry = max_retry
63
65
  self.enable_compression = enable_compression
66
+ self.enable_redirection = enable_redirection
64
67
  self.use_ssl = use_ssl
65
68
  self.ca_certs = ca_certs
66
69
  self.connection_timeout_in_ms = connection_timeout_in_ms
@@ -77,6 +80,8 @@ class SessionPool(object):
77
80
  self.__queue = Queue(max_pool_size)
78
81
  self.__lock = Lock()
79
82
  self.__closed = False
83
+ self.sql_dialect = SQL_DIALECT
84
+ self.database = None
80
85
 
81
86
  def __construct_session(self) -> Session:
82
87
  if len(self.__pool_config.node_urls) > 0:
@@ -86,10 +91,13 @@ class SessionPool(object):
86
91
  self.__pool_config.password,
87
92
  self.__pool_config.fetch_size,
88
93
  self.__pool_config.time_zone,
94
+ enable_redirection=self.__pool_config.enable_redirection,
89
95
  use_ssl=self.__pool_config.use_ssl,
90
96
  ca_certs=self.__pool_config.ca_certs,
91
97
  connection_timeout_in_ms=self.__pool_config.connection_timeout_in_ms,
92
98
  )
99
+ session.sql_dialect = self.sql_dialect
100
+ session.database = self.database
93
101
 
94
102
  else:
95
103
  session = Session(
@@ -99,10 +107,13 @@ class SessionPool(object):
99
107
  self.__pool_config.password,
100
108
  self.__pool_config.fetch_size,
101
109
  self.__pool_config.time_zone,
110
+ enable_redirection=self.__pool_config.enable_redirection,
102
111
  use_ssl=self.__pool_config.use_ssl,
103
112
  ca_certs=self.__pool_config.ca_certs,
104
113
  connection_timeout_in_ms=self.__pool_config.connection_timeout_in_ms,
105
114
  )
115
+ session.sql_dialect = self.sql_dialect
116
+ session.database = self.database
106
117
 
107
118
  session.open(self.__pool_config.enable_compression)
108
119
  return session
@@ -114,6 +125,7 @@ class SessionPool(object):
114
125
  return q
115
126
 
116
127
  def get_session(self) -> Session:
128
+
117
129
  if self.__closed:
118
130
  raise ConnectionError("SessionPool has already been closed.")
119
131
 
@@ -148,6 +160,7 @@ class SessionPool(object):
148
160
  return session
149
161
 
150
162
  def put_back(self, session: Session):
163
+
151
164
  if self.__closed:
152
165
  raise ConnectionError(
153
166
  "SessionPool has already been closed, please close the session manually."
@@ -160,6 +173,7 @@ class SessionPool(object):
160
173
  self.__pool_size -= 1
161
174
 
162
175
  def close(self):
176
+
163
177
  with self.__lock:
164
178
  while not self.__queue.empty():
165
179
  session = self.__queue.get(block=False)