apache-iotdb 2.0.10__py3-none-any.whl → 2.0.12__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apache-iotdb
3
- Version: 2.0.10
3
+ Version: 2.0.12
4
4
  Summary: Apache IoTDB client API
5
5
  Author-email: Apache IoTDB <dev@iotdb.apache.org>
6
6
  License-Expression: Apache-2.0
@@ -112,6 +112,40 @@ Notice: this RPC compression status of client must comply with that of IoTDB ser
112
112
  session.close()
113
113
  ```
114
114
 
115
+ ### SSL and Mutual TLS
116
+
117
+ Use `use_ssl=True` and `ca_certs` to enable SSL and verify the server certificate.
118
+
119
+ ```python
120
+ session = Session(
121
+ ip,
122
+ port_,
123
+ username_,
124
+ password_,
125
+ use_ssl=True,
126
+ ca_certs="/path/ca.crt",
127
+ )
128
+ ```
129
+
130
+ When the server enables Thrift mutual TLS, also configure a client certificate and an unencrypted PEM private key.
131
+
132
+ ```python
133
+ session = Session(
134
+ ip,
135
+ port_,
136
+ username_,
137
+ password_,
138
+ use_ssl=True,
139
+ ca_certs="/path/ca.crt",
140
+ client_cert="/path/client.crt",
141
+ client_key="/path/client.key",
142
+ )
143
+ ```
144
+
145
+ `client_cert` and `client_key` must be set together. `client_key` should be protected by file permissions because encrypted private keys are not supported by this client API.
146
+
147
+ The same SSL parameters are available in `PoolConfig`, `TableSessionConfig`, `TableSessionPoolConfig`, and DBAPI `connect`.
148
+
115
149
  ### Data Definition Interface (DDL Interface)
116
150
 
117
151
  #### DATABASE Management
@@ -628,5 +662,3 @@ Namely, these are
628
662
  * Release to pypi
629
663
 
630
664
 
631
-
632
-
@@ -1,9 +1,9 @@
1
- iotdb/Session.py,sha256=L26uKpMG5LyiXJfvWVFIr0hpDdBNv6StmMMN82XNXtA,102601
2
- iotdb/SessionPool.py,sha256=vBy8vG7fmuDexGPzVqQhM8pWjKLrczN0na1OD-hFDnY,6674
1
+ iotdb/Session.py,sha256=uTfPey1dUefmX_C6s-3zN4QVa9K_7shnvrvF41fp-qE,106381
2
+ iotdb/SessionPool.py,sha256=bF4_xv-rBvWVlkHEwh3nqHA8Dqlduduyl0HM5FOT8V0,7051
3
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
6
- iotdb/dbapi/Connection.py,sha256=t5CuwOTrMJxJ2YVxaEKi2fdaH9Vob-u7nQRCD_9vLcg,2569
4
+ iotdb/table_session.py,sha256=MbPOI80uqkewLrjU1WM1Eg9ykgU4dt4mTwAEBJMwUes,6436
5
+ iotdb/table_session_pool.py,sha256=VZtkmk3WOjkJNGgb9mSJCiF6QpfygMZoX0ZHPB7QneU,5466
6
+ iotdb/dbapi/Connection.py,sha256=vEH41ytAvC-ojwL9KS7aVRv73X62pdlmBcTj3iRQiVA,3421
7
7
  iotdb/dbapi/Cursor.py,sha256=CBFyHsk7cOxLJEwCWMJK0r4guXQ-OkNh39H54cyyH5k,9110
8
8
  iotdb/dbapi/Exceptions.py,sha256=X3qhGXQ_rNL7998DQwFeQc9cG5ByXlfhIQx2sBHOiuw,1278
9
9
  iotdb/dbapi/__init__.py,sha256=98jGNzw_AI1iqbYbUxGRg4Yd92Uo63S1v143_NnKKCs,953
@@ -19,21 +19,21 @@ iotdb/template/TemplateQueryType.py,sha256=6bNiydOiIqFnzutiuxdpWrOm-z9CkSawMCd_5
19
19
  iotdb/template/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
20
20
  iotdb/thrift/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  iotdb/thrift/common/__init__.py,sha256=YFcZTT8Cm-6Y4oTiCaqq0DT1lw2W09WqoEc5_pTAwW0,34
22
- iotdb/thrift/common/constants.py,sha256=IKRM8SpfhYWXERWBgUbUhbdFpn363hmZjXDhEYnVRbw,366
23
- iotdb/thrift/common/ttypes.py,sha256=nLrXuSIWzAsopKtXRvXRsLSvc8x3HovlW55ZQ8Wm2rs,135135
24
- iotdb/thrift/confignode/IConfigNodeRPCService.py,sha256=ojECQ9k3Ekl2cfBvnIWhTfpjyWvR2_AiOfb1PFJ-ElQ,1022990
22
+ iotdb/thrift/common/constants.py,sha256=J1z6mszd_3klwrgFDNrNEiMClInMP87lx5NVK017ckk,388
23
+ iotdb/thrift/common/ttypes.py,sha256=x1x2pfSL8LoX2hOAgHiAzMqfeOdgGBgsS5wHiamKocM,145989
24
+ iotdb/thrift/confignode/IConfigNodeRPCService.py,sha256=_jbA8_IKl_tQnDXzizDWekIkKaUddFPObxLduIc3wfk,1064170
25
25
  iotdb/thrift/confignode/__init__.py,sha256=_SxvW-9GzGZcPWR-szpFI_VrvxJvSfjwu8HEieGWtik,59
26
- iotdb/thrift/confignode/constants.py,sha256=IKRM8SpfhYWXERWBgUbUhbdFpn363hmZjXDhEYnVRbw,366
27
- iotdb/thrift/confignode/ttypes.py,sha256=VIfIoHbm7m7KDFIZujWyecKSiaRUZmqqXfqtSSKiAno,737491
28
- iotdb/thrift/datanode/IDataNodeRPCService.py,sha256=wUiVCAYnl6N-YJ1Mh6b_ImEBPbJpQ5-rIq_5sHwyym4,676639
29
- iotdb/thrift/datanode/MPPDataExchangeService.py,sha256=MHHkiEUu7E4Kt0BNN3maaMgvAdNPye4ZDQ8NZ0kdOKI,35354
26
+ iotdb/thrift/confignode/constants.py,sha256=J1z6mszd_3klwrgFDNrNEiMClInMP87lx5NVK017ckk,388
27
+ iotdb/thrift/confignode/ttypes.py,sha256=fwwRvgVQXVLW8ZUWiVPqw5IdHaAcZyUOgkF_GG8SfA8,780180
28
+ iotdb/thrift/datanode/IDataNodeRPCService.py,sha256=SoKoCuNPLwTafYeokBs-jbYCerZ9p5Dsb6TASY9pTPE,725380
29
+ iotdb/thrift/datanode/MPPDataExchangeService.py,sha256=C5sAIRBNTYzpFJUvIclOfFTQSF9odRMuNOS-DpLlssg,49845
30
30
  iotdb/thrift/datanode/__init__.py,sha256=J5dw3MYQMv2wUCQqOxUUdaNrCJP8j3Iy80Fv-PJ70S4,83
31
- iotdb/thrift/datanode/constants.py,sha256=IKRM8SpfhYWXERWBgUbUhbdFpn363hmZjXDhEYnVRbw,366
32
- iotdb/thrift/datanode/ttypes.py,sha256=1RFKVKIDV2vJHkcaFRLM7zZauYsXweZGgOzvLYhcUWU,490539
33
- iotdb/thrift/rpc/IClientRPCService.py,sha256=ABHZbDroaOZbY5GNkgtQLoDHWci605HKR3FpSbCfcwU,435488
31
+ iotdb/thrift/datanode/constants.py,sha256=J1z6mszd_3klwrgFDNrNEiMClInMP87lx5NVK017ckk,388
32
+ iotdb/thrift/datanode/ttypes.py,sha256=r30Gp93OA0311ghyhpsrMJ8gEyiJ7_bGzorwtQVvQjQ,542556
33
+ iotdb/thrift/rpc/IClientRPCService.py,sha256=grGLFvdVqy2KZ0k944kLRSolBSnfcuZNNvCwoHxdHQ4,442270
34
34
  iotdb/thrift/rpc/__init__.py,sha256=69gRO2XxQu71SDeCRxiZFjK6Xw_61hdl5MdWceI-e1A,55
35
- iotdb/thrift/rpc/constants.py,sha256=IKRM8SpfhYWXERWBgUbUhbdFpn363hmZjXDhEYnVRbw,366
36
- iotdb/thrift/rpc/ttypes.py,sha256=x5i3R9wH5hi9fQjn6vxWQ5EThnRh8Vl6noWGNkKsxRE,315420
35
+ iotdb/thrift/rpc/constants.py,sha256=J1z6mszd_3klwrgFDNrNEiMClInMP87lx5NVK017ckk,388
36
+ iotdb/thrift/rpc/ttypes.py,sha256=IWeKtBMX9_RKhr-ahTN89MW0N9PlB3CE69VdCKyH20Q,318790
37
37
  iotdb/tsfile/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
38
38
  iotdb/tsfile/common/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
39
39
  iotdb/tsfile/common/constant/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
@@ -43,17 +43,18 @@ iotdb/tsfile/utils/date_utils.py,sha256=Z31FexAA_pR72X2PDLT6pVJOFRWguIAEUjOyAwji
43
43
  iotdb/tsfile/utils/pair.py,sha256=91ecijUAlEiMRLlH2hjRi_mT_xWp6Vm-R3n4Z4USFqQ,952
44
44
  iotdb/tsfile/utils/read_write_io_utils.py,sha256=31CKH_1XWz8xc7DyInKaD-avkY-hVqNQILDb5PMucm4,2977
45
45
  iotdb/tsfile/utils/tsblock_serde.py,sha256=V8Lcr_umGL7wL3-6-NScUfcRiRCVGTJX2bNiUQSCAq0,8749
46
- iotdb/utils/BitMap.py,sha256=dGvruuvDJlT4KH7pIrkprZWsY_AG-P8HXe6JHBKDOpI,1436
46
+ iotdb/utils/BitMap.py,sha256=zOlV3ffFsu7kvlUa4ezME8slO9VhhIEu3JVZEwwOsZw,2806
47
47
  iotdb/utils/Field.py,sha256=irpHFsp4FrD2sk17uEOHLFglsE0wyFenJImY3yV6FKg,8240
48
48
  iotdb/utils/IoTDBConstants.py,sha256=mOXYQvaOccFS0cOUEqSXgZ3qSjhe6K8_sIjTT9S6qaI,1950
49
49
  iotdb/utils/NumpyTablet.py,sha256=qfRVenLhXnOlpgpfRCvvqfHbmcEkLaNP57tbe0JNb1o,7951
50
50
  iotdb/utils/RowRecord.py,sha256=TIfQzMdi84GhGGIfVcZ-kvmm7aQwsDWge2kY00sf1lo,1690
51
51
  iotdb/utils/SessionDataSet.py,sha256=wU2fa4xlU8T5NSRPNLeRn5z9df8A5DCru4IO_CmqzXg,6573
52
- iotdb/utils/Tablet.py,sha256=HOYPSV1vyTB79T3e8rsHBN6ZiZJm_rFutEIOI8nDcDk,10198
52
+ iotdb/utils/SessionUtils.py,sha256=UVAs-8QiMAB_cb1bhm-lfhNbzD2bfadfRUwi11aSdSo,4224
53
+ iotdb/utils/Tablet.py,sha256=bi6f6pc_I4Tu8PCXj5Khfkh5FYf-vBkGeLcNJ6bwvMg,10318
53
54
  iotdb/utils/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
54
55
  iotdb/utils/exception.py,sha256=iCSzBE2Cy1q_OwC3nHdGH-OnGuwy0iPRY63VQvO8fcg,1834
55
56
  iotdb/utils/iotdb_rpc_dataset.py,sha256=SyzpddGVTQTaFb_OMmf3xWN6ojv_rcBoFwe5wUZvbKM,19165
56
- iotdb/utils/rpc_utils.py,sha256=3RlCaaVViiIAoU8fg47oTYJqYNZWQHJpLcGvUTuw4JM,5889
57
+ iotdb/utils/rpc_utils.py,sha256=XfKhoEv6jJ4e-eeuIxCMwFwP8cSTPS6bQY3mYi5gRbg,6112
57
58
  tests/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
58
59
  tests/integration/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
59
60
  tests/integration/iotdb_container.py,sha256=nDBwiFwTETVisgVAOpjhECdHdgSfO8i_4k0wOrFmIU0,2551
@@ -78,8 +79,13 @@ tests/integration/sqlalchemy/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a
78
79
  tests/integration/sqlalchemy/test_dialect.py,sha256=HF2lJuV19l4Kfi7u3ZQ5vCFtu-xd3U8EFkgjXvJTi9o,3767
79
80
  tests/unit/__init__.py,sha256=vGVFsdMOp1iKaCQl5rfYcPVa0FV94d-a7MsMDQDhHMc,789
80
81
  tests/unit/test_numpy_tablet.py,sha256=w3lLK8Cft7lGsCj_6Z1Y7kDshltN0osSDJb-EESi6_Y,7235
81
- apache_iotdb-2.0.10.dist-info/METADATA,sha256=H-_9dmV5ep2_RoZIXAa9AqyhG3gJ63ars5QIHE6sJmo,18770
82
- apache_iotdb-2.0.10.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
83
- apache_iotdb-2.0.10.dist-info/entry_points.txt,sha256=BmQWy6NHyWXorQcVm8-VWpt9MSqe46UFyV2hnsl4yok,73
84
- apache_iotdb-2.0.10.dist-info/top_level.txt,sha256=B9jGGOaAAqF1WrWw2jX2K-naWAZn2nhyrL-6hM1qwyM,12
85
- apache_iotdb-2.0.10.dist-info/RECORD,,
82
+ tests/unit/test_rpc_utils.py,sha256=JxIzKEyFHNA9KftCTgVPQGrIdsxNYQZl4pZXxb37Lf4,2359
83
+ tests/unit/test_session_connection.py,sha256=W6anKyz30bhdeN8JqrEtPUIbQAlTTdQumr4NU54RBv0,3576
84
+ tests/unit/test_session_node_url.py,sha256=x06jAMj1qZScJSQyY_2TOQNMtHm8umZu0RNWORqNjyY,2254
85
+ tests/unit/test_session_ssl.py,sha256=sGYz-9HxDNuJh2gfms58ASFYC7I54qAGj5vYFKyLdOQ,4764
86
+ tests/unit/test_session_utils.py,sha256=Se7kvPwzpiA4tX_6ygCGMqJdsiVC9yNPMHIqbKSabrk,5072
87
+ apache_iotdb-2.0.12.dist-info/METADATA,sha256=YHDLiFolJOf8HpMGdPce_4QURygfpDRiWoSZGpdqkSM,19628
88
+ apache_iotdb-2.0.12.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
89
+ apache_iotdb-2.0.12.dist-info/entry_points.txt,sha256=BmQWy6NHyWXorQcVm8-VWpt9MSqe46UFyV2hnsl4yok,73
90
+ apache_iotdb-2.0.12.dist-info/top_level.txt,sha256=B9jGGOaAAqF1WrWw2jX2K-naWAZn2nhyrL-6hM1qwyM,12
91
+ apache_iotdb-2.0.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (83.0.0)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
iotdb/Session.py CHANGED
@@ -16,48 +16,51 @@
16
16
  # under the License.
17
17
  #
18
18
 
19
+ import ipaddress
19
20
  import logging
20
21
  import random
21
- import sys
22
22
  import struct
23
+ import sys
23
24
  import warnings
25
+
26
+ from iotdb.utils.SessionDataSet import SessionDataSet
27
+ from iotdb.utils.SessionUtils import filter_null_columns
24
28
  from thrift.protocol import TBinaryProtocol, TCompactProtocol
25
29
  from thrift.transport import TSocket, TTransport
26
30
  from tzlocal import get_localzone_name
27
31
 
28
- from iotdb.utils.SessionDataSet import SessionDataSet
29
32
  from .template.Template import Template
30
33
  from .template.TemplateQueryType import TemplateQueryType
31
34
  from .thrift.common.ttypes import TEndPoint
32
35
  from .thrift.rpc.IClientRPCService import (
33
36
  Client,
34
- TSCreateTimeseriesReq,
37
+ TSAppendSchemaTemplateReq,
38
+ TSCloseSessionReq,
35
39
  TSCreateAlignedTimeseriesReq,
40
+ TSCreateMultiTimeseriesReq,
41
+ TSCreateSchemaTemplateReq,
42
+ TSCreateTimeseriesReq,
43
+ TSDropSchemaTemplateReq,
44
+ TSExecuteStatementReq,
36
45
  TSInsertRecordReq,
46
+ TSInsertRecordsOfOneDeviceReq,
47
+ TSInsertRecordsReq,
37
48
  TSInsertStringRecordReq,
38
49
  TSInsertTabletReq,
39
- TSExecuteStatementReq,
40
- TSOpenSessionReq,
41
- TSCreateMultiTimeseriesReq,
42
- TSCloseSessionReq,
43
50
  TSInsertTabletsReq,
44
- TSInsertRecordsReq,
45
- TSInsertRecordsOfOneDeviceReq,
46
- TSCreateSchemaTemplateReq,
47
- TSDropSchemaTemplateReq,
48
- TSAppendSchemaTemplateReq,
51
+ TSOpenSessionReq,
49
52
  TSPruneSchemaTemplateReq,
53
+ TSQueryTemplateReq,
50
54
  TSSetSchemaTemplateReq,
51
55
  TSUnsetSchemaTemplateReq,
52
- TSQueryTemplateReq,
53
56
  )
54
57
  from .thrift.rpc.ttypes import (
55
58
  TSDeleteDataReq,
59
+ TSInsertStringRecordsOfOneDeviceReq,
60
+ TSLastDataQueryReq,
56
61
  TSProtocolVersion,
57
- TSSetTimeZoneReq,
58
62
  TSRawDataQueryReq,
59
- TSLastDataQueryReq,
60
- TSInsertStringRecordsOfOneDeviceReq,
63
+ TSSetTimeZoneReq,
61
64
  )
62
65
  from .tsfile.utils.date_utils import parse_date_to_int
63
66
  from .utils import rpc_utils
@@ -67,6 +70,48 @@ logger = logging.getLogger("IoTDB")
67
70
  warnings.simplefilter("always", DeprecationWarning)
68
71
 
69
72
 
73
+ def _parse_endpoint_url(endpoint_url):
74
+ if endpoint_url.startswith("["):
75
+ end_index = endpoint_url.find("]")
76
+ if end_index <= 1 or end_index + 1 >= len(endpoint_url):
77
+ raise RuntimeError("invalid node url: {}".format(endpoint_url))
78
+ if endpoint_url[end_index + 1] != ":":
79
+ raise RuntimeError("invalid node url: {}".format(endpoint_url))
80
+ return endpoint_url[1:end_index], _parse_endpoint_port(
81
+ endpoint_url, endpoint_url[end_index + 2 :]
82
+ )
83
+
84
+ if "[" in endpoint_url or "]" in endpoint_url:
85
+ raise RuntimeError("invalid node url: {}".format(endpoint_url))
86
+ split = endpoint_url.rsplit(":", 1)
87
+ if len(split) != 2:
88
+ raise RuntimeError("invalid node url: {}".format(endpoint_url))
89
+ return split[0], _parse_endpoint_port(endpoint_url, split[1])
90
+
91
+
92
+ def _parse_endpoint_port(endpoint_url, port):
93
+ try:
94
+ return int(port)
95
+ except ValueError as e:
96
+ raise RuntimeError("invalid node url: {}".format(endpoint_url)) from e
97
+
98
+
99
+ def _is_wildcard_address(host):
100
+ if host is None:
101
+ return False
102
+ normalized_host = host
103
+ if normalized_host.startswith("[") and normalized_host.endswith("]"):
104
+ normalized_host = normalized_host[1:-1]
105
+ if normalized_host == "0.0.0.0":
106
+ return True
107
+ if ":" not in normalized_host:
108
+ return False
109
+ try:
110
+ return ipaddress.ip_address(normalized_host).is_unspecified
111
+ except ValueError:
112
+ return False
113
+
114
+
70
115
  class Session(object):
71
116
  DEFAULT_FETCH_SIZE = 5000
72
117
  DEFAULT_USER = "root"
@@ -87,6 +132,8 @@ class Session(object):
87
132
  use_ssl=False,
88
133
  ca_certs=None,
89
134
  connection_timeout_in_ms=None,
135
+ client_cert=None,
136
+ client_key=None,
90
137
  ):
91
138
  self.__host = host
92
139
  self.__port = port
@@ -117,6 +164,8 @@ class Session(object):
117
164
  self.database = None
118
165
  self.__use_ssl = use_ssl
119
166
  self.__ca_certs = ca_certs
167
+ self.__client_cert = client_cert
168
+ self.__client_key = client_key
120
169
  self.__connection_timeout_in_ms = connection_timeout_in_ms
121
170
  self.__time_precision = "ms"
122
171
 
@@ -132,6 +181,8 @@ class Session(object):
132
181
  use_ssl=False,
133
182
  ca_certs=None,
134
183
  connection_timeout_in_ms=None,
184
+ client_cert=None,
185
+ client_key=None,
135
186
  ):
136
187
  if node_urls is None:
137
188
  raise RuntimeError("node urls is empty")
@@ -145,14 +196,16 @@ class Session(object):
145
196
  enable_redirection,
146
197
  use_ssl=use_ssl,
147
198
  ca_certs=ca_certs,
199
+ client_cert=client_cert,
200
+ client_key=client_key,
148
201
  connection_timeout_in_ms=connection_timeout_in_ms,
149
202
  )
150
203
  session.__hosts = []
151
204
  session.__ports = []
152
205
  for node_url in node_urls:
153
- split = node_url.split(":")
154
- session.__hosts.append(split[0])
155
- session.__ports.append(int(split[1]))
206
+ host, port = _parse_endpoint_url(node_url)
207
+ session.__hosts.append(host)
208
+ session.__ports.append(port)
156
209
  session.__host = session.__hosts[0]
157
210
  session.__port = session.__ports[0]
158
211
  session.__default_endpoint = TEndPoint(session.__host, session.__port)
@@ -171,7 +224,7 @@ class Session(object):
171
224
  self.__default_connection = self.init_connection(
172
225
  self.__default_endpoint
173
226
  )
174
- except Exception as e:
227
+ except IoTDBConnectionException as e:
175
228
  if not self.reconnect():
176
229
  if str(e).startswith("Could not connect to any of"):
177
230
  error_msg = (
@@ -232,9 +285,12 @@ class Session(object):
232
285
  session_id = open_resp.sessionId
233
286
  statement_id = client.requestStatementId(session_id)
234
287
 
235
- except Exception as e:
288
+ except TTransport.TTransportException as e:
236
289
  transport.close()
237
290
  raise IoTDBConnectionException(e) from None
291
+ except Exception:
292
+ transport.close()
293
+ raise
238
294
 
239
295
  if self.__zone_id is not None:
240
296
  request = TSSetTimeZoneReq(session_id, self.__zone_id)
@@ -251,6 +307,7 @@ class Session(object):
251
307
  def __get_transport(self, endpoint):
252
308
  if self.__use_ssl:
253
309
  import ssl
310
+
254
311
  from thrift.transport import TSSLSocket
255
312
 
256
313
  if sys.version_info >= (3, 10):
@@ -259,7 +316,21 @@ class Session(object):
259
316
  context = ssl.SSLContext(ssl.PROTOCOL_TLS)
260
317
  context.verify_mode = ssl.CERT_REQUIRED
261
318
  context.check_hostname = True
262
- context.load_verify_locations(cafile=self.__ca_certs)
319
+ context.load_default_certs(ssl.Purpose.SERVER_AUTH)
320
+ if self.__has_text(self.__ca_certs):
321
+ context.load_verify_locations(cafile=self.__ca_certs)
322
+ if self.__has_text(self.__client_cert) or self.__has_text(
323
+ self.__client_key
324
+ ):
325
+ if not self.__has_text(self.__client_cert) or not self.__has_text(
326
+ self.__client_key
327
+ ):
328
+ raise TTransport.TTransportException(
329
+ message="client_cert and client_key must be set together."
330
+ )
331
+ context.load_cert_chain(
332
+ certfile=self.__client_cert, keyfile=self.__client_key
333
+ )
263
334
  socket = TSSLSocket.TSSLSocket(
264
335
  host=endpoint.ip, port=endpoint.port, ssl_context=context
265
336
  )
@@ -275,6 +346,10 @@ class Session(object):
275
346
  raise IoTDBConnectionException(e) from None
276
347
  return transport
277
348
 
349
+ @staticmethod
350
+ def __has_text(value):
351
+ return value is not None and str(value).strip() != ""
352
+
278
353
  def is_open(self):
279
354
  return not self.__is_close
280
355
 
@@ -1021,6 +1096,8 @@ class Session(object):
1021
1096
  :param tablet: a tablet specified above
1022
1097
  """
1023
1098
  request = self.gen_insert_tablet_req(tablet)
1099
+ if request is None:
1100
+ return
1024
1101
  try:
1025
1102
  connection = self.get_connection(tablet.get_insert_target_name())
1026
1103
  request.sessionId = connection.session_id
@@ -1049,19 +1126,24 @@ class Session(object):
1049
1126
  if self.__enable_redirection:
1050
1127
  request_group = {}
1051
1128
  for i in range(len(tablet_lst)):
1052
- connection = self.get_connection(tablet_lst[i].get_insert_target_name())
1129
+ filtered = filter_null_columns(tablet_lst[i])
1130
+ if filtered is None:
1131
+ continue
1132
+ connection = self.get_connection(filtered.get_insert_target_name())
1053
1133
  request = request_group.setdefault(
1054
1134
  connection.client,
1055
1135
  TSInsertTabletsReq(
1056
1136
  connection.session_id, [], [], [], [], [], [], False
1057
1137
  ),
1058
1138
  )
1059
- request.prefixPaths.append(tablet_lst[i].get_insert_target_name())
1060
- request.timestampsList.append(tablet_lst[i].get_binary_timestamps())
1061
- request.measurementsList.append(tablet_lst[i].get_measurements())
1062
- request.valuesList.append(tablet_lst[i].get_binary_values())
1063
- request.sizeList.append(tablet_lst[i].get_row_number())
1064
- request.typesList.append(tablet_lst[i].get_data_types())
1139
+ request.prefixPaths.append(filtered.get_insert_target_name())
1140
+ request.timestampsList.append(filtered.get_binary_timestamps())
1141
+ request.measurementsList.append(filtered.get_measurements())
1142
+ request.valuesList.append(filtered.get_binary_values())
1143
+ request.sizeList.append(filtered.get_row_number())
1144
+ request.typesList.append(filtered.get_data_types())
1145
+ if not request_group:
1146
+ return 0
1065
1147
  for client, request in request_group.items():
1066
1148
  try:
1067
1149
  rpc_utils.verify_success_with_redirection_for_multi_devices(
@@ -1087,6 +1169,8 @@ class Session(object):
1087
1169
  return 0
1088
1170
  else:
1089
1171
  request = self.gen_insert_tablets_req(tablet_lst)
1172
+ if request is None:
1173
+ return 0
1090
1174
  try:
1091
1175
  return rpc_utils.verify_success(self.__client.insertTablets(request))
1092
1176
  except TTransport.TException as e:
@@ -1116,6 +1200,8 @@ class Session(object):
1116
1200
  :param tablet: a tablet specified above
1117
1201
  """
1118
1202
  request = self.gen_insert_tablet_req(tablet, True)
1203
+ if request is None:
1204
+ return
1119
1205
  try:
1120
1206
  connection = self.get_connection(tablet.get_insert_target_name())
1121
1207
  request.sessionId = connection.session_id
@@ -1144,19 +1230,24 @@ class Session(object):
1144
1230
  if self.__enable_redirection:
1145
1231
  request_group = {}
1146
1232
  for i in range(len(tablet_lst)):
1147
- connection = self.get_connection(tablet_lst[i].get_insert_target_name())
1233
+ filtered = filter_null_columns(tablet_lst[i])
1234
+ if filtered is None:
1235
+ continue
1236
+ connection = self.get_connection(filtered.get_insert_target_name())
1148
1237
  request = request_group.setdefault(
1149
1238
  connection.client,
1150
1239
  TSInsertTabletsReq(
1151
1240
  connection.session_id, [], [], [], [], [], [], True
1152
1241
  ),
1153
1242
  )
1154
- request.prefixPaths.append(tablet_lst[i].get_insert_target_name())
1155
- request.timestampsList.append(tablet_lst[i].get_binary_timestamps())
1156
- request.measurementsList.append(tablet_lst[i].get_measurements())
1157
- request.valuesList.append(tablet_lst[i].get_binary_values())
1158
- request.sizeList.append(tablet_lst[i].get_row_number())
1159
- request.typesList.append(tablet_lst[i].get_data_types())
1243
+ request.prefixPaths.append(filtered.get_insert_target_name())
1244
+ request.timestampsList.append(filtered.get_binary_timestamps())
1245
+ request.measurementsList.append(filtered.get_measurements())
1246
+ request.valuesList.append(filtered.get_binary_values())
1247
+ request.sizeList.append(filtered.get_row_number())
1248
+ request.typesList.append(filtered.get_data_types())
1249
+ if not request_group:
1250
+ return 0
1160
1251
  for client, request in request_group.items():
1161
1252
  try:
1162
1253
  rpc_utils.verify_success_with_redirection_for_multi_devices(
@@ -1182,6 +1273,8 @@ class Session(object):
1182
1273
  return 0
1183
1274
  else:
1184
1275
  request = self.gen_insert_tablets_req(tablet_lst, True)
1276
+ if request is None:
1277
+ return 0
1185
1278
  try:
1186
1279
  return rpc_utils.verify_success(self.__client.insertTablets(request))
1187
1280
  except TTransport.TException as e:
@@ -1208,6 +1301,8 @@ class Session(object):
1208
1301
  :param tablet: a tablet specified above
1209
1302
  """
1210
1303
  request = self.gen_insert_relational_tablet_req(tablet)
1304
+ if request is None:
1305
+ return
1211
1306
  try:
1212
1307
  connection = self.get_connection(tablet.get_insert_target_name())
1213
1308
  request.sessionId = connection.session_id
@@ -1406,6 +1501,8 @@ class Session(object):
1406
1501
  :param tablet: a tablet of data
1407
1502
  """
1408
1503
  request = self.gen_insert_tablet_req(tablet)
1504
+ if request is None:
1505
+ return
1409
1506
  try:
1410
1507
  return rpc_utils.verify_success(self.__client.testInsertTablet(request))
1411
1508
  except TTransport.TException as e:
@@ -1427,6 +1524,8 @@ class Session(object):
1427
1524
  :param tablet_list: List of tablets
1428
1525
  """
1429
1526
  request = self.gen_insert_tablets_req(tablet_list)
1527
+ if request is None:
1528
+ return
1430
1529
  try:
1431
1530
  return rpc_utils.verify_success(self.__client.testInsertTablets(request))
1432
1531
  except TTransport.TException as e:
@@ -1442,29 +1541,35 @@ class Session(object):
1442
1541
  raise IoTDBConnectionException(self.connection_error_msg()) from None
1443
1542
 
1444
1543
  def gen_insert_tablet_req(self, tablet, is_aligned=False):
1544
+ filtered = filter_null_columns(tablet)
1545
+ if filtered is None:
1546
+ return None
1445
1547
  return TSInsertTabletReq(
1446
1548
  self.__session_id,
1447
- tablet.get_insert_target_name(),
1448
- tablet.get_measurements(),
1449
- tablet.get_binary_values(),
1450
- tablet.get_binary_timestamps(),
1451
- tablet.get_data_types(),
1452
- tablet.get_row_number(),
1549
+ filtered.get_insert_target_name(),
1550
+ filtered.get_measurements(),
1551
+ filtered.get_binary_values(),
1552
+ filtered.get_binary_timestamps(),
1553
+ filtered.get_data_types(),
1554
+ filtered.get_row_number(),
1453
1555
  is_aligned,
1454
1556
  )
1455
1557
 
1456
1558
  def gen_insert_relational_tablet_req(self, tablet, is_aligned=False):
1559
+ filtered = filter_null_columns(tablet)
1560
+ if filtered is None:
1561
+ return None
1457
1562
  return TSInsertTabletReq(
1458
1563
  self.__session_id,
1459
- tablet.get_insert_target_name(),
1460
- tablet.get_measurements(),
1461
- tablet.get_binary_values(),
1462
- tablet.get_binary_timestamps(),
1463
- tablet.get_data_types(),
1464
- tablet.get_row_number(),
1564
+ filtered.get_insert_target_name(),
1565
+ filtered.get_measurements(),
1566
+ filtered.get_binary_values(),
1567
+ filtered.get_binary_timestamps(),
1568
+ filtered.get_data_types(),
1569
+ filtered.get_row_number(),
1465
1570
  is_aligned,
1466
1571
  True,
1467
- tablet.get_column_categories(),
1572
+ filtered.get_column_categories(),
1468
1573
  )
1469
1574
 
1470
1575
  def gen_insert_tablets_req(self, tablet_lst, is_aligned=False):
@@ -1475,12 +1580,17 @@ class Session(object):
1475
1580
  type_lst = []
1476
1581
  size_lst = []
1477
1582
  for tablet in tablet_lst:
1478
- device_id_lst.append(tablet.get_insert_target_name())
1479
- measurements_lst.append(tablet.get_measurements())
1480
- values_lst.append(tablet.get_binary_values())
1481
- timestamps_lst.append(tablet.get_binary_timestamps())
1482
- type_lst.append(tablet.get_data_types())
1483
- size_lst.append(tablet.get_row_number())
1583
+ filtered = filter_null_columns(tablet)
1584
+ if filtered is None:
1585
+ continue
1586
+ device_id_lst.append(filtered.get_insert_target_name())
1587
+ measurements_lst.append(filtered.get_measurements())
1588
+ values_lst.append(filtered.get_binary_values())
1589
+ timestamps_lst.append(filtered.get_binary_timestamps())
1590
+ type_lst.append(filtered.get_data_types())
1591
+ size_lst.append(filtered.get_row_number())
1592
+ if not device_id_lst:
1593
+ return None
1484
1594
  return TSInsertTabletsReq(
1485
1595
  self.__session_id,
1486
1596
  device_id_lst,
@@ -1960,7 +2070,7 @@ class Session(object):
1960
2070
 
1961
2071
  def handle_redirection(self, device_id, endpoint: TEndPoint):
1962
2072
  if self.__enable_redirection:
1963
- if endpoint.ip == "0.0.0.0":
2073
+ if _is_wildcard_address(endpoint.ip):
1964
2074
  return 0
1965
2075
  if (
1966
2076
  device_id not in self.__device_id_to_endpoint
iotdb/SessionPool.py CHANGED
@@ -49,6 +49,8 @@ class PoolConfig(object):
49
49
  use_ssl: bool = False,
50
50
  ca_certs: str = None,
51
51
  connection_timeout_in_ms: int = None,
52
+ client_cert: str = None,
53
+ client_key: str = None,
52
54
  ):
53
55
  self.host = host
54
56
  self.port = port
@@ -68,6 +70,8 @@ class PoolConfig(object):
68
70
  self.enable_redirection = enable_redirection
69
71
  self.use_ssl = use_ssl
70
72
  self.ca_certs = ca_certs
73
+ self.client_cert = client_cert
74
+ self.client_key = client_key
71
75
  self.connection_timeout_in_ms = connection_timeout_in_ms
72
76
 
73
77
 
@@ -96,6 +100,8 @@ class SessionPool(object):
96
100
  enable_redirection=self.__pool_config.enable_redirection,
97
101
  use_ssl=self.__pool_config.use_ssl,
98
102
  ca_certs=self.__pool_config.ca_certs,
103
+ client_cert=self.__pool_config.client_cert,
104
+ client_key=self.__pool_config.client_key,
99
105
  connection_timeout_in_ms=self.__pool_config.connection_timeout_in_ms,
100
106
  )
101
107
  session.sql_dialect = self.sql_dialect
@@ -112,6 +118,8 @@ class SessionPool(object):
112
118
  enable_redirection=self.__pool_config.enable_redirection,
113
119
  use_ssl=self.__pool_config.use_ssl,
114
120
  ca_certs=self.__pool_config.ca_certs,
121
+ client_cert=self.__pool_config.client_cert,
122
+ client_key=self.__pool_config.client_key,
115
123
  connection_timeout_in_ms=self.__pool_config.connection_timeout_in_ms,
116
124
  )
117
125
  session.sql_dialect = self.sql_dialect
iotdb/dbapi/Connection.py CHANGED
@@ -37,12 +37,29 @@ class Connection(object):
37
37
  zone_id=Session.DEFAULT_ZONE_ID,
38
38
  enable_rpc_compression=False,
39
39
  sqlalchemy_mode=False,
40
+ use_ssl=False,
41
+ ca_certs=None,
42
+ connection_timeout_in_ms=None,
43
+ client_cert=None,
44
+ client_key=None,
40
45
  ):
41
- self.__session = Session(host, port, username, password, fetch_size, zone_id)
46
+ self.__session = Session(
47
+ host,
48
+ port,
49
+ username,
50
+ password,
51
+ fetch_size,
52
+ zone_id,
53
+ use_ssl=self.__to_bool(use_ssl),
54
+ ca_certs=ca_certs,
55
+ connection_timeout_in_ms=self.__to_optional_int(connection_timeout_in_ms),
56
+ client_cert=client_cert,
57
+ client_key=client_key,
58
+ )
42
59
  self.__sqlalchemy_mode = sqlalchemy_mode
43
60
  self.__is_close = True
44
61
  try:
45
- self.__session.open(enable_rpc_compression)
62
+ self.__session.open(self.__to_bool(enable_rpc_compression))
46
63
  self.__is_close = False
47
64
  except Exception as e:
48
65
  raise ConnectionError(e)
@@ -89,3 +106,17 @@ class Connection(object):
89
106
 
90
107
  def __exit__(self, exc_type, exc_val, exc_tb):
91
108
  self.close()
109
+
110
+ @staticmethod
111
+ def __to_bool(value):
112
+ if isinstance(value, bool):
113
+ return value
114
+ if isinstance(value, str):
115
+ return value.strip().lower() in ("true", "1", "yes", "y")
116
+ return bool(value)
117
+
118
+ @staticmethod
119
+ def __to_optional_int(value):
120
+ if value is None or value == "":
121
+ return None
122
+ return int(value)