예제 #1
0
    def run(self):
        time.sleep(5)
        tdSql.execute("use log")

        tdSql.execute(
            "create table cpustrm as select count(*), avg(cpu_taosd), max(cpu_taosd), min(cpu_taosd), avg(cpu_system), max(cpu_cores), min(cpu_cores), last(cpu_cores) from log.dn1 interval(4s)"
        )
        tdSql.execute(
            "create table memstrm as select count(*), avg(mem_taosd), max(mem_taosd), min(mem_taosd), avg(mem_system), first(mem_total), last(mem_total) from log.dn1 interval(4s)"
        )
        tdSql.execute(
            "create table diskstrm as select count(*), avg(disk_used), last(disk_used), avg(disk_total), first(disk_total) from log.dn1 interval(4s)"
        )
        tdSql.execute(
            "create table bandstrm as select count(*), avg(band_speed), last(band_speed) from log.dn1 interval(4s)"
        )
        tdSql.execute(
            "create table reqstrm as select count(*), avg(req_http), last(req_http), avg(req_select), last(req_select), avg(req_insert), last(req_insert) from log.dn1 interval(4s)"
        )
        tdSql.execute(
            "create table iostrm as select count(*), avg(io_read), last(io_read), avg(io_write), last(io_write) from log.dn1 interval(4s)"
        )

        sqls = [
            "select * from cpustrm",
            "select * from memstrm",
            "select * from diskstrm",
            "select * from bandstrm",
            "select * from reqstrm",
            "select * from iostrm",
        ]
        for sql in sqls:
            (rows, _) = tdSql.waitedQuery(sql, 1, 600)
            if rows < 1:
                tdLog.exit("failed: sql:%s, expect at least one row" % sql)
예제 #2
0
    def run(self):
        rowNum = 200
        totalNum = 200
        tdSql.prepare()

        tdLog.info("=============== step1")
        tdSql.execute("create table mt(ts timestamp, tbcol int, tbcol2 float) TAGS(tgcol int)")
        for i in range(5):
            tdSql.execute("create table tb%d using mt tags(%d)" % (i, i))
            for j in range(rowNum):
                tdSql.execute("insert into tb%d values(now + %ds, %d, %d)" % (i, j, j, j))
        time.sleep(0.1)

        tdLog.info("=============== step2")
        tdSql.query("select count(*), count(tbcol), count(tbcol2) from mt interval(10s)")
        tdSql.execute("create table st as select count(*), count(tbcol), count(tbcol2) from mt interval(10s)")

        tdLog.info("=============== step3")
        tdSql.waitedQuery("select * from st", 1, 120)
        v = tdSql.getData(0, 3)
        if v >= 51:
            tdLog.exit("value is %d, which is larger than 51" % v)

        tdLog.info("=============== step4")
        for i in range(5, 10):
            tdSql.execute("create table tb%d using mt tags(%d)" % (i, i))
            for j in range(rowNum):
                tdSql.execute("insert into tb%d values(now + %ds, %d, %d)" % (i, j, j, j))

        tdLog.info("=============== step5")
        tdLog.sleep(40)
        tdSql.waitedQuery("select * from st order by ts desc", 1, 120)
        v = tdSql.getData(0, 3)
        if v <= 51:
            tdLog.exit("value is %d, which is smaller than 51" % v)
예제 #3
0
    def tbase300(self):
        tdLog.debug("begin tbase300")

        tdSql.prepare()
        tdSql.execute(
            "create table mt(ts timestamp, c1 int, c2 int) tags(t1 int)")
        tdSql.execute("create table tb1 using mt tags(1)")
        tdSql.execute("create table tb2 using mt tags(2)")
        tdSql.execute(
            "create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2),first(c1), last(c2) from mt interval(4s) sliding(2s)"
        )
        #tdSql.execute("create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2), first(c1) from mt interval(4s) sliding(2s)")
        tdLog.sleep(10)
        tdSql.execute("insert into tb2 values(now, 1, 1)")
        tdSql.execute("insert into tb1 values(now, 1, 1)")
        tdLog.sleep(4)
        tdSql.query("select * from mt")
        tdSql.query("select * from strm")
        tdSql.execute("drop table tb1")

        tdSql.waitedQuery("select * from strm", 1, 100)
        if tdSql.queryRows < 1 or tdSql.queryRows > 2:
            tdLog.exit("rows should be 1 or 2")

        tdSql.execute("drop table tb2")
        tdSql.execute("drop table mt")
        tdSql.execute("drop table strm")
예제 #4
0
    def tbase304(self):
        tdLog.debug("begin tbase304")
        # we cannot reset query cache in server side, as a workaround,
        # set super table name to mt304, need to change back to mt later
        tdSql.execute(
            "create table mt304 (ts timestamp, c1 int) tags(t1 int, t2 int)")
        tdSql.execute("create table tb1 using mt304 tags(1, 1)")
        tdSql.execute("create table tb2 using mt304 tags(1, -1)")
        time.sleep(0.1)
        tdSql.execute(
            "create table strm as select count(*), avg(c1) from mt304 where t2 >= 0 interval(4s) sliding(2s)"
        )
        tdSql.execute("insert into tb1 values (now,1)")
        tdSql.execute("insert into tb2 values (now,2)")

        tdSql.waitedQuery("select * from strm", 1, 100)
        if tdSql.queryRows < 1 or tdSql.queryRows > 2:
            tdLog.exit("rows should be 1 or 2")

        tdSql.checkData(0, 1, 1)
        tdSql.checkData(0, 2, 1.000000000)
        tdSql.execute("alter table mt304 drop tag t2")
        tdSql.execute("insert into tb2 values (now,2)")
        tdSql.execute("insert into tb1 values (now,1)")
        tdSql.query("select * from strm")
        tdSql.execute("alter table mt304 add tag t2 int")
        tdLog.sleep(1)
        tdSql.query("select * from strm")
예제 #5
0
    def run(self):

        nodes = Nodes()
        nodes.addConfigs("maxVgroupsPerDb", "10")
        nodes.addConfigs("maxTablesPerVnode", "1000")
        nodes.restartAllTaosd()

        ctest = ClusterTest(nodes.node1.hostName)
        ctest.connectDB()
        ctest.createSTable(1)
        ctest.run()
        tdSql.init(ctest.conn.cursor(), False)

        tdSql.execute("use %s" % ctest.dbName)
        tdSql.query("show vgroups")
        dnodes = []
        for i in range(10):
            dnodes.append(int(tdSql.getData(i, 4)))

        s = set(dnodes)
        if len(s) < 3:
            tdLog.exit("cluster is not balanced")

        tdLog.info("cluster is balanced")

        nodes.removeConfigs("maxVgroupsPerDb", "10")
        nodes.removeConfigs("maxTablesPerVnode", "1000")
        nodes.restartAllTaosd()

        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)
예제 #6
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        print("prepare data")
        tdSql.execute("create table db.st (ts timestamp, i int) tags(j int)")
        tdSql.execute("create table db.tb using st tags(1)")
        tdSql.execute("insert into db.tb values(now, 1)")

        print("==============step2")
        print("create table as select")
        try:
            tdSql.execute("create table db.test as select * from db.st")
        except Exception as e:
            tdLog.exit(e)

        # case for defect: https://jira.taosdata.com:18080/browse/TD-2560
        tdSql.execute("create table db.tb02 using st tags(2)")
        tdSql.execute("create table db.tb03 using st tags(3)")
        tdSql.execute("create table db.tb04 using st tags(4)")

        tdSql.query("show tables like 'tb%' ")
        tdSql.checkRows(4)

        tdSql.query("show tables like 'tb0%' ")
        tdSql.checkRows(3)

        tdSql.execute("create table db.st0 (ts timestamp, i int) tags(j int)")
        tdSql.execute("create table db.st1 (ts timestamp, i int, c2 int) tags(j int, loc nchar(20))")

        tdSql.query("show stables like 'st%' ")
        tdSql.checkRows(3)
예제 #7
0
    def run(self):
        try:
            tdSql.execute("create account a&cc PASS 'pass123'")
        except Exception as e:
            print("create account a&cc PASS 'pass123'")
            return

        tdLog.exit("drop built-in user is error.")
예제 #8
0
    def run(self):
        print("==============step1")
        try:
            tdSql.execute("create user abc pass '123456'")
        except Exception as e:
            tdLog.exit(e)
        print("create user abc pass '123456'")

        print("==============step2")
        try:
            tdSql.execute("alter user abc pass 'taosdata'")
        except Exception as e:
            tdLog.exit(e)
        print("alter user abc pass 'taosdata'")

        print("==============step3")
        try:
            tdSql.execute("alter user abc pass ''")
        except Exception as e:
            print("alter user abc pass ''")
        else:
            tdLog.exit("Error: alert user abc pass''")

        print("==============step4")
        try:
            tdSql.execute("alter user abc pass null")
        except Exception as e:
            print("alter user abc pass null")
        else:
            tdLog.exit("Error: alter user abc pass null")
예제 #9
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        print("prepare data")
        tdSql.execute("create table db.st (ts timestamp, i int) tags(j int)")
        tdSql.execute("create table db.tb using st tags(1)")
        tdSql.execute("insert into db.tb values(now, 1)")

        print("==============step2")
        print("create table as select")
        try:
            tdSql.execute("create table db.test as select * from db.st")
        except Exception as e:
            tdLog.exit(e)
예제 #10
0
파일: new.py 프로젝트: taosdata/TDengine
    def run(self):
        rowNum = 200
        tdSql.prepare()
        ts_now = 1633017600000
        tdLog.info("=============== step1")
        tdSql.execute("create table mt(ts timestamp, tbcol int, tbcol2 float) TAGS(tgcol int)")
        for i in range(5):
            tdSql.execute("create table tb%d using mt tags(%d)" % (i, i))
            for j in range(rowNum):
                tdSql.execute("insert into tb%d values(%d, %d, %d)" % (i, ts_now, j, j))
                ts_now += 1000
        time.sleep(0.1)

        tdLog.info("=============== step2")
        tdSql.query("select count(*), count(tbcol), count(tbcol2) from mt interval(10s)")
        tdSql.execute("create table st as select count(*), count(tbcol), count(tbcol2) from mt interval(10s)")

        tdLog.info("=============== step3")
        start = time.time()
        tdSql.waitedQuery("select * from st", 1, 180)
        delay = int(time.time() - start) + 80
        v = tdSql.getData(0, 3)
        if v != 10:
            tdLog.exit("value is %d, expect is 10." % v)

        tdLog.info("=============== step4")
        for i in range(5, 10):
            tdSql.execute("create table tb%d using mt tags(%d)" % (i, i))
            for j in range(rowNum):
                tdSql.execute("insert into tb%d values(%d, %d, %d)" % (i, ts_now, j, j))
                ts_now += 1000                

        tdLog.info("=============== step5")
        maxValue = 0
        for i in range(delay):
            time.sleep(1)
            tdSql.query("select * from st order by ts desc")
            v = tdSql.getData(0, 3)
            if v > maxValue:
                maxValue = v
            if v >= 10:
                break

        if maxValue < 10:
            tdLog.exit("value is %d, expect is 10" % maxValue)
예제 #11
0
    def wildcardFilterOnTags(self):
        tdLog.debug("begin wildcardFilterOnTag")
        tdSql.prepare()
        tdSql.execute(
            "create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10))"
        )
        tdSql.execute("create table tb1 using stb tags('a1')")
        tdSql.execute("create table tb2 using stb tags('b2')")
        tdSql.execute("create table tb3 using stb tags('a3')")
        tdSql.execute(
            "create table strm as select count(*), avg(c1), first(c2) from stb where t1 like 'a%' interval(4s) sliding(2s)"
        )
        tdSql.query("describe strm")
        tdSql.checkRows(4)

        tdLog.sleep(1)
        tdSql.execute("insert into tb1 values (now, 0, 'tb1')")
        tdLog.sleep(4)
        tdSql.execute("insert into tb2 values (now, 2, 'tb2')")
        tdLog.sleep(4)
        tdSql.execute("insert into tb3 values (now, 0, 'tb3')")

        tdSql.waitedQuery("select * from strm", 4, 60)
        tdSql.checkRows(4)
        tdSql.checkData(0, 2, 0.000000000)
        if tdSql.getData(0, 3) == 'tb2':
            tdLog.exit("unexpected value of data03")
        if tdSql.getData(1, 3) == 'tb2':
            tdLog.exit("unexpected value of data13")
        if tdSql.getData(2, 3) == 'tb2':
            tdLog.exit("unexpected value of data23")
        if tdSql.getData(3, 3) == 'tb2':
            tdLog.exit("unexpected value of data33")

        tdLog.info("add table tb4 to see if stream still works correctly")
        # The vnode client needs to refresh metadata cache to allow strm calculate tb4's data.
        # But the current refreshing frequency is every 10 min
        # commented out the case below to save running time
        tdSql.execute("create table tb4 using stb tags('a4')")
        tdSql.execute("insert into tb4 values(now, 4, 'tb4')")
        tdSql.waitedQuery("select * from strm order by ts desc", 6, 60)
        tdSql.checkRows(6)
        tdSql.checkData(0, 2, 4)
        tdSql.checkData(0, 3, "tb4")

        tdLog.info("change tag values to see if stream still works correctly")
        tdSql.execute("alter table tb4 set tag t1='b4'")
        tdLog.sleep(3)
        tdSql.execute("insert into tb1 values (now, 1, 'tb1_a1')")
        tdLog.sleep(4)
        tdSql.execute("insert into tb4 values (now, -4, 'tb4_b4')")
        tdSql.waitedQuery("select * from strm order by ts desc", 8, 100)
        tdSql.checkRows(8)
        tdSql.checkData(0, 2, 1)
        tdSql.checkData(0, 3, "tb1_a1")
예제 #12
0
    def run(self):
        tdSql.query("show users")
        rows = tdSql.queryRows

        tdSql.execute("create user test PASS 'test' ")
        tdSql.query("show users")
        tdSql.checkRows(rows + 1)

        tdSql.error("create user tdenginetdenginetdengine PASS 'test' ")

        tdSql.error("create user tdenginet PASS '1234512345123456' ")

        try:
            tdSql.execute("create account a&cc PASS 'pass123'")
        except Exception as e:
            print("create account a&cc PASS 'pass123'")
            return

        tdLog.exit("drop built-in user is error.")
예제 #13
0
    def run(self):
        print("==============step1")
        try:
            tdSql.execute("create user &abc PASS 'pass123'")
        except Exception as e:
            print(e)

        print("==============step2")
        try:
            tdSql.execute("create user a&bc PASS 'pass123'")
        except Exception as e:
            print(e)

        print("==============step3")
        try:
            tdSql.execute("create user '涛思' PASS 'pass123'")
        except Exception as e:
            print(e)
            return

        tdLog.exit("create user with special character.")
예제 #14
0
    def run(self):
        tdSql.prepare()

        tdSql.execute("drop database if exists db")
        print("==============step1")
        tdSql.execute("create database db")
        tdSql.execute("create table db.st (ts timestamp, i int) tags(j int)")
        tdSql.execute("create table db.tb using st tags(1)")
        tdSql.execute("insert into db.tb values(now, 1)")

        print("==============step2")
        try:
            tdSql.execute("drop table db.st")
        except Exception as e:
            tdLog.exit(e)

        try:
            tdSql.execute("select * from db.st")
        except Exception as e:
            if e.args[0] != 'invalid table name':
                tdLog.exit(e)

        try:
            tdSql.execute("select * from db.tb")
        except Exception as e:
            if e.args[0] != 'invalid table name':
                tdLog.exit(e)
예제 #15
0
    def run(self):
        print("==========step1")
        print("drop built-in account")
        try:
            tdSql.execute("drop account root")
        except Exception as e:
            if len(e.args) > 0 and 'no rights' != e.args[0]:
                tdLog.exit(e)

        print("==========step2")
        print("drop built-in user")
        try:
            tdSql.execute("drop user root")
        except Exception as e:
            if len(e.args) > 0 and 'no rights' != e.args[0]:
                tdLog.exit(e)
            return

        tdLog.exit("drop built-in user is error.")
예제 #16
0
    def run(self):
        tdSql.prepare()
        # test case for https://jira.taosdata.com:18080/browse/TD-4735

        tdSql.execute('''create stable stable_1
                    (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, 
                    q_bool bool , q_binary binary(20) , q_nchar nchar(20) ,
                    q_float float , q_double double , q_ts timestamp) 
                    tags(loc nchar(20) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, 
                    t_bool bool , t_binary binary(20) , t_nchar nchar(20) ,
                    t_float float , t_double double , t_ts timestamp);''')
        tdSql.execute('''create table table_0 using stable_1 
                    tags('table_0' , '0' , '0' , '0' , '0' , 0 , '0' , '0' , '0' , '0' ,'0')'''
                      )
        tdSql.execute('''create table table_1 using stable_1 
                    tags('table_1' , '2147483647' , '9223372036854775807' , '32767' , '127' , 1 , 
                    'binary1' , 'nchar1' , '1' , '11' , \'1999-09-09 09:09:09.090\')'''
                      )
        tdSql.execute('''create table table_2 using stable_1 
                    tags('table_2' , '-2147483647' , '-9223372036854775807' , '-32767' , '-127' , false , 
                    'binary2' , 'nchar2nchar2' , '-2.2' , '-22.22' , \'2099-09-09 09:09:09.090\')'''
                      )
        tdSql.execute('''create table table_3 using stable_1 
                    tags('table_3' , '3' , '3' , '3' , '3' , true , 'binary3' , 'nchar3' , '33.33' , '3333.3333' , '0')'''
                      )
        tdSql.execute('''create table table_4 using stable_1 
                    tags('table_4' , '4' , '4' , '4' , '4' , false , 'binary4' , 'nchar4' , '-444.444' , '-444444.444444' , '0')'''
                      )
        tdSql.execute('''create table table_5 using stable_1 
                    tags('table_5' , '5' , '5' , '5' , '5' , true , 'binary5' , 'nchar5' , '5555.5555' , '55555555.55555555' , '0')'''
                      )
        #regular table
        tdSql.execute('''create table regular_table_1
                    (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, 
                    q_bool bool , q_binary binary(20) , q_nchar nchar(20) ,
                    q_float float , q_double double , q_ts timestamp) ;''')

        for i in range(self.num):
            tdSql.execute(
                '''insert into table_0 values(%d, %d, %d, %d, %d, 0, 'binary.%s', 'nchar.%s', %f, %f, %d)'''
                % (self.ts + i, i, i, i, i, i, i, i, i, self.ts + i))
            tdSql.execute(
                '''insert into table_1 values(%d, %d, %d, %d, %d, 1, 'binary1.%s', 'nchar1.%s', %f, %f, %d)'''
                % (self.ts + i, 2147483647 - i,
                   9223372036854775807 - i, 32767 - i, 127 - i, i, i,
                   random.random(), random.random(), 1262304000001 + i))
            tdSql.execute(
                '''insert into table_2 values(%d, %d, %d, %d, %d, true, 'binary2.%s', 'nchar2nchar2.%s', %f, %f, %d)'''
                % (self.ts + i, -2147483647 + i, -9223372036854775807 + i,
                   -32767 + i, -127 + i, i, i, random.uniform(
                       -1, 0), random.uniform(-1, 0), 1577836800001 + i))
            tdSql.execute(
                '''insert into table_3 values(%d, %d, %d, %d, %d, false, 'binary3.%s', 'nchar3.%s', %f, %f, %d)'''
                % (self.ts + i, random.randint(-2147483647, 2147483647),
                   random.randint(-9223372036854775807, 9223372036854775807),
                   random.randint(-32767, 32767), random.randint(-127, 127),
                   random.randint(-100, 100), random.randint(
                       -10000, 10000), random.uniform(-100000, 100000),
                   random.uniform(-1000000000, 1000000000), self.ts + i))
            tdSql.execute(
                '''insert into table_4 values(%d, %d, %d, %d, %d, true, 'binary4.%s', 'nchar4.%s', %f, %f, %d)'''
                % (self.ts + i, i, i, i, i, i, i, i, i, self.ts + i))
            tdSql.execute(
                '''insert into table_5 values(%d, %d, %d, %d, %d, false, 'binary5.%s', 'nchar5.%s', %f, %f, %d)'''
                % (self.ts + i, i, i, i, i, i, i, i, i, self.ts + i))

            tdSql.execute(
                '''insert into regular_table_1 values(%d, %d, %d, %d, %d, 0, 'binary.%s', 'nchar.%s', %f, %f, %d)'''
                % (self.ts + i, i, i, i, i, i, i, i, i, self.ts + i))
            tdSql.execute(
                '''insert into regular_table_1 values(%d, %d, %d, %d, %d, 1, 'binary1.%s', 'nchar1.%s', %f, %f, %d)'''
                % (self.ts + 100 + i, 2147483647 - i,
                   9223372036854775807 - i, 32767 - i, 127 - i, i, i,
                   random.random(), random.random(), 1262304000001 + i))
            tdSql.execute(
                '''insert into regular_table_1 values(%d, %d, %d, %d, %d, true, 'binary2.%s', 'nchar2nchar2.%s', %f, %f, %d)'''
                % (self.ts + 200 + i, -2147483647 + i, -9223372036854775807 +
                   i, -32767 + i, -127 + i, i, i, random.uniform(
                       -1, 0), random.uniform(-1, 0), 1577836800001 + i))
            tdSql.execute(
                '''insert into regular_table_1 values(%d, %d, %d, %d, %d, false, 'binary3.%s', 'nchar3.%s', %f, %f, %d)'''
                % (self.ts + 300 + i, random.randint(-2147483647, 2147483647),
                   random.randint(-9223372036854775807, 9223372036854775807),
                   random.randint(-32767, 32767), random.randint(-127, 127),
                   random.randint(-100, 100), random.randint(
                       -10000, 10000), random.uniform(-100000, 100000),
                   random.uniform(-1000000000, 1000000000), self.ts + i))
            tdSql.execute(
                '''insert into regular_table_1 values(%d, %d, %d, %d, %d, true, 'binary4.%s', 'nchar4.%s', %f, %f, %d)'''
                % (self.ts + 400 + i, i, i, i, i, i, i, i, i, self.ts + i))
            tdSql.execute(
                '''insert into regular_table_1 values(%d, %d, %d, %d, %d, false, 'binary5.%s', 'nchar5.%s', %f, %f, %d)'''
                % (self.ts + 500 + i, i, i, i, i, i, i, i, i, self.ts + i))

        sql = '''select * from stable_1'''
        tdSql.query(sql)
        tdSql.checkRows(6 * self.num)
        sql = '''select * from regular_table_1'''
        tdSql.query(sql)
        tdSql.checkRows(6 * self.num)

        tdLog.info("=======last_row(*)========")
        sql = '''select last_row(*) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkData(0, 1, self.num - 1)
        sql = '''select last_row(*) from regular_table_1;'''
        tdSql.query(sql)
        tdSql.checkData(0, 1, self.num - 1)

        sql = '''select * from stable_1 
                where loc = 'table_0';'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select last_row(*) from 
                (select * from stable_1 
                where loc = 'table_0');'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last_row(*) from 
                (select * from stable_1);'''
        tdSql.query(sql)
        tdSql.checkData(0, 1, self.num - 1)
        tdSql.checkData(0, 2, self.num - 1)
        tdSql.checkData(0, 3, self.num - 1)
        tdSql.checkData(0, 4, self.num - 1)
        tdSql.checkData(0, 5, 'False')
        tdSql.checkData(0, 6, 'binary5.9')
        tdSql.checkData(0, 7, 'nchar5.9')
        tdSql.checkData(0, 8, 9.00000)
        tdSql.checkData(0, 9, 9.000000000)
        tdSql.checkData(0, 10, '2020-09-13 20:26:40.009')
        tdSql.checkData(0, 11, 'table_5')
        tdSql.checkData(0, 12, 5)
        tdSql.checkData(0, 13, 5)
        tdSql.checkData(0, 14, 5)
        tdSql.checkData(0, 15, 5)
        tdSql.checkData(0, 16, 'True')
        tdSql.checkData(0, 17, 'binary5')
        tdSql.checkData(0, 18, 'nchar5')
        tdSql.checkData(0, 21, '1970-01-01 08:00:00.000')

        sql = '''select * from regular_table_1 ;'''
        tdSql.query(sql)
        tdSql.checkRows(6 * self.num)
        sql = '''select last_row(*) from 
                (select * from regular_table_1);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        tdSql.checkData(0, 1, self.num - 1)
        tdSql.checkData(0, 2, self.num - 1)
        tdSql.checkData(0, 3, self.num - 1)
        tdSql.checkData(0, 4, self.num - 1)
        tdSql.checkData(0, 5, 'False')
        tdSql.checkData(0, 6, 'binary5.9')
        tdSql.checkData(0, 7, 'nchar5.9')
        tdSql.checkData(0, 8, 9.00000)
        tdSql.checkData(0, 9, 9.000000000)
        tdSql.checkData(0, 10, '2020-09-13 20:26:40.009')

        # incorrect result, not support nest > 2
        sql = '''select last_row(*) from 
                ((select * from table_0) union all
                 (select * from table_1) union all
                 (select * from table_2));'''
        tdSql.error(sql)
        #tdSql.checkRows(1)
        #tdSql.checkData(0,1,self.num-1)
        #tdSql.checkData(0,2,self.num-1)
        #tdSql.checkData(0,3,self.num-1)
        #tdSql.checkData(0,4,self.num-1)
        #tdSql.checkData(0,5,'False')
        #tdSql.checkData(0,6,'binary.9')
        #tdSql.checkData(0,7,'nchar.9')
        #tdSql.checkData(0,8,9.00000)
        #tdSql.checkData(0,9,9.000000000)
        #tdSql.checkData(0,10,'2020-09-13 20:26:40.009')

        # bug 5055
        # sql = '''select last_row(*) from
        #         ((select * from stable_1) union all
        #          (select * from table_1) union all
        #          (select * from regular_table_1));'''
        # tdSql.query(sql)
        # tdSql.checkData(0,1,self.num-1)

        sql = '''select last_row(*) from 
                ((select last_row(*) from table_0) union all
                 (select last_row(*) from table_1) union all
                 (select last_row(*) from table_2));'''
        tdSql.error(sql)
        #tdSql.checkRows(1)
        #tdSql.checkData(0,1,self.num-1)
        #tdSql.checkData(0,2,self.num-1)
        #tdSql.checkData(0,3,self.num-1)
        #tdSql.checkData(0,4,self.num-1)
        #tdSql.checkData(0,5,'False')
        #tdSql.checkData(0,6,'binary.9')
        #tdSql.checkData(0,7,'nchar.9')
        #tdSql.checkData(0,8,9.00000)
        #tdSql.checkData(0,9,9.000000000)
        #tdSql.checkData(0,10,'2020-09-13 20:26:40.009')

        # bug 5055
        # sql = '''select last_row(*) from
        #         ((select last_row(*) from stable_1) union all
        #          (select last_row(*) from table_1) union all
        #          (select last_row(*) from regular_table_1));'''
        # tdSql.query(sql)
        # tdSql.checkData(0,1,self.num-1)

        sql = '''select last_row(*) from 
                ((select * from table_0 limit 5 offset 5) union all
                 (select * from table_1 limit 5 offset 5) union all
                 (select * from regular_table_1 limit 5 offset 5));'''
        tdSql.error(sql)
        #tdSql.checkRows(1)
        #tdSql.checkData(0,1,self.num-1)
        #tdSql.checkData(0,2,self.num-1)
        #tdSql.checkData(0,3,self.num-1)
        #tdSql.checkData(0,4,self.num-1)
        #tdSql.checkData(0,5,'False')
        #tdSql.checkData(0,6,'binary.9')
        #tdSql.checkData(0,7,'nchar.9')
        #tdSql.checkData(0,8,9.00000)
        #tdSql.checkData(0,9,9.000000000)
        #tdSql.checkData(0,10,'2020-09-13 20:26:40.009')

        sql = '''select last_row(*)  from 
                (select * from stable_1) 
                having q_int>5;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" having only works with group by")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info("invalid operation: having only works with group by")
예제 #17
0
    def run(self):
        tdSql.prepare()
        # test case for https://jira.taosdata.com:18080/browse/TD-5021

        tdLog.info("\n\n----------step1 : drop db and create db----------\n")
        tdSql.execute('''drop database if exists db ;''')
        tdSql.execute('''create database db ;''')
        sql = '''show databases;'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("\n\n----------step2 : create stable----------\n")
        tdSql.execute('''create stable 
                    db.stable_1 (ts timestamp, payload binary(256)) 
                    tags(t1 binary(16),t2 int);''')
        sql = '''show db.stables;'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("\n\n----------step3 : create table and insert----------\n")
        sql = '''insert into db.table1 using db.stable_1 (t1 , t2) tags ("table_1" , 111) ( values (now,  ;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" unexpected token")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info("DB error: syntax error near ', ;' (unexpected token)")

        sql = '''insert into db.table1(ts , payload) using db.stable_1 (t1 , t2) tags ("table_1" , 111) ( values (now,  ;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" bind columns again")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info(
                "DB error: syntax error near ', ;'  (bind columns again)")

        sql = '''insert into db.table1 using db.stable_1 (t1 , t2) tags ("table_1",111) (ts , payload) ( values (now,  ;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" keyword VALUES or FILE required ")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info(
                "DB error: invalid SQL:   (keyword VALUES or FILE required)")

        tdSql.execute('''insert into db.table1 using db.stable_1 (t1 , t2) 
                        tags ("table_1" , 111) values ( now , 1) ''')
        sql = '''select *  from db.stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        tdSql.checkData(0, 1, 1)
        tdSql.checkData(0, 2, 'table_1')

        tdLog.info(
            "\n\n----------step4 : create table and insert again----------\n")
        sql = '''insert into db.table2 using db.stable_1 (t1) tags ("table_2") ( values (now,  ;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" unexpected token")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info("DB error: syntax error near ', ;' (unexpected token)")

        tdSql.execute('''insert into db.table2 using db.stable_1 (t1) 
                        tags ("table_2") values ( now , 2) ''')
        sql = '''select *  from db.stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(2)
        tdSql.checkData(1, 1, 2)
        tdSql.checkData(1, 2, 'table_2')

        tdLog.info(
            "\n\n----------step5 : create table and insert without db----------\n"
        )
        tdSql.execute('''use db''')
        sql = '''insert into table3 using stable_1 (t1) tags ("table_3") ( values (now,  ;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" unexpected token")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info("DB error: syntax error near ', ;' (unexpected token)")

        tdSql.execute('''insert into table3 using stable_1 (t1 , t2) 
                        tags ("table_3" , 333) values ( now , 3) ''')
        sql = '''select *  from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(3)
        tdSql.checkData(2, 1, 3)
        tdSql.checkData(2, 2, 'table_3')

        tdLog.info(
            "\n\n----------step6 : create tables in one sql ----------\n")
        sql = '''insert into table4 using stable_1 (t1) tags ("table_4")  values (now, 4) 
                             table5 using stable_1 (t1) tags ("table_5") ( values (now,  ;'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" unexpected token")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info("DB error: syntax error near ', ;' (unexpected token)")

        tdSql.execute(
            '''insert into table4 using stable_1 (t1) tags ("table_4")  values (now, 4) 
                                     table5 using stable_1 (t1) tags ("table_5")  values (now, 5) '''
        )
        sql = '''select *  from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(5)
        tdSql.checkData(3, 1, 4)
        tdSql.checkData(3, 2, 'table_4')
        tdSql.checkData(4, 1, 5)
        tdSql.checkData(4, 2, 'table_5')

        sql = '''insert into table6 using stable_1 (t1) tags ("table_6")  ( values (now,  
                             table7 using stable_1 (t1) tags ("table_7")  values (now,  7);'''
        tdLog.info(sql)
        tdSql.error(sql)
        try:
            tdSql.execute(sql)
            tdLog.exit(" invalid SQL")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.info("invalid SQL")

        tdSql.execute(
            '''insert into table6 using stable_1 (t1 , t2) tags ("table_6" , 666)  values (now, 6) 
                                     table7 using stable_1 (t1) tags ("table_7")  values (now, 7) '''
        )
        sql = '''select *  from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(7)
        tdSql.checkData(5, 1, 6)
        tdSql.checkData(5, 2, 'table_6')
        tdSql.checkData(6, 1, 7)
        tdSql.checkData(6, 2, 'table_7')