Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
fe0b6275
I
Iotdb
项目概览
apache
/
Iotdb
12 个月 前同步成功
通知
25
Star
3344
Fork
916
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
Iotdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fe0b6275
编写于
11月 16, 2019
作者:
J
Jackie Tien
提交者:
Jiang Tian
11月 16, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct python example (#561)
* correct python example
上级
2eb8d60d
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
34 addition
and
33 deletion
+34
-33
client-py/readme.md
client-py/readme.md
+1
-1
client-py/src/client_example.py
client-py/src/client_example.py
+33
-32
未找到文件。
client-py/readme.md
浏览文件 @
fe0b6275
...
...
@@ -20,7 +20,7 @@
-->
# Python connection
##
i
ntroduction
##
I
ntroduction
This is an example of how to connect to IoTDB with python, using the thrift rpc interfaces. Things
are almost the same on Windows or Linux, but pay attention to the difference like path separator.
...
...
client-py/src/client_example.py
浏览文件 @
fe0b6275
...
...
@@ -17,6 +17,7 @@
#
import
sys
,
struct
sys
.
path
.
append
(
"../target"
)
from
thrift.protocol
import
TBinaryProtocol
...
...
@@ -26,44 +27,45 @@ from rpc.TSIService import Client, TSCreateTimeseriesReq, TSInsertionReq, \
TSBatchInsertionReq
,
TSExecuteStatementReq
,
\
TS_SessionHandle
,
TSHandleIdentifier
,
TSOpenSessionReq
,
TSQueryDataSet
,
\
TSFetchResultsReq
,
TSCloseOperationReq
,
\
TSCloseSessionReq
,
TSProtocolVersion
TSCloseSessionReq
from
rpc.ttypes
import
TSProtocolVersion
TSDataType
=
{
'BOOLEAN'
:
0
,
'INT32'
:
1
,
'INT64'
:
2
,
'FLOAT'
:
3
,
'DOUBLE'
:
4
,
'TEXT'
:
5
'BOOLEAN'
:
0
,
'INT32'
:
1
,
'INT64'
:
2
,
'FLOAT'
:
3
,
'DOUBLE'
:
4
,
'TEXT'
:
5
}
TSEncoding
=
{
'PLAIN'
:
0
,
'PLAIN_DICTIONARY'
:
1
,
'RLE'
:
2
,
'DIFF'
:
3
,
'TS_2DIFF'
:
4
,
'BITMAP'
:
5
,
'GORILLA'
:
6
,
'REGULAR'
:
7
'PLAIN'
:
0
,
'PLAIN_DICTIONARY'
:
1
,
'RLE'
:
2
,
'DIFF'
:
3
,
'TS_2DIFF'
:
4
,
'BITMAP'
:
5
,
'GORILLA'
:
6
,
'REGULAR'
:
7
}
Compressor
=
{
'UNCOMPRESSED'
:
0
,
'SNAPPY'
:
1
,
'GZIP'
:
2
,
'LZO'
:
3
,
'SDT'
:
4
,
'PAA'
:
5
,
'PLA'
:
6
'UNCOMPRESSED'
:
0
,
'SNAPPY'
:
1
,
'GZIP'
:
2
,
'LZO'
:
3
,
'SDT'
:
4
,
'PAA'
:
5
,
'PLA'
:
6
}
def
convertQueryDataSet
(
queryDataSet
,
dataTypeList
):
bytes
=
queryDataSet
.
values
row_count
=
queryDataSet
.
rowCount
time_bytes
=
bytes
[:
8
*
row_count
]
value_bytes
=
bytes
[
8
*
row_count
:]
time_bytes
=
bytes
[:
8
*
row_count
]
value_bytes
=
bytes
[
8
*
row_count
:]
time_unpack_str
=
'>'
+
str
(
row_count
)
+
'q'
records
=
[]
times
=
struct
.
unpack
(
time_unpack_str
,
time_bytes
)
...
...
@@ -183,9 +185,9 @@ if __name__ == '__main__':
# insert a single row
values
=
[
"1"
,
"11"
,
"1.1"
,
"11.1"
,
"TRUE"
,
"
\'
text0
\'
"
]
timestamp
=
1
status
=
client
.
insert
Row
(
TSInsertionReq
(
deviceId
,
measurements
,
status
=
client
.
insert
(
TSInsertionReq
(
deviceId
,
measurements
,
values
,
timestamp
,
stmtId
))
print
(
status
.
status
Type
)
print
(
status
.
status
)
# insert multiple rows, this interface is more efficient
values
=
bytearray
()
...
...
@@ -217,7 +219,7 @@ if __name__ == '__main__':
print
(
status
.
statusType
)
# execute deletion (or other statements)
resp
=
client
.
executeStatement
(
TSExecuteStatementReq
(
handle
,
"DELETE FROM root.group1 where time < 2"
))
resp
=
client
.
executeStatement
(
TSExecuteStatementReq
(
handle
,
"DELETE FROM root.group1 where time < 2"
,
stmtId
))
status
=
resp
.
status
print
(
status
.
statusType
)
...
...
@@ -225,8 +227,7 @@ if __name__ == '__main__':
stmt
=
"SELECT * FROM root.group1"
fetchSize
=
2
# this is also for resource control, make sure different queries will not use the same id at the same time
queryId
=
1
resp
=
client
.
executeQueryStatement
(
TSExecuteStatementReq
(
handle
,
stmt
))
resp
=
client
.
executeQueryStatement
(
TSExecuteStatementReq
(
handle
,
stmt
,
stmtId
))
# headers
dataTypeList
=
resp
.
dataTypeList
print
(
resp
.
columns
)
...
...
@@ -235,6 +236,8 @@ if __name__ == '__main__':
stmtHandle
=
resp
.
operationHandle
status
=
resp
.
status
print
(
status
.
statusType
)
queryId
=
resp
.
operationHandle
.
operationId
.
queryId
while
True
:
rst
=
client
.
fetchResults
(
TSFetchResultsReq
(
stmt
,
fetchSize
,
queryId
)).
queryDataSet
records
=
convertQueryDataSet
(
rst
,
dataTypeList
)
...
...
@@ -248,5 +251,3 @@ if __name__ == '__main__':
# and do not forget to close the session before exiting
client
.
closeSession
(
TSCloseSessionReq
(
handle
))
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录