提交 65e6dcdb 编写于 作者: C cpwu

fix case

上级 c95e9689
...@@ -25,7 +25,7 @@ BOOLEAN_COL = [ BOOL_COL, ] ...@@ -25,7 +25,7 @@ BOOLEAN_COL = [ BOOL_COL, ]
TS_TYPE_COL = [ TS_COL, ] TS_TYPE_COL = [ TS_COL, ]
ALL_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, BINARY_COL, NCHAR_COL, TS_COL ] ALL_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_COL, BINARY_COL, NCHAR_COL, TS_COL ]
DBNAME = "db"
class TDTestCase: class TDTestCase:
def init(self, conn, logSql): def init(self, conn, logSql):
...@@ -133,32 +133,33 @@ class TDTestCase: ...@@ -133,32 +133,33 @@ class TDTestCase:
return f"explain select {select_clause} from {from_clause} {where_condition} {group_condition}" return f"explain select {select_clause} from {from_clause} {where_condition} {group_condition}"
@property @property
def __tb_list(self): def __tb_list(self, dbname=DBNAME):
return [ return [
"ct1", f"{dbname}.ct1",
"ct4", f"{dbname}.ct4",
"t1", f"{dbname}.t1",
"ct2", f"{dbname}.ct2",
"stb1", f"{dbname}.stb1",
] ]
def sql_list(self): def sql_list(self):
sqls = [] sqls = []
__no_join_tblist = self.__tb_list __no_join_tblist = self.__tb_list
for tb in __no_join_tblist: for tb in __no_join_tblist:
select_claus_list = self.__query_condition(tb) tbname = tb.split(".")[-1]
for select_claus in select_claus_list: select_claus_list = self.__query_condition(tbname)
group_claus = self.__group_condition(col=select_claus) for select_claus in select_claus_list:
where_claus = self.__where_condition(query_conditon=select_claus) group_claus = self.__group_condition(col=select_claus)
having_claus = self.__group_condition(col=select_claus, having=f"{select_claus} is not null") where_claus = self.__where_condition(query_conditon=select_claus)
sqls.extend( having_claus = self.__group_condition(col=select_claus, having=f"{select_claus} is not null")
( sqls.extend(
self.__single_sql(select_claus, tb, where_claus, having_claus), (
self.__single_sql(select_claus, tb,), self.__single_sql(select_claus, tb, where_claus, having_claus),
self.__single_sql(select_claus, tb, where_condition=where_claus), self.__single_sql(select_claus, tb,),
self.__single_sql(select_claus, tb, group_condition=group_claus), self.__single_sql(select_claus, tb, where_condition=where_claus),
) self.__single_sql(select_claus, tb, group_condition=group_claus),
) )
)
# return filter(None, sqls) # return filter(None, sqls)
return list(filter(None, sqls)) return list(filter(None, sqls))
...@@ -170,45 +171,45 @@ class TDTestCase: ...@@ -170,45 +171,45 @@ class TDTestCase:
tdLog.info(f"sql: {sqls[i]}") tdLog.info(f"sql: {sqls[i]}")
tdSql.query(sqls[i]) tdSql.query(sqls[i])
def __test_current(self): def __test_current(self, dbname=DBNAME):
tdSql.query("explain select c1 from ct1") tdSql.query(f"explain select {INT_COL} from {dbname}.ct1")
tdSql.query("explain select 1 from ct2") tdSql.query(f"explain select 1 from {dbname}.ct2")
tdSql.query("explain select cast(ceil(c6) as bigint) from ct4 group by c6") tdSql.query(f"explain select cast(ceil({DOUBLE_COL}) as bigint) from {dbname}.ct4 group by {DOUBLE_COL}")
tdSql.query("explain select count(c3) from ct4 group by c7 having count(c3) > 0") tdSql.query(f"explain select count({SINT_COL}) from {dbname}.ct4 group by {BOOL_COL} having count({SINT_COL}) > 0")
tdSql.query("explain select ct2.c3 from ct4 join ct2 on ct4.ts=ct2.ts") tdSql.query(f"explain select ct2.{SINT_COL} from {dbname}.ct4 ct4 join {dbname}.ct2 ct2 on ct4.ts=ct2.ts")
tdSql.query("explain select c1 from stb1 where c1 is not null and c1 in (0, 1, 2) or c1 between 2 and 100 ") tdSql.query(f"explain select {INT_COL} from {dbname}.stb1 where {INT_COL} is not null and {INT_COL} in (0, 1, 2) or {INT_COL} between 2 and 100 ")
self.explain_check() self.explain_check()
def __test_error(self): def __test_error(self, dbname=DBNAME):
tdLog.printNoPrefix("===step 0: err case, must return err") tdLog.printNoPrefix("===step 0: err case, must return err")
tdSql.error( "explain select hyperloglog(c1) from ct8" ) tdSql.error( f"explain select hyperloglog({INT_COL}) from {dbname}.ct8" )
tdSql.error( "explain show databases " ) tdSql.error( f"explain show databases " )
tdSql.error( "explain show stables " ) tdSql.error( f"explain show {dbname}.stables " )
tdSql.error( "explain show tables " ) tdSql.error( f"explain show {dbname}.tables " )
tdSql.error( "explain show vgroups " ) tdSql.error( f"explain show {dbname}.vgroups " )
tdSql.error( "explain show dnodes " ) tdSql.error( f"explain show dnodes " )
tdSql.error( '''explain select hyperloglog(['c1 + c1', 'c1 + c2', 'c1 + c3', 'c1 + c4', 'c1 + c5', 'c1 + c6', 'c1 + c7', 'c1 + c8', 'c1 + c9', 'c1 + c10']) tdSql.error( f'''explain select hyperloglog(['{INT_COL} + {INT_COL}', '{INT_COL} + {BINT_COL}', '{INT_COL} + {SINT_COL}', '{INT_COL} + {TINT_COL}', '{INT_COL} + {FLOAT_COL}', '{INT_COL} + {DOUBLE_COL}', '{INT_COL} + {BOOL_COL}', '{INT_COL} + {BINARY_COL}', '{INT_COL} + {NCHAR_COL}', '{INT_COL} + {TS_COL}'])
from ct1 from {dbname}.ct1
where ['c1 + c1', 'c1 + c2', 'c1 + c3', 'c1 + c4', 'c1 + c5', 'c1 + c6', 'c1 + c7', 'c1 + c8', 'c1 + c9', 'c1 + c10'] is not null where ['{INT_COL} + {INT_COL}', '{INT_COL} + {BINT_COL}', '{INT_COL} + {SINT_COL}', '{INT_COL} + {TINT_COL}', '{INT_COL} + {FLOAT_COL}', '{INT_COL} + {DOUBLE_COL}', '{INT_COL} + {BOOL_COL}', '{INT_COL} + {BINARY_COL}', '{INT_COL} + {NCHAR_COL}', '{INT_COL} + {TS_COL}'] is not null
group by ['c1 + c1', 'c1 + c2', 'c1 + c3', 'c1 + c4', 'c1 + c5', 'c1 + c6', 'c1 + c7', 'c1 + c8', 'c1 + c9', 'c1 + c10'] group by ['{INT_COL} + {INT_COL}', '{INT_COL} + {BINT_COL}', '{INT_COL} + {SINT_COL}', '{INT_COL} + {TINT_COL}', '{INT_COL} + {FLOAT_COL}', '{INT_COL} + {DOUBLE_COL}', '{INT_COL} + {BOOL_COL}', '{INT_COL} + {BINARY_COL}', '{INT_COL} + {NCHAR_COL}', '{INT_COL} + {TS_COL}']
having ['c1 + c1', 'c1 + c2', 'c1 + c3', 'c1 + c4', 'c1 + c5', 'c1 + c6', 'c1 + c7', 'c1 + c8', 'c1 + c9', 'c1 + c10'] is not null ''' ) having ['{INT_COL} + {INT_COL}', '{INT_COL} + {BINT_COL}', '{INT_COL} + {SINT_COL}', '{INT_COL} + {TINT_COL}', '{INT_COL} + {FLOAT_COL}', '{INT_COL} + {DOUBLE_COL}', '{INT_COL} + {BOOL_COL}', '{INT_COL} + {BINARY_COL}', '{INT_COL} + {NCHAR_COL}', '{INT_COL} + {TS_COL}'] is not null ''' )
def all_test(self): def all_test(self):
self.__test_error() self.__test_error()
self.__test_current() self.__test_current()
def __create_tb(self): def __create_tb(self, dbname=DBNAME):
tdLog.printNoPrefix("==========step1:create table") 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, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
) tags (t1 int) ) tags (t1 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, ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint,
{FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool,
{BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp
...@@ -218,30 +219,30 @@ class TDTestCase: ...@@ -218,30 +219,30 @@ class TDTestCase:
tdSql.execute(create_ntb_sql) tdSql.execute(create_ntb_sql)
for i in range(4): 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} )')
{ i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2} { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}
def __insert_data(self, rows): def __insert_data(self, rows, dbname=DBNAME):
now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000)
for i in range(rows): for i in range(rows):
tdSql.execute( 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( 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( 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( 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 - 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 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } )
''' '''
) )
tdSql.execute( 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 * 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 + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
...@@ -257,7 +258,7 @@ class TDTestCase: ...@@ -257,7 +258,7 @@ class TDTestCase:
) )
tdSql.execute( 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 * 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 + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
...@@ -273,13 +274,13 @@ class TDTestCase: ...@@ -273,13 +274,13 @@ class TDTestCase:
) )
for i in range(rows): 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}, ( { 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(insert_data)
tdSql.execute( 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 + 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 // 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 - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
...@@ -295,7 +296,6 @@ class TDTestCase: ...@@ -295,7 +296,6 @@ class TDTestCase:
''' '''
) )
def run(self): def run(self):
tdSql.prepare() tdSql.prepare()
......
...@@ -32,9 +32,10 @@ class TDTestCase: ...@@ -32,9 +32,10 @@ class TDTestCase:
self.ts = 1537146000000 self.ts = 1537146000000
self.binary_str = 'taosdata' self.binary_str = 'taosdata'
self.nchar_str = '涛思数据' self.nchar_str = '涛思数据'
def first_check_base(self): def first_check_base(self):
tdSql.prepare() dbname = "db"
tdSql.prepare(dbname)
column_dict = { column_dict = {
'col1': 'tinyint', 'col1': 'tinyint',
'col2': 'smallint', 'col2': 'smallint',
...@@ -50,30 +51,25 @@ class TDTestCase: ...@@ -50,30 +51,25 @@ class TDTestCase:
'col12': 'binary(20)', 'col12': 'binary(20)',
'col13': 'nchar(20)' 'col13': 'nchar(20)'
} }
tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, tdSql.execute(f'''create table {dbname}.stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned,
col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''') col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''')
tdSql.execute("create table stb_1 using stb tags('beijing')") tdSql.execute(f"create table {dbname}.stb_1 using {dbname}.stb tags('beijing')")
tdSql.execute("insert into stb_1(ts) values(%d)" % (self.ts - 1)) tdSql.execute(f"insert into {dbname}.stb_1(ts) values({self.ts - 1})")
column_list = ['col1','col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12','col13'] column_list = ['col1','col2','col3','col4','col5','col6','col7','col8','col9','col10','col11','col12','col13']
for i in ['stb_1','db.stb_1','stb_1','db.stb_1']: for i in ['stb_1','stb']:
tdSql.query(f"select first(*) from {i}") tdSql.query(f"select first(*) from {dbname}.{i}")
tdSql.checkRows(1)
tdSql.checkData(0, 1, None)
#!bug TD-16561
for i in ['stb','db.stb']:
tdSql.query(f"select first(*) from {i}")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 1, None) tdSql.checkData(0, 1, None)
for i in column_list: for i in column_list:
for j in ['stb_1','db.stb_1','stb_1','db.stb_1']: for j in ['stb_1']:
tdSql.query(f"select first({i}) from {j}") tdSql.query(f"select first({i}) from {dbname}.{j}")
tdSql.checkRows(0) tdSql.checkRows(0)
for i in range(self.rowNum): for i in range(self.rowNum):
tdSql.execute(f"insert into stb_1 values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')" tdSql.execute(f"insert into {dbname}.stb_1 values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')"
% (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1)) % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1))
for k, v in column_dict.items(): for k, v in column_dict.items():
for j in ['stb_1', 'db.stb_1', 'stb', 'db.stb']: for j in ['stb_1', 'stb']:
tdSql.query(f"select first({k}) from {j}") tdSql.query(f"select first({k}) from {dbname}.{j}")
tdSql.checkRows(1) tdSql.checkRows(1)
# tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned
if v == 'tinyint' or v == 'smallint' or v == 'int' or v == 'bigint' or v == 'tinyint unsigned' or v == 'smallint unsigned'\ if v == 'tinyint' or v == 'smallint' or v == 'int' or v == 'bigint' or v == 'tinyint unsigned' or v == 'smallint unsigned'\
...@@ -92,9 +88,9 @@ class TDTestCase: ...@@ -92,9 +88,9 @@ class TDTestCase:
elif 'nchar' in v: elif 'nchar' in v:
tdSql.checkData(0, 0, f'{self.nchar_str}1') tdSql.checkData(0, 0, f'{self.nchar_str}1')
#!bug TD-16569 #!bug TD-16569
tdSql.query("select first(*),last(*) from stb where ts < 23 interval(1s)") tdSql.query(f"select first(*),last(*) from {dbname}.stb where ts < 23 interval(1s)")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.execute('drop database db') tdSql.execute(f'drop database {dbname}')
def first_check_stb_distribute(self): def first_check_stb_distribute(self):
# prepare data for vgroup 4 # prepare data for vgroup 4
dbname = tdCom.getLongName(10, "letters") dbname = tdCom.getLongName(10, "letters")
...@@ -119,17 +115,17 @@ class TDTestCase: ...@@ -119,17 +115,17 @@ class TDTestCase:
tdSql.execute(f"create database if not exists {dbname} vgroups {vgroup}") tdSql.execute(f"create database if not exists {dbname} vgroups {vgroup}")
tdSql.execute(f'use {dbname}') tdSql.execute(f'use {dbname}')
# build 20 child tables,every table insert 10 rows # build 20 child tables,every table insert 10 rows
tdSql.execute(f'''create table {stbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned, tdSql.execute(f'''create table {dbname}.{stbname}(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 tinyint unsigned, col6 smallint unsigned,
col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''') col7 int unsigned, col8 bigint unsigned, col9 float, col10 double, col11 bool, col12 binary(20), col13 nchar(20)) tags(loc nchar(20))''')
for i in range(child_table_num): for i in range(child_table_num):
tdSql.execute(f"create table {stbname}_{i} using {stbname} tags('beijing')") tdSql.execute(f"create table {dbname}.{stbname}_{i} using {dbname}.{stbname} tags('beijing')")
tdSql.execute(f"insert into {stbname}_{i}(ts) values(%d)" % (self.ts - 1-i)) tdSql.execute(f"insert into {dbname}.{stbname}_{i}(ts) values(%d)" % (self.ts - 1-i))
#!bug TD-16561 #!bug TD-16561
for i in [f'{stbname}', f'{dbname}.{stbname}']: for i in [f'{dbname}.{stbname}']:
tdSql.query(f"select first(*) from {i}") tdSql.query(f"select first(*) from {i}")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 1, None) tdSql.checkData(0, 1, None)
tdSql.query('show tables') tdSql.query(f'show {dbname}.tables')
vgroup_list = [] vgroup_list = []
for i in range(len(tdSql.queryResult)): for i in range(len(tdSql.queryResult)):
vgroup_list.append(tdSql.queryResult[i][6]) vgroup_list.append(tdSql.queryResult[i][6])
...@@ -142,15 +138,15 @@ class TDTestCase: ...@@ -142,15 +138,15 @@ class TDTestCase:
tdLog.info(f'This scene with {vgroups_num} vgroups is ok!') tdLog.info(f'This scene with {vgroups_num} vgroups is ok!')
continue continue
else: else:
tdLog.exit('This scene does not meet the requirements with {vgroups_num} vgroup!\n') tdLog.exit(f'This scene does not meet the requirements with {vgroups_num} vgroup!\n')
for i in range(child_table_num): for i in range(child_table_num):
for j in range(self.rowNum): for j in range(self.rowNum):
tdSql.execute(f"insert into {stbname}_{i} values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')" tdSql.execute(f"insert into {dbname}.{stbname}_{i} values(%d, %d, %d, %d, %d, %d, %d, %d, %d, %f, %f, %d, '{self.binary_str}%d', '{self.nchar_str}%d')"
% (self.ts + j + i, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 0.1, j + 0.1, j % 2, j + 1, j + 1)) % (self.ts + j + i, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 1, j + 0.1, j + 0.1, j % 2, j + 1, j + 1))
for k, v in column_dict.items(): for k, v in column_dict.items():
for j in [f'{stbname}_{i}', f'{dbname}.{stbname}_{i}', f'{stbname}', f'{dbname}.{stbname}']: for j in [f'{dbname}.{stbname}_{i}', f'{dbname}.{stbname}']:
tdSql.query(f"select first({k}) from {j}") tdSql.query(f"select first({k}) from {j}")
tdSql.checkRows(1) tdSql.checkRows(1)
# tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned # tinyint,smallint,int,bigint,tinyint unsigned,smallint unsigned,int unsigned,bigint unsigned
...@@ -170,18 +166,15 @@ class TDTestCase: ...@@ -170,18 +166,15 @@ class TDTestCase:
elif 'nchar' in v: elif 'nchar' in v:
tdSql.checkData(0, 0, f'{self.nchar_str}1') tdSql.checkData(0, 0, f'{self.nchar_str}1')
#!bug TD-16569 #!bug TD-16569
tdSql.query(f"select first(*),last(*) from {stbname} where ts < 23 interval(1s)") tdSql.query(f"select first(*),last(*) from {dbname}.{stbname} where ts < 23 interval(1s)")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.execute(f'drop database {dbname}') tdSql.execute(f'drop database {dbname}')
pass
def run(self): def run(self):
self.first_check_base() self.first_check_base()
self.first_check_stb_distribute() self.first_check_stb_distribute()
def stop(self): def stop(self):
tdSql.close() tdSql.close()
tdLog.success("%s successfully executed" % __file__) tdLog.success("%s successfully executed" % __file__)
......
...@@ -8,50 +8,50 @@ from util.log import * ...@@ -8,50 +8,50 @@ from util.log import *
from util.sql import * from util.sql import *
from util.cases import * from util.cases import *
DBNAME = "db"
class TDTestCase: 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): def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor()) tdSql.init(conn.cursor())
def prepare_datas(self):
def prepare_datas(self, dbname=DBNAME):
tdSql.execute( 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) (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) tags (t1 int)
''' '''
) )
tdSql.execute( tdSql.execute(
''' f'''
create table t1 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) (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): 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): for i in range(9):
tdSql.execute( 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( 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(f"insert into {dbname}.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(f"insert into {dbname}.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(f"insert into {dbname}.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()+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(f"insert into {dbname}.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(f"insert into {dbname}.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()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( 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-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-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 ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a )
...@@ -95,68 +95,68 @@ class TDTestCase: ...@@ -95,68 +95,68 @@ class TDTestCase:
else: else:
tdLog.info("floor value check pass , it work as expected ,sql is \"%s\" "%floor_query ) tdLog.info("floor value check pass , it work as expected ,sql is \"%s\" "%floor_query )
def test_errors(self): def test_errors(self, dbname=DBNAME):
error_sql_lists = [ error_sql_lists = [
"select floor from t1", f"select floor from {dbname}.t1",
# "select floor(-+--+c1) from t1", # f"select floor(-+--+c1) from {dbname}.t1",
# "select +-floor(c1) from t1", # f"select +-floor(c1) from {dbname}.t1",
# "select ++-floor(c1) from t1", # f"select ++-floor(c1) from {dbname}.t1",
# "select ++--floor(c1) from t1", # f"select ++--floor(c1) from {dbname}.t1",
# "select - -floor(c1)*0 from t1", # f"select - -floor(c1)*0 from {dbname}.t1",
# "select floor(tbname+1) from t1 ", # f"select floor(tbname+1) from {dbname}.t1 ",
"select floor(123--123)==1 from t1", f"select floor(123--123)==1 from {dbname}.t1",
"select floor(c1) as 'd1' from t1", f"select floor(c1) as 'd1' from {dbname}.t1",
"select floor(c1 ,c2 ) from t1", f"select floor(c1 ,c2 ) from {dbname}.t1",
"select floor(c1 ,NULL) from t1", f"select floor(c1 ,NULL) from {dbname}.t1",
"select floor(,) from t1;", f"select floor(,) from {dbname}.t1;",
"select floor(floor(c1) ab from t1)", f"select floor(floor(c1) ab from {dbname}.t1)",
"select floor(c1) as int from t1", f"select floor(c1) as int from {dbname}.t1",
"select floor from stb1", f"select floor from {dbname}.stb1",
# "select floor(-+--+c1) from stb1", # f"select floor(-+--+c1) from {dbname}.stb1",
# "select +-floor(c1) from stb1", # f"select +-floor(c1) from {dbname}.stb1",
# "select ++-floor(c1) from stb1", # f"select ++-floor(c1) from {dbname}.stb1",
# "select ++--floor(c1) from stb1", # f"select ++--floor(c1) from {dbname}.stb1",
# "select - -floor(c1)*0 from stb1", # f"select - -floor(c1)*0 from {dbname}.stb1",
# "select floor(tbname+1) from stb1 ", # f"select floor(tbname+1) from {dbname}.stb1 ",
"select floor(123--123)==1 from stb1", f"select floor(123--123)==1 from {dbname}.stb1",
"select floor(c1) as 'd1' from stb1", f"select floor(c1) as 'd1' from {dbname}.stb1",
"select floor(c1 ,c2 ) from stb1", f"select floor(c1 ,c2 ) from {dbname}.stb1",
"select floor(c1 ,NULL) from stb1", f"select floor(c1 ,NULL) from {dbname}.stb1",
"select floor(,) from stb1;", f"select floor(,) from {dbname}.stb1;",
"select floor(floor(c1) ab from stb1)", f"select floor(floor(c1) ab from {dbname}.stb1)",
"select floor(c1) as int from stb1" f"select floor(c1) as int from {dbname}.stb1"
] ]
for error_sql in error_sql_lists: for error_sql in error_sql_lists:
tdSql.error(error_sql) tdSql.error(error_sql)
def support_types(self): def support_types(self, dbname=DBNAME):
type_error_sql_lists = [ type_error_sql_lists = [
"select floor(ts) from t1" , f"select floor(ts) from {dbname}.t1" ,
"select floor(c7) from t1", f"select floor(c7) from {dbname}.t1",
"select floor(c8) from t1", f"select floor(c8) from {dbname}.t1",
"select floor(c9) from t1", f"select floor(c9) from {dbname}.t1",
"select floor(ts) from ct1" , f"select floor(ts) from {dbname}.ct1" ,
"select floor(c7) from ct1", f"select floor(c7) from {dbname}.ct1",
"select floor(c8) from ct1", f"select floor(c8) from {dbname}.ct1",
"select floor(c9) from ct1", f"select floor(c9) from {dbname}.ct1",
"select floor(ts) from ct3" , f"select floor(ts) from {dbname}.ct3" ,
"select floor(c7) from ct3", f"select floor(c7) from {dbname}.ct3",
"select floor(c8) from ct3", f"select floor(c8) from {dbname}.ct3",
"select floor(c9) from ct3", f"select floor(c9) from {dbname}.ct3",
"select floor(ts) from ct4" , f"select floor(ts) from {dbname}.ct4" ,
"select floor(c7) from ct4", f"select floor(c7) from {dbname}.ct4",
"select floor(c8) from ct4", f"select floor(c8) from {dbname}.ct4",
"select floor(c9) from ct4", f"select floor(c9) from {dbname}.ct4",
"select floor(ts) from stb1" , f"select floor(ts) from {dbname}.stb1" ,
"select floor(c7) from stb1", f"select floor(c7) from {dbname}.stb1",
"select floor(c8) from stb1", f"select floor(c8) from {dbname}.stb1",
"select floor(c9) from stb1" , f"select floor(c9) from {dbname}.stb1" ,
"select floor(ts) from stbbb1" , f"select floor(ts) from {dbname}.stbbb1" ,
"select floor(c7) from stbbb1", f"select floor(c7) from {dbname}.stbbb1",
"select floor(ts) from tbname", f"select floor(ts) from {dbname}.tbname",
"select floor(c9) from tbname" f"select floor(c9) from {dbname}.tbname"
] ]
...@@ -165,127 +165,127 @@ class TDTestCase: ...@@ -165,127 +165,127 @@ class TDTestCase:
type_sql_lists = [ type_sql_lists = [
"select floor(c1) from t1", f"select floor(c1) from {dbname}.t1",
"select floor(c2) from t1", f"select floor(c2) from {dbname}.t1",
"select floor(c3) from t1", f"select floor(c3) from {dbname}.t1",
"select floor(c4) from t1", f"select floor(c4) from {dbname}.t1",
"select floor(c5) from t1", f"select floor(c5) from {dbname}.t1",
"select floor(c6) from t1", f"select floor(c6) from {dbname}.t1",
"select floor(c1) from ct1", f"select floor(c1) from {dbname}.ct1",
"select floor(c2) from ct1", f"select floor(c2) from {dbname}.ct1",
"select floor(c3) from ct1", f"select floor(c3) from {dbname}.ct1",
"select floor(c4) from ct1", f"select floor(c4) from {dbname}.ct1",
"select floor(c5) from ct1", f"select floor(c5) from {dbname}.ct1",
"select floor(c6) from ct1", f"select floor(c6) from {dbname}.ct1",
"select floor(c1) from ct3", f"select floor(c1) from {dbname}.ct3",
"select floor(c2) from ct3", f"select floor(c2) from {dbname}.ct3",
"select floor(c3) from ct3", f"select floor(c3) from {dbname}.ct3",
"select floor(c4) from ct3", f"select floor(c4) from {dbname}.ct3",
"select floor(c5) from ct3", f"select floor(c5) from {dbname}.ct3",
"select floor(c6) from ct3", f"select floor(c6) from {dbname}.ct3",
"select floor(c1) from stb1", f"select floor(c1) from {dbname}.stb1",
"select floor(c2) from stb1", f"select floor(c2) from {dbname}.stb1",
"select floor(c3) from stb1", f"select floor(c3) from {dbname}.stb1",
"select floor(c4) from stb1", f"select floor(c4) from {dbname}.stb1",
"select floor(c5) from stb1", f"select floor(c5) from {dbname}.stb1",
"select floor(c6) from stb1", f"select floor(c6) from {dbname}.stb1",
"select floor(c6) as alisb from stb1", f"select floor(c6) as alisb from {dbname}.stb1",
"select floor(c6) alisb from stb1", f"select floor(c6) alisb from {dbname}.stb1",
] ]
for type_sql in type_sql_lists: for type_sql in type_sql_lists:
tdSql.query(type_sql) tdSql.query(type_sql)
def basic_floor_function(self): def basic_floor_function(self, dbname=DBNAME):
# basic query # basic query
tdSql.query("select c1 from ct3") tdSql.query(f"select c1 from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select c1 from t1") tdSql.query(f"select c1 from {dbname}.t1")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.query("select c1 from stb1") tdSql.query(f"select c1 from {dbname}.stb1")
tdSql.checkRows(25) tdSql.checkRows(25)
# used for empty table , ct3 is empty # used for empty table , ct3 is empty
tdSql.query("select floor(c1) from ct3") tdSql.query(f"select floor(c1) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select floor(c2) from ct3") tdSql.query(f"select floor(c2) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select floor(c3) from ct3") tdSql.query(f"select floor(c3) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select floor(c4) from ct3") tdSql.query(f"select floor(c4) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select floor(c5) from ct3") tdSql.query(f"select floor(c5) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select floor(c6) from ct3") tdSql.query(f"select floor(c6) from {dbname}.ct3")
# used for regular table # used for regular table
tdSql.query("select floor(c1) from t1") tdSql.query(f"select floor(c1) from {dbname}.t1")
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(1 , 0, 1) tdSql.checkData(1 , 0, 1)
tdSql.checkData(3 , 0, 3) tdSql.checkData(3 , 0, 3)
tdSql.checkData(5 , 0, None) 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(1, 4, 1.11000)
tdSql.checkData(3, 3, 33) tdSql.checkData(3, 3, 33)
tdSql.checkData(5, 4, None) 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(1, 5, 1.11000)
tdSql.checkData(3, 4, 33) tdSql.checkData(3, 4, 33)
tdSql.checkData(5, 5, None) tdSql.checkData(5, 5, None)
self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from t1") self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from {dbname}.t1")
# used for sub table # used for sub table
tdSql.query("select floor(c1) from ct1") tdSql.query(f"select floor(c1) from {dbname}.ct1")
tdSql.checkData(0, 0, 8) tdSql.checkData(0, 0, 8)
tdSql.checkData(1 , 0, 7) tdSql.checkData(1 , 0, 7)
tdSql.checkData(3 , 0, 5) tdSql.checkData(3 , 0, 5)
tdSql.checkData(5 , 0, 4) tdSql.checkData(5 , 0, 4)
tdSql.query("select floor(c1) from ct1") tdSql.query(f"select floor(c1) from {dbname}.ct1")
self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from ct1") self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from {dbname}.ct1")
self.check_result_auto("select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) self.check_result_auto(f"select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from {dbname}.ct1;",f"select c1 from {dbname}.ct1" )
# used for stable table # used for stable table
tdSql.query("select floor(c1) from stb1") tdSql.query(f"select floor(c1) from {dbname}.stb1")
tdSql.checkRows(25) tdSql.checkRows(25)
self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from ct4") self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.ct4 ", f"select (c1), floor(c2) ,floor(c3), floor(c4), floor(c5) from {dbname}.ct4")
self.check_result_auto("select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) self.check_result_auto(f"select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from {dbname}.ct4;" , f"select c1 from {dbname}.ct4" )
# used for not exists table # used for not exists table
tdSql.error("select floor(c1) from stbbb1") tdSql.error(f"select floor(c1) from {dbname}.stbbb1")
tdSql.error("select floor(c1) from tbname") tdSql.error(f"select floor(c1) from {dbname}.tbname")
tdSql.error("select floor(c1) from ct5") tdSql.error(f"select floor(c1) from {dbname}.ct5")
# mix with common col # mix with common col
tdSql.query("select c1, floor(c1) from ct1") tdSql.query(f"select c1, floor(c1) from {dbname}.ct1")
tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 0 ,8)
tdSql.checkData(0 , 1 ,8) tdSql.checkData(0 , 1 ,8)
tdSql.checkData(4 , 0 ,0) tdSql.checkData(4 , 0 ,0)
tdSql.checkData(4 , 1 ,0) tdSql.checkData(4 , 1 ,0)
tdSql.query("select c1, floor(c1) from ct4") tdSql.query(f"select c1, floor(c1) from {dbname}.ct4")
tdSql.checkData(0 , 0 , None) tdSql.checkData(0 , 0 , None)
tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 1 ,None)
tdSql.checkData(4 , 0 ,5) tdSql.checkData(4 , 0 ,5)
tdSql.checkData(4 , 1 ,5) tdSql.checkData(4 , 1 ,5)
tdSql.checkData(5 , 0 ,None) tdSql.checkData(5 , 0 ,None)
tdSql.checkData(5 , 1 ,None) tdSql.checkData(5 , 1 ,None)
tdSql.query("select c1, floor(c1) from ct4 ") tdSql.query(f"select c1, floor(c1) from {dbname}.ct4 ")
tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 0 ,None)
tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 1 ,None)
tdSql.checkData(4 , 0 ,5) tdSql.checkData(4 , 0 ,5)
tdSql.checkData(4 , 1 ,5) tdSql.checkData(4 , 1 ,5)
# mix with common functions # mix with common functions
tdSql.query("select c1, floor(c1),c5, floor(c5) from ct4 ") tdSql.query(f"select c1, floor(c1),c5, floor(c5) from {dbname}.ct4 ")
tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 0 ,None)
tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 1 ,None)
tdSql.checkData(0 , 2 ,None) tdSql.checkData(0 , 2 ,None)
...@@ -296,34 +296,34 @@ class TDTestCase: ...@@ -296,34 +296,34 @@ class TDTestCase:
tdSql.checkData(3 , 2 ,6.66000) tdSql.checkData(3 , 2 ,6.66000)
tdSql.checkData(3 , 3 ,6.00000) tdSql.checkData(3 , 3 ,6.00000)
tdSql.query("select c1, floor(c1),c5, floor(c5) from stb1 ") tdSql.query(f"select c1, floor(c1),c5, floor(c5) from {dbname}.stb1 ")
# mix with agg functions , not support # mix with agg functions , not support
tdSql.error("select c1, floor(c1),c5, count(c5) from stb1 ") tdSql.error(f"select c1, floor(c1),c5, count(c5) from {dbname}.stb1 ")
tdSql.error("select c1, floor(c1),c5, count(c5) from ct1 ") tdSql.error(f"select c1, floor(c1),c5, count(c5) from {dbname}.ct1 ")
tdSql.error("select floor(c1), count(c5) from stb1 ") tdSql.error(f"select floor(c1), count(c5) from {dbname}.stb1 ")
tdSql.error("select floor(c1), count(c5) from ct1 ") tdSql.error(f"select floor(c1), count(c5) from {dbname}.ct1 ")
tdSql.error("select c1, count(c5) from ct1 ") tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ")
tdSql.error("select c1, count(c5) from stb1 ") tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ")
# agg functions mix with agg functions # agg functions mix with agg functions
tdSql.query("select max(c5), count(c5) from stb1") tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1")
tdSql.query("select max(c5), count(c5) from ct1") tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1")
# bug fix for count # bug fix for count
tdSql.query("select count(c1) from ct4 ") tdSql.query(f"select count(c1) from {dbname}.ct4 ")
tdSql.checkData(0,0,9) tdSql.checkData(0,0,9)
tdSql.query("select count(*) from ct4 ") tdSql.query(f"select count(*) from {dbname}.ct4 ")
tdSql.checkData(0,0,12) tdSql.checkData(0,0,12)
tdSql.query("select count(c1) from stb1 ") tdSql.query(f"select count(c1) from {dbname}.stb1 ")
tdSql.checkData(0,0,22) tdSql.checkData(0,0,22)
tdSql.query("select count(*) from stb1 ") tdSql.query(f"select count(*) from {dbname}.stb1 ")
tdSql.checkData(0,0,25) tdSql.checkData(0,0,25)
# bug fix for compute # bug fix for compute
tdSql.query("select c1, abs(c1) -0 ,floor(c1)-0 from ct4 ") tdSql.query(f"select c1, abs(c1) -0 ,floor(c1)-0 from {dbname}.ct4 ")
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(0, 1, None) tdSql.checkData(0, 1, None)
tdSql.checkData(0, 2, None) tdSql.checkData(0, 2, None)
...@@ -331,7 +331,7 @@ class TDTestCase: ...@@ -331,7 +331,7 @@ class TDTestCase:
tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 1, 8.000000000)
tdSql.checkData(1, 2, 8.000000000) tdSql.checkData(1, 2, 8.000000000)
tdSql.query(" select c1, abs(c1) -0 ,floor(c1-0.1)-0.1 from ct4") tdSql.query(f"select c1, abs(c1) -0 ,floor(c1-0.1)-0.1 from {dbname}.ct4")
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(0, 1, None) tdSql.checkData(0, 1, None)
tdSql.checkData(0, 2, None) tdSql.checkData(0, 2, None)
...@@ -339,9 +339,8 @@ class TDTestCase: ...@@ -339,9 +339,8 @@ class TDTestCase:
tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 1, 8.000000000)
tdSql.checkData(1, 2, 6.900000000) tdSql.checkData(1, 2, 6.900000000)
def abs_func_filter(self): def abs_func_filter(self, dbname=DBNAME):
tdSql.execute("use db") tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1>5 ")
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ")
tdSql.checkRows(3) tdSql.checkRows(3)
tdSql.checkData(0,0,8) tdSql.checkData(0,0,8)
tdSql.checkData(0,1,8.000000000) tdSql.checkData(0,1,8.000000000)
...@@ -349,7 +348,7 @@ class TDTestCase: ...@@ -349,7 +348,7 @@ class TDTestCase:
tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,3,7.900000000)
tdSql.checkData(0,4,3.000000000) tdSql.checkData(0,4,3.000000000)
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-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(log(c1,2)-0.5) from {dbname}.ct4 where c1=5 ")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0,0,5) tdSql.checkData(0,0,5)
tdSql.checkData(0,1,5.000000000) tdSql.checkData(0,1,5.000000000)
...@@ -357,7 +356,7 @@ class TDTestCase: ...@@ -357,7 +356,7 @@ class TDTestCase:
tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,3,4.900000000)
tdSql.checkData(0,4,2.000000000) tdSql.checkData(0,4,2.000000000)
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-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(log(c1,2)-0.5) from {dbname}.ct4 where c1=5 ")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0,0,5) tdSql.checkData(0,0,5)
tdSql.checkData(0,1,5.000000000) tdSql.checkData(0,1,5.000000000)
...@@ -365,7 +364,7 @@ class TDTestCase: ...@@ -365,7 +364,7 @@ class TDTestCase:
tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,3,4.900000000)
tdSql.checkData(0,4,2.000000000) tdSql.checkData(0,4,2.000000000)
tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") tdSql.query(f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1>log(c1,2) limit 1 ")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0,0,8) tdSql.checkData(0,0,8)
tdSql.checkData(0,1,88888) tdSql.checkData(0,1,88888)
...@@ -377,44 +376,44 @@ class TDTestCase: ...@@ -377,44 +376,44 @@ class TDTestCase:
def floor_Arithmetic(self): def floor_Arithmetic(self):
pass pass
def check_boundary_values(self): def check_boundary_values(self, dbname="bound_test"):
tdSql.execute("drop database if exists bound_test") tdSql.execute(f"drop database if exists {dbname}")
tdSql.execute("create database if not exists bound_test") tdSql.execute(f"create database if not exists {dbname}")
time.sleep(3) time.sleep(3)
tdSql.execute("use bound_test") tdSql.execute(f"use {dbname}")
tdSql.execute( 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( 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( 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( 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( 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( 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( 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() )"
) )
self.check_result_auto( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select floor(c1), floor(c2) ,floor(c3), floor(c4), floor(c5) ,floor(c6) from sub1_bound") self.check_result_auto( f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select floor(c1), floor(c2) ,floor(c3), floor(c4), floor(c5) ,floor(c6) from {dbname}.sub1_bound")
self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select floor(c1), floor(c2) ,floor(c3), floor(c3), floor(c2) ,floor(c1) from sub1_bound") self.check_result_auto( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select floor(c1), floor(c2) ,floor(c3), floor(c3), floor(c2) ,floor(c1) from {dbname}.sub1_bound")
self.check_result_auto("select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from sub1_bound;" , "select floor(c1) from sub1_bound" ) self.check_result_auto(f"select floor(floor(floor(floor(floor(floor(floor(floor(floor(floor(c1)))))))))) nest_col_func from {dbname}.sub1_bound;" , f"select floor(c1) from {dbname}.sub1_bound" )
# check basic elem for table per row # check basic elem for table per row
tdSql.query("select floor(c1+0.2) ,floor(c2) , floor(c3+0.3) , floor(c4-0.3), floor(c5/2), floor(c6/2) from sub1_bound ") tdSql.query(f"select floor(c1+0.2) ,floor(c2) , floor(c3+0.3) , floor(c4-0.3), floor(c5/2), floor(c6/2) from {dbname}.sub1_bound ")
tdSql.checkData(0, 0, 2147483647.000000000) tdSql.checkData(0, 0, 2147483647.000000000)
tdSql.checkData(0, 2, 32767.000000000) tdSql.checkData(0, 2, 32767.000000000)
tdSql.checkData(0, 3, 126.000000000) tdSql.checkData(0, 3, 126.000000000)
...@@ -425,23 +424,23 @@ class TDTestCase: ...@@ -425,23 +424,23 @@ class TDTestCase:
tdSql.checkData(4, 3, -124.000000000) tdSql.checkData(4, 3, -124.000000000)
tdSql.checkData(4, 4, -169499995645668991474575059260979281920.000000000) tdSql.checkData(4, 4, -169499995645668991474575059260979281920.000000000)
self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound" ,"select floor(c1+1) ,floor(c2) , floor(c3*1) , floor(c4/2), floor(c5)/2, floor(c6) from sub1_bound ") self.check_result_auto(f"select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from {dbname}.sub1_bound" ,f"select floor(c1+1) ,floor(c2) , floor(c3*1) , floor(c4/2), floor(c5)/2, floor(c6) from {dbname}.sub1_bound ")
def support_super_table_test(self): def support_super_table_test(self, dbname=DBNAME):
tdSql.execute(" use db ") tdSql.execute(f" use {dbname} ")
self.check_result_auto( " select c5 from stb1 order by ts " , "select floor(c5) from stb1 order by ts" ) self.check_result_auto( f"select c5 from {dbname}.stb1 order by ts " , f"select floor(c5) from {dbname}.stb1 order by ts" )
self.check_result_auto( " select c5 from stb1 order by tbname " , "select floor(c5) from stb1 order by tbname" ) self.check_result_auto( f"select c5 from {dbname}.stb1 order by tbname " , f"select floor(c5) from {dbname}.stb1 order by tbname" )
self.check_result_auto( " select c5 from stb1 where c1 > 0 order by tbname " , "select floor(c5) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto( f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select floor(c5) from {dbname}.stb1 where c1 > 0 order by tbname" )
self.check_result_auto( " select c5 from stb1 where c1 > 0 order by tbname " , "select floor(c5) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto( f"select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select floor(c5) from {dbname}.stb1 where c1 > 0 order by tbname" )
self.check_result_auto( " select t1,c5 from stb1 order by ts " , "select floor(t1), floor(c5) from stb1 order by ts" ) self.check_result_auto( f"select t1,c5 from {dbname}.stb1 order by ts " , f"select floor(t1), floor(c5) from {dbname}.stb1 order by ts" )
self.check_result_auto( " select t1,c5 from stb1 order by tbname " , "select floor(t1) ,floor(c5) from stb1 order by tbname" ) self.check_result_auto( f"select t1,c5 from {dbname}.stb1 order by tbname " , f"select floor(t1) ,floor(c5) from {dbname}.stb1 order by tbname" )
self.check_result_auto( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select floor(t1) ,floor(c5) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto( f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select floor(t1) ,floor(c5) from {dbname}.stb1 where c1 > 0 order by tbname" )
self.check_result_auto( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select floor(t1) , floor(c5) from stb1 where c1 > 0 order by tbname" ) self.check_result_auto( f"select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select floor(t1) , floor(c5) from {dbname}.stb1 where c1 > 0 order by tbname" )
pass pass
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
tdSql.prepare() tdSql.prepare(DBNAME)
tdLog.printNoPrefix("==========step1:create table ==============") tdLog.printNoPrefix("==========step1:create table ==============")
......
...@@ -10,65 +10,62 @@ import random ...@@ -10,65 +10,62 @@ import random
class TDTestCase: 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): def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor(), True) tdSql.init(conn.cursor(), False)
self.tb_nums = 10 self.tb_nums = 10
self.row_nums = 20 self.row_nums = 20
self.ts = 1434938400000 self.ts = 1434938400000
self.time_step = 1000 self.time_step = 1000
def prepare_tag_datas(self): def prepare_tag_datas(self, dbname="testdb"):
# prepare datas # prepare datas
tdSql.execute( tdSql.execute(
"create database if not exists testdb keep 3650 duration 1000") f"create database if not exists {dbname} keep 3650 duration 1000")
tdSql.execute(" use testdb ") tdSql.execute(f"use {dbname} ")
tdSql.execute( 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) (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 (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) tags (t0 timestamp, tag1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32))
''' '''
) )
tdSql.execute( tdSql.execute(
''' f'''
create table t1 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) (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): for i in range(4):
tdSql.execute( tdSql.execute(
f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )')
for i in range(9): for i in range(9):
tdSql.execute( 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( 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( tdSql.execute(
"insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )")
tdSql.execute( tdSql.execute(
"insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
tdSql.execute( tdSql.execute(
"insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )")
tdSql.execute( tdSql.execute(
"insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
tdSql.execute( tdSql.execute(
"insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( tdSql.execute(
"insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( tdSql.execute(
"insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( 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-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-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 ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a )
...@@ -84,15 +81,15 @@ class TDTestCase: ...@@ -84,15 +81,15 @@ class TDTestCase:
''' '''
) )
def function_for_null_data(self): def function_for_null_data(self, dbname="testdb"):
function_names = ["abs" , "floor" , "ceil" , "round"] function_names = ["abs" , "floor" , "ceil" , "round"]
for function_name in function_names: for function_name in function_names:
scalar_sql_1 = f"select {function_name}(c1)/0 from t1 group by c1 order by c1" scalar_sql_1 = f"select {function_name}(c1)/0 from {dbname}.t1 group by c1 order by c1"
scalar_sql_2 = f"select {function_name}(c1/0) from t1 group by c1 order by c1" scalar_sql_2 = f"select {function_name}(c1/0) from {dbname}.t1 group by c1 order by c1"
scalar_sql_3 = f"select {function_name}(NULL) from t1 group by c1 order by c1" scalar_sql_3 = f"select {function_name}(NULL) from {dbname}.t1 group by c1 order by c1"
tdSql.query(scalar_sql_1) tdSql.query(scalar_sql_1)
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.checkData(0,0,None) tdSql.checkData(0,0,None)
...@@ -111,127 +108,127 @@ class TDTestCase: ...@@ -111,127 +108,127 @@ class TDTestCase:
PI = 3.141592654 PI = 3.141592654
# sin # sin
tdSql.query(" select sin(c1/0) from t1 group by c1 order by c1") tdSql.query(f"select sin(c1/0) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select sin(NULL) from t1 group by c1 order by c1") tdSql.query(f"select sin(NULL) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select sin(0.00) from t1 group by c1 order by c1") tdSql.query(f"select sin(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,0.000000000) tdSql.checkData(9,0,0.000000000)
tdSql.query(f" select sin({PI/2}) from t1 group by c1 order by c1") tdSql.query(f"select sin({PI/2}) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,1.0) tdSql.checkData(9,0,1.0)
tdSql.query(" select sin(1000) from t1 group by c1 order by c1") tdSql.query(f"select sin(1000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,0.826879541) tdSql.checkData(9,0,0.826879541)
# cos # cos
tdSql.query(" select cos(c1/0) from t1 group by c1 order by c1") tdSql.query(f"select cos(c1/0) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select cos(NULL) from t1 group by c1 order by c1") tdSql.query(f"select cos(NULL) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select cos(0.00) from t1 group by c1 order by c1") tdSql.query(f"select cos(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,1.000000000) tdSql.checkData(9,0,1.000000000)
tdSql.query(f" select cos({PI}/2) from t1 group by c1 order by c1") tdSql.query(f"select cos({PI}/2) from {dbname}.t1 group by c1 order by c1")
tdSql.query(" select cos(1000) from t1 group by c1 order by c1") tdSql.query(f"select cos(1000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,0.562379076) tdSql.checkData(9,0,0.562379076)
# tan # tan
tdSql.query(" select tan(c1/0) from t1 group by c1 order by c1") tdSql.query(f"select tan(c1/0) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select tan(NULL) from t1 group by c1 order by c1") tdSql.query(f"select tan(NULL) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select tan(0.00) from t1 group by c1 order by c1") tdSql.query(f"select tan(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,0.000000000) tdSql.checkData(9,0,0.000000000)
tdSql.query(f" select tan({PI}/2) from t1 group by c1 order by c1") tdSql.query(f"select tan({PI}/2) from {dbname}.t1 group by c1 order by c1")
tdSql.query(" select tan(1000) from t1 group by c1 order by c1") tdSql.query(f"select tan(1000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,1.470324156) tdSql.checkData(9,0,1.470324156)
# atan # atan
tdSql.query(" select atan(c1/0) from t1 group by c1 order by c1") tdSql.query(f"select atan(c1/0) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select atan(NULL) from t1 group by c1 order by c1") tdSql.query(f"select atan(NULL) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select atan(0.00) from t1 group by c1 order by c1") tdSql.query(f"select atan(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,0.000000000) tdSql.checkData(9,0,0.000000000)
tdSql.query(f" select atan({PI}/2) from t1 group by c1 order by c1") tdSql.query(f"select atan({PI}/2) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,1.003884822) tdSql.checkData(9,0,1.003884822)
tdSql.query(" select atan(1000) from t1 group by c1 order by c1") tdSql.query(f"select atan(1000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,1.569796327) tdSql.checkData(9,0,1.569796327)
# asin # asin
tdSql.query(" select asin(c1/0) from t1 group by c1 order by c1") tdSql.query(f"select asin(c1/0) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select asin(NULL) from t1 group by c1 order by c1") tdSql.query(f"select asin(NULL) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select asin(0.00) from t1 group by c1 order by c1") tdSql.query(f"select asin(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,0.000000000) tdSql.checkData(9,0,0.000000000)
tdSql.query(f" select asin({PI}/2) from t1 group by c1 order by c1") tdSql.query(f"select asin({PI}/2) from {dbname}.t1 group by c1 order by c1")
tdSql.query(" select asin(1000) from t1 group by c1 order by c1") tdSql.query(f"select asin(1000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
# acos # acos
tdSql.query(" select acos(c1/0) from t1 group by c1 order by c1") tdSql.query(f"select acos(c1/0) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select acos(NULL) from t1 group by c1 order by c1") tdSql.query(f"select acos(NULL) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select acos(0.00) from t1 group by c1 order by c1") tdSql.query(f"select acos(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,1.570796327) tdSql.checkData(9,0,1.570796327)
tdSql.query(f" select acos({PI}/2) from t1 group by c1 order by c1") tdSql.query(f"select acos({PI}/2) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select acos(1000) from t1 group by c1 order by c1") tdSql.query(f"select acos(1000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
function_names = ["log" ,"pow"] function_names = ["log" ,"pow"]
# log # log
tdSql.query(" select log(-10) from t1 group by c1 order by c1") tdSql.query(f"select log(-10) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select log(NULL ,2) from t1 group by c1 order by c1") tdSql.query(f"select log(NULL ,2) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select log(c1)/0 from t1 group by c1 order by c1") tdSql.query(f"select log(c1)/0 from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(f" select log(0.00) from t1 group by c1 order by c1") tdSql.query(f"select log(0.00) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
# pow # pow
tdSql.query(" select pow(c1,10000) from t1 group by c1 order by c1") tdSql.query(f"select pow(c1,10000) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select pow(c1,2)/0 from t1 group by c1 order by c1") tdSql.query(f"select pow(c1,2)/0 from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(" select pow(NULL,2) from t1 group by c1 order by c1") tdSql.query(f"select pow(NULL,2) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
tdSql.query(f" select pow(c1/0 ,1 ) from t1 group by c1 order by c1") tdSql.query(f"select pow(c1/0 ,1 ) from {dbname}.t1 group by c1 order by c1")
tdSql.checkData(9,0,None) tdSql.checkData(9,0,None)
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
tdSql.prepare() tdSql.prepare()
...@@ -243,7 +240,7 @@ class TDTestCase: ...@@ -243,7 +240,7 @@ class TDTestCase:
tdLog.printNoPrefix("==========step2:test errors ==============") tdLog.printNoPrefix("==========step2:test errors ==============")
self.function_for_null_data() self.function_for_null_data()
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
from math import floor
from random import randint, random
from numpy import equal
import taos
import sys
import datetime
import inspect
from util.log import * from util.log import *
from util.sql import * from util.sql import *
from util.cases import * from util.cases import *
DBNAME = "db"
class TDTestCase: 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): def init(self, conn, logSql):
tdLog.debug(f"start to excute {__file__}") tdLog.debug(f"start to excute {__file__}")
tdSql.init(conn.cursor()) tdSql.init(conn.cursor())
def prepare_datas(self): def prepare_datas(self, dbname=DBNAME):
tdSql.execute( 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) (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) tags (t1 int)
''' '''
) )
tdSql.execute( tdSql.execute(
''' f'''
create table t1 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) (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): 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): for i in range(9):
tdSql.execute( 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( 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(f"insert into {dbname}.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(f"insert into {dbname}.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(f"insert into {dbname}.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()+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(f"insert into {dbname}.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(f"insert into {dbname}.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()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
tdSql.execute( 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-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-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 ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a )
...@@ -69,68 +59,68 @@ class TDTestCase: ...@@ -69,68 +59,68 @@ class TDTestCase:
''' '''
) )
def test_errors(self): def test_errors(self, dbname=DBNAME):
error_sql_lists = [ error_sql_lists = [
# "select stateduration(c1,'GT',5,1s) from t1" # f"select stateduration(c1,'GT',5,1s) from {dbname}.t1"
"select stateduration from t1", f"select stateduration from {dbname}.t1",
"select stateduration(123--123)==1 from t1", f"select stateduration(123--123)==1 from {dbname}.t1",
"select stateduration(123,123) from t1", f"select stateduration(123,123) from {dbname}.t1",
"select stateduration(c1,ts) from t1", f"select stateduration(c1,ts) from {dbname}.t1",
"select stateduration(c1,c1,ts) from t1", f"select stateduration(c1,c1,ts) from {dbname}.t1",
"select stateduration(c1 ,c2 ) from t1", f"select stateduration(c1 ,c2 ) from {dbname}.t1",
"select stateduration(c1 ,NULL) from t1", f"select stateduration(c1 ,NULL) from {dbname}.t1",
#"select stateduration(c1 ,'NULL',1.0,1s) from t1", #f"select stateduration(c1 ,'NULL',1.0,1s) from {dbname}.t1",
"select stateduration(c1 ,'GT','1',1s) from t1", f"select stateduration(c1 ,'GT','1',1s) from {dbname}.t1",
"select stateduration(c1 ,'GT','tbname',1s) from t1", f"select stateduration(c1 ,'GT','tbname',1s) from {dbname}.t1",
"select stateduration(c1 ,'GT','*',1s) from t1", f"select stateduration(c1 ,'GT','*',1s) from {dbname}.t1",
"select stateduration(c1 ,'GT',ts,1s) from t1", f"select stateduration(c1 ,'GT',ts,1s) from {dbname}.t1",
"select stateduration(c1 ,'GT',max(c1),1s) from t1", f"select stateduration(c1 ,'GT',max(c1),1s) from {dbname}.t1",
# "select stateduration(abs(c1) ,'GT',1,1s) from t1", # f"select stateduration(abs(c1) ,'GT',1,1s) from {dbname}.t1",
# "select stateduration(c1+2 ,'GT',1,1s) from t1", # f"select stateduration(c1+2 ,'GT',1,1s) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,1u) from t1", f"select stateduration(c1 ,'GT',1,1u) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,now) from t1", f"select stateduration(c1 ,'GT',1,now) from {dbname}.t1",
"select stateduration(c1 ,'GT','1',1s) from t1", f"select stateduration(c1 ,'GT','1',1s) from {dbname}.t1",
"select stateduration(c1 ,'GT','1',True) from t1", f"select stateduration(c1 ,'GT','1',True) from {dbname}.t1",
"select stateduration(stateduration(c1) ab from t1)", f"select stateduration(stateduration(c1) ab from {dbname}.t1)",
"select stateduration(c1 ,'GT',1,,)int from t1", f"select stateduration(c1 ,'GT',1,,)int from {dbname}.t1",
"select stateduration('c1','GT',1) from t1", f"select stateduration('c1','GT',1) from {dbname}.t1",
"select stateduration('c1','GT', 1 , NULL) from t1", f"select stateduration('c1','GT', 1 , NULL) from {dbname}.t1",
"select stateduration('c1','GT', 1 , '') from t1", f"select stateduration('c1','GT', 1 , '') from {dbname}.t1",
"select stateduration('c1','GT', 1 ,c%) from t1", f"select stateduration('c1','GT', 1 ,c%) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,t1) from t1", f"select stateduration(c1 ,'GT',1,t1) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,True) from t1", f"select stateduration(c1 ,'GT',1,True) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,1s) , count(c1) from t1", f"select stateduration(c1 ,'GT',1,1s) , count(c1) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,1s) , avg(c1) from t1", f"select stateduration(c1 ,'GT',1,1s) , avg(c1) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,1s) , min(c1) from t1", f"select stateduration(c1 ,'GT',1,1s) , min(c1) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,1s) , spread(c1) from t1", f"select stateduration(c1 ,'GT',1,1s) , spread(c1) from {dbname}.t1",
"select stateduration(c1 ,'GT',1,1s) , diff(c1) from t1", f"select stateduration(c1 ,'GT',1,1s) , diff(c1) from {dbname}.t1",
] ]
for error_sql in error_sql_lists: for error_sql in error_sql_lists:
tdSql.error(error_sql) tdSql.error(error_sql)
pass pass
def support_types(self): def support_types(self, dbname=DBNAME):
other_no_value_types = [ other_no_value_types = [
"select stateduration(ts,'GT',1,1s) from t1" , f"select stateduration(ts,'GT',1,1s) from {dbname}.t1" ,
"select stateduration(c7,'GT',1,1s) from t1", f"select stateduration(c7,'GT',1,1s) from {dbname}.t1",
"select stateduration(c8,'GT',1,1s) from t1", f"select stateduration(c8,'GT',1,1s) from {dbname}.t1",
"select stateduration(c9,'GT',1,1s) from t1", f"select stateduration(c9,'GT',1,1s) from {dbname}.t1",
"select stateduration(ts,'GT',1,1s) from ct1" , f"select stateduration(ts,'GT',1,1s) from {dbname}.ct1" ,
"select stateduration(c7,'GT',1,1s) from ct1", f"select stateduration(c7,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c8,'GT',1,1s) from ct1", f"select stateduration(c8,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c9,'GT',1,1s) from ct1", f"select stateduration(c9,'GT',1,1s) from {dbname}.ct1",
"select stateduration(ts,'GT',1,1s) from ct3" , f"select stateduration(ts,'GT',1,1s) from {dbname}.ct3" ,
"select stateduration(c7,'GT',1,1s) from ct3", f"select stateduration(c7,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c8,'GT',1,1s) from ct3", f"select stateduration(c8,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c9,'GT',1,1s) from ct3", f"select stateduration(c9,'GT',1,1s) from {dbname}.ct3",
"select stateduration(ts,'GT',1,1s) from ct4" , f"select stateduration(ts,'GT',1,1s) from {dbname}.ct4" ,
"select stateduration(c7,'GT',1,1s) from ct4", f"select stateduration(c7,'GT',1,1s) from {dbname}.ct4",
"select stateduration(c8,'GT',1,1s) from ct4", f"select stateduration(c8,'GT',1,1s) from {dbname}.ct4",
"select stateduration(c9,'GT',1,1s) from ct4", f"select stateduration(c9,'GT',1,1s) from {dbname}.ct4",
"select stateduration(ts,'GT',1,1s) from stb1 partition by tbname" , f"select stateduration(ts,'GT',1,1s) from {dbname}.stb1 partition by tbname" ,
"select stateduration(c7,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c7,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c8,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c8,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c9,'GT',1,1s) from stb1 partition by tbname" f"select stateduration(c9,'GT',1,1s) from {dbname}.stb1 partition by tbname"
] ]
for type_sql in other_no_value_types: for type_sql in other_no_value_types:
...@@ -138,266 +128,264 @@ class TDTestCase: ...@@ -138,266 +128,264 @@ class TDTestCase:
tdLog.info("support type ok , sql is : %s"%type_sql) tdLog.info("support type ok , sql is : %s"%type_sql)
type_sql_lists = [ type_sql_lists = [
"select stateduration(c1,'GT',1,1s) from t1", f"select stateduration(c1,'GT',1,1s) from {dbname}.t1",
"select stateduration(c2,'GT',1,1s) from t1", f"select stateduration(c2,'GT',1,1s) from {dbname}.t1",
"select stateduration(c3,'GT',1,1s) from t1", f"select stateduration(c3,'GT',1,1s) from {dbname}.t1",
"select stateduration(c4,'GT',1,1s) from t1", f"select stateduration(c4,'GT',1,1s) from {dbname}.t1",
"select stateduration(c5,'GT',1,1s) from t1", f"select stateduration(c5,'GT',1,1s) from {dbname}.t1",
"select stateduration(c6,'GT',1,1s) from t1", f"select stateduration(c6,'GT',1,1s) from {dbname}.t1",
"select stateduration(c1,'GT',1,1s) from ct1", f"select stateduration(c1,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c2,'GT',1,1s) from ct1", f"select stateduration(c2,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c3,'GT',1,1s) from ct1", f"select stateduration(c3,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c4,'GT',1,1s) from ct1", f"select stateduration(c4,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c5,'GT',1,1s) from ct1", f"select stateduration(c5,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c6,'GT',1,1s) from ct1", f"select stateduration(c6,'GT',1,1s) from {dbname}.ct1",
"select stateduration(c1,'GT',1,1s) from ct3", f"select stateduration(c1,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c2,'GT',1,1s) from ct3", f"select stateduration(c2,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c3,'GT',1,1s) from ct3", f"select stateduration(c3,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c4,'GT',1,1s) from ct3", f"select stateduration(c4,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c5,'GT',1,1s) from ct3", f"select stateduration(c5,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c6,'GT',1,1s) from ct3", f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3",
"select stateduration(c1,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c1,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c2,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c2,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c3,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c3,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c4,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c4,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c5,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c5,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c6,'GT',1,1s) from stb1 partition by tbname", f"select stateduration(c6,'GT',1,1s) from {dbname}.stb1 partition by tbname",
"select stateduration(c6,'GT',1,1s) as alisb from stb1 partition by tbname", f"select stateduration(c6,'GT',1,1s) as alisb from {dbname}.stb1 partition by tbname",
"select stateduration(c6,'GT',1,1s) alisb from stb1 partition by tbname", f"select stateduration(c6,'GT',1,1s) alisb from {dbname}.stb1 partition by tbname",
] ]
for type_sql in type_sql_lists: for type_sql in type_sql_lists:
tdSql.query(type_sql) tdSql.query(type_sql)
def support_opers(self): def support_opers(self, dbname=DBNAME):
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_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"] oper_errors = [",","*","NULL","tbname","ts","sum","_c0"]
for oper in oper_lists: for oper in oper_lists:
tdSql.query(f"select stateduration(c1 ,'{oper}',1,1s) as col from t1") tdSql.query(f"select stateduration(c1 ,'{oper}',1,1s) as col from {dbname}.t1")
tdSql.checkRows(12) tdSql.checkRows(12)
for oper in oper_errors: for oper in oper_errors:
tdSql.error(f"select stateduration(c1 ,'{oper}',1,1s) as col from t1") tdSql.error(f"select stateduration(c1 ,'{oper}',1,1s) as col from {dbname}.t1")
def basic_stateduration_function(self): def basic_stateduration_function(self, dbname=DBNAME):
# basic query # basic query
tdSql.query("select c1 from ct3") tdSql.query(f"select c1 from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select c1 from t1") tdSql.query(f"select c1 from {dbname}.t1")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.query("select c1 from stb1") tdSql.query(f"select c1 from {dbname}.stb1")
tdSql.checkRows(25) tdSql.checkRows(25)
# used for empty table , ct3 is empty # used for empty table , ct3 is empty
tdSql.query("select stateduration(c6,'GT',1,1s) from ct3") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select stateduration(c6,'GT',1,1s) from ct3") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select stateduration(c6,'GT',1,1s) from ct3") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select stateduration(c6,'GT',1,1s) from ct3") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select stateduration(c6,'GT',1,1s) from ct3") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3")
tdSql.checkRows(0) tdSql.checkRows(0)
tdSql.query("select stateduration(c6,'GT',1,1s) from ct3") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct3")
# will support _rowts mix with # will support _rowts mix with
# tdSql.query("select (c6,'GT',1,1s),_rowts from ct3") # tdSql.query(f"select (c6,'GT',1,1s),_rowts from {dbname}.ct3")
# auto check for t1 table # auto check for t1 table
# used for regular table # used for regular table
tdSql.query("select stateduration(c6,'GT',1,1s) from t1") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.t1")
# unique with super tags # unique with super tags
tdSql.query("select stateduration(c6,'GT',1,1s) from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
tdSql.query("select stateduration(c6,'GT',1,1s) from ct4") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct4")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.query("select stateduration(c6,'GT',1,1s),tbname from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s),tbname from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
tdSql.query("select stateduration(c6,'GT',1,1s),t1 from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s),t1 from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
# unique with common col # unique with common col
tdSql.query("select stateduration(c6,'GT',1,1s) ,ts from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s) ,ts from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
tdSql.query("select stateduration(c6,'GT',1,1s) ,c1 from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s) ,c1 from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
# unique with scalar function # unique with scalar function
tdSql.query("select stateduration(c6,'GT',1,1s) , abs(c1) from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s) , abs(c1) from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
tdSql.query("select stateduration(c6,'GT',1,1s) , abs(c2)+2 from ct1") tdSql.query(f"select stateduration(c6,'GT',1,1s) , abs(c2)+2 from {dbname}.ct1")
tdSql.checkRows(13) tdSql.checkRows(13)
tdSql.error("select stateduration(c6,'GT',1,1s) , unique(c2) from ct1") tdSql.error(f"select stateduration(c6,'GT',1,1s) , unique(c2) from {dbname}.ct1")
# unique with aggregate function # unique with aggregate function
tdSql.error("select stateduration(c6,'GT',1,1s) ,sum(c1) from ct1") tdSql.error(f"select stateduration(c6,'GT',1,1s) ,sum(c1) from {dbname}.ct1")
tdSql.error("select stateduration(c6,'GT',1,1s) ,max(c1) from ct1") tdSql.error(f"select stateduration(c6,'GT',1,1s) ,max(c1) from {dbname}.ct1")
tdSql.error("select stateduration(c6,'GT',1,1s) ,csum(c1) from ct1") tdSql.error(f"select stateduration(c6,'GT',1,1s) ,csum(c1) from {dbname}.ct1")
tdSql.error("select stateduration(c6,'GT',1,1s) ,count(c1) from ct1") tdSql.error(f"select stateduration(c6,'GT',1,1s) ,count(c1) from {dbname}.ct1")
# unique with filter where # unique with filter where
tdSql.query("select stateduration(c6,'GT',1,1s) from ct4 where c1 is null") tdSql.query(f"select stateduration(c6,'GT',1,1s) from {dbname}.ct4 where c1 is null")
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, None) tdSql.checkData(1, 0, None)
tdSql.checkData(2, 0, None) tdSql.checkData(2, 0, None)
tdSql.query("select stateduration(c1,'GT',1,1s) from t1 where c1 >2 ") tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.t1 where c1 >2 ")
tdSql.checkData(0, 0, 0) tdSql.checkData(0, 0, 0)
tdSql.checkData(1, 0, 10886404) tdSql.checkData(1, 0, 10886404)
tdSql.checkData(2, 0, 23500810) tdSql.checkData(2, 0, 23500810)
tdSql.checkData(4, 0, 57456020) tdSql.checkData(4, 0, 57456020)
tdSql.checkData(5, 0, 60393624) tdSql.checkData(5, 0, 60393624)
tdSql.query("select stateduration(c2,'GT',1,1s) from t1 where c2 between 0 and 99999") tdSql.query(f"select stateduration(c2,'GT',1,1s) from {dbname}.t1 where c2 between 0 and 99999")
tdSql.checkData(0, 0, 0) tdSql.checkData(0, 0, 0)
tdSql.checkData(1, 0, 6134400) tdSql.checkData(1, 0, 6134400)
tdSql.checkData(6, 0, -1) tdSql.checkData(6, 0, -1)
# unique with union all # unique with union all
tdSql.query("select stateduration(c1,'GT',1,1s) from ct4 union all select stateduration(c1,'GT',1,1s) from ct1") tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.ct4 union all select stateduration(c1,'GT',1,1s) from {dbname}.ct1")
tdSql.checkRows(25) tdSql.checkRows(25)
tdSql.query("select stateduration(c1,'GT',1,1s) from ct4 union all select distinct(c1) from ct4") tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.ct4 union all select distinct(c1) from {dbname}.ct4")
tdSql.checkRows(22) tdSql.checkRows(22)
# unique with join # unique with join
# prepare join datas with same ts # prepare join datas with same ts
tdSql.execute(" use db ") tdSql.execute(f"create stable {dbname}.st1 (ts timestamp , num int) tags(ind int)")
tdSql.execute(" create stable st1 (ts timestamp , num int) tags(ind int)") tdSql.execute(f"create table {dbname}.tb1 using {dbname}.st1 tags(1)")
tdSql.execute(" create table tb1 using st1 tags(1)") tdSql.execute(f"create table {dbname}.tb2 using {dbname}.st1 tags(2)")
tdSql.execute(" create table tb2 using st1 tags(2)")
tdSql.execute(" create stable st2 (ts timestamp , num int) tags(ind int)") tdSql.execute(f"create stable {dbname}.st2 (ts timestamp , num int) tags(ind int)")
tdSql.execute(" create table ttb1 using st2 tags(1)") tdSql.execute(f"create table {dbname}.ttb1 using {dbname}.st2 tags(1)")
tdSql.execute(" create table ttb2 using st2 tags(2)") tdSql.execute(f"create table {dbname}.ttb2 using {dbname}.st2 tags(2)")
start_ts = 1622369635000 # 2021-05-30 18:13:55 start_ts = 1622369635000 # 2021-05-30 18:13:55
for i in range(10): for i in range(10):
ts_value = start_ts+i*1000 ts_value = start_ts+i*1000
tdSql.execute(f" insert into tb1 values({ts_value} , {i})") tdSql.execute(f"insert into {dbname}.tb1 values({ts_value} , {i})")
tdSql.execute(f" insert into tb2 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 {dbname}.ttb1 values({ts_value} , {i})")
tdSql.execute(f" insert into ttb2 values({ts_value} , {i})") tdSql.execute(f"insert into {dbname}.ttb2 values({ts_value} , {i})")
tdSql.query("select stateduration(tb1.num,'GT',1,1s) from tb1, tb2 where tb1.ts=tb2.ts ") tdSql.query(f"select stateduration(tb1.num,'GT',1,1s) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts ")
tdSql.checkRows(10) tdSql.checkRows(10)
tdSql.checkData(0,0,-1) tdSql.checkData(0,0,-1)
tdSql.checkData(1,0,-1) tdSql.checkData(1,0,-1)
tdSql.checkData(2,0,0) tdSql.checkData(2,0,0)
tdSql.checkData(9,0,7) tdSql.checkData(9,0,7)
tdSql.query("select stateduration(tb1.num,'GT',1,1s) from tb1, tb2 where tb1.ts=tb2.ts union all select stateduration(tb2.num,'GT',1,1s) from tb1, tb2 where tb1.ts=tb2.ts ") tdSql.query(f"select stateduration(tb1.num,'GT',1,1s) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts union all select stateduration(tb2.num,'GT',1,1s) from {dbname}.tb1 tb1, {dbname}.tb2 tb2 where tb1.ts=tb2.ts ")
tdSql.checkRows(20) tdSql.checkRows(20)
# nest query # nest query
# tdSql.query("select unique(c1) from (select c1 from ct1)") # tdSql.query(f"select unique(c1) from (select c1 from {dbname}.ct1)")
tdSql.query("select c1 from (select stateduration(c1,'GT',1,1s) c1 from t1)") tdSql.query(f"select c1 from (select stateduration(c1,'GT',1,1s) c1 from {dbname}.t1)")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, -1) tdSql.checkData(1, 0, -1)
tdSql.checkData(2, 0, 0) tdSql.checkData(2, 0, 0)
tdSql.checkData(10, 0, 63072035) tdSql.checkData(10, 0, 63072035)
tdSql.query("select sum(c1) from (select stateduration(c1,'GT',1,1d) c1 from t1)") tdSql.query(f"select sum(c1) from (select stateduration(c1,'GT',1,1d) c1 from {dbname}.t1)")
tdSql.checkRows(1) tdSql.checkRows(1)
tdSql.checkData(0, 0, 2893) tdSql.checkData(0, 0, 2893)
tdSql.query("select sum(c1) from (select distinct(c1) c1 from ct1) union all select sum(c1) from (select stateduration(c1,'GT',1,1s) c1 from ct1)") tdSql.query(f"select sum(c1) from (select distinct(c1) c1 from {dbname}.ct1) union all select sum(c1) from (select stateduration(c1,'GT',1,1s) c1 from {dbname}.ct1)")
tdSql.checkRows(2) tdSql.checkRows(2)
tdSql.query("select 1-abs(c1) from (select stateduration(c1,'GT',1,1s) c1 from t1)") tdSql.query(f"select 1-abs(c1) from (select stateduration(c1,'GT',1,1s) c1 from {dbname}.t1)")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.checkData(0, 0, None) tdSql.checkData(0, 0, None)
tdSql.checkData(1, 0, 0.000000000) tdSql.checkData(1, 0, 0.000000000)
tdSql.checkData(3, 0, -86404.000000000) tdSql.checkData(3, 0, -86404.000000000)
tdSql.query("select stateduration(abs(c1) ,'GT',1,1s) from t1") tdSql.query(f"select stateduration(abs(c1) ,'GT',1,1s) from {dbname}.t1")
tdSql.checkRows(12) tdSql.checkRows(12)
tdSql.query("select stateduration(c1+2 ,'GT',1,1s) from t1") tdSql.query(f"select stateduration(c1+2 ,'GT',1,1s) from {dbname}.t1")
tdSql.checkRows(12) tdSql.checkRows(12)
# bug for stable # bug for stable
#partition by tbname #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.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) # tdSql.checkRows(21)
# group by # group by
tdSql.error("select stateduration(c1,'GT',1,1s) from ct1 group by c1") tdSql.error(f"select stateduration(c1,'GT',1,1s) from {dbname}.ct1 group by c1")
tdSql.error("select stateduration(c1,'GT',1,1s) from ct1 group by tbname") tdSql.error(f"select stateduration(c1,'GT',1,1s) from {dbname}.ct1 group by tbname")
# super table # super table
def check_unit_time(self): def check_unit_time(self, dbname=DBNAME):
tdSql.execute(" use db ") tdSql.error(f"select stateduration(c1,'GT',1,1b) from {dbname}.ct1")
tdSql.error("select stateduration(c1,'GT',1,1b) from ct1") tdSql.error(f"select stateduration(c1,'GT',1,1u) from {dbname}.ct1")
tdSql.error("select stateduration(c1,'GT',1,1u) from ct1") tdSql.error(f"select stateduration(c1,'GT',1,1000s) from {dbname}.t1")
tdSql.error("select stateduration(c1,'GT',1,1000s) from t1") tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.t1")
tdSql.query("select stateduration(c1,'GT',1,1s) from t1")
tdSql.checkData(10,0,63072035) 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.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.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.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)) tdSql.checkData(10,0,int(63072035/60/7/24/60))
def check_boundary_values(self): def check_boundary_values(self, dbname="bound_test"):
tdSql.execute("drop database if exists bound_test") tdSql.execute(f"drop database if exists {dbname}")
tdSql.execute("create database if not exists bound_test") tdSql.execute(f"create database if not exists {dbname}")
tdSql.execute("use bound_test") tdSql.execute(f"use {dbname}")
tdSql.execute( 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( 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( 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( 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( 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( 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( 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 stateduration(c1,'GT',1,1s) from sub1_bound") tdSql.query(f"select stateduration(c1,'GT',1,1s) from {dbname}.sub1_bound")
tdSql.checkRows(5) tdSql.checkRows(5)
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
......
...@@ -96,7 +96,16 @@ python3 ./test.py -f 2-query/distribute_agg_stddev.py ...@@ -96,7 +96,16 @@ python3 ./test.py -f 2-query/distribute_agg_stddev.py
python3 ./test.py -f 2-query/distribute_agg_stddev.py -R python3 ./test.py -f 2-query/distribute_agg_stddev.py -R
python3 ./test.py -f 2-query/distribute_agg_sum.py python3 ./test.py -f 2-query/distribute_agg_sum.py
python3 ./test.py -f 2-query/distribute_agg_sum.py -R python3 ./test.py -f 2-query/distribute_agg_sum.py -R
python3 ./test.py -f 2-query/explain.py
python3 ./test.py -f 2-query/explain.py -R
python3 ./test.py -f 2-query/first.py
python3 ./test.py -f 2-query/first.py -R
python3 ./test.py -f 2-query/floor.py
python3 ./test.py -f 2-query/floor.py -R
python3 ./test.py -f 2-query/function_null.py
python3 ./test.py -f 2-query/function_null.py -R
python3 ./test.py -f 2-query/function_stateduration.py
python3 ./test.py -f 2-query/function_stateduration.py -R
...@@ -118,7 +127,6 @@ python3 ./test.py -f 2-query/union1.py ...@@ -118,7 +127,6 @@ python3 ./test.py -f 2-query/union1.py
python3 ./test.py -f 2-query/concat2.py python3 ./test.py -f 2-query/concat2.py
python3 ./test.py -f 2-query/spread.py python3 ./test.py -f 2-query/spread.py
python3 ./test.py -f 2-query/hyperloglog.py python3 ./test.py -f 2-query/hyperloglog.py
python3 ./test.py -f 2-query/explain.py
python3 ./test.py -f 2-query/leastsquares.py python3 ./test.py -f 2-query/leastsquares.py
python3 ./test.py -f 2-query/histogram.py python3 ./test.py -f 2-query/histogram.py
...@@ -129,7 +137,6 @@ python3 ./test.py -f 2-query/Today.py ...@@ -129,7 +137,6 @@ python3 ./test.py -f 2-query/Today.py
python3 ./test.py -f 2-query/max.py python3 ./test.py -f 2-query/max.py
python3 ./test.py -f 2-query/min.py python3 ./test.py -f 2-query/min.py
python3 ./test.py -f 2-query/last.py python3 ./test.py -f 2-query/last.py
python3 ./test.py -f 2-query/first.py
python3 ./test.py -f 2-query/To_iso8601.py python3 ./test.py -f 2-query/To_iso8601.py
python3 ./test.py -f 2-query/To_unixtimestamp.py python3 ./test.py -f 2-query/To_unixtimestamp.py
python3 ./test.py -f 2-query/timetruncate.py python3 ./test.py -f 2-query/timetruncate.py
...@@ -138,7 +145,6 @@ python3 ./test.py -f 2-query/json_tag.py ...@@ -138,7 +145,6 @@ python3 ./test.py -f 2-query/json_tag.py
python3 ./test.py -f 2-query/top.py python3 ./test.py -f 2-query/top.py
python3 ./test.py -f 2-query/percentile.py python3 ./test.py -f 2-query/percentile.py
python3 ./test.py -f 2-query/floor.py
python3 ./test.py -f 2-query/round.py python3 ./test.py -f 2-query/round.py
python3 ./test.py -f 2-query/log.py python3 ./test.py -f 2-query/log.py
python3 ./test.py -f 2-query/pow.py python3 ./test.py -f 2-query/pow.py
...@@ -158,13 +164,11 @@ python3 ./test.py -f 2-query/sample.py ...@@ -158,13 +164,11 @@ python3 ./test.py -f 2-query/sample.py
python3 ./test.py -f 2-query/function_diff.py python3 ./test.py -f 2-query/function_diff.py
python3 ./test.py -f 2-query/unique.py python3 ./test.py -f 2-query/unique.py
python3 ./test.py -f 2-query/stateduration.py python3 ./test.py -f 2-query/stateduration.py
python3 ./test.py -f 2-query/function_stateduration.py
python3 ./test.py -f 2-query/statecount.py python3 ./test.py -f 2-query/statecount.py
python3 ./test.py -f 2-query/tail.py python3 ./test.py -f 2-query/tail.py
python3 ./test.py -f 2-query/ttl_comment.py python3 ./test.py -f 2-query/ttl_comment.py
python3 ./test.py -f 2-query/twa.py python3 ./test.py -f 2-query/twa.py
python3 ./test.py -f 2-query/irate.py python3 ./test.py -f 2-query/irate.py
python3 ./test.py -f 2-query/function_null.py
python3 ./test.py -f 2-query/queryQnode.py python3 ./test.py -f 2-query/queryQnode.py
python3 ./test.py -f 2-query/max_partition.py python3 ./test.py -f 2-query/max_partition.py
python3 ./test.py -f 2-query/last_row.py python3 ./test.py -f 2-query/last_row.py
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册