-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsession_ssl_example.py
More file actions
99 lines (89 loc) · 2.89 KB
/
Copy pathsession_ssl_example.py
File metadata and controls
99 lines (89 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# 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
from iotdb.table_session import TableSession, TableSessionConfig
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"
# Configure client certificate and private key when the server enables mTLS.
client_cert = "/path/client.crt"
client_key = "/path/client.key"
def get_data():
session = Session(
ip,
port_,
username_,
password_,
use_ssl=use_ssl,
ca_certs=ca_certs,
client_cert=client_cert,
client_key=client_key,
)
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="Asia/Shanghai",
max_retry=3,
use_ssl=use_ssl,
ca_certs=ca_certs,
client_cert=client_cert,
client_key=client_key,
)
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()
def get_table_data():
pool_config = TableSessionConfig(
node_urls=["127.0.0.1:6667"],
username=username_,
password=password_,
fetch_size=1024,
time_zone="Asia/Shanghai",
use_ssl=use_ssl,
ca_certs=ca_certs,
client_cert=client_cert,
client_key=client_key,
)
session = TableSession(pool_config)
result = session.execute_query_statement("select * from test")
df = result.todf()
session.close()
if __name__ == "__main__":
df = get_data()