From 53e3b2e5f5bf0cb362009d0ab4aec5ac49fa27a4 Mon Sep 17 00:00:00 2001 From: cpwu Date: Thu, 18 Aug 2022 11:14:05 +0800 Subject: [PATCH] fix case, add case support rest api --- tests/pytest/util/sql.py | 20 +- tests/system-test/2-query/statecount.py | 414 ++++++++++---------- tests/system-test/2-query/substr.py | 46 +-- tests/system-test/2-query/sum.py | 65 ++-- tests/system-test/2-query/tail.py | 486 ++++++++++++------------ tests/system-test/2-query/tan.py | 459 +++++++++++----------- tests/system-test/fulltest.sh | 17 +- 7 files changed, 733 insertions(+), 774 deletions(-) diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 753c41e094..c0c86f0d85 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -102,7 +102,7 @@ class TDSql: caller = inspect.getframeinfo(inspect.stack()[1][0]) args = (caller.filename, caller.lineno, sql, repr(e)) tdLog.notice("%s(%d) failed: sql:%s, %s" % args) - raise Exception(repr(e)) + raise Exception(repr(e)) i+=1 time.sleep(1) pass @@ -254,21 +254,7 @@ class TDSql: args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) - if data is None: - tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % - (self.sql, row, col, self.queryResult[row][col], data)) - elif isinstance(data, str): - tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % - (self.sql, row, col, self.queryResult[row][col], data)) - elif isinstance(data, datetime.date): - tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % - (self.sql, row, col, self.queryResult[row][col], data)) - elif isinstance(data, float): - tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % - (self.sql, row, col, self.queryResult[row][col], data)) - else: - tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%d" % - (self.sql, row, col, self.queryResult[row][col], data)) + tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}") def getData(self, row, col): self.checkRowCol(row, col) @@ -307,7 +293,7 @@ class TDSql: caller = inspect.getframeinfo(inspect.stack()[1][0]) args = (caller.filename, caller.lineno, sql, repr(e)) tdLog.notice("%s(%d) failed: sql:%s, %s" % args) - raise Exception(repr(e)) + raise Exception(repr(e)) i+=1 time.sleep(1) pass diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py index a88c4aef9f..c73c955de4 100644 --- a/tests/system-test/2-query/statecount.py +++ b/tests/system-test/2-query/statecount.py @@ -11,50 +11,47 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -70,68 +67,68 @@ class TDTestCase: ''' ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - # "select statecount(c1,'GT',5) from t1" - "select statecount from t1", - "select statecount(123--123)==1 from t1", - "select statecount(123,123) from t1", - "select statecount(c1,ts) from t1", - "select statecount(c1,c1,ts) from t1", - "select statecount(c1 ,c2 ) from t1", - "select statecount(c1 ,NULL) from t1", - #"select statecount(c1 ,'NULL',1.0) from t1", - "select statecount(c1 ,'GT','1') from t1", - "select statecount(c1 ,'GT','tbname') from t1", - "select statecount(c1 ,'GT','*') from t1", - "select statecount(c1 ,'GT',ts) from t1", - "select statecount(c1 ,'GT',max(c1)) from t1", - # "select statecount(abs(c1) ,'GT',1) from t1", - # "select statecount(c1+2 ,'GT',1) from t1", - "select statecount(c1 ,'GT',1,1u) from t1", - "select statecount(c1 ,'GT',1,now) from t1", - "select statecount(c1 ,'GT','1') from t1", - "select statecount(c1 ,'GT','1',True) from t1", - "select statecount(statecount(c1) ab from t1)", - "select statecount(c1 ,'GT',1,,)int from t1", - "select statecount('c1','GT',1) from t1", - "select statecount('c1','GT' , NULL) from t1", - "select statecount('c1','GT', 1 , '') from t1", - "select statecount('c1','GT', 1 ,c%) from t1", - "select statecount(c1 ,'GT',1,t1) from t1", - "select statecount(c1 ,'GT',1,True) from t1", - "select statecount(c1 ,'GT',1) , count(c1) from t1", - "select statecount(c1 ,'GT',1) , avg(c1) from t1", - "select statecount(c1 ,'GT',1) , min(c1) from t1", - "select statecount(c1 ,'GT',1) , spread(c1) from t1", - "select statecount(c1 ,'GT',1) , diff(c1) from t1", + # f"select statecount(c1,'GT',5) from {dbname}.t1" + f"select statecount from {dbname}.t1", + f"select statecount(123--123)==1 from {dbname}.t1", + f"select statecount(123,123) from {dbname}.t1", + f"select statecount(c1,ts) from {dbname}.t1", + f"select statecount(c1,c1,ts) from {dbname}.t1", + f"select statecount(c1 ,c2 ) from {dbname}.t1", + f"select statecount(c1 ,NULL) from {dbname}.t1", + #f"select statecount(c1 ,'NULL',1.0) from {dbname}.t1", + f"select statecount(c1 ,'GT','1') from {dbname}.t1", + f"select statecount(c1 ,'GT','tbname') from {dbname}.t1", + f"select statecount(c1 ,'GT','*') from {dbname}.t1", + f"select statecount(c1 ,'GT',ts) from {dbname}.t1", + f"select statecount(c1 ,'GT',max(c1)) from {dbname}.t1", + # f"select statecount(abs(c1) ,'GT',1) from {dbname}.t1", + # f"select statecount(c1+2 ,'GT',1) from {dbname}.t1", + f"select statecount(c1 ,'GT',1,1u) from {dbname}.t1", + f"select statecount(c1 ,'GT',1,now) from {dbname}.t1", + f"select statecount(c1 ,'GT','1') from {dbname}.t1", + f"select statecount(c1 ,'GT','1',True) from {dbname}.t1", + f"select statecount(statecount(c1) ab from {dbname}.t1)", + f"select statecount(c1 ,'GT',1,,)int from {dbname}.t1", + f"select statecount('c1','GT',1) from {dbname}.t1", + f"select statecount('c1','GT' , NULL) from {dbname}.t1", + f"select statecount('c1','GT', 1 , '') from {dbname}.t1", + f"select statecount('c1','GT', 1 ,c%) from {dbname}.t1", + f"select statecount(c1 ,'GT',1,t1) from {dbname}.t1", + f"select statecount(c1 ,'GT',1,True) from {dbname}.t1", + f"select statecount(c1 ,'GT',1) , count(c1) from {dbname}.t1", + f"select statecount(c1 ,'GT',1) , avg(c1) from {dbname}.t1", + f"select statecount(c1 ,'GT',1) , min(c1) from {dbname}.t1", + f"select statecount(c1 ,'GT',1) , spread(c1) from {dbname}.t1", + f"select statecount(c1 ,'GT',1) , diff(c1) from {dbname}.t1", ] for error_sql in error_sql_lists: tdSql.error(error_sql) pass - def support_types(self): + def support_types(self, dbname="db"): other_no_value_types = [ - "select statecount(ts,'GT',1) from t1" , - "select statecount(c7,'GT',1) from t1", - "select statecount(c8,'GT',1) from t1", - "select statecount(c9,'GT',1) from t1", - "select statecount(ts,'GT',1) from ct1" , - "select statecount(c7,'GT',1) from ct1", - "select statecount(c8,'GT',1) from ct1", - "select statecount(c9,'GT',1) from ct1", - "select statecount(ts,'GT',1) from ct3" , - "select statecount(c7,'GT',1) from ct3", - "select statecount(c8,'GT',1) from ct3", - "select statecount(c9,'GT',1) from ct3", - "select statecount(ts,'GT',1) from ct4" , - "select statecount(c7,'GT',1) from ct4", - "select statecount(c8,'GT',1) from ct4", - "select statecount(c9,'GT',1) from ct4", - "select statecount(ts,'GT',1) from stb1 partition by tbname" , - "select statecount(c7,'GT',1) from stb1 partition by tbname", - "select statecount(c8,'GT',1) from stb1 partition by tbname", - "select statecount(c9,'GT',1) from stb1 partition by tbname" + f"select statecount(ts,'GT',1) from {dbname}.t1" , + f"select statecount(c7,'GT',1) from {dbname}.t1", + f"select statecount(c8,'GT',1) from {dbname}.t1", + f"select statecount(c9,'GT',1) from {dbname}.t1", + f"select statecount(ts,'GT',1) from {dbname}.ct1" , + f"select statecount(c7,'GT',1) from {dbname}.ct1", + f"select statecount(c8,'GT',1) from {dbname}.ct1", + f"select statecount(c9,'GT',1) from {dbname}.ct1", + f"select statecount(ts,'GT',1) from {dbname}.ct3" , + f"select statecount(c7,'GT',1) from {dbname}.ct3", + f"select statecount(c8,'GT',1) from {dbname}.ct3", + f"select statecount(c9,'GT',1) from {dbname}.ct3", + f"select statecount(ts,'GT',1) from {dbname}.ct4" , + f"select statecount(c7,'GT',1) from {dbname}.ct4", + f"select statecount(c8,'GT',1) from {dbname}.ct4", + f"select statecount(c9,'GT',1) from {dbname}.ct4", + f"select statecount(ts,'GT',1) from {dbname}.stb1 partition by tbname" , + f"select statecount(c7,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c8,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c9,'GT',1) from {dbname}.stb1 partition by tbname" ] for type_sql in other_no_value_types: @@ -139,224 +136,222 @@ class TDTestCase: tdLog.info("support type ok , sql is : %s"%type_sql) type_sql_lists = [ - "select statecount(c1,'GT',1) from t1", - "select statecount(c2,'GT',1) from t1", - "select statecount(c3,'GT',1) from t1", - "select statecount(c4,'GT',1) from t1", - "select statecount(c5,'GT',1) from t1", - "select statecount(c6,'GT',1) from t1", - - "select statecount(c1,'GT',1) from ct1", - "select statecount(c2,'GT',1) from ct1", - "select statecount(c3,'GT',1) from ct1", - "select statecount(c4,'GT',1) from ct1", - "select statecount(c5,'GT',1) from ct1", - "select statecount(c6,'GT',1) from ct1", - - "select statecount(c1,'GT',1) from ct3", - "select statecount(c2,'GT',1) from ct3", - "select statecount(c3,'GT',1) from ct3", - "select statecount(c4,'GT',1) from ct3", - "select statecount(c5,'GT',1) from ct3", - "select statecount(c6,'GT',1) from ct3", - - "select statecount(c1,'GT',1) from stb1 partition by tbname", - "select statecount(c2,'GT',1) from stb1 partition by tbname", - "select statecount(c3,'GT',1) from stb1 partition by tbname", - "select statecount(c4,'GT',1) from stb1 partition by tbname", - "select statecount(c5,'GT',1) from stb1 partition by tbname", - "select statecount(c6,'GT',1) from stb1 partition by tbname", - - "select statecount(c6,'GT',1) as alisb from stb1 partition by tbname", - "select statecount(c6,'GT',1) alisb from stb1 partition by tbname", + f"select statecount(c1,'GT',1) from {dbname}.t1", + f"select statecount(c2,'GT',1) from {dbname}.t1", + f"select statecount(c3,'GT',1) from {dbname}.t1", + f"select statecount(c4,'GT',1) from {dbname}.t1", + f"select statecount(c5,'GT',1) from {dbname}.t1", + f"select statecount(c6,'GT',1) from {dbname}.t1", + + f"select statecount(c1,'GT',1) from {dbname}.ct1", + f"select statecount(c2,'GT',1) from {dbname}.ct1", + f"select statecount(c3,'GT',1) from {dbname}.ct1", + f"select statecount(c4,'GT',1) from {dbname}.ct1", + f"select statecount(c5,'GT',1) from {dbname}.ct1", + f"select statecount(c6,'GT',1) from {dbname}.ct1", + + f"select statecount(c1,'GT',1) from {dbname}.ct3", + f"select statecount(c2,'GT',1) from {dbname}.ct3", + f"select statecount(c3,'GT',1) from {dbname}.ct3", + f"select statecount(c4,'GT',1) from {dbname}.ct3", + f"select statecount(c5,'GT',1) from {dbname}.ct3", + f"select statecount(c6,'GT',1) from {dbname}.ct3", + + f"select statecount(c1,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c2,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c3,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c4,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c5,'GT',1) from {dbname}.stb1 partition by tbname", + f"select statecount(c6,'GT',1) from {dbname}.stb1 partition by tbname", + + f"select statecount(c6,'GT',1) as alisb from {dbname}.stb1 partition by tbname", + f"select statecount(c6,'GT',1) alisb from {dbname}.stb1 partition by tbname", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def support_opers(self): + def support_opers(self, dbname="db"): oper_lists = ['LT','lt','Lt','lT','GT','gt','Gt','gT','LE','le','Le','lE','GE','ge','Ge','gE','NE','ne','Ne','nE','EQ','eq','Eq','eQ'] oper_errors = [",","*","NULL","tbname","ts","sum","_c0"] for oper in oper_lists: - tdSql.query(f"select statecount(c1 ,'{oper}',1) as col from t1") + tdSql.query(f"select statecount(c1 ,'{oper}',1) as col from {dbname}.t1") tdSql.checkRows(12) for oper in oper_errors: - tdSql.error(f"select statecount(c1 ,'{oper}',1) as col from t1") - + tdSql.error(f"select statecount(c1 ,'{oper}',1) as col from {dbname}.t1") - def basic_statecount_function(self): + def basic_statecount_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select statecount(c6,'GT',1) from ct3") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select statecount(c6,'GT',1) from ct3") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select statecount(c6,'GT',1) from ct3") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select statecount(c6,'GT',1) from ct3") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select statecount(c6,'GT',1) from ct3") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select statecount(c6,'GT',1) from ct3") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct3") # will support _rowts mix with - # tdSql.query("select (c6,'GT',1),_rowts from ct3") + # tdSql.query(f"select (c6,'GT',1),_rowts from {dbname}.ct3") # auto check for t1 table # used for regular table - tdSql.query("select statecount(c6,'GT',1) from t1") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.t1") # unique with super tags - tdSql.query("select statecount(c6,'GT',1) from ct1") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select statecount(c6,'GT',1) from ct4") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct4") tdSql.checkRows(12) - tdSql.query("select statecount(c6,'GT',1),tbname from ct1") + tdSql.query(f"select statecount(c6,'GT',1),tbname from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select statecount(c6,'GT',1),t1 from ct1") + tdSql.query(f"select statecount(c6,'GT',1),t1 from {dbname}.ct1") tdSql.checkRows(13) # unique with common col - tdSql.query("select statecount(c6,'GT',1) ,ts from ct1") + tdSql.query(f"select statecount(c6,'GT',1) ,ts from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select ts, statecount(c6,'GT',1) from ct1") + tdSql.query(f"select ts, statecount(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select statecount(c6,'GT',1) ,c1 from ct1") + tdSql.query(f"select statecount(c6,'GT',1) ,c1 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select c1, statecount(c6,'GT',1) from ct1") + tdSql.query(f"select c1, statecount(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select ts, c1, c2, c3, statecount(c6,'GT',1) from ct1") + tdSql.query(f"select ts, c1, c2, c3, statecount(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select statecount(c6,'GT',1), ts, c1, c2, c3 from ct1") + tdSql.query(f"select statecount(c6,'GT',1), ts, c1, c2, c3 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select ts, c1, c2, c3, statecount(c6,'GT',1), ts, c4, c5, c6 from ct1") + tdSql.query(f"select ts, c1, c2, c3, statecount(c6,'GT',1), ts, c4, c5, c6 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select stateduration(c6,'GT',1) ,ts from ct1") + tdSql.query(f"select stateduration(c6,'GT',1) ,ts from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select ts, stateduration(c6,'GT',1) from ct1") + tdSql.query(f"select ts, stateduration(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select stateduration(c6,'GT',1) ,c1 from ct1") + tdSql.query(f"select stateduration(c6,'GT',1) ,c1 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select c1, stateduration(c6,'GT',1) from ct1") + tdSql.query(f"select c1, stateduration(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select ts, c1, c2, c3, stateduration(c6,'GT',1) from ct1") + tdSql.query(f"select ts, c1, c2, c3, stateduration(c6,'GT',1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select stateduration(c6,'GT',1), ts, c1, c2, c3 from ct1") + tdSql.query(f"select stateduration(c6,'GT',1), ts, c1, c2, c3 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select ts, c1, c2, c3, stateduration(c6,'GT',1), ts, c4, c5, c6 from ct1") + tdSql.query(f"select ts, c1, c2, c3, stateduration(c6,'GT',1), ts, c4, c5, c6 from {dbname}.ct1") tdSql.checkRows(13) # unique with scalar function - tdSql.query("select statecount(c6,'GT',1) , abs(c1) from ct1") + tdSql.query(f"select statecount(c6,'GT',1) , abs(c1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select statecount(c6,'GT',1) , abs(c2)+2 from ct1") + tdSql.query(f"select statecount(c6,'GT',1) , abs(c2)+2 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.error("select statecount(c6,'GT',1) , unique(c2) from ct1") + tdSql.error(f"select statecount(c6,'GT',1) , unique(c2) from {dbname}.ct1") - tdSql.query("select stateduration(c6,'GT',1) , abs(c1) from ct1") + tdSql.query(f"select stateduration(c6,'GT',1) , abs(c1) from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select stateduration(c6,'GT',1) , abs(c2)+2 from ct1") + tdSql.query(f"select stateduration(c6,'GT',1) , abs(c2)+2 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.error("select stateduration(c6,'GT',1) , unique(c2) from ct1") + tdSql.error(f"select stateduration(c6,'GT',1) , unique(c2) from {dbname}.ct1") # unique with aggregate function - tdSql.error("select statecount(c6,'GT',1) ,sum(c1) from ct1") - tdSql.error("select statecount(c6,'GT',1) ,max(c1) from ct1") - tdSql.error("select statecount(c6,'GT',1) ,csum(c1) from ct1") - tdSql.error("select statecount(c6,'GT',1) ,count(c1) from ct1") + tdSql.error(f"select statecount(c6,'GT',1) ,sum(c1) from {dbname}.ct1") + tdSql.error(f"select statecount(c6,'GT',1) ,max(c1) from {dbname}.ct1") + tdSql.error(f"select statecount(c6,'GT',1) ,csum(c1) from {dbname}.ct1") + tdSql.error(f"select statecount(c6,'GT',1) ,count(c1) from {dbname}.ct1") # unique with filter where - tdSql.query("select statecount(c6,'GT',1) from ct4 where c1 is null") + tdSql.query(f"select statecount(c6,'GT',1) from {dbname}.ct4 where c1 is null") tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, None) tdSql.checkData(2, 0, None) - tdSql.query("select statecount(c1,'GT',1) from t1 where c1 >2 ") + tdSql.query(f"select statecount(c1,'GT',1) from {dbname}.t1 where c1 >2 ") tdSql.checkData(0, 0, 1) tdSql.checkData(1, 0, 2) tdSql.checkData(2, 0, 3) tdSql.checkData(4, 0, 5) tdSql.checkData(5, 0, 6) - tdSql.query("select statecount(c2,'GT',1) from t1 where c2 between 0 and 99999") + tdSql.query(f"select statecount(c2,'GT',1) from {dbname}.t1 where c2 between 0 and 99999") tdSql.checkData(0, 0, 1) tdSql.checkData(1, 0, 2) tdSql.checkData(6, 0, -1) # unique with union all - tdSql.query("select statecount(c1,'GT',1) from ct4 union all select statecount(c1,'GT',1) from ct1") + tdSql.query(f"select statecount(c1,'GT',1) from {dbname}.ct4 union all select statecount(c1,'GT',1) from {dbname}.ct1") tdSql.checkRows(25) - tdSql.query("select statecount(c1,'GT',1) from ct4 union all select distinct(c1) from ct4") + tdSql.query(f"select statecount(c1,'GT',1) from {dbname}.ct4 union all select distinct(c1) from {dbname}.ct4") tdSql.checkRows(22) # unique with join # prepare join datas with same ts - tdSql.execute(" use db ") - tdSql.execute(" create stable st1 (ts timestamp , num int) tags(ind int)") - tdSql.execute(" create table tb1 using st1 tags(1)") - tdSql.execute(" create table tb2 using st1 tags(2)") + tdSql.execute(f"create stable {dbname}.st1 (ts timestamp , num int) tags(ind int)") + tdSql.execute(f"create table {dbname}.tb1 using {dbname}.st1 tags(1)") + tdSql.execute(f"create table {dbname}.tb2 using {dbname}.st1 tags(2)") - tdSql.execute(" create stable st2 (ts timestamp , num int) tags(ind int)") - tdSql.execute(" create table ttb1 using st2 tags(1)") - tdSql.execute(" create table ttb2 using st2 tags(2)") + tdSql.execute(f"create stable {dbname}.st2 (ts timestamp , num int) tags(ind int)") + tdSql.execute(f"create table {dbname}.ttb1 using {dbname}.st2 tags(1)") + tdSql.execute(f"create table {dbname}.ttb2 using {dbname}.st2 tags(2)") start_ts = 1622369635000 # 2021-05-30 18:13:55 for i in range(10): ts_value = start_ts+i*1000 - tdSql.execute(f" insert into tb1 values({ts_value} , {i})") - tdSql.execute(f" insert into tb2 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.tb1 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.tb2 values({ts_value} , {i})") - tdSql.execute(f" insert into ttb1 values({ts_value} , {i})") - tdSql.execute(f" insert into ttb2 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.ttb1 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.ttb2 values({ts_value} , {i})") - tdSql.query("select statecount(tb1.num,'GT',1) from tb1, tb2 where tb1.ts=tb2.ts ") + tdSql.query(f"select statecount(tb1.num,'GT',1) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts ") tdSql.checkRows(10) tdSql.checkData(0,0,-1) tdSql.checkData(1,0,-1) tdSql.checkData(2,0,1) tdSql.checkData(9,0,8) - tdSql.query("select statecount(tb1.num,'GT',1) from tb1, tb2 where tb1.ts=tb2.ts union all select statecount(tb2.num,'GT',1) from tb1, tb2 where tb1.ts=tb2.ts ") + tdSql.query(f"select statecount(tb1.num,'GT',1) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts union all select statecount(tb2.num,'GT',1) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts ") tdSql.checkRows(20) # nest query - # tdSql.query("select unique(c1) from (select c1 from ct1)") - tdSql.query("select c1 from (select statecount(c1,'GT',1) c1 from t1)") + # tdSql.query(f"select unique(c1) from (select c1 from {dbname}.ct1)") + tdSql.query(f"select c1 from (select statecount(c1,'GT',1) c1 from {dbname}.t1)") tdSql.checkRows(12) tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, -1) tdSql.checkData(2, 0, 1) tdSql.checkData(10, 0, 8) - tdSql.query("select sum(c1) from (select statecount(c1,'GT',1) c1 from t1)") + tdSql.query(f"select sum(c1) from (select statecount(c1,'GT',1) c1 from {dbname}.t1)") tdSql.checkRows(1) tdSql.checkData(0, 0, 35) - tdSql.query("select sum(c1) from (select distinct(c1) c1 from ct1) union all select sum(c1) from (select statecount(c1,'GT',1) c1 from ct1)") + tdSql.query(f"select sum(c1) from (select distinct(c1) c1 from {dbname}.ct1) union all select sum(c1) from (select statecount(c1,'GT',1) c1 from {dbname}.ct1)") tdSql.checkRows(2) - tdSql.query("select 1-abs(c1) from (select statecount(c1,'GT',1) c1 from t1)") + tdSql.query(f"select 1-abs(c1) from (select statecount(c1,'GT',1) c1 from {dbname}.t1)") tdSql.checkRows(12) tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, 0.000000000) @@ -365,43 +360,41 @@ class TDTestCase: # bug for stable #partition by tbname - # tdSql.query(" select unique(c1) from stb1 partition by tbname ") + # tdSql.query(f"select unique(c1) from {dbname}.stb1 partition by tbname ") # tdSql.checkRows(21) - # tdSql.query(" select unique(c1) from stb1 partition by tbname ") + # tdSql.query(f"select unique(c1) from {dbname}.stb1 partition by tbname ") # tdSql.checkRows(21) # group by - tdSql.error("select statecount(c1,'GT',1) from ct1 group by c1") - tdSql.error("select statecount(c1,'GT',1) from ct1 group by tbname") - - # super table - - def check_unit_time(self): - tdSql.execute(" use db ") - tdSql.error("select stateduration(c1,'GT',1,1b) from ct1") - tdSql.error("select stateduration(c1,'GT',1,1u) from ct1") - tdSql.error("select stateduration(c1,'GT',1,1000s) from t1") - tdSql.error("select stateduration(c1,'GT',1,10m) from t1") - tdSql.error("select stateduration(c1,'GT',1,10d) from t1") - tdSql.query("select stateduration(c1,'GT',1,1s) from t1") + tdSql.error(f"select statecount(c1,'GT',1) from {dbname}.ct1 group by c1") + tdSql.error(f"select statecount(c1,'GT',1) from {dbname}.ct1 group by tbname") + + def check_unit_time(self, dbname="db"): + tdSql.error(f"select stateduration(c1,'GT',1,1b) from {dbname}.ct1") + tdSql.error(f"select stateduration(c1,'GT',1,1u) from {dbname}.ct1") + tdSql.error(f"select stateduration(c1,'GT',1,1000s) from {dbname}.t1") + tdSql.error(f"select stateduration(c1,'GT',1,10m) from {dbname}.t1") + tdSql.error(f"select stateduration(c1,'GT',1,10d) from {dbname}.t1") + tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.t1") tdSql.checkData(10,0,63072035) - tdSql.query("select stateduration(c1,'GT',1,1m) from t1") + tdSql.query(f"select stateduration(c1,'GT',1,1m) from {dbname}.t1") tdSql.checkData(10,0,int(63072035/60)) - tdSql.query("select stateduration(c1,'GT',1,1h) from t1") + tdSql.query(f"select stateduration(c1,'GT',1,1h) from {dbname}.t1") tdSql.checkData(10,0,int(63072035/60/60)) - tdSql.query("select stateduration(c1,'GT',1,1d) from t1") + tdSql.query(f"select stateduration(c1,'GT',1,1d) from {dbname}.t1") tdSql.checkData(10,0,int(63072035/60/24/60)) - tdSql.query("select stateduration(c1,'GT',1,1w) from t1") + tdSql.query(f"select stateduration(c1,'GT',1,1w) from {dbname}.t1") tdSql.checkData(10,0,int(63072035/60/7/24/60)) def query_precision(self): def generate_data(precision="ms"): - tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision)) + dbname = f"db_{precision}" + tdSql.execute(f"create database if not exists db_%s precision '%s';" %(precision, precision)) tdSql.execute("use db_%s;" %precision) - tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision) - tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision) - tdSql.execute("create table db_%s.tb2 using st tags(2);"%precision) + tdSql.execute(f"create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision) + tdSql.execute(f"create table db_%s.tb1 using {dbname}.st tags(1);"%precision) + tdSql.execute(f"create table db_%s.tb2 using {dbname}.st tags(2);"%precision) if precision == "ms": start_ts = self.ts @@ -432,55 +425,54 @@ class TDTestCase: if pres == "ms": if unit in ["1u","1b"]: - tdSql.error("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + tdSql.error(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) pass else: - tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + tdSql.query(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) elif pres == "us" and unit in ["1b"]: if unit in ["1b"]: - tdSql.error("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + tdSql.error(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) pass else: - tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + tdSql.query(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) else: - tdSql.query("select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) + tdSql.query(f"select stateduration(id,'GT',1,%s) from db_%s.tb1 "%(unit,pres)) basic_result = 70 tdSql.checkData(9,0,basic_result*pow(1000,index)) - def check_boundary_values(self): + def check_boundary_values(self, dbname="bound_test"): - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") - tdSql.execute("use bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - tdSql.query("select statecount(c1,'GT',1) from sub1_bound") + tdSql.query(f"select statecount(c1,'GT',1) from {dbname}.sub1_bound") tdSql.checkRows(5) def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring diff --git a/tests/system-test/2-query/substr.py b/tests/system-test/2-query/substr.py index f833a42b57..ea55c5e44e 100644 --- a/tests/system-test/2-query/substr.py +++ b/tests/system-test/2-query/substr.py @@ -127,16 +127,16 @@ class TDTestCase: return sqls - def __test_current(self): # sourcery skip: use-itertools-product + def __test_current(self, dbname="db"): # sourcery skip: use-itertools-product tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") - tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"] for tb in tbname: self.__substr_check(tb, CURRENT_POS, LENS) tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") - tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"] for tb in tbname: for errsql in self.__substr_err_check(tb): @@ -145,22 +145,21 @@ class TDTestCase: tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") - def all_test(self): - self.__test_current() - self.__test_error() + def all_test(self, dbname="db"): + self.__test_current(dbname) + self.__test_error(dbname) - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp ) tags (tag1 int) ''' - create_ntb_sql = f'''create table t1( + create_ntb_sql = f'''create table {dbname}.t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp @@ -170,29 +169,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) for i in range(rows): tdSql.execute( - f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {dbname}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -208,7 +207,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -224,13 +223,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -259,10 +258,7 @@ class TDTestCase: tdLog.printNoPrefix("==========step3:all check") self.all_test() - tdDnodes.stop(1) - tdDnodes.start(1) - - tdSql.execute("use db") + tdSql.execute("flush database db") tdLog.printNoPrefix("==========step4:after wal, all check again ") self.all_test() diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index 4f5ed34419..dbc79e25f5 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -89,14 +89,14 @@ class TDTestCase: return sqls - def __test_current(self): + def __test_current(self, dbname="db"): tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") tbname = ["ct1", "ct2", "ct4", "t1"] for tb in tbname: self.__sum_current_check(tb) tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") tbname = ["ct1", "ct2", "ct4", "t1"] @@ -106,21 +106,21 @@ class TDTestCase: tdLog.printNoPrefix(f"==========err sql condition check in {tb} over==========") - def all_test(self): - self.__test_current() - self.__test_error() + def all_test(self, dbname="db"): + self.__test_current(dbname) + self.__test_error(dbname) - def __create_tb(self): + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table {DBNAME}.stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) tags (t1 int) + ) tags (tag1 int) ''' - create_ntb_sql = f'''create table {DBNAME}.t1( + create_ntb_sql = f'''create table {dbname}.t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp @@ -130,83 +130,82 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table {DBNAME}.ct{i+1} using {DBNAME}.stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) for i in range(rows): tdSql.execute( - f"insert into {DBNAME}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into {DBNAME}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into {DBNAME}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into {DBNAME}.ct1 values - ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) - ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) + f'''insert into {dbname}.ct1 values + ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) + ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into {DBNAME}.ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000} + { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000} ) ( { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000} + { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000} ) ''' ) tdSql.execute( - f'''insert into {DBNAME}.ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, - { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } ) ( { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, - { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } ) ''' ) for i in range(rows): - insert_data = f'''insert into {DBNAME}.t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, - "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) + "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into {DBNAME}.t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, - "binary_limit-1", "nchar_limit-1", { now_time - 86400000 } + "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } ) ( { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, - "binary_limit-2", "nchar_limit-2", { now_time - 172800000 } + "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } ) ''' ) - def run(self): tdSql.prepare() @@ -219,12 +218,8 @@ class TDTestCase: tdLog.printNoPrefix("==========step3:all check") self.all_test() - # tdDnodes.stop(1) - # tdDnodes.start(1) - tdSql.execute("flush database db") - tdSql.execute("use db") tdLog.printNoPrefix("==========step4:after wal, all check again ") diff --git a/tests/system-test/2-query/tail.py b/tests/system-test/2-query/tail.py index d708873d6f..687023f57e 100644 --- a/tests/system-test/2-query/tail.py +++ b/tests/system-test/2-query/tail.py @@ -10,49 +10,46 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - - def prepare_datas(self): + + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) - + tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -67,115 +64,115 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - - def test_errors(self): + + def test_errors(self, dbname="db"): error_sql_lists = [ - "select tail from t1", - "select tail(123--123)==1 from t1", - "select tail(123,123) from t1", - "select tail(c1,ts) from t1", - "select tail(c1,c1,ts) from t1", - "select tail(c1) as 'd1' from t1", - "select tail(c1 ,c2 ) from t1", - "select tail(c1 ,NULL) from t1", - "select tail(,) from t1;", - "select tail(tail(c1) ab from t1)", - "select tail(c1) as int from t1", - "select tail('c1') from t1", - "select tail(NULL) from t1", - "select tail('') from t1", - "select tail(c%) from t1", - "select tail(t1) from t1", - "select tail(True) from t1", - "select tail(c1,1) , count(c1) from t1", - "select tail(c1,1) , avg(c1) from t1", - "select tail(c1,1) , min(c1) from t1", - "select tail(c1,1) , spread(c1) from t1", - "select tail(c1,1) , diff(c1) from t1", - "select tail from stb1 partition by tbname", - "select tail(123--123)==1 from stb1 partition by tbname", - "select tail(123,123) from stb1 partition by tbname", - "select tail(c1,ts) from stb1 partition by tbname", - "select tail(c1,c1,ts) from stb1 partition by tbname", - "select tail(c1) as 'd1' from stb1 partition by tbname", - "select tail(c1 ,c2 ) from stb1 partition by tbname", - "select tail(c1 ,NULL) from stb1 partition by tbname", - "select tail(,) from stb1 partition by tbname;", - "select tail(tail(c1) ab from stb1 partition by tbname)", - "select tail(c1) as int from stb1 partition by tbname", - "select tail('c1') from stb1 partition by tbname", - "select tail(NULL) from stb1 partition by tbname", - "select tail('') from stb1 partition by tbname", - "select tail(c%) from stb1 partition by tbname", - "select tail(t1) from stb1 partition by tbname", - "select tail(True) from stb1 partition by tbname", - "select tail(c1,1) , count(c1) from stb1 partition by tbname", - "select tail(c1,1) , avg(c1) from stb1 partition by tbname", - "select tail(c1,1) , min(c1) from stb1 partition by tbname", - "select tail(c1,1) , spread(c1) from stb1 partition by tbname", - "select tail(c1,1) , diff(c1) from stb1 partition by tbname", + f"select tail from {dbname}.t1", + f"select tail(123--123)==1 from {dbname}.t1", + f"select tail(123,123) from {dbname}.t1", + f"select tail(c1,ts) from {dbname}.t1", + f"select tail(c1,c1,ts) from {dbname}.t1", + f"select tail(c1) as 'd1' from {dbname}.t1", + f"select tail(c1 ,c2 ) from {dbname}.t1", + f"select tail(c1 ,NULL) from {dbname}.t1", + f"select tail(,) from {dbname}.t1;", + f"select tail(tail(c1) ab from {dbname}.t1)", + f"select tail(c1) as int from {dbname}.t1", + f"select tail('c1') from {dbname}.t1", + f"select tail(NULL) from {dbname}.t1", + f"select tail('') from {dbname}.t1", + f"select tail(c%) from {dbname}.t1", + f"select tail(t1) from {dbname}.t1", + f"select tail(True) from {dbname}.t1", + f"select tail(c1,1) , count(c1) from {dbname}.t1", + f"select tail(c1,1) , avg(c1) from {dbname}.t1", + f"select tail(c1,1) , min(c1) from {dbname}.t1", + f"select tail(c1,1) , spread(c1) from {dbname}.t1", + f"select tail(c1,1) , diff(c1) from {dbname}.t1", + f"select tail from {dbname}.stb1 partition by tbname", + f"select tail(123--123)==1 from {dbname}.stb1 partition by tbname", + f"select tail(123,123) from {dbname}.stb1 partition by tbname", + f"select tail(c1,ts) from {dbname}.stb1 partition by tbname", + f"select tail(c1,c1,ts) from {dbname}.stb1 partition by tbname", + f"select tail(c1) as 'd1' from {dbname}.stb1 partition by tbname", + f"select tail(c1 ,c2 ) from {dbname}.stb1 partition by tbname", + f"select tail(c1 ,NULL) from {dbname}.stb1 partition by tbname", + f"select tail(,) from {dbname}.stb1 partition by tbname;", + f"select tail(tail(c1) ab from {dbname}.stb1 partition by tbname)", + f"select tail(c1) as int from {dbname}.stb1 partition by tbname", + f"select tail('c1') from {dbname}.stb1 partition by tbname", + f"select tail(NULL) from {dbname}.stb1 partition by tbname", + f"select tail('') from {dbname}.stb1 partition by tbname", + f"select tail(c%) from {dbname}.stb1 partition by tbname", + f"select tail(t1) from {dbname}.stb1 partition by tbname", + f"select tail(True) from {dbname}.stb1 partition by tbname", + f"select tail(c1,1) , count(c1) from {dbname}.stb1 partition by tbname", + f"select tail(c1,1) , avg(c1) from {dbname}.stb1 partition by tbname", + f"select tail(c1,1) , min(c1) from {dbname}.stb1 partition by tbname", + f"select tail(c1,1) , spread(c1) from {dbname}.stb1 partition by tbname", + f"select tail(c1,1) , diff(c1) from {dbname}.stb1 partition by tbname", ] for error_sql in error_sql_lists: tdSql.error(error_sql) - - def support_types(self): + + def support_types(self, dbname="db"): other_no_value_types = [ - "select tail(ts,1) from t1" , - "select tail(c7,1) from t1", - "select tail(c8,1) from t1", - "select tail(c9,1) from t1", - "select tail(ts,1) from ct1" , - "select tail(c7,1) from ct1", - "select tail(c8,1) from ct1", - "select tail(c9,1) from ct1", - "select tail(ts,1) from ct3" , - "select tail(c7,1) from ct3", - "select tail(c8,1) from ct3", - "select tail(c9,1) from ct3", - "select tail(ts,1) from ct4" , - "select tail(c7,1) from ct4", - "select tail(c8,1) from ct4", - "select tail(c9,1) from ct4", - "select tail(ts,1) from stb1 partition by tbname" , - "select tail(c7,1) from stb1 partition by tbname", - "select tail(c8,1) from stb1 partition by tbname", - "select tail(c9,1) from stb1 partition by tbname" + f"select tail(ts,1) from {dbname}.t1" , + f"select tail(c7,1) from {dbname}.t1", + f"select tail(c8,1) from {dbname}.t1", + f"select tail(c9,1) from {dbname}.t1", + f"select tail(ts,1) from {dbname}.ct1" , + f"select tail(c7,1) from {dbname}.ct1", + f"select tail(c8,1) from {dbname}.ct1", + f"select tail(c9,1) from {dbname}.ct1", + f"select tail(ts,1) from {dbname}.ct3" , + f"select tail(c7,1) from {dbname}.ct3", + f"select tail(c8,1) from {dbname}.ct3", + f"select tail(c9,1) from {dbname}.ct3", + f"select tail(ts,1) from {dbname}.ct4" , + f"select tail(c7,1) from {dbname}.ct4", + f"select tail(c8,1) from {dbname}.ct4", + f"select tail(c9,1) from {dbname}.ct4", + f"select tail(ts,1) from {dbname}.stb1 partition by tbname" , + f"select tail(c7,1) from {dbname}.stb1 partition by tbname", + f"select tail(c8,1) from {dbname}.stb1 partition by tbname", + f"select tail(c9,1) from {dbname}.stb1 partition by tbname" ] - + for type_sql in other_no_value_types: tdSql.query(type_sql) - + type_sql_lists = [ - "select tail(c1,1) from t1", - "select tail(c2,1) from t1", - "select tail(c3,1) from t1", - "select tail(c4,1) from t1", - "select tail(c5,1) from t1", - "select tail(c6,1) from t1", - - "select tail(c1,1) from ct1", - "select tail(c2,1) from ct1", - "select tail(c3,1) from ct1", - "select tail(c4,1) from ct1", - "select tail(c5,1) from ct1", - "select tail(c6,1) from ct1", - - "select tail(c1,1) from ct3", - "select tail(c2,1) from ct3", - "select tail(c3,1) from ct3", - "select tail(c4,1) from ct3", - "select tail(c5,1) from ct3", - "select tail(c6,1) from ct3", - - "select tail(c1,1) from stb1 partition by tbname", - "select tail(c2,1) from stb1 partition by tbname", - "select tail(c3,1) from stb1 partition by tbname", - "select tail(c4,1) from stb1 partition by tbname", - "select tail(c5,1) from stb1 partition by tbname", - "select tail(c6,1) from stb1 partition by tbname", - - "select tail(c6,1) as alisb from stb1 partition by tbname", - "select tail(c6,1) alisb from stb1 partition by tbname", + f"select tail(c1,1) from {dbname}.t1", + f"select tail(c2,1) from {dbname}.t1", + f"select tail(c3,1) from {dbname}.t1", + f"select tail(c4,1) from {dbname}.t1", + f"select tail(c5,1) from {dbname}.t1", + f"select tail(c6,1) from {dbname}.t1", + + f"select tail(c1,1) from {dbname}.ct1", + f"select tail(c2,1) from {dbname}.ct1", + f"select tail(c3,1) from {dbname}.ct1", + f"select tail(c4,1) from {dbname}.ct1", + f"select tail(c5,1) from {dbname}.ct1", + f"select tail(c6,1) from {dbname}.ct1", + + f"select tail(c1,1) from {dbname}.ct3", + f"select tail(c2,1) from {dbname}.ct3", + f"select tail(c3,1) from {dbname}.ct3", + f"select tail(c4,1) from {dbname}.ct3", + f"select tail(c5,1) from {dbname}.ct3", + f"select tail(c6,1) from {dbname}.ct3", + + f"select tail(c1,1) from {dbname}.stb1 partition by tbname", + f"select tail(c2,1) from {dbname}.stb1 partition by tbname", + f"select tail(c3,1) from {dbname}.stb1 partition by tbname", + f"select tail(c4,1) from {dbname}.stb1 partition by tbname", + f"select tail(c5,1) from {dbname}.stb1 partition by tbname", + f"select tail(c6,1) from {dbname}.stb1 partition by tbname", + + f"select tail(c6,1) as alisb from {dbname}.stb1 partition by tbname", + f"select tail(c6,1) alisb from {dbname}.stb1 partition by tbname", ] for type_sql in type_sql_lists: @@ -189,7 +186,6 @@ class TDTestCase: tail_result = tdSql.queryResult tdSql.query(equal_sql) - print(equal_sql) equal_result = tdSql.queryResult @@ -198,257 +194,255 @@ class TDTestCase: else: tdLog.exit(" tail query check fail , tail sql is: %s " %tail_sql) - def basic_tail_function(self): + def basic_tail_function(self, dbname="db"): - # basic query - tdSql.query("select c1 from ct3") + # basic query + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select tail(c1,1) from ct3") + tdSql.query(f"select tail(c1,1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tail(c2,1) from ct3") + tdSql.query(f"select tail(c2,1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tail(c3,1) from ct3") + tdSql.query(f"select tail(c3,1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tail(c4,1) from ct3") + tdSql.query(f"select tail(c4,1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tail(c5,1) from ct3") + tdSql.query(f"select tail(c5,1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tail(c6,1) from ct3") - + tdSql.query(f"select tail(c6,1) from {dbname}.ct3") + # auto check for t1 table # used for regular table - tdSql.query("select tail(c1,1) from t1") - - tdSql.query("desc t1") + tdSql.query(f"select tail(c1,1) from {dbname}.t1") + + tdSql.query(f"desc {dbname}.t1") col_lists_rows = tdSql.queryResult col_lists = [] for col_name in col_lists_rows: if col_name[0] =="ts": continue - + col_lists.append(col_name[0]) - + for col in col_lists: - for loop in range(100): + for loop in range(100): limit = randint(1,100) offset = randint(0,100) - self.check_tail_table("t1" , col , limit , offset) + self.check_tail_table(f"{dbname}.t1" , col , limit , offset) # tail for invalid params - - tdSql.error("select tail(c1,-10,10) from ct1") - tdSql.error("select tail(c1,10,10000) from ct1") - tdSql.error("select tail(c1,10,-100) from ct1") - tdSql.error("select tail(c1,100/2,10) from ct1") - tdSql.error("select tail(c1,5,10*2) from ct1") - tdSql.query("select tail(c1,100,100) from ct1") + + tdSql.error(f"select tail(c1,-10,10) from {dbname}.ct1") + tdSql.error(f"select tail(c1,10,10000) from {dbname}.ct1") + tdSql.error(f"select tail(c1,10,-100) from {dbname}.ct1") + tdSql.error(f"select tail(c1,100/2,10) from {dbname}.ct1") + tdSql.error(f"select tail(c1,5,10*2) from {dbname}.ct1") + tdSql.query(f"select tail(c1,100,100) from {dbname}.ct1") tdSql.checkRows(0) - tdSql.query("select tail(c1,10,100) from ct1") + tdSql.query(f"select tail(c1,10,100) from {dbname}.ct1") tdSql.checkRows(0) - tdSql.error("select tail(c1,10,101) from ct1") - tdSql.query("select tail(c1,10,0) from ct1") - tdSql.query("select tail(c1,100,10) from ct1") + tdSql.error(f"select tail(c1,10,101) from {dbname}.ct1") + tdSql.query(f"select tail(c1,10,0) from {dbname}.ct1") + tdSql.query(f"select tail(c1,100,10) from {dbname}.ct1") tdSql.checkRows(3) - + # tail with super tags - tdSql.query("select tail(c1,10,10) from ct1") + tdSql.query(f"select tail(c1,10,10) from {dbname}.ct1") tdSql.checkRows(3) - tdSql.query("select tail(c1,10,10),tbname from ct1") - tdSql.query("select tail(c1,10,10),t1 from ct1") + tdSql.query(f"select tail(c1,10,10),tbname from {dbname}.ct1") + tdSql.query(f"select tail(c1,10,10),t1 from {dbname}.ct1") + + # tail with common col + tdSql.query(f"select tail(c1,10,10) ,ts from {dbname}.ct1") + tdSql.query(f"select tail(c1,10,10) ,c1 from {dbname}.ct1") - # tail with common col - tdSql.query("select tail(c1,10,10) ,ts from ct1") - tdSql.query("select tail(c1,10,10) ,c1 from ct1") + # tail with scalar function + tdSql.query(f"select tail(c1,10,10) ,abs(c1) from {dbname}.ct1") + tdSql.error(f"select tail(c1,10,10) , tail(c2,10,10) from {dbname}.ct1") + tdSql.query(f"select tail(c1,10,10) , abs(c2)+2 from {dbname}.ct1") - # tail with scalar function - tdSql.query("select tail(c1,10,10) ,abs(c1) from ct1") - tdSql.error("select tail(c1,10,10) , tail(c2,10,10) from ct1") - tdSql.query("select tail(c1,10,10) , abs(c2)+2 from ct1") - # bug need fix for scalar value or compute again - # tdSql.error(" select tail(c1,10,10) , 123 from ct1") - # tdSql.error(" select abs(tail(c1,10,10)) from ct1") - # tdSql.error(" select abs(tail(c1,10,10)) + 2 from ct1") + # tdSql.error(f"select tail(c1,10,10) , 123 from {dbname}.ct1") + # tdSql.error(f"select abs(tail(c1,10,10)) from {dbname}.ct1") + # tdSql.error(f"select abs(tail(c1,10,10)) + 2 from {dbname}.ct1") - # tail with aggregate function - tdSql.error("select tail(c1,10,10) ,sum(c1) from ct1") - tdSql.error("select tail(c1,10,10) ,max(c1) from ct1") - tdSql.error("select tail(c1,10,10) ,csum(c1) from ct1") - tdSql.error("select tail(c1,10,10) ,count(c1) from ct1") + # tail with aggregate function + tdSql.error(f"select tail(c1,10,10) ,sum(c1) from {dbname}.ct1") + tdSql.error(f"select tail(c1,10,10) ,max(c1) from {dbname}.ct1") + tdSql.error(f"select tail(c1,10,10) ,csum(c1) from {dbname}.ct1") + tdSql.error(f"select tail(c1,10,10) ,count(c1) from {dbname}.ct1") # tail with filter where - tdSql.query("select tail(c1,3,1) from ct4 where c1 is null") + tdSql.query(f"select tail(c1,3,1) from {dbname}.ct4 where c1 is null") tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, None) - tdSql.query("select tail(c1,3,2) from ct4 where c1 >2 order by 1") + tdSql.query(f"select tail(c1,3,2) from {dbname}.ct4 where c1 >2 order by 1") tdSql.checkData(0, 0, 5) tdSql.checkData(1, 0, 6) tdSql.checkData(2, 0, 7) - tdSql.query("select tail(c1,2,1) from ct4 where c2 between 0 and 99999 order by 1") + tdSql.query(f"select tail(c1,2,1) from {dbname}.ct4 where c2 between 0 and 99999 order by 1") tdSql.checkData(0, 0, 1) tdSql.checkData(1, 0, 2) - # tail with union all - tdSql.query("select tail(c1,2,1) from ct4 union all select c1 from ct1") + # tail with union all + tdSql.query(f"select tail(c1,2,1) from {dbname}.ct4 union all select c1 from {dbname}.ct1") tdSql.checkRows(15) - tdSql.query("select tail(c1,2,1) from ct4 union all select c1 from ct2 order by 1") + tdSql.query(f"select tail(c1,2,1) from {dbname}.ct4 union all select c1 from {dbname}.ct2 order by 1") tdSql.checkRows(2) tdSql.checkData(0, 0, 0) tdSql.checkData(1, 0, 1) - tdSql.query("select tail(c2,2,1) from ct4 union all select abs(c2)/2 from ct4") + tdSql.query(f"select tail(c2,2,1) from {dbname}.ct4 union all select abs(c2)/2 from {dbname}.ct4") tdSql.checkRows(14) - # tail with join - # prepare join datas with same ts + # tail with join + # prepare join datas with same ts - tdSql.execute(" use db ") - tdSql.execute(" create stable st1 (ts timestamp , num int) tags(ind int)") - tdSql.execute(" create table tb1 using st1 tags(1)") - tdSql.execute(" create table tb2 using st1 tags(2)") + tdSql.execute(f" create stable {dbname}.st1 (ts timestamp , num int) tags(ind int)") + tdSql.execute(f" create table {dbname}.tb1 using {dbname}.st1 tags(1)") + tdSql.execute(f" create table {dbname}.tb2 using {dbname}.st1 tags(2)") - tdSql.execute(" create stable st2 (ts timestamp , num int) tags(ind int)") - tdSql.execute(" create table ttb1 using st2 tags(1)") - tdSql.execute(" create table ttb2 using st2 tags(2)") + tdSql.execute(f" create stable {dbname}.st2 (ts timestamp , num int) tags(ind int)") + tdSql.execute(f" create table {dbname}.ttb1 using {dbname}.st2 tags(1)") + tdSql.execute(f" create table {dbname}.ttb2 using {dbname}.st2 tags(2)") start_ts = 1622369635000 # 2021-05-30 18:13:55 for i in range(10): ts_value = start_ts+i*1000 - tdSql.execute(f" insert into tb1 values({ts_value} , {i})") - tdSql.execute(f" insert into tb2 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.tb1 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.tb2 values({ts_value} , {i})") - tdSql.execute(f" insert into ttb1 values({ts_value} , {i})") - tdSql.execute(f" insert into ttb2 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.ttb1 values({ts_value} , {i})") + tdSql.execute(f" insert into {dbname}.ttb2 values({ts_value} , {i})") - tdSql.query("select tail(tb2.num,3,2) from tb1, tb2 where tb1.ts=tb2.ts order by 1 desc") + tdSql.query(f"select tail(tb2.num,3,2) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts order by 1 desc") tdSql.checkRows(3) tdSql.checkData(0,0,7) tdSql.checkData(1,0,6) tdSql.checkData(2,0,5) # nest query - # tdSql.query("select tail(c1,2) from (select _rowts , c1 from ct1)") - tdSql.query("select c1 from (select tail(c1,2) c1 from ct4) order by 1 nulls first") + # tdSql.query(f"select tail(c1,2) from (select _rowts , c1 from {dbname}.ct1)") + tdSql.query(f"select c1 from (select tail(c1,2) c1 from {dbname}.ct4) order by 1 nulls first") tdSql.checkRows(2) tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, 0) - tdSql.query("select sum(c1) from (select tail(c1,2) c1 from ct1)") + tdSql.query(f"select sum(c1) from (select tail(c1,2) c1 from {dbname}.ct1)") tdSql.checkRows(1) tdSql.checkData(0, 0, 18) - tdSql.query("select abs(c1) from (select tail(c1,2) c1 from ct1)") + tdSql.query(f"select abs(c1) from (select tail(c1,2) c1 from {dbname}.ct1)") tdSql.checkRows(2) tdSql.checkData(0, 0, 9) - + #partition by tbname - tdSql.query(" select tail(c1,5) from stb1 partition by tbname ") + tdSql.query(f"select tail(c1,5) from {dbname}.stb1 partition by tbname ") tdSql.checkRows(10) - tdSql.query(" select tail(c1,3) from stb1 partition by tbname ") + tdSql.query(f"select tail(c1,3) from {dbname}.stb1 partition by tbname ") tdSql.checkRows(6) - - # group by - tdSql.error("select tail(c1,2) from ct1 group by c1") - tdSql.error("select tail(c1,2) from ct1 group by tbname") + + # group by + tdSql.error(f"select tail(c1,2) from {dbname}.ct1 group by c1") + tdSql.error(f"select tail(c1,2) from {dbname}.ct1 group by tbname") # super table - tdSql.error("select tbname , tail(c1,2) from stb1 group by tbname") - tdSql.query("select tail(c1,2) from stb1 partition by tbname") + tdSql.error(f"select tbname , tail(c1,2) from {dbname}.stb1 group by tbname") + tdSql.query(f"select tail(c1,2) from {dbname}.stb1 partition by tbname") tdSql.checkRows(4) - # bug need fix - # tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname") + # bug need fix + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 partition by tbname") # tdSql.checkRows(4) - # tdSql.query("select tbname , tail(c1,2) from stb1 partition by tbname order by tbname") + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 partition by tbname order by tbname") # tdSql.checkRows(4) - # tdSql.query(" select tbname , count(c1) from stb1 partition by tbname order by tbname ") + # tdSql.query(f"select tbname , count(c1) from {dbname}.stb1 partition by tbname order by tbname ") # tdSql.checkRows(2) - # tdSql.query(" select tbname , max(c1) ,c1 from stb1 partition by tbname order by tbname ") + # tdSql.query(f"select tbname , max(c1) ,c1 from {dbname}.stb1 partition by tbname order by tbname ") # tdSql.checkRows(2) - # tdSql.query(" select tbname ,first(c1) from stb1 partition by tbname order by tbname ") + # tdSql.query(f"select tbname ,first(c1) from {dbname}.stb1 partition by tbname order by tbname ") # tdSql.checkRows(2) - tdSql.query("select tail(c1,2) from stb1 partition by tbname") + tdSql.query(f"select tail(c1,2) from {dbname}.stb1 partition by tbname") tdSql.checkRows(4) - # # bug need fix - # tdSql.query(" select tbname , tail(c1,2) from stb1 where t1 = 0 partition by tbname ") + # # bug need fix + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 where t1 = 0 partition by tbname ") # tdSql.checkRows(2) - # tdSql.query(" select tbname , tail(c1,2) from stb1 where t1 = 0 partition by tbname order by tbname ") + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 where t1 = 0 partition by tbname order by tbname ") # tdSql.checkRows(2) - # tdSql.query(" select tbname , tail(c1,2) from stb1 where c1 = 0 partition by tbname order by tbname ") + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 where c1 = 0 partition by tbname order by tbname ") # tdSql.checkRows(3) - # tdSql.query(" select tbname , tail(c1,2) from stb1 where c1 = 0 partition by tbname ") + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 where c1 = 0 partition by tbname ") # tdSql.checkRows(3) - # tdSql.query(" select tbname , tail(c1,2) from stb1 where c1 = 0 partition by tbname ") + # tdSql.query(f"select tbname , tail(c1,2) from {dbname}.stb1 where c1 = 0 partition by tbname ") # tdSql.checkRows(3) - tdSql.query(" select tail(t1,2) from stb1 ") + tdSql.query(f"select tail(t1,2) from {dbname}.stb1 ") tdSql.checkRows(2) - tdSql.query(" select tail(t1+c1,2) from stb1 ") + tdSql.query(f"select tail(t1+c1,2) from {dbname}.stb1 ") tdSql.checkRows(2) - tdSql.query(" select tail(t1+c1,2) from stb1 partition by tbname ") + tdSql.query(f"select tail(t1+c1,2) from {dbname}.stb1 partition by tbname ") tdSql.checkRows(4) - tdSql.query(" select tail(t1,2) from stb1 partition by tbname ") + tdSql.query(f"select tail(t1,2) from {dbname}.stb1 partition by tbname ") tdSql.checkRows(4) - # nest query - tdSql.query(" select tail(c1,2) from (select _rowts , t1 ,c1 , tbname from stb1 ) ") + # nest query + tdSql.query(f"select tail(c1,2) from (select _rowts , t1 ,c1 , tbname from {dbname}.stb1 ) ") tdSql.checkRows(2) tdSql.checkData(0,0,None) tdSql.checkData(1,0,9) - tdSql.query("select tail(t1,2) from (select _rowts , t1 , tbname from stb1 )") + tdSql.query(f"select tail(t1,2) from (select _rowts , t1 , tbname from {dbname}.stb1 )") tdSql.checkRows(2) tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) - def check_boundary_values(self): + def check_boundary_values(self, dbname="bound_test"): - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") - tdSql.execute("use bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - + tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - - tdSql.query("select tail(c2,2) from sub1_bound order by 1 desc") + + tdSql.query(f"select tail(c2,2) from {dbname}.sub1_bound order by 1 desc") tdSql.checkRows(2) tdSql.checkData(0,0,9223372036854775803) @@ -456,22 +450,22 @@ class TDTestCase: tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: tail basic query ============") + tdLog.printNoPrefix("==========step4: tail basic query ============") self.basic_tail_function() - tdLog.printNoPrefix("==========step5: tail boundary query ============") + tdLog.printNoPrefix("==========step5: tail boundary query ============") self.check_boundary_values() diff --git a/tests/system-test/2-query/tan.py b/tests/system-test/2-query/tan.py index da47c1c2b2..bb696757d2 100644 --- a/tests/system-test/2-query/tan.py +++ b/tests/system-test/2-query/tan.py @@ -9,48 +9,46 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - - def prepare_datas(self): + + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) - + tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -65,14 +63,14 @@ class TDTestCase: ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ''' ) - + def check_result_auto_tan(self ,origin_query , pow_query): pow_result = tdSql.getResult(pow_query) origin_result = tdSql.getResult(origin_query) auto_result =[] - + for row in origin_result: row_check = [] for elem in row: @@ -90,7 +88,7 @@ class TDTestCase: if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): check_status = False elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001): - check_status = False + check_status = False else: pass if not check_status: @@ -98,174 +96,174 @@ class TDTestCase: sys.exit(1) else: tdLog.info("tan value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - - def test_errors(self): + + def test_errors(self, dbname="db"): error_sql_lists = [ - "select tan from t1", - # "select tan(-+--+c1 ) from t1", - # "select +-tan(c1) from t1", - # "select ++-tan(c1) from t1", - # "select ++--tan(c1) from t1", - # "select - -tan(c1)*0 from t1", - # "select tan(tbname+1) from t1 ", - "select tan(123--123)==1 from t1", - "select tan(c1) as 'd1' from t1", - "select tan(c1 ,c2) from t1", - "select tan(c1 ,NULL ) from t1", - "select tan(,) from t1;", - "select tan(tan(c1) ab from t1)", - "select tan(c1 ) as int from t1", - "select tan from stb1", - # "select tan(-+--+c1) from stb1", - # "select +-tan(c1) from stb1", - # "select ++-tan(c1) from stb1", - # "select ++--tan(c1) from stb1", - # "select - -tan(c1)*0 from stb1", - # "select tan(tbname+1) from stb1 ", - "select tan(123--123)==1 from stb1", - "select tan(c1) as 'd1' from stb1", - "select tan(c1 ,c2 ) from stb1", - "select tan(c1 ,NULL) from stb1", - "select tan(,) from stb1;", - "select tan(tan(c1) ab from stb1)", - "select tan(c1) as int from stb1" + f"select tan from {dbname}.t1", + # f"select tan(-+--+c1 ) from {dbname}.t1", + # f"select +-tan(c1) from {dbname}.t1", + # f"select ++-tan(c1) from {dbname}.t1", + # f"select ++--tan(c1) from {dbname}.t1", + # f"select - -tan(c1)*0 from {dbname}.t1", + # f"select tan(tbname+1) from {dbname}.t1 ", + f"select tan(123--123)==1 from {dbname}.t1", + f"select tan(c1) as 'd1' from {dbname}.t1", + f"select tan(c1 ,c2) from {dbname}.t1", + f"select tan(c1 ,NULL ) from {dbname}.t1", + f"select tan(,) from {dbname}.t1;", + f"select tan(tan(c1) ab from {dbname}.t1)", + f"select tan(c1 ) as int from {dbname}.t1", + f"select tan from {dbname}.stb1", + # f"select tan(-+--+c1) from {dbname}.stb1", + # f"select +-tan(c1) from {dbname}.stb1", + # f"select ++-tan(c1) from {dbname}.stb1", + # f"select ++--tan(c1) from {dbname}.stb1", + # f"select - -tan(c1)*0 from {dbname}.stb1", + # f"select tan(tbname+1) from {dbname}.stb1 ", + f"select tan(123--123)==1 from {dbname}.stb1", + f"select tan(c1) as 'd1' from {dbname}.stb1", + f"select tan(c1 ,c2 ) from {dbname}.stb1", + f"select tan(c1 ,NULL) from {dbname}.stb1", + f"select tan(,) from {dbname}.stb1;", + f"select tan(tan(c1) ab from {dbname}.stb1)", + f"select tan(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - - def support_types(self): + + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select tan(ts) from t1" , - "select tan(c7) from t1", - "select tan(c8) from t1", - "select tan(c9) from t1", - "select tan(ts) from ct1" , - "select tan(c7) from ct1", - "select tan(c8) from ct1", - "select tan(c9) from ct1", - "select tan(ts) from ct3" , - "select tan(c7) from ct3", - "select tan(c8) from ct3", - "select tan(c9) from ct3", - "select tan(ts) from ct4" , - "select tan(c7) from ct4", - "select tan(c8) from ct4", - "select tan(c9) from ct4", - "select tan(ts) from stb1" , - "select tan(c7) from stb1", - "select tan(c8) from stb1", - "select tan(c9) from stb1" , - - "select tan(ts) from stbbb1" , - "select tan(c7) from stbbb1", - - "select tan(ts) from tbname", - "select tan(c9) from tbname" + f"select tan(ts) from {dbname}.t1" , + f"select tan(c7) from {dbname}.t1", + f"select tan(c8) from {dbname}.t1", + f"select tan(c9) from {dbname}.t1", + f"select tan(ts) from {dbname}.ct1" , + f"select tan(c7) from {dbname}.ct1", + f"select tan(c8) from {dbname}.ct1", + f"select tan(c9) from {dbname}.ct1", + f"select tan(ts) from {dbname}.ct3" , + f"select tan(c7) from {dbname}.ct3", + f"select tan(c8) from {dbname}.ct3", + f"select tan(c9) from {dbname}.ct3", + f"select tan(ts) from {dbname}.ct4" , + f"select tan(c7) from {dbname}.ct4", + f"select tan(c8) from {dbname}.ct4", + f"select tan(c9) from {dbname}.ct4", + f"select tan(ts) from {dbname}.stb1" , + f"select tan(c7) from {dbname}.stb1", + f"select tan(c8) from {dbname}.stb1", + f"select tan(c9) from {dbname}.stb1" , + + f"select tan(ts) from {dbname}.stbbb1" , + f"select tan(c7) from {dbname}.stbbb1", + + f"select tan(ts) from {dbname}.tbname", + f"select tan(c9) from {dbname}.tbname" ] - + for type_sql in type_error_sql_lists: tdSql.error(type_sql) - - + + type_sql_lists = [ - "select tan(c1) from t1", - "select tan(c2) from t1", - "select tan(c3) from t1", - "select tan(c4) from t1", - "select tan(c5) from t1", - "select tan(c6) from t1", - - "select tan(c1) from ct1", - "select tan(c2) from ct1", - "select tan(c3) from ct1", - "select tan(c4) from ct1", - "select tan(c5) from ct1", - "select tan(c6) from ct1", - - "select tan(c1) from ct3", - "select tan(c2) from ct3", - "select tan(c3) from ct3", - "select tan(c4) from ct3", - "select tan(c5) from ct3", - "select tan(c6) from ct3", - - "select tan(c1) from stb1", - "select tan(c2) from stb1", - "select tan(c3) from stb1", - "select tan(c4) from stb1", - "select tan(c5) from stb1", - "select tan(c6) from stb1", - - "select tan(c6) as alisb from stb1", - "select tan(c6) alisb from stb1", + f"select tan(c1) from {dbname}.t1", + f"select tan(c2) from {dbname}.t1", + f"select tan(c3) from {dbname}.t1", + f"select tan(c4) from {dbname}.t1", + f"select tan(c5) from {dbname}.t1", + f"select tan(c6) from {dbname}.t1", + + f"select tan(c1) from {dbname}.ct1", + f"select tan(c2) from {dbname}.ct1", + f"select tan(c3) from {dbname}.ct1", + f"select tan(c4) from {dbname}.ct1", + f"select tan(c5) from {dbname}.ct1", + f"select tan(c6) from {dbname}.ct1", + + f"select tan(c1) from {dbname}.ct3", + f"select tan(c2) from {dbname}.ct3", + f"select tan(c3) from {dbname}.ct3", + f"select tan(c4) from {dbname}.ct3", + f"select tan(c5) from {dbname}.ct3", + f"select tan(c6) from {dbname}.ct3", + + f"select tan(c1) from {dbname}.stb1", + f"select tan(c2) from {dbname}.stb1", + f"select tan(c3) from {dbname}.stb1", + f"select tan(c4) from {dbname}.stb1", + f"select tan(c5) from {dbname}.stb1", + f"select tan(c6) from {dbname}.stb1", + + f"select tan(c6) as alisb from {dbname}.stb1", + f"select tan(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - - def basic_tan_function(self): - # basic query - tdSql.query("select c1 from ct3") + def basic_tan_function(self, dbname="db"): + + # basic query + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select tan(c1) from ct3") + tdSql.query(f"select tan(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tan(c2) from ct3") + tdSql.query(f"select tan(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tan(c3) from ct3") + tdSql.query(f"select tan(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tan(c4) from ct3") + tdSql.query(f"select tan(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tan(c5) from ct3") + tdSql.query(f"select tan(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select tan(c6) from ct3") + tdSql.query(f"select tan(c6) from {dbname}.ct3") tdSql.checkRows(0) # # used for regular table - tdSql.query("select tan(c1) from t1") + tdSql.query(f"select tan(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1 , 0, 1.557407725) tdSql.checkData(3 , 0, -0.142546543) tdSql.checkData(5 , 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto_tan( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from t1") - + self.check_result_auto_tan( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.t1", f"select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from {dbname}.t1") + # used for sub table - tdSql.query("select c2 ,tan(c2) from ct1") + tdSql.query(f"select c2 ,tan(c2) from {dbname}.ct1") tdSql.checkData(0, 1, -0.226288661) tdSql.checkData(1 , 1, 0.670533806) tdSql.checkData(3 , 1, -1.325559275) tdSql.checkData(4 , 1, 0.000000000) - tdSql.query("select c1, c5 ,tan(c5) from ct4") + tdSql.query(f"select c1, c5 ,tan(c5) from {dbname}.ct4") tdSql.checkData(0 , 2, None) tdSql.checkData(1 , 2, -0.605942929) tdSql.checkData(2 , 2, 11.879355609) tdSql.checkData(3 , 2, 0.395723765) tdSql.checkData(5 , 2, None) - self.check_result_auto_tan( "select c1, c2, c3 , c4, c5 from ct1", "select tan(c1), tan(c2) ,tan(c3), tan(c4), tan(c5) from ct1") - + self.check_result_auto_tan( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select tan(c1), tan(c2) ,tan(c3), tan(c4), tan(c5) from {dbname}.ct1") + # nest query for tan functions - tdSql.query("select c4 , tan(c4) ,tan(tan(c4)) , tan(tan(tan(c4))) from ct1;") + tdSql.query(f"select c4 , tan(c4) ,tan(tan(c4)) , tan(tan(tan(c4))) from {dbname}.ct1;") tdSql.checkData(0 , 0 , 88) tdSql.checkData(0 , 1 , 0.035420501) tdSql.checkData(0 , 2 , 0.035435322) @@ -281,52 +279,52 @@ class TDTestCase: tdSql.checkData(11 , 2 , -0.040227928) tdSql.checkData(11 , 3 , -0.040249642) - # used for stable table - - tdSql.query("select tan(c1) from stb1") + # used for stable table + + tdSql.query(f"select tan(c1) from {dbname}.stb1") tdSql.checkRows(25) - + # used for not exists table - tdSql.error("select tan(c1) from stbbb1") - tdSql.error("select tan(c1) from tbname") - tdSql.error("select tan(c1) from ct5") + tdSql.error(f"select tan(c1) from {dbname}.stbbb1") + tdSql.error(f"select tan(c1) from {dbname}.tbname") + tdSql.error(f"select tan(c1) from {dbname}.ct5") + + # mix with common col + tdSql.query(f"select c1, tan(c1) from {dbname}.ct1") + tdSql.query(f"select c2, tan(c2) from {dbname}.ct4") - # mix with common col - tdSql.query("select c1, tan(c1) from ct1") - tdSql.query("select c2, tan(c2) from ct4") - # mix with common functions - tdSql.query("select c1, tan(c1),tan(c1), tan(tan(c1)) from ct4 ") + tdSql.query(f"select c1, tan(c1),tan(c1), tan(tan(c1)) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 3 ,None) - + tdSql.checkData(3 , 0 , 6) tdSql.checkData(3 , 1 ,-0.291006191) tdSql.checkData(3 , 2 ,-0.291006191) tdSql.checkData(3 , 3 ,-0.299508909) - tdSql.query("select c1, tan(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, tan(c1),c5, floor(c5) from {dbname}.stb1 ") # # mix with agg functions , not support - tdSql.error("select c1, tan(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, tan(c1),c5, count(c5) from ct1 ") - tdSql.error("select tan(c1), count(c5) from stb1 ") - tdSql.error("select tan(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, tan(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, tan(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select tan(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select tan(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") - - # # bug fix for compute - tdSql.query("select c1, tan(c1) -0 ,tan(c1-4)-0 from ct4 ") + + # # bug fix for compute + tdSql.query(f"select c1, tan(c1) -0 ,tan(c1-4)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -334,7 +332,7 @@ class TDTestCase: tdSql.checkData(1, 1, -6.799711455) tdSql.checkData(1, 2, 1.157821282) - tdSql.query(" select c1, tan(c1) -0 ,tan(c1-0.1)-0.1 from ct4") + tdSql.query(f"select c1, tan(c1) -0 ,tan(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -342,35 +340,33 @@ class TDTestCase: tdSql.checkData(1, 1, -6.799711455) tdSql.checkData(1, 2, -21.815112681) - tdSql.query("select c1, tan(c1), c2, tan(c2), c3, tan(c3) from ct1") + tdSql.query(f"select c1, tan(c1), c2, tan(c2), c3, tan(c3) from {dbname}.ct1") - def test_big_number(self): + def test_big_number(self, dbname="db"): - tdSql.query("select c1, tan(100000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, tan(100000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, math.tan(100000000)) - - tdSql.query("select c1, tan(10000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, tan(10000000000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, math.tan(10000000000000)) - tdSql.query("select c1, tan(10000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, tan(10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, tan(10000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, tan(10000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(1, 1, math.tan(10000000000000000000000000.0)) - tdSql.query("select c1, tan(10000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, tan(10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, tan(10000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, tan(10000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, math.tan(10000000000000000000000000000000000.0)) - tdSql.query("select c1, tan(10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, tan(10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, tan(10000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, tan(10000000000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, math.tan(10000000000000000000000000000000000000000.0)) - tdSql.query("select c1, tan(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, tan(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow - def abs_func_filter(self): - tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from ct4 where c1>5 ") + def abs_func_filter(self, dbname="db"): + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0,0,8) tdSql.checkData(0,1,8.000000000) @@ -378,7 +374,7 @@ class TDTestCase: tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,4,-7.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -386,7 +382,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,-3.000000000) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from ct4 where c1>tan(c1) limit 1 ") + tdSql.query(f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(tan(c1)-0.5) from {dbname}.ct4 where c1>tan(c1) limit 1 ") tdSql.checkRows(1) tdSql.checkData(0,0,8) tdSql.checkData(0,1,88888) @@ -394,22 +390,17 @@ class TDTestCase: tdSql.checkData(0,3,8.000000000) tdSql.checkData(0,4,7.900000000) tdSql.checkData(0,5,-7.000000000) - - def pow_Arithmetic(self): - pass - - def check_boundary_values(self): + + def check_boundary_values(self, dbname="bound_test"): PI=3.1415926 - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") - time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) @@ -425,14 +416,14 @@ class TDTestCase: tdSql.error( f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - self.check_result_auto_tan( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from sub1_bound ", "select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from sub1_bound") - - self.check_result_auto_tan( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select tan(c1), tan(c2) ,tan(c3), tan(c3), tan(c2) ,tan(c1) from sub1_bound") + self.check_result_auto_tan( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ", f"select tan(abs(c1)), tan(abs(c2)) ,tan(abs(c3)), tan(abs(c4)), tan(abs(c5)) from {dbname}.sub1_bound") + + self.check_result_auto_tan( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select tan(c1), tan(c2) ,tan(c3), tan(c3), tan(c2) ,tan(c1) from {dbname}.sub1_bound") + + self.check_result_auto_tan(f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from {dbname}.sub1_bound" , f"select tan(abs(c1)) from {dbname}.sub1_bound" ) - self.check_result_auto_tan("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select tan(abs(c1)) from sub1_bound" ) - # check basic elem for table per row - tdSql.query("select tan(abs(c1)) ,tan(abs(c2)) , tan(abs(c3)) , tan(abs(c4)), tan(abs(c5)), tan(abs(c6)) from sub1_bound ") + tdSql.query(f"select tan(abs(c1)) ,tan(abs(c2)) , tan(abs(c3)) , tan(abs(c4)), tan(abs(c5)), tan(abs(c6)) from {dbname}.sub1_bound ") tdSql.checkData(0,0,math.tan(2147483647)) tdSql.checkData(0,1,math.tan(9223372036854775807)) tdSql.checkData(0,2,math.tan(32767)) @@ -450,76 +441,74 @@ class TDTestCase: tdSql.checkData(3,4,math.tan(339999995214436424907732413799364296704.00000)) # check + - * / in functions - tdSql.query("select tan(abs(c1+1)) ,tan(abs(c2)) , tan(abs(c3*1)) , tan(abs(c4/2)), tan(abs(c5))/2, tan(abs(c6)) from sub1_bound ") + tdSql.query(f"select tan(abs(c1+1)) ,tan(abs(c2)) , tan(abs(c3*1)) , tan(abs(c4/2)), tan(abs(c5))/2, tan(abs(c6)) from {dbname}.sub1_bound ") tdSql.checkData(0,0,math.tan(2147483648.000000000)) tdSql.checkData(0,1,math.tan(9223372036854775807)) tdSql.checkData(0,2,math.tan(32767.000000000)) tdSql.checkData(0,3,math.tan(63.500000000)) - tdSql.execute("create stable st (ts timestamp, num1 float, num2 double) tags (t1 int);") - tdSql.execute(f'create table tb1 using st tags (1)') - tdSql.execute(f'create table tb2 using st tags (2)') - tdSql.execute(f'create table tb3 using st tags (3)') - tdSql.execute('insert into tb1 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) - tdSql.execute('insert into tb1 values (now()-30s, {}, {})'.format(PI ,PI )) - tdSql.execute('insert into tb1 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) - tdSql.execute('insert into tb1 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) - tdSql.execute('insert into tb1 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) - - tdSql.execute('insert into tb2 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) - tdSql.execute('insert into tb2 values (now()-30s, {}, {})'.format(PI ,PI )) - tdSql.execute('insert into tb2 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) - tdSql.execute('insert into tb2 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) - tdSql.execute('insert into tb2 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) + tdSql.execute(f"create stable {dbname}.st (ts timestamp, num1 float, num2 double) tags (t1 int);") + tdSql.execute(f'create table {dbname}.tb1 using {dbname}.st tags (1)') + tdSql.execute(f'create table {dbname}.tb2 using {dbname}.st tags (2)') + tdSql.execute(f'create table {dbname}.tb3 using {dbname}.st tags (3)') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-40s, {PI/2}, {PI/2})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-30s, {PI}, {PI})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-20s, {PI*1.5}, {PI*1.5})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-10s, {PI*2}, {PI*2})') + tdSql.execute(f'insert into {dbname}.tb1 values (now(), {PI*2.5}, {PI*2.5})') + + tdSql.execute(f'insert into {dbname}.tb2 values (now()-40s, {PI/2}, {PI/2})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-30s, {PI}, {PI})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-20s, {PI*1.5}, {PI*1.5})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-10s, {PI*2}, {PI*2})') + tdSql.execute(f'insert into {dbname}.tb2 values (now(), {PI*2.5}, {PI*2.5})') for i in range(100): - tdSql.execute('insert into tb3 values (now()+{}s, {}, {})'.format(i,PI*(5+i)/2 ,PI*(5+i)/2)) + tdSql.execute(f'insert into tb3 values (now()+{i}s, {PI*(5+i)/2}, {PI*(5+i)/2})') - self.check_result_auto_tan("select num1,num2 from tb3;" , "select tan(num1),tan(num2) from tb3") + self.check_result_auto_tan(f"select num1,num2 from {dbname}.tb3;" , f"select tan(num1),tan(num2) from {dbname}.tb3") - def support_super_table_test(self): - tdSql.execute(" use db ") - self.check_result_auto_tan( " select c5 from stb1 order by ts " , "select tan(c5) from stb1 order by ts" ) - self.check_result_auto_tan( " select c5 from stb1 order by tbname " , "select tan(c5) from stb1 order by tbname" ) - self.check_result_auto_tan( " select c5 from stb1 where c1 > 0 order by tbname " , "select tan(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_tan( " select c5 from stb1 where c1 > 0 order by tbname " , "select tan(c5) from stb1 where c1 > 0 order by tbname" ) + def support_super_table_test(self, dbname="db"): + self.check_result_auto_tan( f"select c5 from {dbname}.stb1 order by ts " , f"select tan(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_tan( f"select c5 from {dbname}.stb1 order by tbname " , f"select tan(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_tan( f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_tan( f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_tan( " select t1,c5 from stb1 order by ts " , "select tan(t1), tan(c5) from stb1 order by ts" ) - self.check_result_auto_tan( " select t1,c5 from stb1 order by tbname " , "select tan(t1) ,tan(c5) from stb1 order by tbname" ) - self.check_result_auto_tan( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select tan(t1) ,tan(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_tan( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select tan(t1) , tan(c5) from stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_tan( f"select t1,c5 from {dbname}.stb1 order by ts " , f"select tan(t1), tan(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_tan( f"select t1,c5 from {dbname}.stb1 order by tbname " , f"select tan(t1) ,tan(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_tan( f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select tan(t1) ,tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_tan( f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select tan(t1) , tan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) pass - - + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - tdLog.printNoPrefix("==========step2:test errors ==============") + tdLog.printNoPrefix("==========step2:test errors ==============") self.test_errors() - - tdLog.printNoPrefix("==========step3:support types ============") + + tdLog.printNoPrefix("==========step3:support types ============") self.support_types() - tdLog.printNoPrefix("==========step4: tan basic query ============") + tdLog.printNoPrefix("==========step4: tan basic query ============") self.basic_tan_function() - tdLog.printNoPrefix("==========step5: big number tan query ============") + tdLog.printNoPrefix("==========step5: big number tan query ============") self.test_big_number() - - tdLog.printNoPrefix("==========step6: tan boundary query ============") + tdLog.printNoPrefix("==========step6: tan boundary query ============") self.check_boundary_values() - tdLog.printNoPrefix("==========step7: tan filter query ============") + tdLog.printNoPrefix("==========step7: tan filter query ============") self.abs_func_filter() diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index d741b6745b..a91ec01a3b 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -156,6 +156,18 @@ python3 ./test.py -f 2-query/spread.py python3 ./test.py -f 2-query/spread.py -R python3 ./test.py -f 2-query/sqrt.py # python3 ./test.py -f 2-query/sqrt.py -R +python3 ./test.py -f 2-query/statecount.py +python3 ./test.py -f 2-query/statecount.py -R +python3 ./test.py -f 2-query/stateduration.py +python3 ./test.py -f 2-query/stateduration.py -R +python3 ./test.py -f 2-query/substr.py +python3 ./test.py -f 2-query/substr.py -R +python3 ./test.py -f 2-query/sum.py +python3 ./test.py -f 2-query/sum.py -R +python3 ./test.py -f 2-query/tail.py +python3 ./test.py -f 2-query/tail.py -R +python3 ./test.py -f 2-query/tan.py +python3 ./test.py -f 2-query/tan.py -R python3 ./test.py -f 1-insert/update_data.py @@ -166,7 +178,6 @@ python3 ./test.py -f 2-query/varchar.py python3 ./test.py -f 2-query/upper.py python3 ./test.py -f 2-query/lower.py python3 ./test.py -f 2-query/join2.py -python3 ./test.py -f 2-query/substr.py python3 ./test.py -f 2-query/union.py python3 ./test.py -f 2-query/union1.py python3 ./test.py -f 2-query/concat2.py @@ -182,7 +193,6 @@ python3 ./test.py -f 2-query/json_tag.py python3 ./test.py -f 2-query/top.py python3 ./test.py -f 2-query/log.py -python3 ./test.py -f 2-query/tan.py # python3 ./test.py -f 2-query/nestedQuery.py # TD-15983 subquery output duplicate name column. # Please Xiangyang Guo modify the following script @@ -193,9 +203,6 @@ python3 ./test.py -f 2-query/csum.py python3 ./test.py -f 2-query/mavg.py python3 ./test.py -f 2-query/function_diff.py python3 ./test.py -f 2-query/unique.py -python3 ./test.py -f 2-query/stateduration.py -python3 ./test.py -f 2-query/statecount.py -python3 ./test.py -f 2-query/tail.py python3 ./test.py -f 2-query/ttl_comment.py python3 ./test.py -f 2-query/twa.py python3 ./test.py -f 2-query/queryQnode.py -- GitLab