提交 99b9b787 编写于 作者: S shenglian zhou

Merge remote-tracking branch 'origin/develop' into hotfix/TD-12344

###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
import taos
import time
import os
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql
class TDTestCase:
def caseDescription(self):
'''
case1<xyguo>:The escape char "`" can be used for both tag name and column name
case2<xyguo>:create stable(column&tag); insert data; show stable; show create table; add stable(column&tag);change stable(tag);drop stable(column&tag);modify stable(column&tag)(binary and nchar);drop stable;
case3<xyguo>:create stable_child; insert data; show stable_child; show create stable_child; drop stable_child;
case4<xyguo>:create regular_table(column); insert data; show regular_table; show create regular_table; add regular_table(column);drop regular_table(column);modify regular_table(column)(binary and nchar);drop regular_table;
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
now = time.time()
self.ts = int(round(now * 1000))
def table1_checkall(self,sql):
tdLog.info(sql)
tdSql.query(sql)
tdSql.checkData(0,1,1)
tdSql.checkData(0,2,2)
tdSql.checkData(0,3,3)
tdSql.checkData(0,4,4)
tdSql.checkData(0,5,'True')
tdSql.checkData(0,6,6)
tdSql.checkData(0,7,7)
tdSql.checkData(0,8,8)
tdSql.checkData(0,9,9)
tdSql.checkData(0,10,'1970-01-01 08:00:00.010')
def table1_checkall_1(self,sql):
tdSql.query(sql)
tdSql.checkData(0,1,1)
def table1_checkall_2(self,sql):
self.table1_checkall_1(sql)
tdSql.checkData(0,2,2)
def table1_checkall_3(self,sql):
self.table1_checkall_2(sql)
tdSql.checkData(0,3,3)
def table1_checkall_4(self,sql):
self.table1_checkall_3(sql)
tdSql.checkData(0,4,4)
def table1_checkall_5(self,sql):
self.table1_checkall_4(sql)
tdSql.checkData(0,5,'True')
def table1_checkall_6(self,sql):
self.table1_checkall_5(sql)
tdSql.checkData(0,6,6)
def table1_checkall_7(self,sql):
self.table1_checkall_6(sql)
tdSql.checkData(0,7,7)
def table1_checkall_8(self,sql):
self.table1_checkall_7(sql)
tdSql.checkData(0,8,8)
def table1_checkall_9(self,sql):
self.table1_checkall_8(sql)
tdSql.checkData(0,9,9)
def table1_checkall_10(self,sql):
self.table1_checkall_9(sql)
tdSql.checkData(0,10,'1970-01-01 08:00:00.010')
def run(self):
testcaseFilename = os.path.split(__file__)[-1]
os.system("rm -rf 0-management/1-stable/%s.sql" % testcaseFilename )
tdSql.prepare()
print("==============step1")
print("prepare data")
# case for defect: https://jira.taosdata.com:18080/browse/TD-2693
tdSql.execute("create database db2")
tdSql.execute("use db2")
print("==============new version [escape character] for stable==============")
print("==============step1,#create db.stable,db.table; insert db.table; show db.table; select db.table; drop db.table;")
print("prepare data")
self.stb1 = "stable_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
self.tb1 = "table_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
self.col_base = "123~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
self.col_int = "stable_col_int%s" %self.col_base
print(self.col_int)
self.col_bigint = "stable_col_bigint%s" %self.col_base
self.col_smallint = "stable_col_smallint%s" %self.col_base
self.col_tinyint = "stable_col_tinyint%s" %self.col_base
self.col_bool = "stable_col_bool%s" %self.col_base
self.col_binary = "stable_col_binary%s" %self.col_base
self.col_nchar = "stable_col_nchar%s" %self.col_base
self.col_float = "stable_col_float%s" %self.col_base
self.col_double = "stable_col_double%s" %self.col_base
self.col_ts = "stable_col_ts%s" %self.col_base
self.tag_base = "abc~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
self.tag_int = "stable_tag_int%s" %self.tag_base
self.tag_bigint = "stable_tag_bigint%s" %self.tag_base
self.tag_smallint = "stable_tag_smallint%s" %self.tag_base
self.tag_tinyint = "stable_tag_tinyint%s" %self.tag_base
self.tag_bool = "stable_tag_bool%s" %self.tag_base
self.tag_binary = "stable_tag_binary%s" %self.tag_base
self.tag_nchar = "stable_tag_nchar%s" %self.tag_base
self.tag_float = "stable_tag_float%s" %self.tag_base
self.tag_double = "stable_tag_double%s" %self.tag_base
self.tag_ts = "stable_tag_ts%s" %self.tag_base
tdSql.execute('''create stable db.`%s` (ts timestamp, `%s` int , `%s` bigint , `%s` smallint , `%s` tinyint, `%s` bool ,
`%s` binary(20) , `%s` nchar(20) ,`%s` float , `%s` double , `%s` timestamp)
tags(loc nchar(20), `%s` int , `%s` bigint , `%s` smallint , `%s` tinyint, `%s` bool ,
`%s` binary(20) , `%s` nchar(20) ,`%s` float , `%s` double , `%s` timestamp);'''
%(self.stb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool,
self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,
self.tag_int, self.tag_bigint, self.tag_smallint, self.tag_tinyint, self.tag_bool,
self.tag_binary, self.tag_nchar, self.tag_float, self.tag_double, self.tag_ts))
tdSql.query("describe db.`%s` ; " %self.stb1)
tdSql.checkRows(22)
tdSql.query("select _block_dist() from db.`%s` ; " %self.stb1)
tdSql.checkRows(0)
tdSql.query("show create stable db.`%s` ; " %self.stb1)
tdSql.checkData(0, 0, self.stb1)
tdSql.checkData(0, 1, "create table `%s` (`ts` TIMESTAMP,`%s` INT,`%s` BIGINT,`%s` SMALLINT,`%s` TINYINT,`%s` BOOL,`%s` BINARY(20),`%s` NCHAR(20),`%s` FLOAT,`%s` DOUBLE,`%s` TIMESTAMP)\
TAGS (`loc` NCHAR(20),`%s` INT,`%s` BIGINT,`%s` SMALLINT,`%s` TINYINT,`%s` BOOL,`%s` BINARY(20),`%s` NCHAR(20),`%s` FLOAT,`%s` DOUBLE,`%s` TIMESTAMP)"
%(self.stb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool,
self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,
self.tag_int, self.tag_bigint, self.tag_smallint, self.tag_tinyint, self.tag_bool,
self.tag_binary, self.tag_nchar, self.tag_float, self.tag_double, self.tag_ts))
tdSql.execute("create table db.`table!1` using db.`%s` tags('table_1' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0')" %self.stb1)
tdSql.query("describe db.`table!1` ; ")
tdSql.checkRows(22)
time.sleep(10)
tdSql.query("show create table db.`table!1` ; ")
tdSql.checkData(0, 0, "table!1")
tdSql.checkData(0, 1, "CREATE TABLE `table!1` USING `%s` TAGS (\"table_1\",0,0,0,0,false,\"0\",\"0\",0.000000,0.000000,\"0\")" %self.stb1)
tdSql.execute("insert into db.`table!1` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)")
sql = " select * from db.`table!1`; "
datacheck = self.table1_checkall(sql)
tdSql.checkRows(1)
sql = '''select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`table!1`; '''\
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(1)
time.sleep(1)
tdSql.execute('''insert into db.`table!1`(ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`) values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)'''\
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) )
sql = " select * from db.`table!1`; "
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
tdSql.query("select count(*) from db.`table!1`; ")
tdSql.checkData(0, 0, 2)
tdSql.query("select _block_dist() from db.`%s` ; " %self.stb1)
tdSql.checkRows(1)
tdSql.execute("create table db.`%s` using db.`%s` TAGS (\"table_2\",2,2,2,2,true,\"2\",\"2\",2.000000,2.000000,\"2\")" %(self.tb1,self.stb1))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.query("show create table db.`%s` ; " %self.tb1)
tdSql.checkData(0, 0, self.tb1)
tdSql.checkData(0, 1, "CREATE TABLE `%s` USING `%s` TAGS (\"table_2\",2,2,2,2,true,\"2\",\"2\",2.000000,2.000000,\"2\")" %(self.tb1,self.stb1))
tdSql.execute("insert into db.`%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.tb1)
sql = "select * from db.`%s` ; " %self.tb1
datacheck = self.table1_checkall(sql)
tdSql.checkRows(1)
sql = '''select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s` ; '''\
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\
self.tag_int, self.tag_bigint, self.tag_smallint, self.tag_tinyint, self.tag_bool, self.tag_binary, self.tag_nchar, self.tag_float, self.tag_double, self.tag_ts, self.tb1)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(1)
time.sleep(1)
tdSql.execute('''insert into db.`%s`(ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`) values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)'''\
%(self.tb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) )
sql = " select * from db.`%s` ; " %self.tb1
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
sql = " select * from db.`%s` where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10; " \
%(self.tb1, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
tdSql.query("select count(*) from db.`%s`; " %self.tb1)
tdSql.checkData(0, 0, 2)
sql = "select * from db.`%s` ; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.checkRows(4)
tdSql.query("select count(*) from db.`%s`; " %self.stb1)
tdSql.checkData(0, 0, 4)
sql = "select * from (select * from db.`%s`) ; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.checkRows(4)
tdSql.query("select count(*) from (select * from db.`%s`) ; " %self.stb1)
tdSql.checkData(0, 0, 4)
sql = "select * from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s`) ; " \
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.stb1)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(4)
sql = "select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s`) ; " \
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\
self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.stb1)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(4)
sql = "select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db.`%s`\
where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10 ) ; " \
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\
self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.stb1, \
self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(4)
tdSql.query("show db.stables like 'stable_1%' ")
tdSql.checkRows(1)
tdSql.query("show db.tables like 'table%' ")
tdSql.checkRows(2)
self.cr_tb1 = "create_table_1~!@#$%^&*()-_+=[]{}':,<.>/?stST13579"
tdSql.execute("create table db.`%s` as select avg(`%s`) from db.`%s` where ts > now interval(1m) sliding(30s);" %(self.cr_tb1,self.col_bigint,self.stb1))
tdSql.query("show db.tables like 'create_table_%' ")
tdSql.checkRows(1)
print("==============drop\ add\ change\ modify column or tag")
print("==============drop==============")
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_ts))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(21)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_double))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(20)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_float))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(19)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_nchar))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(18)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_binary))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(17)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_bool))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(16)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_tinyint))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(15)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_smallint))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(14)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_bigint))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(13)
tdSql.execute("ALTER TABLE db.`%s` DROP TAG `%s`; " %(self.stb1, self.tag_int))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(12)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_ts))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_9(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(11)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_double))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_8(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(10)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_float))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_7(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(9)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_nchar))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_6(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(8)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_binary))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_5(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(7)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_bool))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_4(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(6)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_tinyint))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_3(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(5)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_smallint))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_2(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(4)
tdSql.execute("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_bigint))
sql = " select * from db.`%s`; " %self.stb1
datacheck = self.table1_checkall_1(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(3)
tdSql.error("ALTER TABLE db.`%s` DROP COLUMN `%s`; " %(self.stb1, self.col_int))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(3)
print("==============add==============")
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` bigint; " %(self.stb1, self.col_bigint))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(4)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` smallint; " %(self.stb1, self.col_smallint))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(5)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` tinyint; " %(self.stb1, self.col_tinyint))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(6)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` bool; " %(self.stb1, self.col_bool))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(7)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` binary(20); " %(self.stb1, self.col_binary))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(8)
tdSql.execute("insert into db.`%s` values(now, 1 , 2, 3, 4, 5, 6)" %self.tb1)
sql = "select * from db.`%s` order by ts desc; " %self.tb1
datacheck = self.table1_checkall_5(sql)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` nchar(20); " %(self.stb1, self.col_nchar))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(9)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` float; " %(self.stb1, self.col_float))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(10)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` double; " %(self.stb1, self.col_double))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(11)
tdSql.execute("ALTER TABLE db.`%s` ADD COLUMN `%s` timestamp; " %(self.stb1, self.col_ts))
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(12)
tdSql.execute("insert into db.`%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.tb1)
sql = "select * from db.`%s` order by ts desc; " %self.tb1
datacheck = self.table1_checkall(sql)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` int; " %(self.stb1, self.tag_int))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(13)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` bigint; " %(self.stb1, self.tag_bigint))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(14)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` smallint; " %(self.stb1, self.tag_smallint))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(15)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` tinyint; " %(self.stb1, self.tag_tinyint))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(16)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` bool; " %(self.stb1, self.tag_bool))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(17)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` binary(20); " %(self.stb1, self.tag_binary))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(18)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` nchar(20); " %(self.stb1, self.tag_nchar))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(19)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` float; " %(self.stb1, self.tag_float))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(20)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` double; " %(self.stb1, self.tag_double))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(21)
tdSql.execute("ALTER TABLE db.`%s` ADD TAG `%s` timestamp; " %(self.stb1, self.tag_ts))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
print("==============change==============")
self.tag_base_change = "abcdas"
self.tag_int_change = "stable_tag_int%s" %self.tag_base_change
self.tag_bigint_change = "stable_tag_bigint%s" %self.tag_base_change
self.tag_smallint_change = "stable_tag_smallint%s" %self.tag_base_change
self.tag_tinyint_change = "stable_tag_tinyint%s" %self.tag_base_change
self.tag_bool_change = "stable_tag_bool%s" %self.tag_base_change
self.tag_binary_change = "stable_tag_binary%s" %self.tag_base_change
self.tag_nchar_change = "stable_tag_nchar%s" %self.tag_base_change
self.tag_float_change = "stable_tag_float%s" %self.tag_base_change
self.tag_double_change = "stable_tag_double%s" %self.tag_base_change
self.tag_ts_change = "stable_tag_ts%s" %self.tag_base_change
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_int, self.tag_int_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_bigint, self.tag_bigint_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_smallint, self.tag_smallint_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_tinyint, self.tag_tinyint_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_bool, self.tag_bool_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_binary, self.tag_binary_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_nchar, self.tag_nchar_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_float, self.tag_float_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_double, self.tag_double_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER TABLE db.`%s` CHANGE TAG `%s` `%s`; " %(self.stb1, self.tag_ts, self.tag_ts_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
print("==============modify==============")
# TD-10810
tdSql.execute("ALTER STABLE db.`%s` MODIFY TAG `%s` binary(30); ; " %(self.stb1, self.tag_binary_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER STABLE db.`%s` MODIFY TAG `%s` nchar(30); ; " %(self.stb1, self.tag_nchar_change))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER STABLE db.`%s` MODIFY COLUMN `%s` binary(30); ; " %(self.stb1, self.col_binary))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
tdSql.execute("ALTER STABLE db.`%s` MODIFY COLUMN `%s` nchar(30); ; " %(self.stb1, self.col_nchar))
sql = " select * from db.`%s` order by ts desc; " %self.stb1
datacheck = self.table1_checkall(sql)
tdSql.query("describe db.`%s` ; " %self.tb1)
tdSql.checkRows(22)
print("==============drop table\stable")
try:
tdSql.execute("drop table db.`%s` " %self.tb1)
except Exception as e:
tdLog.exit(e)
tdSql.error("select * from db.`%s`" %self.tb1)
tdSql.query("show db.stables like 'stable_1%' ")
tdSql.checkRows(1)
try:
tdSql.execute("drop table db.`%s` " %self.stb1)
except Exception as e:
tdLog.exit(e)
tdSql.error("select * from db.`%s`" %self.tb1)
tdSql.error("select * from db.`%s`" %self.stb1)
print("==============step2,#create stable,table; insert table; show table; select table; drop table")
self.stb2 = "stable_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
self.tb2 = "table_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
tdSql.execute("create stable `%s` (ts timestamp, i int) tags(j int);" %self.stb2)
tdSql.query("describe `%s` ; "%self.stb2)
tdSql.checkRows(3)
tdSql.query("select _block_dist() from `%s` ; " %self.stb2)
tdSql.checkRows(0)
tdSql.query("show create stable `%s` ; " %self.stb2)
tdSql.checkData(0, 0, self.stb2)
tdSql.checkData(0, 1, "create table `%s` (`ts` TIMESTAMP,`i` INT) TAGS (`j` INT)" %self.stb2)
tdSql.execute("create table `table!2` using `%s` tags(1)" %self.stb2)
tdSql.query("describe `table!2` ; ")
tdSql.checkRows(3)
time.sleep(10)
tdSql.query("show create table `table!2` ; ")
tdSql.checkData(0, 0, "table!2")
tdSql.checkData(0, 1, "CREATE TABLE `table!2` USING `%s` TAGS (1)" %self.stb2)
tdSql.execute("insert into `table!2` values(now, 1)")
tdSql.query("select * from `table!2`; ")
tdSql.checkRows(1)
tdSql.query("select count(*) from `table!2`; ")
tdSql.checkData(0, 0, 1)
tdSql.query("select _block_dist() from `%s` ; " %self.stb2)
tdSql.checkRows(1)
tdSql.execute("create table `%s` using `%s` tags(1)" %(self.tb2,self.stb2))
tdSql.query("describe `%s` ; " %self.tb2)
tdSql.checkRows(3)
tdSql.query("show create table `%s` ; " %self.tb2)
tdSql.checkData(0, 0, self.tb2)
tdSql.checkData(0, 1, "CREATE TABLE `%s` USING `%s` TAGS (1)" %(self.tb2,self.stb2))
tdSql.execute("insert into `%s` values(now, 1)" %self.tb2)
tdSql.query("select * from `%s` ; " %self.tb2)
tdSql.checkRows(1)
tdSql.query("select count(*) from `%s`; " %self.tb2)
tdSql.checkData(0, 0, 1)
tdSql.query("select * from `%s` ; " %self.stb2)
tdSql.checkRows(2)
tdSql.query("select count(*) from `%s`; " %self.stb2)
tdSql.checkData(0, 0, 2)
tdSql.query("select * from (select * from `%s`) ; " %self.stb2)
tdSql.checkRows(2)
tdSql.query("select count(*) from (select * from `%s` ); " %self.stb2)
tdSql.checkData(0, 0, 2)
tdSql.query("show stables like 'stable_2%' ")
tdSql.checkRows(1)
tdSql.query("show tables like 'table%' ")
tdSql.checkRows(2)
#TD-10536
self.cr_tb2 = "create_table_2~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
tdSql.execute("create table `%s` as select * from `%s` ;" %(self.cr_tb2,self.stb2))
tdSql.query("show db.tables like 'create_table_%' ")
tdSql.checkRows(1)
print("==============drop table\stable")
try:
tdSql.execute("drop table `%s` " %self.tb2)
except Exception as e:
tdLog.exit(e)
tdSql.error("select * from `%s`" %self.tb2)
tdSql.query("show stables like 'stable_2%' ")
tdSql.checkRows(1)
try:
tdSql.execute("drop table `%s` " %self.stb2)
except Exception as e:
tdLog.exit(e)
tdSql.error("select * from `%s`" %self.tb2)
tdSql.error("select * from `%s`" %self.stb2)
print("==============step3,#create regular_table; insert regular_table; show regular_table; select regular_table; drop regular_table")
self.regular_table = "regular_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
self.regular_col_base = "123@#$%^&*()-_+=[]{};:,<.>/?~!$%^"
self.col_int = "regular_table_col_int%s" %self.regular_col_base
print(self.col_int)
self.col_bigint = "regular_table_col_bigint%s" %self.regular_col_base
self.col_smallint = "regular_table_col_smallint%s" %self.regular_col_base
self.col_tinyint = "regular_table_col_tinyint%s" %self.regular_col_base
self.col_bool = "regular_table_col_bool%s" %self.regular_col_base
self.col_binary = "regular_table_col_binary%s" %self.regular_col_base
self.col_nchar = "regular_table_col_nchar%s" %self.regular_col_base
self.col_float = "regular_table_col_float%s" %self.regular_col_base
self.col_double = "regular_table_col_double%s" %self.regular_col_base
self.col_ts = "regular_table_col_ts%s" %self.regular_col_base
tdSql.execute("create table `%s` (ts timestamp,`%s` int , `%s` bigint , `%s` smallint , `%s` tinyint, `%s` bool , \
`%s` binary(20) , `%s` nchar(20) ,`%s` float , `%s` double , `%s` timestamp) ;"\
%(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool,
self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts))
tdSql.query("describe `%s` ; "%self.regular_table)
tdSql.checkRows(11)
tdSql.query("select _block_dist() from `%s` ; " %self.regular_table)
tdSql.checkRows(1)
tdSql.query("show create table `%s` ; " %self.regular_table)
tdSql.checkData(0, 0, self.regular_table)
tdSql.checkData(0, 1, "create table `%s` (`ts` TIMESTAMP,`%s` INT,`%s` BIGINT,`%s` SMALLINT,`%s` TINYINT,`%s` BOOL,`%s` BINARY(20),`%s` NCHAR(20),`%s` FLOAT,`%s` DOUBLE,`%s` TIMESTAMP)"
%(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool,
self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts))
tdSql.execute("insert into `%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.regular_table)
sql = "select * from `%s` ; " %self.regular_table
datacheck = self.table1_checkall(sql)
tdSql.checkRows(1)
sql = '''select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db2.`%s`; '''\
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.regular_table)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(1)
time.sleep(1)
tdSql.execute('''insert into db2.`%s` (ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`) values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)'''\
%(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts) )
sql = " select * from db2.`%s`; " %self.regular_table
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
sql = " select * from db2.`%s` where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10; " \
%(self.regular_table, self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
tdSql.query("select count(*) from `%s`; " %self.regular_table)
tdSql.checkData(0, 0, 2)
tdSql.query("select _block_dist() from `%s` ; " %self.regular_table)
tdSql.checkRows(1)
sql = "select * from (select * from `%s`) ; " %self.regular_table
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
sql = "select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from (select ts ,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s`,`%s` from db2.`%s`\
where `%s`=1 and `%s`=2 and `%s`=3 and `%s`=4 and `%s`='True' and `%s`=6 and `%s`=7 and `%s`=8 and `%s`=9 and `%s`=10 ) ; " \
%(self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts,\
self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts, self.regular_table, \
self.col_int, self.col_bigint, self.col_smallint, self.col_tinyint, self.col_bool, self.col_binary, self.col_nchar, self.col_float, self.col_double, self.col_ts)
datacheck = self.table1_checkall(sql)
tdSql.checkRows(2)
tdSql.query("select count(*) from (select * from `%s` ); " %self.regular_table)
tdSql.checkData(0, 0, 2)
tdSql.query("show tables like 'regular_table%' ")
tdSql.checkRows(1)
self.crr_tb = "create_r_table~!@#$%^&*()-_+=[]{}';:,<.>/?stST24680~!@#$%^&*()-_+=[]{}"
tdSql.execute("create table `%s` as select * from `%s` ;" %(self.crr_tb,self.regular_table))
tdSql.query("show db2.tables like 'create_r_table%' ")
tdSql.checkRows(1)
print("==============drop\ add\ change\ modify column ")
print("==============drop==============")
tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_ts))
sql = " select * from db2.`%s`; " %self.regular_table
datacheck = self.table1_checkall_9(sql)
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(10)
tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_double))
sql = " select * from `%s`; " %self.regular_table
datacheck = self.table1_checkall_8(sql)
tdSql.query("describe `%s` ; " %self.regular_table)
tdSql.checkRows(9)
tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_float))
sql = " select * from db2.`%s`; " %self.regular_table
datacheck = self.table1_checkall_7(sql)
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(8)
tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_nchar))
sql = " select * from `%s`; " %self.regular_table
datacheck = self.table1_checkall_6(sql)
tdSql.query("describe `%s` ; " %self.regular_table)
tdSql.checkRows(7)
tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_binary))
sql = " select * from db2.`%s`; " %self.regular_table
datacheck = self.table1_checkall_5(sql)
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(6)
tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_bool))
sql = " select * from `%s`; " %self.regular_table
datacheck = self.table1_checkall_4(sql)
tdSql.query("describe `%s` ; " %self.regular_table)
tdSql.checkRows(5)
tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_tinyint))
sql = " select * from db2.`%s`; " %self.regular_table
datacheck = self.table1_checkall_3(sql)
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(4)
tdSql.execute("ALTER TABLE `%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_smallint))
sql = " select * from `%s`; " %self.regular_table
datacheck = self.table1_checkall_2(sql)
tdSql.query("describe `%s` ; " %self.regular_table)
tdSql.checkRows(3)
tdSql.execute("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_bigint))
sql = " select * from db2.`%s`; " %self.regular_table
datacheck = self.table1_checkall_1(sql)
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(2)
tdSql.error("ALTER TABLE db2.`%s` DROP COLUMN `%s`; " %(self.regular_table, self.col_int))
tdSql.query("describe `%s` ; " %self.regular_table)
tdSql.checkRows(2)
print("==============add==============")
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` bigint; " %(self.regular_table, self.col_bigint))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(3)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` smallint; " %(self.regular_table, self.col_smallint))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(4)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` tinyint; " %(self.regular_table, self.col_tinyint))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(5)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` bool; " %(self.regular_table, self.col_bool))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(6)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` binary(20); " %(self.regular_table, self.col_binary))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(7)
tdSql.execute("insert into db2.`%s` values(now, 1 , 2, 3, 4, 5, 6)" %self.regular_table)
sql = "select * from db2.`%s` order by ts desc; " %self.regular_table
datacheck = self.table1_checkall_5(sql)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` nchar(20); " %(self.regular_table, self.col_nchar))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(8)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` float; " %(self.regular_table, self.col_float))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(9)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` double; " %(self.regular_table, self.col_double))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(10)
tdSql.execute("ALTER TABLE db2.`%s` ADD COLUMN `%s` timestamp; " %(self.regular_table, self.col_ts))
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(11)
tdSql.execute("insert into db2.`%s` values(now, 1 , 2, 3, 4, 5, 6 ,7 ,8 ,9 ,10)" %self.regular_table)
sql = "select * from db2.`%s` order by ts desc; " %self.regular_table
datacheck = self.table1_checkall(sql)
print("==============change, regular not support==============")
print("==============modify==============")
# TD-10810
tdSql.execute("ALTER TABLE db2.`%s` MODIFY COLUMN `%s` binary(30); ; " %(self.regular_table, self.col_binary))
sql = " select * from db2.`%s` order by ts desc; " %self.regular_table
datacheck = self.table1_checkall(sql)
tdSql.query("describe db2.`%s` ; " %self.regular_table)
tdSql.checkRows(11)
tdSql.execute("ALTER TABLE `%s` MODIFY COLUMN `%s` nchar(30); ; " %(self.regular_table, self.col_nchar))
sql = " select * from `%s` order by ts desc; " %self.regular_table
datacheck = self.table1_checkall(sql)
tdSql.query("describe `%s` ; " %self.regular_table)
tdSql.checkRows(11)
print("==============drop table\stable")
try:
tdSql.execute("drop table `%s` " %self.regular_table)
except Exception as e:
tdLog.exit(e)
tdSql.error("select * from `%s`" %self.regular_table)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2020 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
from posixpath import split
import sys
import os
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record
self.num = 10
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def caseDescription(self):
'''
case1 <wenzhouwww>: [TD-11389] :
this test case is an test case for cache error , it will let the cached data obtained by the client that has connected to taosd incorrect,
root cause : table schema is changed, tag hostname size is increased through schema-less insertion. The schema cache of client taos is not refreshed.
'''
return
def run(self):
tdSql.prepare()
tdSql.execute("create database if not exists testdb keep 36500;")
tdSql.execute("use testdb;")
tdSql.execute("create stable st (ts timestamp , id int , value double) tags(hostname binary(10) ,ind int);")
for i in range(self.num):
tdSql.execute("insert into sub_%s using st tags('host_%s' , %d) values (%d , %d , %f );"%(str(i),str(i),i*10,self.ts+10000*i,i*2,i+10.00))
tdSql.query("select distinct(hostname) from st;")
tdSql.checkRows(10)
binPath = self.getBuildPath() + "/build/bin/"
os.system( "taos -s ' ALTER STABLE testdb.st MODIFY TAG hostname binary(100); '" )
os.system("taos -s ' insert into testdb.sub_test using testdb.st tags(\"host_10000000000000000000\" , 100) values (now , 100 , 100.0 ); '")
tdLog.info (" ===============The correct result should be 11 rows ,there is error query result ====================")
os.system("taos -s ' select distinct(hostname) from testdb.st '")
# this bug will occor at this connect ,it should get 11 rows ,but return 10 rows ,this error is caused by cache
for i in range(10):
tdSql.checkRows(11) # query 10 times every 10 second , test cache refresh
sleep(10)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confspeedential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provspeeded by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
from util.log import *
from util.cases import *
from util.sql import *
class TDTestCase:
def caseDescription(self):
'''
case1:<wenzhouwww>: [TD-11945] this test case is an issue about taoshell and taosd crash , it now has been repaired on branch https://github.com/taosdata/TDengine/tree/feature%2FTD-6140
the root source maybe :
The four arithmetic operations do not perform the verification of the numeric type,so that the numeric type and string type will coredump about Four arithmetic operations
'''
return
def init(self, conn, logSql):
tdLog.debug("start test case for TD-11945 execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record
self.num = 10
def run(self):
tdSql.prepare()
tdSql.execute('create database if not exists testdb')
tdSql.execute('create table tb (ts timestamp, speed int)')
tdSql.execute('create stable st (ts timestamp, speed int) tags(ind int)')
for i in range(self.num):
tdSql.execute('insert into tb values(%d,%d) '%(self.ts+i*10000,i))
tdSql.execute('insert into sub1 using st tags(1) values(%d,%d) '%(self.ts+i*10000,i))
tdSql.execute('insert into sub2 using st tags(2) values(%d,%d) '%(self.ts+i*10000,i))
tdLog.info(" ==================execute query =============")
tdSql.error('select 1*tbname, min(speed) , ind from st;')
tdSql.execute('select tbname, min(speed) , ind from st group by ind;')
tdSql.error('select tbname , tbname,ind ,ind, * ,speed+"ab" from st;')
tdSql.error('select tbname , ind ,speed+"abc" from st;')
tdSql.error('select speed+"abc" from st;')
tdSql.error('select speed+"abc" from sub1;')
tdSql.error('select speed+"abc" from sub2;')
tdSql.error('select max(speed) + "abc" from st;')
tdSql.error('select max(speed) + "abc" from sub1;')
tdSql.error('select max(speed) + "abc" from sub2;')
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2020 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import taos
import time
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
class TDTestCase:
def __init__(self):
self.err_case = 0
self.curret_case = 0
def caseDescription(self):
'''
case1 <cpwu>: [TD-12340] : group by ts should resturn two column ;\n
case2 <cpwu>: [TD-12342] : "group by ts order by first-tag" should return error
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
def create_stb(self):
basetime = int(round(time.time() * 1000))
tdSql.prepare()
tdSql.execute(f"create stable stb1(ts timestamp, c1 int) tags (tag1 int)")
for i in range(10):
tdSql.execute(f"create table t{i} using stb1 tags({i})")
tdSql.execute(f"insert into t{i} values ({basetime}, {i})")
pass
def check_td12342(self):
# this case expect return err when using "group by ts order by first-tag"
try:
tdSql.error("select count(*) from stb1 group by ts order by tag1")
self.curret_case += 1
tdLog.printNoPrefix("the case2: td-12342 run passed")
except:
self.err_case += 1
tdLog.printNoPrefix("the case2: td-12342 run failed")
pass
def run(self):
self.create_stb()
self.check_td12342()
if self.err_case > 0:
tdLog.exit(f"{self.err_case} is failed")
else:
tdLog.success("2 case is all passed")
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2020 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
from posixpath import split
import sys
import os
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record
self.num = 10
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root) - len("/build/bin")]
break
return buildPath
def caseDescription(self):
'''
case1 <wenzhouwww>: [TD-11389] :
this test case is an test case for cache error , it will let the cached data obtained by the client that has connected to taosd incorrect,
root cause : table schema is changed, tag hostname size is increased through schema-less insertion. The schema cache of client taos is not refreshed.
'''
return
def getBuildPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
for root, dirs, files in os.walk(projPath):
if ("taosd" in files):
rootRealPath = os.path.dirname(os.path.realpath(root))
if ("packaging" not in rootRealPath):
buildPath = root[:len(root)-len("/build/bin")]
break
return buildPath
def getcfgPath(self):
selfPath = os.path.dirname(os.path.realpath(__file__))
print(selfPath)
if ("community" in selfPath):
projPath = selfPath[:selfPath.find("community")]
else:
projPath = selfPath[:selfPath.find("tests")]
cfgPath = projPath + "/sim/dnode1/cfg "
return cfgPath
def run(self):
tdSql.prepare()
tdSql.execute("create database if not exists testdb keep 36500;")
tdSql.execute("use testdb;")
tdSql.execute("create stable st (ts timestamp , id int , value double) tags(hostname binary(10) ,ind int);")
for i in range(self.num):
tdSql.execute("insert into sub_%s using st tags('host_%s' , %d) values (%d , %d , %f );"%(str(i),str(i),i*10,self.ts+10000*i,i*2,i+10.00))
tdSql.query('select elapsed(ts,10s) from sub_1 where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1d) ;')
cfg_path = self.getcfgPath()
print(cfg_path)
# tdSql.execute('select elapsed(ts,10s) from st where ts>="2015-01-01 00:00:00.000" and ts < "2015-01-01 00:10:00.000" session(ts,1d) group by tbname;') # session not support super table
os.system("taos -c %s -s 'select elapsed(ts,10s) from testdb.st where ts>=\"2015-01-01 00:00:00.000\" and ts < \"2015-01-01 00:10:00.000\" session(ts,1d) group by tbname;' " % (cfg_path))
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
{"base_url": "127.0.0.1", "precision": "ms", "clear_data": true, "database_name": "db", "tbnum": 10, "data_row": 100, "case_file": "data_insert.csv", "basetime": 1639969683873, "all_case": false, "all_err": false, "all_current": true, "err_case": {"port_err": true, "api_err": true, "header_err": true, "db_tb_err": true, "data_err": true}, "current_case": {"port_current": true, "api_current": true, "header_current": true, "db_tb_current": true, "data_current": true}}
\ No newline at end of file
{"base_url": "127.0.0.1", "precision": "ms", "clear_data": true, "database_name": "db", "tbnum": 10, "data_row": 100, "basetime": 1639969706198, "all_case": false, "all_err": false, "all_current": true, "err_case": {"port_err": true, "api_err": true, "header_err": true, "sql_err": true}, "current_case": {"port_current": true, "api_current": true, "header_current": true, "sql_current": true}}
\ No newline at end of file
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
import random
import inspect
import taos
import requests
import json
import traceback
import simplejson.errors
import csv
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
class RestMsgInfo:
def __init__(self, base_url,
port=6041,
api_url="/rest/sql",
header={'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='}
):
self.base_url = base_url
self.port = port
self.api_url = api_url
self.header = header
self.full_url = f"http://{base_url}:{port}{api_url}"
class TDTestCase:
def __init__(self):
self.base_url = "127.0.0.1"
self.dbname = "db"
self.precision = "ms"
self.tbnum = 0
self.data_row = 0
self.basetime = 0
self.file = ""
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def caseDescription(self):
'''
case1 <cpwu>: create/alter/drop database/normal_table/child_table/stable \n
case2 <cpwu>: insert into table multiple records \n
case3 <cpwu>: insert multiple records into a given column \n
case4 <cpwu>: insert multiple records into multiple tables \n
case5 <cpwu>: automatically create a table when inserting, and specify a given tags column \n
case6 <cpwu>: insert with files \n
case7 <cpwu>: api_url test \n
case8 <cpwu>: base_url test \n
case9 <cpwu>: header test
'''
return
def rest_test_table(self, dbname: str, tbnum: int) -> None :
tdSql.execute(f"drop database if exists {dbname}")
tdSql.execute(f"create database if not exists {dbname} keep 3650 precision '{self.precision}' ")
tdSql.execute(f"use {dbname}")
tdSql.execute(
f'''
create stable {dbname}.stb1 (
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
)
tags(
tag1 int, tag2 float, tag3 timestamp, tag4 binary(16), tag5 double, tag6 bool,
tag7 bigint, tag8 smallint, tag9 tinyint, tag10 nchar(16)
)
'''
)
tdSql.execute(
f"create stable {dbname}.stb2 (ts timestamp, c1 int) tags(ttag1 int)"
)
for i in range(tbnum):
tdSql.execute(
f'''
create table {dbname}.t{i} using {dbname}.stb1
tags(
{i}, {i}, {1639032680000+i*10}, 'binary_{i}',{i},{random.choice([0, 1])}, {i},{i%32767},{i%127},'nchar_{i}'
)'''
)
tdSql.execute(f"create table {dbname}.tt{i} using {dbname}.stb2 tags({i})")
tdSql.execute(
f"create table {dbname}.nt1 (ts timestamp, c1 int, c2 float)"
)
tdSql.execute(
f"create table {dbname}.nt2 (ts timestamp, c1 int, c2 float)"
)
pass
def rest_test_data(self, tbnum:int, data_row:int, basetime:int) -> None :
for i in range(tbnum):
for j in range(data_row):
tdSql.execute(
f"insert into t{i} values ("
f"{basetime + (j+1)*10}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)}, "
f"'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, "
f"{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' )"
)
tdSql.execute(
f"insert into tt{i} values ( {basetime-(j+1) * 10}, {random.randint(1, 200)} )"
)
def check_err_case(self,query_msg: RestMsgInfo, data):
url, header = query_msg.full_url, query_msg.header
try:
conn = requests.post(url=url, data=data, headers=header)
resp_code = conn.status_code
resp = conn.json()
if resp_code != 200:
tdLog.success(f"expect error occured, usrl: {url}, sql: {data}, error code is :{resp_code}")
return
status = resp["status"]
desc = resp["desc"]
if resp_code == 200 and status == "error":
tdLog.success(f"expect error occured, usrl: {url}, sql: {data}, error is :{desc}")
return
else:
tdLog.exit(f"expect error not occured")
except requests.exceptions.InvalidHeader as e:
print(f"expect error occured, request header error, header: {header}, error: {e}")
except requests.exceptions.InvalidURL as e:
print(f"expect error occured, request url error, url: {url}, error: {e}")
except requests.exceptions.ConnectionError as e:
print(f"expect error occured, request connection error,url: {url}, error: {e}")
except simplejson.errors.JSONDecodeError as e:
print(f"expect error occured, request json error,url: {url}, header: {header}, error: {e}")
except Exception as e:
print(f"expect error occured, url: {url}, header: {header}, {traceback.print_exc()}")
# finally:
# conn.close()
pass
def check_err_sql_case(self,query_msg: RestMsgInfo, data):
url, header = query_msg.full_url, query_msg.header
conn = requests.post(url=url, data=data, headers=header)
resp_code = conn.status_code
resp = conn.json()
try:
status = resp["status"]
desc = resp["desc"]
if resp_code == 200 and status == "error":
tdLog.success(f"expect error occured, url: {url}, error is :{desc}")
return
else:
tdLog.exit(f"expect error not occured")
except Exception as e:
tdLog.debug(f"url: {url}, resp: {resp} ")
traceback.print_exc()
raise e
def check_current_case(self,query_msg: RestMsgInfo, data):
url, header = query_msg.full_url, query_msg.header
conn = requests.post(url=url, data=data, headers=header)
resp_code = conn.status_code
resp = conn.json()
try:
status = resp["status"]
if resp_code == 200 and status == "succ":
tdLog.success(f"restfull run success! url:{url}")
else:
tdLog.exit(f"restful api test failed, url:{url}, sql: {data}, resp: {resp}")
except:
tdLog.debug(f"resp_code: {resp_code}, url: {url}, resp:{resp}")
traceback.print_exc()
raise
pass
def check_case_res_data(self, query_msg: RestMsgInfo, data):
url, header, api = query_msg.full_url, query_msg.header, query_msg.api_url
try:
ts_col = []
stb_list = [f"describe {self.dbname}.stb1", f"describe {self.dbname}.stb2"]
for stb in stb_list:
conn = requests.post(url=url, data=stb, headers=header)
resp = conn.json()
for col in resp["data"]:
if "TIMESTAMP" == col[1]:
ts_col.append(col[0])
check_column = []
conn = requests.post(url=url, data=data, headers=header)
resp = conn.json()
if len(resp["data"]) < 1:
return
for meta in resp["column_meta"]:
if meta[0] in ts_col:
check_column.append(meta[0])
if len(check_column) < 1:
return
if self.precision == "ms" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"):
return
except:
raise
pass
def db_tb_case_current(self):
# when version > 2.6, add the follow case:
# f"alter table {self.dbname}.tb1 add column c2 float",
# f"alter table {self.dbname}.tb1 drop column c2 ",
# f"alter table {self.dbname}.tb1 add column c2 float ; alter table {self.dbname}.tb1 drop column c2 ",
case_list = [
"create database if not exists db",
"create database if not exists db",
"create database if not exists db1",
"alter database db1 comp 2",
"alter database db1 keep 36500",
"drop database if exists db1",
"drop database if exists db1",
"drop database if exists db",
f"create database if not exists {self.dbname}",
f"create table if not exists {self.dbname}.tb1 (ts timestamp , c1 int)",
f"create table if not exists {self.dbname}.tb1 (ts timestamp , c1 float)",
f"create table if not exists {self.dbname}.stb1 (ts timestamp , c1 int) tags(tag1 int )",
f"create table if not exists {self.dbname}.stb1 (ts timestamp , c1 float) tags(tag2 int )",
f"create table if not exists {self.dbname}.stb2 (ts timestamp , c1 int) tags(tag1 int )",
f"create table if not exists {self.dbname}.stb3 (ts timestamp , c1 int) tags(tag1 int )",
f"create table if not exists {self.dbname}.tb2 using {self.dbname}.stb2 tags(2)",
f"create table if not exists {self.dbname}.tb3 using {self.dbname}.stb2 tags(2)",
f"drop table if exists {self.dbname}.tb2",
f"drop table if exists {self.dbname}.tb2",
f"drop table if exists {self.dbname}.stb2",
f"drop table if exists {self.dbname}.stb2",
f"drop table if exists {self.dbname}.t3",
f"drop table if exists {self.dbname}.stb3",
]
return case_list
def db_tb_case_err(self):
case_list = [
"create database if exists db",
f"drop database if not exists db",
f"drop database db3",
f"create table if exists {self.dbname}.t1 ",
f"create table if exists {self.dbname}.stb1 ",
f"drop table if not exists {self.dbname}.stb1 ",
f"drop table {self.dbname}.stb4 ",
f"create table if not exists {self.dbname}.stb2 (c1 int, c2 timestamp ) tags(tag1 int)",
f"create table if exists {self.dbname}.stb3 (ts timestamp ,c1 int) ",
f"create table if exists {self.dbname}.t2 (c1 int) "
]
return case_list
def data_case_current(self, tbnum:int, data_row:int, basetime: int, file:str):
case_list = []
body_list = []
row_times = data_row // 100
row_alone = data_row % 100
for i in range(row_times):
body = ""
for j in range(100):
body += f"(\
{basetime + (j+1)*10+ i*1000}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)},\
'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, \
{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' \
)"
body_list.append(body)
if row_alone != 0:
body = ""
for j in range(row_alone):
body += f"( \
{basetime + (j+1)*10+ row_times*1000}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, \
{basetime + random.randint(-200, -1)},'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, \
{random.randint(-200,-1)},{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' \
)"
body_list.append(body)
for i in range(tbnum):
pre_insert = f"insert into {self.dbname}.t{i} values "
for value_body in body_list:
insert_sql = pre_insert + value_body
case_list.append(insert_sql)
case_list.append(f'insert into {self.dbname}.nt1 values (now, 1, 1.0)')
case_list.append(f'insert into {self.dbname}.nt1 values ({basetime + 10}, 2, 2.0)')
case_list.append(f'insert into {self.dbname}.nt1 values ({basetime + 20}, 3, 3.0) {self.dbname}.nt2 values (now, 1, 1.0)')
case_list.append(f'insert into {self.dbname}.nt1 (ts, c2, c1) values ({basetime + 20}, 4.0, 4) ')
# exchange column order
case_list.append(f'insert into {self.dbname}.ct1 using {self.dbname}.stb1 (tag1) tags(1) (ts, c1) values (now, 1)')
# insert with file
if not os.path.isfile(file):
with open(file=file, mode="w", encoding="utf-8", newline="") as f:
for j in range(data_row):
writer = csv.writer(f)
data_line = [
basetime - (j + 1) * 10, random.randint(-200, -1), random.uniform(200, -1),
basetime + random.randint(-200, -1), f'"binary_{j}"', random.uniform(-200, -1),
random.choice([0, 1]), random.randint(-200, -1), random.randint(-200, -1),
random.randint(-127, -1), f'"nchar_{j}"'
]
writer.writerow(data_line)
case_list.append(f"insert into {self.dbname}.ct1 file {file}")
return case_list
pass
def data_case_err(self):
case_list = []
nowtime = int(round(time.time()*1000))
bigger_insert_sql = f"insert into {self.dbname}.nt1 values"
for i in range(40000):
bigger_insert_sql += f"({nowtime-i*10}, {i}, {i*1.0})"
case_list.append(bigger_insert_sql)
nodata_sql = f"insert into {self.dbname}.nt1 values()"
case_list.append(nodata_sql)
less_data_sql = f"insert into {self.dbname}.nt1 values(now)"
case_list.append(less_data_sql)
errtype_data_sql = f"insert into {self.dbname}.nt1 values(now+2, 1.0, 'binary_2')"
case_list.append(errtype_data_sql)
# insert into super table directly
insert_super_data_sql = f"insert into {self.dbname}.stb1 values(now+3, 1, 1.0)"
case_list.append(insert_super_data_sql)
return case_list
def port_case_current(self):
case_list = [6041]
return case_list
def port_case_err(self):
case_list = [
6030,
6051,
666666666,
None,
"abcd"
]
return case_list
def api_case_current(self):
case_List = [
"/rest/sql",
f"/rest/sql/{self.dbname}",
"/rest/sqlt",
f"/rest/sqlt/{self.dbname}",
"/rest/sqlutc",
f"/rest/sqlutc/{self.dbname}"
]
return case_List
def api_case_err(self):
case_list = [
"",
"/rest1/sql",
"/rest/sqlsqltsqlutc",
1,
["/rest", "/sql"],
"/influxdb/v1/write",
"/opentsdb/v1/put/json/db",
"/opentsdb/v1/put/telnet/db",
"/rest*",
"*"
]
return case_list
def header_case_current(self):
case_list = [
{'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='},
{'Authorization': 'Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04'}
]
return case_list
def header_case_err(self):
case_list = [
{'Authorization': 'Basic '},
{'Authorization': 'Taosd /root/taosdata'},
{'Authorization': True}
]
return case_list
def run_case_api_err(self):
err_cases = self.api_case_err()
count = 0
data = "create database if not exists db"
for case in err_cases:
print(f"err api case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, api_url=case)
self.check_err_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_port_err(self):
err_cases = self.port_case_err()
count = 0
data = "create database if not exists db"
for case in err_cases:
print(f"err port case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, port=case)
self.check_err_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_header_err(self):
err_cases = self.header_case_err()
count = 0
data = "create database if not exists db"
for case in err_cases:
print(f"err header case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, header=case)
self.check_err_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_db_tb_err(self):
err_cases = self.db_tb_case_err()
count = 0
query_msg = RestMsgInfo(base_url=self.base_url)
for case in err_cases:
print(f"err create db/tb case{count}: ", end="")
self.check_err_sql_case(query_msg=query_msg, data=case)
count += 1
pass
def run_case_data_err(self):
err_cases = self.data_case_err()
count = 0
tdSql.execute(f"drop database if exists {self.dbname}")
tdSql.execute(f"create database if not exists {self.dbname} keep 3650 precision '{self.precision}' ")
tdSql.execute(f"use {self.dbname}")
tdSql.execute(
f'''
create stable {self.dbname}.stb1 (
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
)
tags(
tag1 int, tag2 float, tag3 timestamp, tag4 binary(16), tag5 double, tag6 bool,
tag7 bigint, tag8 smallint, tag9 tinyint, tag10 nchar(16)
)
'''
)
query_msg = RestMsgInfo(base_url=self.base_url)
for case in err_cases:
print(f"err insert data case{count}: ", end="")
self.check_err_sql_case(query_msg=query_msg, data=case)
count += 1
tdSql.execute(f"drop database if exists {self.dbname}")
pass
def run_case_port_current(self):
current_cases = self.port_case_current()
count = 0
data = "create database if not exists db"
for case in current_cases:
print(f"current port case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, port=case)
self.check_current_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_api_current(self):
current_cases = self.api_case_current()
count = 0
data = "create database if not exists db"
for case in current_cases:
print(f"current api case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, api_url=case)
self.check_current_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_header_current(self):
current_cases = self.header_case_current()
count = 0
data = "create database if not exists db"
for case in current_cases:
print(f"current header case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, header=case)
self.check_current_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_db_tb_current(self):
current_cases = self.db_tb_case_current()
count = 0
for case in current_cases:
print(f"current insert db/tb case{count}: ", end="")
for api in ["/rest/sql", "/rest/sqlt", "/rest/sqlutc"]:
query_msg = RestMsgInfo(base_url=self.base_url, api_url=api)
self.check_current_case(query_msg=query_msg, data=case)
count += 1
pass
def run_case_data_current(self):
self.rest_test_table(dbname=self.dbname, tbnum=self.tbnum)
current_cases = self.data_case_current(tbnum=self.tbnum, data_row=self.data_row, basetime=self.basetime, file=self.file)
count = 0
print(current_cases[12])
api_cases = self.api_case_current()
for case in current_cases:
print(f"current insert data case{count}: ", end="")
for api in api_cases:
query_msg = RestMsgInfo(base_url=self.base_url, api_url=api)
self.check_current_case(query_msg=query_msg, data=case)
count += 1
pass
def run_case_err(self):
self.run_case_api_err()
self.run_case_port_err()
self.run_case_header_err()
self.run_case_db_tb_err()
self.run_case_data_err()
pass
def run_case_current(self):
self.run_case_api_current()
self.run_case_port_current()
self.run_case_header_current()
self.run_case_db_tb_current()
self.run_case_data_current()
pass
def run_all_case(self):
self.run_case_err()
self.run_case_current()
pass
def set_default_args(self):
nowtime = int(round(time.time() * 1000))
url = "127.0.0.1"
per_table_rows = 100
tbnum = 10
database_name = "db"
precision ="ms"
clear_data = True
insert_case_filename = "data_insert.csv"
config_default = {
"base_url" : url,
"precision" : precision,
"clear_data" : clear_data,
"database_name" : database_name,
"tbnum" : tbnum,
"data_row" : per_table_rows,
"case_file" : insert_case_filename,
"basetime" : nowtime,
"all_case" : False,
"all_err" : False,
"all_current" : True,
"err_case" : {
"port_err" : True,
"api_err" : True,
"header_err" : True,
"db_tb_err" : True,
"data_err" : True,
},
"current_case" : {
"port_current" : True,
"api_current" : True,
"header_current" : True,
"db_tb_current" : True,
"data_current" : True,
}
}
config_file_name = f"{os.path.dirname(os.path.abspath(__file__))}/rest_insert_config.json"
with open(config_file_name, "w") as f:
json.dump(config_default, f)
return config_file_name
def run(self):
config_file = f"{os.path.dirname(os.path.abspath(__file__))}/rest_insert_config.json"
if not os.path.isfile(config_file):
config_file = self.set_default_args()
with open(config_file, "r", encoding="utf-8") as f:
cfg = json.load(f)
self.tbnum = cfg["tbnum"]
self.data_row = cfg["data_row"]
self.basetime = cfg["basetime"]
self.dbname = cfg["database_name"]
self.base_url = cfg["base_url"]
self.precision = cfg["precision"]
self.file = cfg["case_file"]
clear_data = True if cfg["clear_data"] else False
if clear_data:
self.rest_test_table(dbname=self.dbname, tbnum=self.tbnum)
run_all_case = True if cfg["all_case"] else False
run_all_err_case = True if cfg["all_err"] else False
run_all_current_case = True if cfg["all_current"] else False
run_port_err_case = True if cfg["err_case"]["port_err"] else False
run_api_err_case = True if cfg["err_case"]["api_err"] else False
run_header_err_case = True if cfg["err_case"]["header_err"] else False
run_db_tb_err_case = True if cfg["err_case"]["db_tb_err"] else False
run_data_err_case = True if cfg["err_case"]["data_err"] else False
run_port_current_case = True if cfg["current_case"]["port_current"] else False
run_api_current_case = True if cfg["current_case"]["api_current"] else False
run_header_current_case = True if cfg["current_case"]["header_current"] else False
run_db_tb_current_case = True if cfg["current_case"]["db_tb_current"] else False
run_data_current_case = True if cfg["current_case"]["data_current"] else False
print("run_all_case:" ,run_all_case)
print("run_all_err_case:" ,run_all_err_case)
print("run_all_current_case:" ,run_all_current_case)
print("run_port_err_case:" ,run_port_err_case)
print("run_api_err_case:" ,run_api_err_case)
print("run_header_err_case:" ,run_header_err_case)
print("run_db_tb_err_case:" ,run_db_tb_err_case)
print("run_data_err_case:" ,run_data_err_case)
print("run_port_current_case:" ,run_port_current_case)
print("run_api_current_case:" ,run_api_current_case)
print("run_header_current_case:" ,run_header_current_case)
print("run_db_tb_current_case:" ,run_db_tb_current_case)
print("run_data_current_case:" ,run_data_current_case)
if not (run_all_err_case | run_all_current_case | run_port_err_case | run_api_err_case | run_header_err_case |
run_db_tb_err_case | run_data_err_case | run_port_current_case | run_api_current_case |
run_header_current_case | run_db_tb_current_case | run_data_current_case ):
run_all_case = True
if run_all_err_case & run_all_current_case:
run_all_case = True
if run_all_case:
self.run_all_case()
return
if run_all_err_case :
self.run_case_err()
return
if run_all_current_case:
self.run_case_current()
return
if run_port_err_case:
self.run_case_port_err()
if run_api_err_case:
self.run_case_api_err()
if run_header_err_case:
self.run_case_header_err()
if run_db_tb_err_case:
self.run_case_db_tb_err()
if run_data_err_case:
self.run_case_data_err()
if run_port_current_case:
self.run_case_port_current()
if run_api_current_case:
self.run_case_api_current()
if run_header_current_case:
self.run_case_header_current()
if run_db_tb_current_case:
self.run_case_db_tb_current()
if run_data_current_case:
self.run_case_data_current()
pass
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
import os
import subprocess
import random
import inspect
import taos
import requests
import json
import traceback
import simplejson.errors
import math
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
from collections import defaultdict
class RestMsgInfo:
def __init__(self, base_url,
port=6041,
api_url="/rest/sql",
header={'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='}
):
self.base_url = base_url
self.port = port
self.api_url = api_url
self.header = header
self.full_url = f"http://{base_url}:{port}{api_url}"
class TDTestCase:
def __init__(self):
self.base_url = "127.0.0.1"
self.dbname = "db"
self.precision = "ms"
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
def caseDescription(self):
'''
case1 <cpwu>: specified SQL
case2 <cpwu>: select sql,include stable 、child table and normal table, include correct SQL and invalid SQL \n
case3 <cpwu>: port test \n
case4 <cpwu>: api_url test \n
case5 <cpwu>: base_url test \n
case6 <cpwu>: header test \n
case7 <cpwu>: big data test
'''
return
def rest_test_table(self, dbname: str, tbnum: int) -> None :
tdSql.execute(f"drop database if exists {dbname}")
tdSql.execute(f"create database if not exists {dbname} keep 3650 precision '{self.precision}' ")
tdSql.execute(f"use {dbname}")
tdSql.execute(
f'''
create stable {dbname}.stb1 (
ts timestamp, c1 int, c2 float, c3 timestamp, c4 binary(16), c5 double, c6 bool,
c7 bigint, c8 smallint, c9 tinyint, c10 nchar(16)
)
tags(
tag1 int, tag2 float, tag3 timestamp, tag4 binary(16), tag5 double, tag6 bool,
tag7 bigint, tag8 smallint, tag9 tinyint, tag10 nchar(16)
)
'''
)
tdSql.execute(
f"create stable {dbname}.stb2 (ts timestamp, c1 int) tags(ttag1 int)"
)
for i in range(tbnum):
tdSql.execute(
f'''
create table {dbname}.t{i} using {dbname}.stb1
tags({i}, {i}, {1639032680000+i*10}, 'binary_{i}',{i},{random.choice([0, 1])}, {i},{i%32767},{i%127},'nchar_{i}')
'''
)
tdSql.execute(f"create table {dbname}.tt{i} using {dbname}.stb2 tags({i})")
pass
def rest_test_data(self, tbnum:int, data_row:int, basetime:int) -> None :
for i in range(tbnum):
for j in range(data_row):
tdSql.execute(
f"insert into t{i} values ("
f"{basetime + (j+1)*10}, {random.randint(-200, -1)}, {random.uniform(200, -1)}, {basetime + random.randint(-200, -1)}, "
f"'binary_{j}', {random.uniform(-200, -1)}, {random.choice([0,1])}, {random.randint(-200,-1)}, "
f"{random.randint(-200, -1)}, {random.randint(-127, -1)}, 'nchar_{j}' )"
)
tdSql.execute(
f"insert into tt{i} values ( {basetime-(j+1) * 10}, {random.randint(1, 200)} )"
)
def check_err_case(self,query_msg: RestMsgInfo, data):
url, header = query_msg.full_url, query_msg.header
try:
conn = requests.post(url=url, data=data, headers=header)
resp_code = conn.status_code
resp = conn.json()
if resp_code != 200:
print(f"expect error occured, url: {url}, sql: {data}, error code is :{resp_code}")
return
status = resp["status"]
desc = resp["desc"]
if resp_code == 200 and status == "error":
print(f"expect error occured, url: {url}, sql: {data}, error is :{desc}")
return
else:
tdLog.exit(f"expect error not occured")
except requests.exceptions.InvalidHeader as e:
tdLog.success(f"expect error occured, request header error, header: {header}, error: {e}")
except requests.exceptions.InvalidURL as e:
tdLog.success(f"expect error occured, request url error, url: {url}, error: {e}")
except requests.exceptions.ConnectionError as e:
tdLog.success(f"expect error occured, request connection error,url: {url}, error: {e}")
except simplejson.errors.JSONDecodeError as e:
tdLog.success(f"expect error occured, request json error,url: {url}, header: {header}, error: {e}")
except Exception as e:
tdLog.success(f"expect error occured, url: {url}, header: {header}, {traceback.print_exc()}")
# finally:
# conn.close()
pass
def check_err_sql_case(self,query_msg: RestMsgInfo, data):
url, header = query_msg.full_url, query_msg.header
try:
conn = requests.post(url=url, data=data, headers=header)
resp_code = conn.status_code
resp = conn.json()
status = resp["status"]
desc = resp["desc"]
if resp_code == 200 and status == "error":
tdLog.success(f"expect error occured, url: {url}, sql: {data}, error is :{desc}")
return
else:
tdLog.exit(f"expect error not occured")
except Exception as e:
traceback.print_exc()
raise e
def check_current_case(self,query_msg: RestMsgInfo, data):
url, header = query_msg.full_url, query_msg.header
conn = requests.post(url=url, data=data, headers=header)
try:
resp_code = conn.status_code
resp = conn.json()
status = resp["status"]
if resp_code == 200 and status == "succ":
tdLog.printNoPrefix(f"restfull run success! url:{url}, sql: {data}")
else:
tdLog.exit(f"restful api test failed, url:{url}, sql: {data}")
except:
tdLog.debug(f"resp_code: {resp_code}, url: {url}")
traceback.print_exc()
raise
pass
def check_case_res_data(self, query_msg: RestMsgInfo, data):
url, header, api = query_msg.full_url, query_msg.header, query_msg.api_url
try:
ts_col = []
stb_list = [f"describe {self.dbname}.stb1", f"describe {self.dbname}.stb2"]
for stb in stb_list:
conn = requests.post(url=url, data=stb, headers=header)
resp = conn.json()
for col in resp["data"]:
if "TIMESTAMP" == col[1]:
ts_col.append(col[0])
index_dict = defaultdict(int)
conn = requests.post(url=url, data=data, headers=header)
resp = conn.json()
if resp["data"] is None:
return
for index, meta in enumerate(resp["column_meta"]):
if meta[0] in ts_col:
index_dict[meta[0]] = index
if len(index_dict) < 1:
return
if self.precision == "ms" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if len(res_data[col_index]) !=23:
print(res_data)
tdLog.exit(f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}")
return
if self.precision == "ms" and (api == "/rest/sqlt" or api == f"/rest/sqlt/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if not isinstance(res_data[col_index], int) or round(math.log10(res_data[col_index])) != 12:
print(res_data)
tdLog.exit(
f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}"
)
return
if self.precision == "ms" and (api == "/rest/sqlutc" or api == f"/rest/sqlutc/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if len(res_data[col_index]) != 29 and len(res_data[col_index]) != 28 and len(res_data[col_index]) != 27 and len(res_data[col_index]) != 25:
print(res_data)
tdLog.exit(
f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}, length is: {len(res_data[col_index])}"
)
return
if self.precision == "us" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if len(res_data[col_index]) !=26:
print(res_data)
tdLog.exit(f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}")
return
if self.precision == "us" and (api == "/rest/sqlt" or api == f"/rest/sqlt/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if not isinstance(res_data[col_index], int) or round(math.log10(res_data[col_index])) != 15:
print(res_data)
tdLog.exit(
f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}"
)
return
if self.precision == "us" and (api == "/rest/sqlutc" or api == f"/rest/sqlutc/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if len(res_data[col_index]) != 32 and len(res_data[col_index]) != 31 and len(res_data[col_index]) != 30 and len(res_data[col_index]) != 28:
print(res_data)
tdLog.exit(
f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}"
)
return
if self.precision == "ns" and (api == "/rest/sql" or api == f"/rest/sql/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if len(res_data[col_index]) !=29:
print(res_data)
tdLog.exit(f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}")
return
if self.precision == "ns" and (api == "/rest/sqlt" or api == f"/rest/sqlt/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if not isinstance(res_data[col_index], int) or round(math.log10(res_data[col_index])) != 18:
print(res_data)
tdLog.exit(
f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}"
)
return
if self.precision == "ns" and (api == "/rest/sqlutc" or api == f"/rest/sqlutc/{self.dbname}"):
for col_name, col_index in index_dict.items():
for res_data in resp["data"]:
if len(res_data[col_index]) != 35 and len(res_data[col_index]) != 34 and len(res_data[col_index]) != 33 and len(res_data[col_index]) != 31:
print(res_data)
tdLog.exit(
f"restful timestamp column err, url:{url}, sql: {data},result is: {res_data[col_index]}"
)
return
except:
traceback.print_exc()
raise
pass
def sql_case_current(self):
case_list = [
"show databases",
f"show {self.dbname}.stables",
f"show {self.dbname}.tables",
"select server_status()",
"select client_version()",
"select server_version()",
"select database()",
f"show create database {self.dbname}",
f"show create stable {self.dbname}.stb1",
f"select * from {self.dbname}.stb1",
f"select ts from {self.dbname}.stb1",
f"select _c0 from {self.dbname}.stb1",
f"select c1 from {self.dbname}.stb1",
f"select c2 from {self.dbname}.stb1",
f"select c3 from {self.dbname}.stb1",
f"select c4 from {self.dbname}.stb1",
f"select c5 from {self.dbname}.stb1",
f"select c6 from {self.dbname}.stb1",
f"select c7 from {self.dbname}.stb1",
f"select c8 from {self.dbname}.stb1",
f"select c9 from {self.dbname}.stb1",
f"select c10 from {self.dbname}.stb1",
f"select tbname from {self.dbname}.stb1",
f"select tag1 from {self.dbname}.stb1",
f"select tag2 from {self.dbname}.stb1",
f"select tag3 from {self.dbname}.stb1",
f"select tag4 from {self.dbname}.stb1",
f"select tag5 from {self.dbname}.stb1",
f"select tag6 from {self.dbname}.stb1",
f"select tag7 from {self.dbname}.stb1",
f"select tag8 from {self.dbname}.stb1",
f"select tag9 from {self.dbname}.stb1",
f"select tag10 from {self.dbname}.stb1",
f"select count(*) from {self.dbname}.stb1",
f"select count(c1) from {self.dbname}.stb1",
f"select avg(c1) from {self.dbname}.stb1",
f"select twa(c1) from {self.dbname}.stb1 group by tbname",
f"select sum(c1) from {self.dbname}.stb1",
f"select stddev(c1) from {self.dbname}.stb1",
f"select min(c1) from {self.dbname}.stb1",
f"select max(c1) from {self.dbname}.stb1",
f"select first(c1) from {self.dbname}.stb1",
f"select first(*) from {self.dbname}.stb1",
f"select last(c1) from {self.dbname}.stb1",
f"select last(*) from {self.dbname}.stb1",
f"select top(c1, 3) from {self.dbname}.stb1",
f"select bottom(c1, 3) from {self.dbname}.stb1",
f"select apercentile(c1, 50, 't-digest') from {self.dbname}.stb1",
f"select last_row(c1) from {self.dbname}.stb1",
f"select last_row(*) from {self.dbname}.stb1",
f"select interp(c1) from {self.dbname}.stb1 where ts=0 group by tbname",
f"select interp(c1) from {self.dbname}.stb1 where ts=0 fill(next) group by tbname",
f"select interp(c1) from {self.dbname}.stb1 where ts>0 and ts <100000000 every(5s) group by tbname",
f"select diff(c1) from {self.dbname}.stb1 group by tbname",
f"select derivative(c1, 10m, 0) from {self.dbname}.stb1 group by tbname",
f"select derivative(c1, 10m, 1) from {self.dbname}.stb1 group by tbname",
f"select spread(c1) from {self.dbname}.stb1",
f"select ceil(c1) from {self.dbname}.stb1",
f"select floor(c1) from {self.dbname}.stb1",
f"select round(c1) from {self.dbname}.stb1",
f"select c1*2+2%c2-c2/2 from {self.dbname}.stb1",
f"select max(c1) from {self.dbname}.stb1 where ts>'2021-12-05 18:25:41.136' and ts<'2021-12-05 18:25:44.13' interval(1s) sliding(500a) fill(NULL) group by tbname",
f"select max(c1) from {self.dbname}.stb1 where (c1 >=0 and c1 <> 0 and c2 is not null or c1 < -1 or (c2 between 1 and 10) ) and tbname like 't_' ",
f"select max(c1) from {self.dbname}.stb1 group by tbname order by ts desc slimit 2 soffset 2 limit 1 offset 0",
f"select max(c1) from {self.dbname}.stb1 group by c6 order by ts desc slimit 1 soffset 1 limit 1 offset 0 ",
f"select * from {self.dbname}.t1",
f"select ts from {self.dbname}.t1",
f"select _c0 from {self.dbname}.t1",
f"select c1 from {self.dbname}.t1",
f"select c2 from {self.dbname}.t1",
f"select c3 from {self.dbname}.t1",
f"select c4 from {self.dbname}.t1",
f"select c5 from {self.dbname}.t1",
f"select c6 from {self.dbname}.t1",
f"select c7 from {self.dbname}.t1",
f"select c8 from {self.dbname}.t1",
f"select c9 from {self.dbname}.t1",
f"select c10 from {self.dbname}.t1",
f"select tbname from {self.dbname}.t1",
f"select tag1 from {self.dbname}.t1",
f"select tag2 from {self.dbname}.t1",
f"select tag3 from {self.dbname}.t1",
f"select tag4 from {self.dbname}.t1",
f"select tag5 from {self.dbname}.t1",
f"select tag6 from {self.dbname}.t1",
f"select tag7 from {self.dbname}.t1",
f"select tag8 from {self.dbname}.t1",
f"select tag9 from {self.dbname}.t1",
f"select tag10 from {self.dbname}.t1",
f"select count(*) from {self.dbname}.t1",
f"select count(c1) from {self.dbname}.t1",
f"select avg(c1) from {self.dbname}.t1",
f"select twa(c1) from {self.dbname}.t1",
f"select sum(c1) from {self.dbname}.t1",
f"select stddev(c1) from {self.dbname}.t1",
f"select leastsquares(c1, 1, 1) from {self.dbname}.t1",
f"select min(c1) from {self.dbname}.t1",
f"select max(c1) from {self.dbname}.t1",
f"select first(c1) from {self.dbname}.t1",
f"select first(*) from {self.dbname}.t1",
f"select last(c1) from {self.dbname}.t1",
f"select last(*) from {self.dbname}.t1",
f"select top(c1, 3) from {self.dbname}.t1",
f"select bottom(c1, 3) from {self.dbname}.t1",
f"select percentile(c1, 50) from {self.dbname}.t1",
f"select apercentile(c1, 50, 't-digest') from {self.dbname}.t1",
f"select last_row(c1) from {self.dbname}.t1",
f"select last_row(*) from {self.dbname}.t1",
f"select interp(c1) from {self.dbname}.t1 where ts=0 ",
f"select interp(c1) from {self.dbname}.t1 where ts=0 fill(next)",
f"select interp(c1) from {self.dbname}.t1 where ts>0 and ts <100000000 every(5s)",
f"select diff(c1) from {self.dbname}.t1",
f"select derivative(c1, 10m, 0) from {self.dbname}.t1",
f"select derivative(c1, 10m, 1) from {self.dbname}.t1",
f"select spread(c1) from {self.dbname}.t1",
f"select ceil(c1) from {self.dbname}.t1",
f"select floor(c1) from {self.dbname}.t1",
f"select round(c1) from {self.dbname}.t1",
f"select c1*2+2%c2-c2/2 from {self.dbname}.t1",
f"select max(c1) from {self.dbname}.t1 where ts>'2021-12-05 18:25:41.136' and ts<'2021-12-05 18:25:44.13' interval(1s) sliding(500a) fill(NULL)",
f"select max(c1) from {self.dbname}.t1 where (c1 >=0 and c1 <> 0 and c2 is not null or c1 < -1 or (c2 between 1 and 10) ) and c10 like 'nchar___1' ",
f"select max(c1) from {self.dbname}.t1 group by c6 order by ts desc ",
f"select stb1.c1, stb2.c1 from {self.dbname}.stb1 stb1, {self.dbname}.stb2 stb2 where stb1.ts=stb2.ts and stb1.tag1=stb2.ttag1",
f"select t1.c1, t2.c1 from {self.dbname}.t1 t1, {self.dbname}.t2 t2 where t1.ts=t2.ts",
f"select c1 from (select c2 c1 from {self.dbname}.stb1) ",
f"select c1 from {self.dbname}.t1 union all select c1 from {self.dbname}.t2"
]
return case_list
def sql_case_err(self):
case_list = [
"show database",
f"select percentile(c1, 50) from {self.dbname}.stb1 group by tbname",
f"select leastsquares(c1, 1, 1) from {self.dbname}.stb1",
]
return case_list
def port_case_current(self):
case_list = [6041]
return case_list
def port_case_err(self):
case_list = [
6030,
6051,
666666666,
None,
"abcd"
]
return case_list
def api_case_current(self):
case_List = [
"/rest/sql",
f"/rest/sql/{self.dbname}",
"/rest/sqlt",
f"/rest/sqlt/{self.dbname}",
"/rest/sqlutc",
f"/rest/sqlutc/{self.dbname}"
]
return case_List
def api_case_err(self):
case_list = [
"",
"/rest1/sql",
"/rest/sqlsqltsqlutc",
1,
["/rest", "/sql"],
"/influxdb/v1/write",
"/opentsdb/v1/put/json/db",
"/opentsdb/v1/put/telnet/db",
"/rest*",
"*"
]
return case_list
def header_case_current(self):
case_list = [
{'Authorization': 'Basic cm9vdDp0YW9zZGF0YQ=='},
{'Authorization': 'Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04'}
]
return case_list
def header_case_err(self):
case_list = [
{'Authorization': 'Basic '},
{'Authorization': 'Taosd /root/taosdata'},
{'Authorization': True}
]
return case_list
def run_case_api_err(self):
err_cases = self.api_case_err()
count = 0
data = "show databases"
for case in err_cases:
print(f"err api case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, api_url=case)
self.check_err_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_port_err(self):
err_cases = self.port_case_err()
count = 0
data = "show databases"
for case in err_cases:
print(f"err port case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, port=case)
self.check_err_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_header_err(self):
err_cases = self.header_case_err()
count = 0
data = "show databases"
for case in err_cases:
print(f"err header case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, header=case)
self.check_err_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_sql_err(self):
err_cases = self.sql_case_err()
count = 0
for case in err_cases:
print(f"err sql case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url)
self.check_err_sql_case(query_msg=query_msg, data=case)
count += 1
pass
def run_case_port_current(self):
current_cases = self.port_case_current()
count = 0
data = "show databases"
for case in current_cases:
print(f"current port case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, port=case)
self.check_current_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_api_current(self):
current_cases = self.api_case_current()
count = 0
data = "show databases"
for case in current_cases:
print(f"current api case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, api_url=case)
self.check_current_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_header_current(self):
current_cases = self.header_case_current()
count = 0
data = "show databases"
for case in current_cases:
print(f"current header case{count}: ", end="")
query_msg = RestMsgInfo(base_url=self.base_url, header=case)
self.check_current_case(query_msg=query_msg, data=data)
count += 1
pass
def run_case_sql_current(self):
current_cases = self.sql_case_current()
count = 0
api_cases = self.api_case_current()
for case in current_cases:
print(f"current sql case{count}: ", end="")
for api in api_cases:
query_msg = RestMsgInfo(base_url=self.base_url, api_url=api)
self.check_current_case(query_msg=query_msg, data=case)
self.check_case_res_data(query_msg=query_msg, data=case)
count += 1
pass
def run_case_err(self):
self.run_case_api_err()
self.run_case_port_err()
self.run_case_header_err()
self.run_case_sql_err()
pass
def run_case_current(self):
self.run_case_api_current()
self.run_case_port_current()
self.run_case_header_current()
self.run_case_sql_current()
pass
def run_all_case(self):
self.run_case_err()
self.run_case_current()
pass
def set_default_args(self):
nowtime = int(round(time.time() * 1000))
url = "127.0.0.1"
per_table_rows = 100
tbnum = 10
database_name = "db"
precision ="ms"
clear_data = True
config_default = {
"base_url" : url,
"precision" : precision,
"clear_data" : clear_data,
"database_name": database_name,
"tbnum" : tbnum,
"data_row" : per_table_rows,
"basetime" : nowtime,
"all_case" : False,
"all_err" : False,
"all_current" : True,
"err_case" : {
"port_err" : True,
"api_err" : True,
"header_err" : True,
"sql_err" : True,
},
"current_case" : {
"port_current" : True,
"api_current" : True,
"header_current" : True,
"sql_current" : True,
}
}
config_file_name = f"{os.path.dirname(os.path.abspath(__file__))}/rest_query_config.json"
with open(config_file_name, "w") as f:
json.dump(config_default, f)
return config_file_name
def run(self):
config_file = f"{os.path.dirname(os.path.abspath(__file__))}/rest_query_config.json"
if not os.path.isfile(config_file):
config_file = self.set_default_args()
with open(config_file, "r", encoding="utf-8") as f:
cfg = json.load(f)
tbnum = cfg["tbnum"]
data_row = cfg["data_row"]
basetime = cfg["basetime"]
self.dbname = cfg["database_name"]
self.base_url = cfg["base_url"]
self.precision = cfg["precision"]
clear_data = True if cfg["clear_data"] else False
if clear_data:
self.rest_test_table(dbname=self.dbname, tbnum=tbnum)
self.rest_test_data(tbnum=tbnum, data_row=data_row, basetime=basetime)
run_all_case = True if cfg["all_case"] else False
run_all_err_case = True if cfg["all_err"] else False
run_all_current_case = True if cfg["all_current"] else False
run_port_err_case = True if cfg["err_case"]["port_err"] else False
run_api_err_case = True if cfg["err_case"]["api_err"] else False
run_header_err_case = True if cfg["err_case"]["header_err"] else False
run_sql_err_case = True if cfg["err_case"]["sql_err"] else False
run_port_current_case = True if cfg["current_case"]["port_current"] else False
run_api_current_case = True if cfg["current_case"]["api_current"] else False
run_header_current_case = True if cfg["current_case"]["header_current"] else False
run_sql_current_case = True if cfg["current_case"]["sql_current"] else False
if not (run_all_err_case | run_all_current_case | run_port_err_case | run_api_err_case |
run_header_err_case | run_sql_err_case | run_port_current_case | run_api_current_case
| run_header_current_case | run_sql_current_case):
run_all_case = True
if run_all_err_case & run_all_current_case:
run_all_case = True
if run_all_case:
self.run_all_case()
return
if run_all_err_case :
self.run_case_err()
return
if run_all_current_case:
self.run_case_current()
return
if run_port_err_case:
self.run_case_port_err()
if run_api_err_case:
self.run_case_api_err()
if run_header_err_case:
self.run_case_header_err()
if run_sql_err_case:
self.run_case_sql_err()
if run_port_current_case:
self.run_case_port_current()
if run_api_current_case:
self.run_case_api_current()
if run_header_current_case:
self.run_case_header_current()
if run_sql_current_case:
self.run_case_sql_current()
pass
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# Copyright (c) 2016 by TAOS Technologies, Inc.
# All rights reserved.
#
# This file is proprietary and confidential to TAOS Technologies.
# No part of this file may be reproduced, stored, transmitted,
# disclosed or used in any form or by any means other than as
# expressly provided by the written permission from Jianhui Tao
#
###################################################################
# -*- coding: utf-8 -*-
import sys
import os
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
import subprocess
class TDTestCase:
def caseDescription(self):
'''
case1<pxiao>: [TD-11977] start taosdump without taosd
case1<pxiao>: [TD-11977] start taosBenchmark without taosd
case1<pxiao>: [TD-11977] start taosAdaptor without taosd
'''
return
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor(), logSql)
def run(self):
tdSql.prepare()
tools = ["taosdump", "taosBenchmark", "taosAdaptor"]
tdDnodes.stop(1)
for tool in tools:
path = tdDnodes.dnodes[1].getBuildPath(tool)
try:
path += "/build/bin/"
print(f"{path}{tool}")
if tool == "taosBenchmark":
os.system(f"{path}{tool} -y")
else:
os.system(f"{path}{tool}")
except:
pass
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
python3 ./test.py -f 1-insert/batchInsert.py
python3 ./test.py -f 0-others/json_tag.py
python3 ./test.py -f 2-query/ts_hidden_column.py
python3 ./test.py -f 2-query/union-order.py
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册