diff --git a/src/UserGuide/Master/Tree/API/Programming-Python-Native-API.md b/src/UserGuide/Master/Tree/API/Programming-Python-Native-API.md index 01ade47f8..ac8553bb3 100644 --- a/src/UserGuide/Master/Tree/API/Programming-Python-Native-API.md +++ b/src/UserGuide/Master/Tree/API/Programming-Python-Native-API.md @@ -94,6 +94,7 @@ Notice: this RPC compression status of client must comply with that of IoTDB ser ```python session.close() ``` + ## 4. Managing Session through SessionPool Utilizing SessionPool to manage sessions eliminates the need to worry about session reuse. When the number of session connections reaches the maximum capacity of the pool, requests for acquiring a session will be blocked, and you can set the blocking wait time through parameters. After using a session, it should be returned to the SessionPool using the `putBack` method for proper management. @@ -131,6 +132,99 @@ session_pool.put_back(session) # When closing the sessionPool, all managed sessions will be closed as well session_pool.close() ``` +### 4.4 SSL Connection + +#### 4.4.1 Server Certificate Configuration + +In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### 4.4.2 Configure Python Client Certificate + +- Set `use_ssl` to True to enable SSL. +- Specify the client certificate path using the `ca_certs` parameter. + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**Example Code: Using SSL to Connect to IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` ## 5. Data Definition Interface (DDL Interface) diff --git a/src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md b/src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md index cb8916d0f..2f16b4205 100644 --- a/src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md +++ b/src/UserGuide/V1.3.x/API/Programming-Python-Native-API.md @@ -131,6 +131,101 @@ session_pool.put_back(session) session_pool.close() ``` +### SSL Connection + +#### Server Certificate Configuration + +In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### Configure Python Client Certificate + +- Set `use_ssl` to True to enable SSL. +- Specify the client certificate path using the `ca_certs` parameter. + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**Example Code: Using SSL to Connect to IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` + + ## Data Definition Interface (DDL Interface) ### Database Management diff --git a/src/UserGuide/dev-1.3/API/Programming-Python-Native-API.md b/src/UserGuide/dev-1.3/API/Programming-Python-Native-API.md index cb8916d0f..0e8ec1450 100644 --- a/src/UserGuide/dev-1.3/API/Programming-Python-Native-API.md +++ b/src/UserGuide/dev-1.3/API/Programming-Python-Native-API.md @@ -131,6 +131,100 @@ session_pool.put_back(session) session_pool.close() ``` +### SSL Connection + +#### Server Certificate Configuration + +In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### Configure Python Client Certificate + +- Set `use_ssl` to True to enable SSL. +- Specify the client certificate path using the `ca_certs` parameter. + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**Example Code: Using SSL to Connect to IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` + ## Data Definition Interface (DDL Interface) ### Database Management diff --git a/src/UserGuide/latest/API/Programming-Python-Native-API.md b/src/UserGuide/latest/API/Programming-Python-Native-API.md index 01ade47f8..ac8553bb3 100644 --- a/src/UserGuide/latest/API/Programming-Python-Native-API.md +++ b/src/UserGuide/latest/API/Programming-Python-Native-API.md @@ -94,6 +94,7 @@ Notice: this RPC compression status of client must comply with that of IoTDB ser ```python session.close() ``` + ## 4. Managing Session through SessionPool Utilizing SessionPool to manage sessions eliminates the need to worry about session reuse. When the number of session connections reaches the maximum capacity of the pool, requests for acquiring a session will be blocked, and you can set the blocking wait time through parameters. After using a session, it should be returned to the SessionPool using the `putBack` method for proper management. @@ -131,6 +132,99 @@ session_pool.put_back(session) # When closing the sessionPool, all managed sessions will be closed as well session_pool.close() ``` +### 4.4 SSL Connection + +#### 4.4.1 Server Certificate Configuration + +In the `conf/iotdb-system.properties` configuration file, locate or add the following configuration items: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### 4.4.2 Configure Python Client Certificate + +- Set `use_ssl` to True to enable SSL. +- Specify the client certificate path using the `ca_certs` parameter. + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**Example Code: Using SSL to Connect to IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` ## 5. Data Definition Interface (DDL Interface) diff --git a/src/zh/UserGuide/Master/Tree/API/Programming-Python-Native-API.md b/src/zh/UserGuide/Master/Tree/API/Programming-Python-Native-API.md index e47cb6c7c..2412301a1 100644 --- a/src/zh/UserGuide/Master/Tree/API/Programming-Python-Native-API.md +++ b/src/zh/UserGuide/Master/Tree/API/Programming-Python-Native-API.md @@ -134,6 +134,100 @@ session_pool.put_back(session) session_pool.close() ``` +### 3.3 SSL 连接 + +#### 3.3.1 服务器端配置证书 + +`conf/iotdb-system.properties` 配置文件中查找或添加以下配置项: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### 3.3.2 配置 python 客户端证书 + +- 设置 use_ssl 为 True 以启用 SSL。 +- 指定客户端证书路径,使用 ca_certs 参数。 + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**示例代码:使用 SSL 连接 IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` + ## 4. 数据定义接口 DDL ### 4.1 Database 管理 diff --git a/src/zh/UserGuide/V1.3.x/API/Programming-Python-Native-API.md b/src/zh/UserGuide/V1.3.x/API/Programming-Python-Native-API.md index be241baf7..7664ad9f4 100644 --- a/src/zh/UserGuide/V1.3.x/API/Programming-Python-Native-API.md +++ b/src/zh/UserGuide/V1.3.x/API/Programming-Python-Native-API.md @@ -134,6 +134,100 @@ session_pool.put_back(session) session_pool.close() ``` +### SSL 连接 + +#### 服务器端配置证书 + +`conf/iotdb-system.properties` 配置文件中查找或添加以下配置项: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### 配置 python 客户端证书 + +- 设置 use_ssl 为 True 以启用 SSL。 +- 指定客户端证书路径,使用 ca_certs 参数。 + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**示例代码:使用 SSL 连接 IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` + ## 数据定义接口 DDL ### Database 管理 diff --git a/src/zh/UserGuide/dev-1.3/API/Programming-Python-Native-API.md b/src/zh/UserGuide/dev-1.3/API/Programming-Python-Native-API.md index be241baf7..7664ad9f4 100644 --- a/src/zh/UserGuide/dev-1.3/API/Programming-Python-Native-API.md +++ b/src/zh/UserGuide/dev-1.3/API/Programming-Python-Native-API.md @@ -134,6 +134,100 @@ session_pool.put_back(session) session_pool.close() ``` +### SSL 连接 + +#### 服务器端配置证书 + +`conf/iotdb-system.properties` 配置文件中查找或添加以下配置项: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### 配置 python 客户端证书 + +- 设置 use_ssl 为 True 以启用 SSL。 +- 指定客户端证书路径,使用 ca_certs 参数。 + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**示例代码:使用 SSL 连接 IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` + ## 数据定义接口 DDL ### Database 管理 diff --git a/src/zh/UserGuide/latest/API/Programming-Python-Native-API.md b/src/zh/UserGuide/latest/API/Programming-Python-Native-API.md index e47cb6c7c..2412301a1 100644 --- a/src/zh/UserGuide/latest/API/Programming-Python-Native-API.md +++ b/src/zh/UserGuide/latest/API/Programming-Python-Native-API.md @@ -134,6 +134,100 @@ session_pool.put_back(session) session_pool.close() ``` +### 3.3 SSL 连接 + +#### 3.3.1 服务器端配置证书 + +`conf/iotdb-system.properties` 配置文件中查找或添加以下配置项: + +```Java +enable_thrift_ssl=true +key_store_path=/path/to/your/server_keystore.jks +key_store_pwd=your_keystore_password +``` + +#### 3.3.2 配置 python 客户端证书 + +- 设置 use_ssl 为 True 以启用 SSL。 +- 指定客户端证书路径,使用 ca_certs 参数。 + +```Java +use_ssl = True +ca_certs = "/path/to/your/server.crt" # 或 ca_certs = "/path/to/your//ca_cert.pem" +``` +**示例代码:使用 SSL 连接 IoTDB** + +```Java +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from iotdb.SessionPool import PoolConfig, SessionPool +from iotdb.Session import Session + +ip = "127.0.0.1" +port_ = "6667" +username_ = "root" +password_ = "root" +# Configure SSL enabled +use_ssl = True +# Configure certificate path +ca_certs = "/path/server.crt" + + +def get_data(): + session = Session( + ip, port_, username_, password_, use_ssl=use_ssl, ca_certs=ca_certs + ) + session.open(False) + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session.close() + return df + + +def get_data2(): + pool_config = PoolConfig( + host=ip, + port=port_, + user_name=username_, + password=password_, + fetch_size=1024, + time_zone="UTC+8", + max_retry=3, + use_ssl=use_ssl, + ca_certs=ca_certs, + ) + max_pool_size = 5 + wait_timeout_in_ms = 3000 + session_pool = SessionPool(pool_config, max_pool_size, wait_timeout_in_ms) + session = session_pool.get_session() + result = session.execute_query_statement("select * from root.eg.etth") + df = result.todf() + df.rename(columns={"Time": "date"}, inplace=True) + session_pool.put_back(session) + session_pool.close() + + +if __name__ == "__main__": + df = get_data() +``` + ## 4. 数据定义接口 DDL ### 4.1 Database 管理