提交 538cd4ed 编写于 作者: haoranc's avatar haoranc

teset:add testcase of stmt

上级 fbc206d4
...@@ -78,21 +78,29 @@ class TDTestCase: ...@@ -78,21 +78,29 @@ class TDTestCase:
password = "taosdata" password = "taosdata"
port =6030 port =6030
con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port) con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port)
print(con) tdLog.debug(con)
return con return con
def stmtExe(self,conn,sql,bindStat):
queryStat=conn.statement("%s"%sql)
queryStat.bind_param(bindStat)
queryStat.execute()
result=queryStat.use_result()
rows=result.fetch_all()
return rows
def test_stmt_set_tbname_tag(self,conn): def test_stmt_set_tbname_tag(self,conn):
dbname = "stmt_set_tbname_tag" dbname = "stmt_tag"
stablename = 'log'
try: try:
conn.execute("drop database if exists %s" % dbname) conn.execute("drop database if exists %s" % dbname)
conn.execute("create database if not exists %s PRECISION 'us' " % dbname) conn.execute("create database if not exists %s PRECISION 'us' " % dbname)
conn.select_db(dbname) conn.select_db(dbname)
conn.execute("create table if not exists log(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\ conn.execute("create table if not exists %s(ts timestamp, bo bool, nil tinyint, ti tinyint, si smallint, ii int,\
bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \ bi bigint, tu tinyint unsigned, su smallint unsigned, iu int unsigned, bu bigint unsigned, \
ff float, dd double, bb binary(100), nn nchar(100), tt timestamp , vc varchar(100)) tags (t1 timestamp, t2 bool,\ ff float, dd double, bb binary(100), nn nchar(100), tt timestamp , vc varchar(100)) tags (t1 timestamp, t2 bool,\
t3 tinyint, t4 tinyint, t5 smallint, t6 int, t7 bigint, t8 tinyint unsigned, t9 smallint unsigned, \ t3 tinyint, t4 tinyint, t5 smallint, t6 int, t7 bigint, t8 tinyint unsigned, t9 smallint unsigned, \
t10 int unsigned, t11 bigint unsigned, t12 float, t13 double, t14 binary(100), t15 nchar(100), t16 timestamp)") t10 int unsigned, t11 bigint unsigned, t12 float, t13 double, t14 binary(100), t15 nchar(100), t16 timestamp)"%stablename)
stmt = conn.statement("insert into ? using log tags (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) \ stmt = conn.statement("insert into ? using log tags (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) \
values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)") values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")
...@@ -139,142 +147,93 @@ class TDTestCase: ...@@ -139,142 +147,93 @@ class TDTestCase:
assert stmt.affected_rows == 3 assert stmt.affected_rows == 3
#query all #query all
querystmt1=conn.statement("select * from log where bu < ?") queryparam=new_bind_params(1)
queryparam1=new_bind_params(1) queryparam[0].int(10)
print(type(queryparam1)) rows=self.stmtExe(conn,"select * from log where bu < ?",queryparam)
queryparam1[0].int(10) tdLog.debug("assert 1st case %s"%rows)
querystmt1.bind_param(queryparam1) assert str(rows[0][0]) == "2021-07-21 17:56:32.589111"
querystmt1.execute() assert rows[0][10] == 3 , '1st case is failed'
result1=querystmt1.use_result() assert rows[1][10] == 4 , '1st case is failed'
rows1=result1.fetch_all()
print(rows1[0])
print(rows1[1])
print(rows1[2])
assert str(rows1[0][0]) == "2021-07-21 17:56:32.589111"
assert rows1[0][10] == 3
assert rows1[1][10] == 4
#query: Numeric Functions #query: Numeric Functions
querystmt2=conn.statement("select abs(?) from log where bu < ?") queryparam=new_bind_params(2)
queryparam2=new_bind_params(2) queryparam[0].int(5)
print(type(queryparam2)) queryparam[1].int(5)
queryparam2[0].int(5) rows=self.stmtExe(conn,"select abs(?) from log where bu < ?",queryparam)
queryparam2[1].int(5) tdLog.debug("assert 2nd case %s"%rows)
querystmt2.bind_param(queryparam2) assert rows[0][0] == 5 , '2nd case is failed'
querystmt2.execute() assert rows[1][0] == 5 , '2nd case is failed'
result2=querystmt2.use_result()
rows2=result2.fetch_all()
print("2",rows2)
assert rows2[0][0] == 5
assert rows2[1][0] == 5
#query: Numeric Functions and escapes #query: Numeric Functions and escapes
queryparam=new_bind_params(1)
querystmt3=conn.statement("select abs(?) from log where nn= 'a? long string with 中文字符' ") queryparam[0].int(5)
queryparam3=new_bind_params(1) rows=self.stmtExe(conn,"select abs(?) from log where nn= 'a? long string with 中文字符'",queryparam)
print(type(queryparam3)) tdLog.debug("assert 3rd case %s"%rows)
queryparam3[0].int(5) assert rows == [] , '3rd case is failed'
querystmt3.bind_param(queryparam3)
querystmt3.execute() #query: string Functions
result3=querystmt3.use_result() queryparam=new_bind_params(1)
rows3=result3.fetch_all() queryparam[0].binary('中文字符')
print("3",rows3) rows=self.stmtExe(conn,"select CHAR_LENGTH(?) from log ",queryparam)
assert rows3 == [] tdLog.debug("assert 4th case %s"%rows)
assert rows[0][0] == 12, '4th case is failed'
# #query: string Functions assert rows[1][0] == 12, '4th case is failed'
# querystmt3=conn.statement("select CHAR_LENGTH(?) from log ") queryparam=new_bind_params(1)
# queryparam3=new_bind_params(1) queryparam[0].binary('123')
# print(type(queryparam3)) rows=self.stmtExe(conn,"select CHAR_LENGTH(?) from log ",queryparam)
# queryparam3[0].binary('中文字符') tdLog.debug("assert 4th case %s"%rows)
# querystmt3.bind_param(queryparam3) assert rows[0][0] == 3, '4th.1 case is failed'
# querystmt3.execute() assert rows[1][0] == 3, '4th.1 case is failed'
# result3=querystmt3.use_result()
# rows3=result3.fetch_all() #query: conversion Functions
# print("4",rows3) queryparam=new_bind_params(1)
# assert rows3[0][0] == 12, 'fourth case is failed' queryparam[0].binary('1232a')
# assert rows3[1][0] == 12, 'fourth case is failed' rows=self.stmtExe(conn,"select cast( ? as bigint) from log",queryparam)
tdLog.debug("assert 5th case %s"%rows)
# #query: conversion Functions assert rows[0][0] == 1232, '5th.1 case is failed'
assert rows[1][0] == 1232, '5th.1 case is failed'
# querystmt4=conn.statement("select cast( ? as bigint) from log ")
# queryparam4=new_bind_params(1) querystmt4=conn.statement("select cast( ? as binary(10)) from log ")
# print(type(queryparam4)) queryparam=new_bind_params(1)
# queryparam4[0].binary('1232a') queryparam[0].int(123)
# querystmt4.bind_param(queryparam4) rows=self.stmtExe(conn,"select cast( ? as bigint) from log",queryparam)
# querystmt4.execute() tdLog.debug("assert 6th case %s"%rows)
# result4=querystmt4.use_result() assert rows[0][0] == 123, '6th.1 case is failed'
# rows4=result4.fetch_all() assert rows[1][0] == 123, '6th.1 case is failed'
# print("5",rows4)
# assert rows4[0][0] == 1232 #query: datatime Functions
# assert rows4[1][0] == 1232 queryparam=new_bind_params(1)
queryparam[0].timestamp(1626861392591112)
# querystmt4=conn.statement("select cast( ? as binary(10)) from log ") rows=self.stmtExe(conn,"select timediff('2021-07-21 17:56:32.590111',?,1a) from log",queryparam)
# queryparam4=new_bind_params(1) tdLog.debug("assert 7th case %s"%rows)
# print(type(queryparam4)) assert rows[0][0] == 1, '7th case is failed'
# queryparam4[0].int(123) assert rows[1][0] == 1, '7th case is failed'
# querystmt4.bind_param(queryparam4)
# querystmt4.execute()
# result4=querystmt4.use_result()
# rows4=result4.fetch_all()
# print("6",rows4)
# assert rows4[0][0] == '123'
# assert rows4[1][0] == '123'
# #query: datatime Functions
# querystmt4=conn.statement(" select timediff('2021-07-21 17:56:32.590111',?,1s) from log ")
# queryparam4=new_bind_params(1)
# print(type(queryparam4))
# queryparam4[0].timestamp(1626861392591111)
# querystmt4.bind_param(queryparam4)
# querystmt4.execute()
# result4=querystmt4.use_result()
# rows4=result4.fetch_all()
# print("7",rows4)
# assert rows4[0][0] == 1, 'seventh case is failed'
# assert rows4[1][0] == 1, 'seventh case is failed'
#query: aggregate Functions #query: aggregate Functions
queryparam=new_bind_params(1)
querystmt4=conn.statement(" select count(?) from log ") queryparam[0].int(123)
queryparam4=new_bind_params(1) rows=self.stmtExe(conn,"select count(?) from log ",queryparam)
print(type(queryparam4)) tdLog.debug("assert 8th case %s"%rows)
queryparam4[0].int(123) assert rows[0][0] == 3, ' 8th case is failed'
querystmt4.bind_param(queryparam4)
querystmt4.execute() # #query: selector Functions 9
result4=querystmt4.use_result() # queryparam=new_bind_params(1)
rows4=result4.fetch_all() # queryparam[0].int(2)
print("8",rows4) # rows=self.stmtExe(conn,"select bottom(bu,?) from log group by bu ; ",queryparam)
assert rows4[0][0] == 3, ' 8 case is failed' # tdLog.debug("assert 9th case %s"%rows)
# assert rows[0][0] == 4, ' 9 case is failed'
#query: selector Functions 9 # assert rows[1][0] == 3, ' 9 case is failed'
querystmt4=conn.statement(" select bottom(bu,?) from log group by bu ; ")
queryparam4=new_bind_params(1)
print(type(queryparam4))
queryparam4[0].int(2)
querystmt4.bind_param(queryparam4)
querystmt4.execute()
result4=querystmt4.use_result()
rows4=result4.fetch_all()
print("9",rows4)
assert rows4[0][0] == 4, ' 9 case is failed'
assert rows4[1][0] == 3, ' 9 case is failed'
# #query: time-series specific Functions 10 # #query: time-series specific Functions 10
querystmt4=conn.statement(" select twa(?) from log; ") querystmt=conn.statement(" select twa(?) from log; ")
queryparam4=new_bind_params(1) queryparam=new_bind_params(1)
print(type(queryparam4)) queryparam[0].int(15)
queryparam4[0].int(15) rows=self.stmtExe(conn," select twa(?) from log; ",queryparam)
querystmt4.bind_param(queryparam4) tdLog.debug("assert 10th case %s"%rows)
querystmt4.execute() assert rows[0][0] == 15, ' 10th case is failed'
result4=querystmt4.use_result()
rows4=result4.fetch_all()
print("10",rows4)
assert rows4[0][0] == 15, ' 10 case is failed'
# conn.execute("drop database if exists %s" % dbname) # conn.execute("drop database if exists %s" % dbname)
......
...@@ -63,8 +63,9 @@ if __name__ == "__main__": ...@@ -63,8 +63,9 @@ if __name__ == "__main__":
mnodeNums = 0 mnodeNums = 0
updateCfgDict = {} updateCfgDict = {}
execCmd = "" execCmd = ""
opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:', [ queryPolicy = 1
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums']) opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:', [
'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy'])
for key, value in opts: for key, value in opts:
if key in ['-h', '--help']: if key in ['-h', '--help']:
tdLog.printNoPrefix( tdLog.printNoPrefix(
...@@ -82,6 +83,7 @@ if __name__ == "__main__": ...@@ -82,6 +83,7 @@ if __name__ == "__main__":
tdLog.printNoPrefix('-e eval str to run') tdLog.printNoPrefix('-e eval str to run')
tdLog.printNoPrefix('-N create dnodes numbers in clusters') tdLog.printNoPrefix('-N create dnodes numbers in clusters')
tdLog.printNoPrefix('-M create mnode numbers in clusters') tdLog.printNoPrefix('-M create mnode numbers in clusters')
tdLog.printNoPrefix('-Q set queryPolicy in one dnode')
sys.exit(0) sys.exit(0)
...@@ -138,6 +140,9 @@ if __name__ == "__main__": ...@@ -138,6 +140,9 @@ if __name__ == "__main__":
if key in ['-M', '--mnodeNums']: if key in ['-M', '--mnodeNums']:
mnodeNums = value mnodeNums = value
if key in ['-Q', '--queryPolicy']:
queryPolicy = value
if not execCmd == "": if not execCmd == "":
tdDnodes.init(deployPath) tdDnodes.init(deployPath)
print(execCmd) print(execCmd)
...@@ -276,6 +281,22 @@ if __name__ == "__main__": ...@@ -276,6 +281,22 @@ if __name__ == "__main__":
tdDnodes.deploy(1,updateCfgDict) tdDnodes.deploy(1,updateCfgDict)
tdDnodes.start(1) tdDnodes.start(1)
tdCases.logSql(logSql) tdCases.logSql(logSql)
if queryPolicy != 1:
queryPolicy=int(queryPolicy)
conn = taos.connect(
host,
config=tdDnodes.getSimCfgPath())
tdSql.init(conn.cursor())
tdSql.execute("create qnode on dnode 1")
tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy)
tdSql.query("show local variables;")
for i in range(tdSql.queryRows):
if tdSql.queryResult[i][0] == "queryPolicy" :
if int(tdSql.queryResult[i][1]) == int(queryPolicy):
tdLog.success('alter queryPolicy to %d successfully'%queryPolicy)
else :
tdLog.debug(tdSql.queryResult)
tdLog.exit("alter queryPolicy to %d failed"%queryPolicy)
else : else :
tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums))
dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册