Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cbb534c2
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cbb534c2
编写于
2月 02, 2021
作者:
sangshuduo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-2771] <feature>: python taosdemo, natvie interface.
上级
e66f2dbd
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
15 deletion
+32
-15
tests/examples/python/taosdemo/taosdemo.py
tests/examples/python/taosdemo/taosdemo.py
+32
-15
未找到文件。
tests/examples/python/taosdemo/taosdemo.py
浏览文件 @
cbb534c2
...
...
@@ -32,6 +32,18 @@ def v_print(msg: str, arg: str):
print
(
msg
%
arg
)
@
dispatch
(
str
,
str
,
str
)
def
v_print
(
msg
:
str
,
arg1
:
str
,
arg2
:
str
):
if
verbose
:
print
(
msg
%
(
arg1
,
arg2
))
@
dispatch
(
str
,
str
,
str
,
str
)
def
v_print
(
msg
:
str
,
arg1
:
str
,
arg2
:
str
,
arg3
:
str
):
if
verbose
:
print
(
msg
%
(
arg1
,
arg2
,
arg3
))
@
dispatch
(
str
,
str
,
str
,
str
,
str
)
def
v_print
(
msg
:
str
,
arg1
:
str
,
arg2
:
str
,
arg3
:
str
,
arg4
:
str
):
if
verbose
:
...
...
@@ -83,8 +95,7 @@ def v_print(msg: str, arg1: int, arg2: int, arg3: int, arg4: int):
def
restful_execute
(
host
:
str
,
port
:
int
,
user
:
str
,
password
:
str
,
cmd
:
str
):
url
=
"http://%s:%d/rest/sql"
%
(
host
,
restPort
)
if
verbose
:
v_print
(
"cmd: %s"
,
cmd
)
v_print
(
"restful_execute - cmd: %s"
,
cmd
)
resp
=
requests
.
post
(
url
,
cmd
,
auth
=
(
user
,
password
))
...
...
@@ -103,6 +114,7 @@ def restful_execute(host: str, port: int, user: str, password: str, cmd: str):
def
query_func
(
process
:
int
,
thread
:
int
,
cmd
:
str
):
v_print
(
"%d process %d thread cmd: %s"
,
process
,
thread
,
cmd
)
if
oneMoreHost
!=
"NotSupported"
and
random
.
randint
(
0
,
1
)
==
1
:
v_print
(
"%s"
,
"Send to second host"
)
...
...
@@ -140,6 +152,7 @@ def query_data_process(i: int, cmd: str):
def
query_data
(
cmd
:
str
):
v_print
(
"query_data processes: %d, cmd: %s"
,
processes
,
cmd
)
pool
=
Pool
(
processes
)
for
i
in
range
(
processes
):
pool
.
apply_async
(
query_data_process
,
args
=
(
i
,
cmd
))
...
...
@@ -199,7 +212,6 @@ def create_stb():
def
use_database
():
current_db
=
"%s%d"
%
(
dbName
,
(
numOfDb
-
1
))
if
native
:
cursor
.
execute
(
"USE %s"
%
current_db
)
...
...
@@ -272,14 +284,14 @@ def insert_func(process: int, thread: int):
sqlCmd
=
[
'INSERT INTO '
]
try
:
sqlCmd
.
append
(
"%s.
tb%s "
%
(
current_db
,
thread
))
"%s.
%s%d "
%
(
current_db
,
tbName
,
thread
))
if
(
numOfStb
>
0
and
autosubtable
):
sqlCmd
.
append
(
"USING %s.
st
%d TAGS('%s') "
%
(
current_db
,
numOfStb
-
1
,
uuid
))
sqlCmd
.
append
(
"USING %s.
%s
%d TAGS('%s') "
%
(
current_db
,
stbName
,
numOfStb
-
1
,
uuid
))
start_time
=
datetime
.
datetime
(
202
0
,
9
,
25
)
+
datetime
.
timedelta
(
seconds
=
row
)
202
1
,
1
,
25
)
+
datetime
.
timedelta
(
seconds
=
row
)
sqlCmd
.
append
(
"VALUES "
)
for
batchIter
in
range
(
0
,
batch
):
...
...
@@ -302,7 +314,10 @@ def insert_func(process: int, thread: int):
exec_start_time
=
datetime
.
datetime
.
now
()
if
native
:
cursor
.
execute
(
cmd
)
v_print
(
"insert_func - cursor:%x cmd:%s"
,
hex
(
id
(
cursor
)),
cmd
)
cursor
.
execute
(
"SHOW DATABASES"
)
# cursor.execute("%s" % cmd)
v_print
(
"insert_func - cursor:%x cmd:%s done"
,
hex
(
id
(
cursor
)),
cmd
)
else
:
restful_execute
(
host
,
port
,
user
,
password
,
cmd
)
...
...
@@ -398,9 +413,9 @@ def printConfig():
print
(
"# Database name: %s"
%
dbName
)
print
(
"# Replica: %s"
%
replica
)
print
(
"# Use STable: %s"
%
useStable
)
print
(
"# Table prefix: %s"
%
tbName
Prefix
)
print
(
"# Table prefix: %s"
%
tbName
)
if
useStable
:
print
(
"# STable prefix: %s"
%
stbName
Prefix
)
print
(
"# STable prefix: %s"
%
stbName
)
print
(
"# Data order: %s"
%
outOfOrder
)
print
(
"# Data out of order rate: %s"
%
rateOOOO
)
...
...
@@ -425,10 +440,10 @@ if __name__ == "__main__":
replica
=
1
batch
=
1
numOfTb
=
1
tbName
Prefix
=
"tb"
tbName
=
"tb"
useStable
=
False
numOfStb
=
0
stbName
Prefix
=
"stb"
stbName
=
"stb"
numOfRec
=
10
ieration
=
1
host
=
"127.0.0.1"
...
...
@@ -547,14 +562,14 @@ if __name__ == "__main__":
sys
.
exit
(
1
)
if
key
in
[
'-m'
,
'--tbname'
]:
tbName
Prefix
=
value
tbName
=
value
if
key
in
[
'-M'
,
'--stable'
]:
useStable
=
True
numOfStb
=
1
if
key
in
[
'-s'
,
'--stbname'
]:
stbName
Prefix
=
value
stbName
=
value
if
key
in
[
'-Q'
,
'--query'
]:
queryCmd
=
str
(
value
)
...
...
@@ -633,7 +648,7 @@ if __name__ == "__main__":
user
=
user
,
password
=
password
,
config
=
configDir
)
print
(
"conn: %
p"
%
conn
)
print
(
"conn: %
s"
%
str
(
conn
.
__class__
)
)
except
Exception
as
e
:
print
(
"Error: %s"
%
e
.
args
[
0
])
sys
.
exit
(
1
)
...
...
@@ -641,6 +656,7 @@ if __name__ == "__main__":
if
native
:
try
:
cursor
=
conn
.
cursor
()
print
(
"cursor:%d %s"
%
(
id
(
cursor
),
str
(
cursor
.
__class__
)))
except
Exception
as
e
:
print
(
"Error: %s"
%
e
.
args
[
0
])
sys
.
exit
(
1
)
...
...
@@ -669,6 +685,7 @@ if __name__ == "__main__":
start_time
=
time
.
time
()
# use last database
current_db
=
"%s%d"
%
(
dbName
,
(
numOfDb
-
1
))
use_database
()
if
numOfStb
>
0
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录