Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Iotdb
提交
b11703c6
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,发现更多精彩内容 >>
提交
b11703c6
编写于
11月 04, 2019
作者:
J
Jiang Tian
提交者:
Jialin Qiao
11月 04, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update python example to adapt to new QueryDataSet (#509)
* update python example to adapt to new QueryDataSet
上级
b845dd7a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
101 addition
and
14 deletion
+101
-14
client-py/src/client_example.py
client-py/src/client_example.py
+101
-14
未找到文件。
client-py/src/client_example.py
浏览文件 @
b11703c6
...
...
@@ -59,6 +59,54 @@ Compressor = {
}
def
convertQueryDataSet
(
queryDataSet
,
dataTypeList
):
bytes
=
queryDataSet
.
values
row_count
=
queryDataSet
.
rowCount
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
)
for
i
in
range
(
row_count
):
records
.
append
([
times
[
i
]])
for
i
in
range
(
len
(
dataTypeList
)):
type
=
dataTypeList
[
i
]
for
j
in
range
(
row_count
):
is_null
=
value_bytes
[
0
]
value_bytes
=
value_bytes
[
1
:]
if
is_null
==
1
:
records
[
j
].
append
(
'null'
)
else
:
if
type
==
'BOOLEAN'
:
value
=
value_bytes
[
0
]
value_bytes
=
value_bytes
[
1
:]
records
[
j
].
append
(
struct
.
unpack
(
'>?'
,
value
)[
0
])
elif
type
==
'INT32'
:
value
=
value_bytes
[:
4
]
value_bytes
=
value_bytes
[
4
:]
records
[
j
].
append
(
struct
.
unpack
(
'>i'
,
value
)[
0
])
elif
type
==
'INT64'
:
value
=
value_bytes
[:
8
]
value_bytes
=
value_bytes
[
8
:]
records
[
j
].
append
(
struct
.
unpack
(
'>q'
,
value
)[
0
])
elif
type
==
'FLOAT'
:
value
=
value_bytes
[:
4
]
value_bytes
=
value_bytes
[
4
:]
records
[
j
].
append
(
struct
.
unpack
(
'>f'
,
value
)[
0
])
elif
type
==
'DOUBLE'
:
value
=
value_bytes
[:
8
]
value_bytes
=
value_bytes
[
8
:]
records
[
j
].
append
(
struct
.
unpack
(
'>d'
,
value
)[
0
])
elif
type
==
'TEXT'
:
size
=
value_bytes
[:
4
]
value_bytes
=
value_bytes
[
4
:]
size
=
struct
.
unpack
(
'>i'
,
size
)[
0
]
records
[
j
].
append
(
value_bytes
[:
size
])
value_bytes
=
value_bytes
[
size
:]
return
records
if
__name__
==
'__main__'
:
ip
=
"localhost"
port
=
"6667"
...
...
@@ -98,32 +146,68 @@ if __name__ == '__main__':
print
(
status
.
statusType
)
# create timeseries
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s1"
,
TSDataType
[
'INT64'
],
TSEncoding
[
'PLAIN'
],
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s1"
,
TSDataType
[
'INT64'
],
TSEncoding
[
'PLAIN'
],
Compressor
[
'UNCOMPRESSED'
]))
print
(
status
.
statusType
)
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s2"
,
TSDataType
[
'INT32'
],
TSEncoding
[
'PLAIN'
],
Compressor
[
'UNCOMPRESSED'
]))
print
(
status
.
statusType
)
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s2"
,
TSDataType
[
'INT64'
],
TSEncoding
[
'PLAIN'
],
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s3"
,
TSDataType
[
'DOUBLE'
],
TSEncoding
[
'PLAIN'
],
Compressor
[
'UNCOMPRESSED'
]))
print
(
status
.
statusType
)
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s3"
,
TSDataType
[
'INT64'
],
TSEncoding
[
'PLAIN'
],
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s4"
,
TSDataType
[
'FLOAT'
],
TSEncoding
[
'PLAIN'
],
Compressor
[
'UNCOMPRESSED'
]))
print
(
status
.
statusType
)
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s5"
,
TSDataType
[
'BOOLEAN'
],
TSEncoding
[
'PLAIN'
],
Compressor
[
'UNCOMPRESSED'
]))
print
(
status
.
statusType
)
status
=
client
.
createTimeseries
(
TSCreateTimeseriesReq
(
"root.group1.s6"
,
TSDataType
[
'TEXT'
],
TSEncoding
[
'PLAIN'
],
Compressor
[
'UNCOMPRESSED'
]))
print
(
status
.
statusType
)
deviceId
=
"root.group1"
measurements
=
[
"s1"
,
"s2"
,
"s3"
,
"s4"
,
"s5"
,
"s6"
]
# insert a single row
status
=
client
.
insertRow
(
TSInsertionReq
(
"root.group1"
,
[
"s1"
,
"s2"
,
"s3"
],
[
"1"
,
"11"
,
"111"
],
1
,
1
))
values
=
[
"1"
,
"11"
,
"1.1"
,
"11.1"
,
"TRUE"
,
"
\'
text0
\'
"
]
timestamp
=
1
status
=
client
.
insertRow
(
TSInsertionReq
(
deviceId
,
measurements
,
values
,
timestamp
,
stmtId
))
print
(
status
.
statusType
)
# insert multiple rows, this interface is more efficient
values
=
bytearray
()
times
=
bytearray
()
deviceId
=
"root.group1"
measurements
=
[
"s1"
,
"s2"
,
"s3"
]
dataSize
=
3
dataTypes
=
[
TSDataType
[
'INT64'
],
TSDataType
[
'INT64'
],
TSDataType
[
'INT64'
]]
# the first 3 belong to 's1', the mid 3 belong to 's2', the last 3 belong to 's3'
values
.
extend
(
struct
.
pack
(
'>qqqqqqqqq'
,
2
,
3
,
4
,
22
,
33
,
44
,
222
,
333
,
444
))
times
.
extend
(
struct
.
pack
(
'>qqq'
,
2
,
3
,
4
))
resp
=
client
.
insertBatch
(
TSBatchInsertionReq
(
deviceId
,
measurements
,
values
,
times
,
dataTypes
,
dataSize
))
rowCnt
=
3
dataTypes
=
[
TSDataType
[
'INT64'
],
TSDataType
[
'INT32'
],
TSDataType
[
'DOUBLE'
],
TSDataType
[
'FLOAT'
],
TSDataType
[
'BOOLEAN'
],
TSDataType
[
'TEXT'
]]
# the first 3 belong to 's1', the second 3 belong to 's2'... the last 3
# belong to 's6'
# to transfer a string, you must first send its length and then its bytes
# (like the last 3 'i7s'). Text values should start and end with ' or ".
# IoTDB use big endian in rpc
value_pack_str
=
'>3q3i3d3f3bi7si7si7s'
time_pack_str
=
'>3q'
values
.
extend
(
struct
.
pack
(
value_pack_str
,
2
,
3
,
4
,
22
,
33
,
44
,
2.2
,
3.3
,
4.4
,
22.2
,
33.3
,
44.4
,
True
,
True
,
False
,
len
(
'
\'
text1
\'
'
),
'
\'
text1
\'
'
,
len
(
'
\'
text2
\'
'
),
'
\'
text2
\'
'
,
len
(
'
\'
text3
\'
'
),
'
\'
text3
\'
'
))
times
.
extend
(
struct
.
pack
(
time_pack_str
,
2
,
3
,
4
))
resp
=
client
.
insertBatch
(
TSBatchInsertionReq
(
deviceId
,
measurements
,
values
,
times
,
dataTypes
,
rowCnt
))
status
=
resp
.
status
print
(
status
.
statusType
)
...
...
@@ -139,13 +223,16 @@ if __name__ == '__main__':
queryId
=
1
resp
=
client
.
executeQueryStatement
(
TSExecuteStatementReq
(
handle
,
stmt
))
# headers
dataTypeList
=
resp
.
dataTypeList
print
(
resp
.
columns
)
print
(
dataTypeList
)
stmtHandle
=
resp
.
operationHandle
status
=
resp
.
status
print
(
status
.
statusType
)
while
True
:
rst
=
client
.
fetchResults
(
TSFetchResultsReq
(
stmt
,
fetchSize
,
queryId
)).
queryDataSet
records
=
rst
.
records
records
=
convertQueryDataSet
(
rst
,
dataTypeList
)
if
len
(
records
)
==
0
:
break
for
record
in
records
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录