提交 cbb534c2 编写于 作者: sangshuduo's avatar sangshuduo

[TD-2771] <feature>: python taosdemo, natvie interface.

上级 e66f2dbd
...@@ -32,6 +32,18 @@ def v_print(msg: str, arg: str): ...@@ -32,6 +32,18 @@ def v_print(msg: str, arg: str):
print(msg % arg) 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) @dispatch(str, str, str, str, str)
def v_print(msg: str, arg1: str, arg2: str, arg3: str, arg4: str): def v_print(msg: str, arg1: str, arg2: str, arg3: str, arg4: str):
if verbose: if verbose:
...@@ -83,8 +95,7 @@ def v_print(msg: str, arg1: int, arg2: int, arg3: int, arg4: int): ...@@ -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): def restful_execute(host: str, port: int, user: str, password: str, cmd: str):
url = "http://%s:%d/rest/sql" % (host, restPort) url = "http://%s:%d/rest/sql" % (host, restPort)
if verbose: v_print("restful_execute - cmd: %s", cmd)
v_print("cmd: %s", cmd)
resp = requests.post(url, cmd, auth=(user, password)) 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): ...@@ -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): def query_func(process: int, thread: int, cmd: str):
v_print("%d process %d thread cmd: %s", process, thread, cmd) v_print("%d process %d thread cmd: %s", process, thread, cmd)
if oneMoreHost != "NotSupported" and random.randint( if oneMoreHost != "NotSupported" and random.randint(
0, 1) == 1: 0, 1) == 1:
v_print("%s", "Send to second host") v_print("%s", "Send to second host")
...@@ -140,6 +152,7 @@ def query_data_process(i: int, cmd: str): ...@@ -140,6 +152,7 @@ def query_data_process(i: int, cmd: str):
def query_data(cmd: str): def query_data(cmd: str):
v_print("query_data processes: %d, cmd: %s", processes, cmd) v_print("query_data processes: %d, cmd: %s", processes, cmd)
pool = Pool(processes) pool = Pool(processes)
for i in range(processes): for i in range(processes):
pool.apply_async(query_data_process, args=(i, cmd)) pool.apply_async(query_data_process, args=(i, cmd))
...@@ -199,7 +212,6 @@ def create_stb(): ...@@ -199,7 +212,6 @@ def create_stb():
def use_database(): def use_database():
current_db = "%s%d" % (dbName, (numOfDb - 1))
if native: if native:
cursor.execute("USE %s" % current_db) cursor.execute("USE %s" % current_db)
...@@ -272,14 +284,14 @@ def insert_func(process: int, thread: int): ...@@ -272,14 +284,14 @@ def insert_func(process: int, thread: int):
sqlCmd = ['INSERT INTO '] sqlCmd = ['INSERT INTO ']
try: try:
sqlCmd.append( sqlCmd.append(
"%s.tb%s " % (current_db, thread)) "%s.%s%d " % (current_db, tbName, thread))
if (numOfStb > 0 and autosubtable): if (numOfStb > 0 and autosubtable):
sqlCmd.append("USING %s.st%d TAGS('%s') " % sqlCmd.append("USING %s.%s%d TAGS('%s') " %
(current_db, numOfStb - 1, uuid)) (current_db, stbName, numOfStb - 1, uuid))
start_time = datetime.datetime( start_time = datetime.datetime(
2020, 9, 25) + datetime.timedelta(seconds=row) 2021, 1, 25) + datetime.timedelta(seconds=row)
sqlCmd.append("VALUES ") sqlCmd.append("VALUES ")
for batchIter in range(0, batch): for batchIter in range(0, batch):
...@@ -302,7 +314,10 @@ def insert_func(process: int, thread: int): ...@@ -302,7 +314,10 @@ def insert_func(process: int, thread: int):
exec_start_time = datetime.datetime.now() exec_start_time = datetime.datetime.now()
if native: 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: else:
restful_execute( restful_execute(
host, port, user, password, cmd) host, port, user, password, cmd)
...@@ -398,9 +413,9 @@ def printConfig(): ...@@ -398,9 +413,9 @@ def printConfig():
print("# Database name: %s" % dbName) print("# Database name: %s" % dbName)
print("# Replica: %s" % replica) print("# Replica: %s" % replica)
print("# Use STable: %s" % useStable) print("# Use STable: %s" % useStable)
print("# Table prefix: %s" % tbNamePrefix) print("# Table prefix: %s" % tbName)
if useStable: if useStable:
print("# STable prefix: %s" % stbNamePrefix) print("# STable prefix: %s" % stbName)
print("# Data order: %s" % outOfOrder) print("# Data order: %s" % outOfOrder)
print("# Data out of order rate: %s" % rateOOOO) print("# Data out of order rate: %s" % rateOOOO)
...@@ -425,10 +440,10 @@ if __name__ == "__main__": ...@@ -425,10 +440,10 @@ if __name__ == "__main__":
replica = 1 replica = 1
batch = 1 batch = 1
numOfTb = 1 numOfTb = 1
tbNamePrefix = "tb" tbName = "tb"
useStable = False useStable = False
numOfStb = 0 numOfStb = 0
stbNamePrefix = "stb" stbName = "stb"
numOfRec = 10 numOfRec = 10
ieration = 1 ieration = 1
host = "127.0.0.1" host = "127.0.0.1"
...@@ -547,14 +562,14 @@ if __name__ == "__main__": ...@@ -547,14 +562,14 @@ if __name__ == "__main__":
sys.exit(1) sys.exit(1)
if key in ['-m', '--tbname']: if key in ['-m', '--tbname']:
tbNamePrefix = value tbName = value
if key in ['-M', '--stable']: if key in ['-M', '--stable']:
useStable = True useStable = True
numOfStb = 1 numOfStb = 1
if key in ['-s', '--stbname']: if key in ['-s', '--stbname']:
stbNamePrefix = value stbName = value
if key in ['-Q', '--query']: if key in ['-Q', '--query']:
queryCmd = str(value) queryCmd = str(value)
...@@ -633,7 +648,7 @@ if __name__ == "__main__": ...@@ -633,7 +648,7 @@ if __name__ == "__main__":
user=user, user=user,
password=password, password=password,
config=configDir) config=configDir)
print("conn: %p" % conn) print("conn: %s" % str(conn.__class__))
except Exception as e: except Exception as e:
print("Error: %s" % e.args[0]) print("Error: %s" % e.args[0])
sys.exit(1) sys.exit(1)
...@@ -641,6 +656,7 @@ if __name__ == "__main__": ...@@ -641,6 +656,7 @@ if __name__ == "__main__":
if native: if native:
try: try:
cursor = conn.cursor() cursor = conn.cursor()
print("cursor:%d %s" % (id(cursor), str(cursor.__class__)))
except Exception as e: except Exception as e:
print("Error: %s" % e.args[0]) print("Error: %s" % e.args[0])
sys.exit(1) sys.exit(1)
...@@ -669,6 +685,7 @@ if __name__ == "__main__": ...@@ -669,6 +685,7 @@ if __name__ == "__main__":
start_time = time.time() start_time = time.time()
# use last database # use last database
current_db = "%s%d" % (dbName, (numOfDb - 1))
use_database() use_database()
if numOfStb > 0: if numOfStb > 0:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册