Exemplo n.º 1
0
    def run(self):
        tbNum = 10
        rowNum = 20
        ts_begin = 1633017600000

        tdSql.prepare()

        tdLog.info("===== preparing data =====")
        tdSql.execute(
            "create table stb(ts timestamp, tbcol int, tbcol2 float) tags(tgcol int)"
        )
        for i in range(tbNum):
            tdSql.execute("create table tb%d using stb tags(%d)" % (i, i))
            for j in range(rowNum):
                tdSql.execute("insert into tb%d values (%d, %d, %d)" %
                              (i, ts_begin + j, j, j))
        time.sleep(0.1)

        self.createFuncStream("count(*)", "c1", 200)
        self.createFuncStream("count(tbcol)", "c2", 200)
        self.createFuncStream("count(tbcol2)", "c3", 200)
        self.createFuncStream("avg(tbcol)", "av", 9.5)
        self.createFuncStream("sum(tbcol)", "su", 1900)
        self.createFuncStream("min(tbcol)", "mi", 0)
        self.createFuncStream("max(tbcol)", "ma", 19)
        self.createFuncStream("first(tbcol)", "fi", 0)
        self.createFuncStream("last(tbcol)", "la", 19)
        #tdSql.query("select stddev(tbcol) from stb interval(1d)")
        #tdSql.query("select leastsquares(tbcol, 1, 1) from stb interval(1d)")
        tdSql.query("select top(tbcol, 1) from stb interval(1d)")
        tdSql.query("select bottom(tbcol, 1) from stb interval(1d)")
        #tdSql.query("select percentile(tbcol, 1) from stb interval(1d)")
        #tdSql.query("select diff(tbcol) from stb interval(1d)")

        tdSql.query(
            "select count(tbcol) from stb where ts < now + 4m interval(1d)")
        tdSql.checkData(0, 1, 200)
        #tdSql.execute("create table strm_wh as select count(tbcol) from stb where ts < now + 4m interval(1d)")

        self.createFuncStream("count(tbcol)", "as", 200)

        tdSql.query("select count(tbcol) from stb interval(1d) group by tgcol")
        tdSql.checkData(0, 1, 20)

        tdSql.query(
            "select count(tbcol) from stb where ts < now + 4m interval(1d) group by tgcol"
        )
        tdSql.checkData(0, 1, 20)

        self.checkStreamData("c1", 200)
        self.checkStreamData("c2", 200)
        self.checkStreamData("c3", 200)
        self.checkStreamData("av", 9.5)
        self.checkStreamData("su", 1900)
        self.checkStreamData("mi", 0)
        self.checkStreamData("ma", 19)
        self.checkStreamData("fi", 0)
        self.checkStreamData("la", 19)
        #self.checkStreamData("wh", 200)
        self.checkStreamData("as", 200)
Exemplo n.º 2
0
    def run(self):
        self.writeCSV()

        tdSql.prepare()
        tdSql.execute(
            "create table t1(ts timestamp, c1 int, c2 float, c3 int, c4 int)")
        startTime = time.time()
        tdSql.execute("insert into t1 file '%s'" % self.csvfile)
        duration = time.time() - startTime
        print("Insert time: %d" % duration)
        tdSql.query("select * from t1")
        tdSql.checkRows(self.rows)

        tdSql.execute(
            "create table stb(ts timestamp, c1 int, c2 float, c3 int, c4 int) tags(t1 int, t2 binary(20))"
        )
        tdSql.execute("insert into t2 using stb(t1) tags(1) file '%s'" %
                      self.csvfile)
        tdSql.query("select * from stb")
        tdSql.checkRows(self.rows)

        tdSql.execute("insert into t3 using stb tags(1, 'test') file '%s'" %
                      self.csvfile)
        tdSql.query("select * from stb")
        tdSql.checkRows(self.rows * 2)
Exemplo n.º 3
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)
Exemplo n.º 4
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute(
            "create table if not exists stb (ts timestamp, col1 int, col2 int, col3 int) tags(loc nchar(20), id int)")
                
        currTs = self.ts

        for i in range(100):
            sql = "create table tb%d using stb tags('city%d', 1)" % (i, i)
            tdSql.execute(sql)

            sql = "insert into tb%d values" % i            
            for j in range(5):
                val = 1 + j
                sql += "(%d, %d, %d, %d)" % (currTs, val, val, val)
                currTs += 1000000
            tdSql.execute(sql)    

        tdSql.query("select first(col1) - avg(col1) from stb where ts > '2018-09-17 08:00:00.000' and ts < '2018-09-23 04:36:40.000' interval(1h)")
        tdSql.checkRows(139)        

        tdSql.query("select first(col1) - avg(col1) from stb where ts > '2018-09-17 08:00:00.000' and ts < '2018-09-23 04:36:40.000' interval(1h) fill(null)")
        tdSql.checkRows(141)
        tdSql.checkData(0, 1, None)
        tdSql.checkData(140, 1, None)       

        tdSql.query("select max(col1) - min(col1) from stb where ts > '2018-09-17 08:00:00.000' and ts < '2018-09-23 04:36:40.000' and id = 1 group by loc, id")
        rows = tdSql.queryRows

        tdSql.query("select spread(col1) from stb where ts > '2018-09-17 08:00:00.000' and ts < '2018-09-23 04:36:40.000' and id = 1 group by loc, id")
        tdSql.checkRows(rows)
Exemplo n.º 5
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute(
            "CREATE TABLE IF NOT EXISTS ampere (ts TIMESTAMP,ampere DOUBLE) TAGS (device_name BINARY(50),build_id BINARY(50),project_id BINARY(50),alias BINARY(50))")
        tdSql.execute("insert into d1001 using ampere tags('test', '2', '2', '2') VALUES (now, 123)")
        tdSql.execute("ALTER TABLE ampere ADD TAG variable_id BINARY(50)")

        print("==============step2")

        tdSql.execute("insert into d1002 using ampere tags('test', '2', '2', '2', 'test') VALUES (now, 124)")

        tdSql.query("select * from ampere")
        tdSql.checkRows(2)
        tdSql.checkData(0, 6, None)
        tdSql.checkData(1, 6, 'test')

        # Test case for: https://jira.taosdata.com:18080/browse/TD-2423 
        tdSql.execute("create table stb(ts timestamp, col1 int, col2 nchar(20)) tags(tg1 int, tg2 binary(20), tg3 nchar(25))")
        tdSql.execute("insert into tb1 using stb(tg1, tg3) tags(1, 'test1') values(now, 1, 'test1')")        
        tdSql.query("select *, tg1, tg2, tg3 from tb1")
        tdSql.checkRows(1)
        tdSql.checkData(0, 3, 1)
        tdSql.checkData(0, 4, None)
        tdSql.checkData(0, 5, 'test1')

        tdSql.execute("create table tb2 using stb(tg3, tg2) tags('test3', 'test2')")
        tdSql.query("select tg1, tg2, tg3 from tb2")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, None)
        tdSql.checkData(0, 1, 'test2')
        tdSql.checkData(0, 2, 'test3')
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute("create database if not exists demo;")
        tdSql.execute("use demo;")
        tdSql.execute(
            "CREATE TABLE IF NOT EXISTS test1 (ts TIMESTAMP, ValueID int, "
            "VariantValue float, Quality int, Flags int);")
        tdSql.execute(
            "CREATE TABLE IF NOT EXISTS test2 (ts TIMESTAMP, ValueID int, "
            "VariantValue float, Quality int, Flags int);")
        ordered_csv = __file__.split('query')[0] + 'test_data/ordered.csv'
        disordered_csv = __file__.split(
            'query')[0] + 'test_data/disordered.csv'

        tdSql.execute(
            " insert into test1 file '{file}';".format(file=ordered_csv))
        tdSql.execute(
            " insert into test2 file '{file}';".format(file=disordered_csv))
        print("==============insert into test1 and test2 form test file")

        print("==============step2")
        tdSql.query('select * from test1;')
        with open(ordered_csv) as f1:
            num1 = len(f1.readlines())
        tdSql.checkRows(num1)

        tdSql.query('select * from test2;')
        with open(disordered_csv) as f2:
            num2 = len(f2.readlines())
        tdSql.checkRows(num2)
        print("=============execute select count(*) from xxx")
Exemplo n.º 7
0
    def run(self):
        tdSql.prepare()

        tdSql.execute("create table cars(ts timestamp, s int) tags(id int)")
        tdSql.execute("create table car0 using cars tags(0)")
        tdSql.execute("create table car1 using cars tags(1)")
        tdSql.execute("create table car2 using cars tags(2)")
        tdSql.execute("create table car3 using cars tags(3)")
        tdSql.execute("create table car4 using cars tags(4)")

        tdSql.execute("insert into car0 values('2019-01-01 00:00:00.103', 1)")
        tdSql.execute("insert into car1 values('2019-01-01 00:00:00.234', 1)")
        tdSql.execute("insert into car0 values('2019-01-01 00:00:01.012', 1)")
        tdSql.execute("insert into car0 values('2019-01-01 00:00:02.003', 1)")
        tdSql.execute("insert into car2 values('2019-01-01 00:00:02.328', 1)")
        tdSql.execute("insert into car0 values('2019-01-01 00:00:03.139', 1)")
        tdSql.execute("insert into car0 values('2019-01-01 00:00:04.348', 1)")
        tdSql.execute("insert into car0 values('2019-01-01 00:00:05.783', 1)")
        tdSql.execute("insert into car1 values('2019-01-01 00:00:01.893', 1)")
        tdSql.execute("insert into car1 values('2019-01-01 00:00:02.712', 1)")
        tdSql.execute("insert into car1 values('2019-01-01 00:00:03.982', 1)")
        tdSql.execute("insert into car3 values('2019-01-01 00:00:01.389', 1)")
        tdSql.execute("insert into car4 values('2019-01-01 00:00:01.829', 1)")

        tdSql.error("create table strm as select count(*) from cars")

        tdSql.execute(
            "create table strm as select count(*) from cars interval(4s)")
        tdSql.waitedQuery("select * from strm", 2, 100)
        tdSql.checkData(0, 1, 11)
        tdSql.checkData(1, 1, 2)
Exemplo n.º 8
0
    def run(self):
        tdSql.prepare()

        startTime = time.time()
        print("==============step1")
        sql = "create table stb(ts timestamp, "
        for i in range(1022):
            sql += "col%d binary(14), " % (i + 1)
        sql += "col1023 binary(22))"
        tdSql.execute(sql)

        for i in range(4096):
            sql = "insert into stb values(%d, "
            for j in range(1022):
                str = "'%s', " % self.get_random_string(14)
                sql += str
            sql += "'%s')" % self.get_random_string(22)
            tdSql.execute(sql % (self.ts + i))

        tdSql.query("select * from stb")
        tdSql.checkRows(4096)

        tdDnodes.stop(1)
        tdDnodes.start(1)

        tdSql.query("select * from stb")
        tdSql.checkRows(4096)

        endTime = time.time()

        print("total time %ds" % (endTime - startTime))
Exemplo n.º 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)

        # 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)
Exemplo n.º 10
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "create table stest(ts timestamp,size INT,filenum INT) tags (appname binary(500),tenant binary(500))"
        )
        tdSql.execute(
            "insert into test1 using stest tags('test1','aaa') values ('2020-09-04 16:53:54.003',210,3)"
        )
        tdSql.execute(
            "insert into test2 using stest tags('test1','aaa') values ('2020-09-04 16:53:56.003',210,3)"
        )
        tdSql.execute(
            "insert into test11 using stest tags('test11','bbb') values ('2020-09-04 16:53:57.003',210,3)"
        )
        tdSql.execute(
            "insert into test12 using stest tags('test11','bbb') values ('2020-09-04 16:53:58.003',210,3)"
        )
        tdSql.execute(
            "insert into test21 using stest tags('test21','ccc') values ('2020-09-04 16:53:59.003',210,3)"
        )
        tdSql.execute(
            "insert into test22 using stest tags('test21','ccc') values ('2020-09-04 16:54:54.003',210,3)"
        )

        tdSql.query(
            "select sum(size) from stest interval(1d) group by appname")
        tdSql.checkRows(3)
Exemplo n.º 11
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "create table meters(ts timestamp, col1 int) tags(id int, loc nchar(20))"
        )
        sql = "insert into t0 using meters tags(1, 'beijing') values"
        for i in range(100):
            sql += "(%d, %d)" % (self.ts + i * 1000, random.randint(1, 100))
        tdSql.execute(sql)

        sql = "insert into t1 using meters tags(2, 'shanghai') values"
        for i in range(100):
            sql += "(%d, %d)" % (self.ts + i * 1000, random.randint(1, 100))
        tdSql.execute(sql)

        tdSql.query("select count(*) from meters interval(10s) sliding(5s)")
        tdSql.checkRows(21)

        tdSql.error("select count(*) from meters sliding(5s)")

        tdSql.error("select count(*) from meters sliding(5s) interval(10s)")

        tdSql.error("select * from meters sliding(5s) order by ts desc")

        tdSql.query("select count(*) from meters group by loc")
        tdSql.checkRows(2)

        tdSql.error("select * from meters group by loc sliding(5s)")
Exemplo n.º 12
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "create table st(ts timestamp, c1 int) tags(loc nchar(20))")
        tdSql.execute("create table t0 using st tags('nchar0')")
        tdSql.execute("create table t1 using st tags('nchar1')")
        tdSql.execute("create table t2 using st tags('nchar2')")
        tdSql.execute("create table t3 using st tags('nchar3')")
        tdSql.execute("create table t4 using st tags('nchar4')")
        tdSql.execute("create table t5 using st tags('nchar5')")

        for i in range(self.num):
            tdSql.execute("insert into t0 values(%d, %d)" % (self.ts + i, i))
            tdSql.execute("insert into t1 values(%d, %d)" % (self.ts + i, i))
            tdSql.execute("insert into t2 values(%d, %d)" % (self.ts + i, i))
            tdSql.execute("insert into t3 values(%d, %d)" % (self.ts + i, i))
            tdSql.execute("insert into t4 values(%d, %d)" % (self.ts + i, i))
            tdSql.execute("insert into t5 values(%d, %d)" % (self.ts + i, i))

        sql = ''' select * from st where loc = 'nchar0' limit 1 union all select * from st where loc = 'nchar1' limit 1 union all select * from st where loc = 'nchar2' limit 1
            union all select * from st where loc = 'nchar3' limit 1 union all select * from st where loc = 'nchar4' limit 1'''
        tdSql.query(sql)
        tdSql.checkRows(5)

        sql = ''' select * from st where loc = 'nchar0' limit 1 union all select * from st where loc = 'nchar1' limit 1 union all select * from st where loc = 'nchar2' limit 1
            union all select * from st where loc = 'nchar3' limit 1 union all select * from st where loc = 'nchar4' limit 1 union all select * from st where loc = 'nchar5' limit 1'''
        tdSql.query(sql)
        tdSql.checkRows(6)
Exemplo n.º 13
0
    def datatypes(self):
        tdLog.debug("begin data types")
        tdSql.prepare()
        tdSql.execute(
            "create table stb3 (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(15), c6 nchar(15), c7 bool) tags(t1 int, t2 binary(15))"
        )
        tdSql.execute("create table tb0 using stb3 tags(0, 'tb0')")
        tdSql.execute("create table tb1 using stb3 tags(1, 'tb1')")
        tdSql.execute("create table tb2 using stb3 tags(2, 'tb2')")
        tdSql.execute("create table tb3 using stb3 tags(3, 'tb3')")
        tdSql.execute("create table tb4 using stb3 tags(4, 'tb4')")

        tdSql.execute(
            "create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5), last(c6) from stb3 where ts < now + 30s interval(4s) sliding(2s)"
        )
        #tdSql.execute("create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5) from stb where ts < now + 30s interval(4s) sliding(2s)")
        tdLog.sleep(1)
        tdSql.execute(
            "insert into tb0 values (now, 0, 0, 0, 0, 'binary0', '涛思0', true) tb1 values (now, 1, 1, 1, 1, 'binary1', '涛思1', false) tb2 values (now, 2, 2, 2, 2, 'binary2', '涛思2', true) tb3 values (now, 3, 3, 3, 3, 'binary3', '涛思3', false) tb4 values (now, 4, 4, 4, 4, 'binary4', '涛思4', true) "
        )

        tdSql.waitedQuery("select * from strm0 order by ts desc", 2, 120)
        tdSql.checkRows(2)

        tdSql.execute(
            "insert into tb0 values (now, 10, 10, 10, 10, 'binary0', '涛思0', true) tb1 values (now, 11, 11, 11, 11, 'binary1', '涛思1', false) tb2 values (now, 12, 12, 12, 12, 'binary2', '涛思2', true) tb3 values (now, 13, 13, 13, 13, 'binary3', '涛思3', false) tb4 values (now, 14, 14, 14, 14, 'binary4', '涛思4', true) "
        )
        tdSql.waitedQuery("select * from strm0 order by ts desc", 4, 120)
        tdSql.checkRows(4)
Exemplo n.º 14
0
    def run(self):
        tdSql.prepare()

        print("==============step1")

        tdLog.info("create database and table")
        tdSql.execute("create database db_test")
        tdSql.execute(
            "create table if not exists db_test.st(ts timestamp, tagtype int) tags(dev nchar(50))"
        )
        tdSql.execute(
            "CREATE TABLE if not exists db_test.dev_001 using db_test.st tags('dev_01')"
        )

        print("==============step2")
        tdLog.info("alter table add column")
        tdSql.execute(
            "ALTER TABLE db_test.st add COLUMN tag_version nchar(20)")
        tdSql.query("describe db_test.st")
        tdSql.checkRows(4)

        print("==============step3")
        tdLog.info("alter table drop column")
        tdSql.execute("ALTER TABLE db_test.st drop COLUMN tag_version")
        tdSql.query("describe db_test.st")
        tdSql.checkRows(3)

        print("==============step4")
        tdLog.info("drop table")
        tdSql.execute("drop table db_test.st")
        tdSql.execute(
            "create table if not exists db_test.st(ts timestamp, tagtype int) tags(dev nchar(50))"
        )
        tdSql.execute(
            "CREATE TABLE if not exists db_test.dev_001 using db_test.st tags('dev_01')"
        )
        tdSql.execute(
            "INSERT INTO db_test.dev_001 VALUES ('2020-05-13 10:00:00.000', 1)"
        )
        tdSql.query("select * from db_test.dev_001")
        tdSql.checkRows(1)

        print("==============step5")
        tdLog.info("alter table add column")
        tdSql.execute(
            "ALTER TABLE db_test.st add COLUMN tag_version nchar(20)")
        tdSql.query("describe db_test.st")
        tdSql.checkRows(4)

        tdSql.execute(
            "INSERT INTO db_test.dev_001 VALUES ('2020-05-13 10:00:00.010', 1, '1.2.1')"
        )
        tdSql.query("select * from db_test.st")
        tdSql.checkRows(2)

        print("==============step6")
        tdLog.info("alter table drop column")
        tdSql.execute("ALTER TABLE db_test.st drop COLUMN tag_version")
        tdSql.query("describe db_test.st")
        tdSql.checkRows(3)
Exemplo n.º 15
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")
Exemplo n.º 16
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)
Exemplo n.º 17
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "create table st (ts timestamp, voltage int) tags (loc nchar(30))")
        tdSql.execute(
            "insert into t0 using st tags('beijing') values(now, 220) (now - 15d, 221) (now - 30d, 225) (now - 35d, 228) (now - 45d, 222)"
        )
        tdSql.execute(
            "insert into t1 using st tags('shanghai') values(now, 220) (now - 60d, 221) (now - 50d, 225) (now - 40d, 228) (now - 20d, 222)"
        )

        tdSql.query("select avg(voltage) from st interval(1n)")
        tdSql.checkRows(3)
        tdSql.checkData(0, 1, 223.0)
        tdSql.checkData(1, 1, 225.0)
        tdSql.checkData(2, 1, 220.333333)

        tdSql.query("select avg(voltage) from st interval(1n, 15d)")
        tdSql.checkRows(3)
        tdSql.checkData(0, 1, 224.8)
        tdSql.checkData(1, 1, 222.666666)
        tdSql.checkData(2, 1, 220.0)

        tdSql.query(
            "select avg(voltage) from st interval(1n, 15d) group by loc")
        tdSql.checkRows(6)
        tdSql.checkData(0, 1, 225.0)
        tdSql.checkData(1, 1, 223.0)
        tdSql.checkData(2, 1, 220.0)
        tdSql.checkData(3, 1, 224.666666)
        tdSql.checkData(4, 1, 222.0)
        tdSql.checkData(5, 1, 220.0)
Exemplo n.º 18
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute(
            "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50))"
        )
        tdSql.execute(
            'CREATE TABLE if not exists dev_001 using st tags("dev_01")')
        tdSql.execute(
            'CREATE TABLE if not exists dev_002 using st tags("dev_02")')

        print("==============step2")

        tdSql.execute(
            """INSERT INTO dev_001(ts, tagtype) VALUES('2020-05-13 10:00:00.000', 1),
            ('2020-05-13 10:00:00.001', 1)
             dev_002 VALUES('2020-05-13 10:00:00.001', 1)""")

        tdSql.query("select * from db.st where dev='dev_01'")
        tdSql.checkRows(2)

        tdSql.query("select * from db.st where dev='dev_02'")
        tdSql.checkRows(1)

        #For: https://jira.taosdata.com:18080/browse/TD-2671
        print("==============step3")
        tdSql.execute(
            "create stable if not exists stb (ts timestamp, tagtype int) tags(dev nchar(50))"
        )
        tdSql.execute(
            'CREATE TABLE if not exists dev_01 using stb tags("dev_01")')
        tdSql.execute(
            'CREATE TABLE if not exists dev_02 using stb tags("dev_02")')

        print("==============step4")

        tdSql.execute(
            """INSERT INTO dev_01(ts, tagtype) VALUES('2020-05-13 10:00:00.000', 1),
            ('2020-05-13 10:00:00.001', 1)
             dev_02 VALUES('2020-05-13 10:00:00.001', 1)""")

        tdSql.query("select * from db.stb where dev='dev_01'")
        tdSql.checkRows(2)

        tdSql.query("select * from db.stb where dev='dev_02'")
        tdSql.checkRows(1)

        tdSql.query("describe db.stb")
        tdSql.checkRows(3)

        tdSql.execute("alter stable db.stb add tag t1 int")
        tdSql.query("describe db.stb")
        tdSql.checkRows(4)

        tdSql.execute("drop stable db.stb")
        tdSql.query("show stables")
        tdSql.checkRows(1)
Exemplo n.º 19
0
    def run(self):
        tdSql.prepare()

        tdSql.execute("create table st (ts timestamp, voltage int) tags (loc nchar(30))")
        tdSql.execute("insert into t0 using st tags('beijing') values(%d, 220) (%d, 221) (%d, 225) (%d, 228) (%d, 222)" 
                        % (self.ts, self.ts + 1000000000, self.ts + 2000000000, self.ts + 3000000000, self.ts + 6000000000))
        tdSql.execute("insert into t1 using st tags('shanghai') values(%d, 220) (%d, 221) (%d, 225) (%d, 228) (%d, 222)" 
                        % (self.ts, self.ts + 2000000000, self.ts + 4000000000, self.ts + 5000000000, self.ts + 7000000000))             
                

        tdSql.query("select avg(voltage) from st interval(1n)")
        tdSql.checkRows(3)        
        tdSql.checkData(0, 0, "2020-07-01 00:00:00")
        tdSql.checkData(0, 1, 221.4)        
        tdSql.checkData(1, 0, "2020-08-01 00:00:00")
        tdSql.checkData(1, 1, 227.0)        
        tdSql.checkData(2, 0, "2020-09-01 00:00:00")
        tdSql.checkData(2, 1, 222.0)
        
        tdSql.query("select avg(voltage) from st interval(1n, 15d)")
        tdSql.checkRows(4)
        tdSql.checkData(0, 0, "2020-06-16 00:00:00")
        tdSql.checkData(0, 1, 220.333333)
        tdSql.checkData(1, 0, "2020-07-16 00:00:00")
        tdSql.checkData(1, 1, 224.666666)
        tdSql.checkData(2, 0, "2020-08-16 00:00:00")
        tdSql.checkData(2, 1, 225.0)
        tdSql.checkData(3, 0, "2020-09-16 00:00:00")
        tdSql.checkData(3, 1, 222.0)

        tdSql.query("select avg(voltage) from st interval(1n, 15d) group by loc")
        tdSql.checkRows(7)
        tdSql.checkData(0, 0, "2020-06-16 00:00:00")
        tdSql.checkData(0, 1, 220.5)
        tdSql.checkData(1, 0, "2020-07-16 00:00:00")
        tdSql.checkData(1, 1, 226.5)
        tdSql.checkData(2, 0, "2020-08-16 00:00:00")
        tdSql.checkData(2, 1, 222.0)
        tdSql.checkData(3, 0, "2020-06-16 00:00:00")
        tdSql.checkData(3, 1, 220.0)
        tdSql.checkData(4, 0, "2020-07-16 00:00:00")
        tdSql.checkData(4, 1, 221.0)
        tdSql.checkData(5, 0, "2020-08-16 00:00:00")
        tdSql.checkData(5, 1, 226.5)
        tdSql.checkData(6, 0, "2020-09-16 00:00:00")
        tdSql.checkData(6, 1, 222.0)

        # test case for https://jira.taosdata.com:18080/browse/TD-2298
        tdSql.execute("create database test keep 36500")
        tdSql.execute("use test")
        tdSql.execute("create table t (ts timestamp, voltage int)")
        for i in range(10000):
            tdSql.execute("insert into t values(%d, 0)" % (1000000 + i * 6000))
        
        tdDnodes.stop(1)
        tdDnodes.start(1)
        tdSql.query("select last(*) from t interval(1s)")
        tdSql.checkRows(10000)
Exemplo n.º 20
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute("create table if not exists tb (ts timestamp, col1 int)")
        tdSql.execute("insert into tb values(%d, 1)" % self.ts)

        print("==============step2")
        tdSql.query("select * from tb")
        tdSql.checkRows(1)

        p = Process(target=self.updateMetadata, args=())
        p.start()
        p.join()
        p.terminate()

        tdSql.execute("insert into tb(ts, col1, col2) values(%d, 1, 2)" %
                      (self.ts + 2))

        print("==============step2")
        tdSql.query("select * from tb")
        tdSql.checkRows(2)

        # Add test case: https://jira.taosdata.com:18080/browse/TD-3474

        print("==============step1")
        tdSql.execute("create database test")
        tdSql.execute("use test")
        tdSql.execute(
            "create table if not exists stb (ts timestamp, col1 int) tags(areaid int, city nchar(20))"
        )

        for i in range(self.tables):
            city = "beijing" if i % 2 == 0 else "shanghai"
            tdSql.execute("create table tb%d using stb tags(%d, '%s')" %
                          (i, i, city))
            for j in range(self.rows):
                tdSql.execute("insert into tb%d values(%d, %d)" %
                              (i, self.ts + j, j * 100000))

        tdSql.query("select count(*) from stb")
        tdSql.checkData(0, 0, 10000)

        tdSql.query("select count(*) from tb1")
        tdSql.checkData(0, 0, 1000)

        p = Process(target=self.deleteTableAndRecreate, args=())
        p.start()
        p.join()
        p.terminate()

        tdSql.query("select count(*) from stb")
        tdSql.checkData(0, 0, 10000)

        tdSql.query("select count(*) from tb1")
        tdSql.checkData(0, 0, 1000)
Exemplo n.º 21
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute(
            "create table db.cars(ts timestamp, c int) tags(id int);")
        tdSql.execute("create database db2")
        tdSql.error("create table db2.car1 using db.cars tags(1)")
        tdSql.error(
            "insert into db2.car1 using db1.cars tags(1) values(now, 1);")
Exemplo n.º 22
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")
Exemplo n.º 23
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "CREATE TABLE meters (ts timestamp, current float, voltage int, phase float) TAGS (location binary(64), groupId int, t3 float, t4 double)"
        )
        tdSql.execute(
            "CREATE TABLE D1001 USING meters TAGS ('Beijing.Chaoyang', 2 , NULL, NULL)"
        )
        tdSql.execute(
            "CREATE TABLE D1002 USING meters TAGS ('Beijing.Chaoyang', 3 , NULL , 1.7)"
        )
        tdSql.execute(
            "CREATE TABLE D1003 USING meters TAGS ('Beijing.Chaoyang', 3 , 1.1 , 1.7)"
        )
        tdSql.execute(
            "INSERT INTO D1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33) (1538548696800, 12.3, 221, 0.31)"
        )
        tdSql.execute(
            "INSERT INTO D1002 VALUES (1538548685001, 10.5, 220, 0.28)  (1538548696800, 12.3, 221, 0.31)"
        )
        tdSql.execute(
            "INSERT INTO D1003 VALUES (1538548685001, 10.5, 220, 0.28)  (1538548696800, 12.3, 221, 0.31)"
        )
        tdSql.query(
            "SELECT SUM(current), AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by ts DESC"
        )
        tdSql.checkRows(3)
        tdSql.checkData(0, 0, "2018-10-03 14:38:16")
        tdSql.checkData(1, 0, "2018-10-03 14:38:15")
        tdSql.checkData(2, 0, "2018-10-03 14:38:05")

        tdSql.query(
            "SELECT SUM(current), AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by ts ASC"
        )
        tdSql.checkRows(3)
        tdSql.checkData(0, 0, "2018-10-03 14:38:05")
        tdSql.checkData(1, 0, "2018-10-03 14:38:15")
        tdSql.checkData(2, 0, "2018-10-03 14:38:16")

        tdSql.error(
            "SELECT SUM(current) as s, AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by s ASC"
        )

        tdSql.error(
            "SELECT SUM(current) as s, AVG(voltage) FROM meters WHERE groupId > 1 INTERVAL(1s) GROUP BY location order by s DESC"
        )

        #add for TD-3170
        tdSql.query("select avg(current) from meters group by t3;")
        tdSql.checkData(0, 0, 11.6)
        tdSql.query("select avg(current) from meters group by t4;")
        tdSql.query("select avg(current) from meters group by t3,t4;")
Exemplo n.º 24
0
    def run(self):
        tdSql.prepare()

        print("test case for TS-783")
        tdSql.execute("drop table if exists db.state1;")
        tdSql.execute("create table db.state1 (ts timestamp, c1 int);")
        tdSql.error("create table db.test1 using db.state1 tags('tt');")

        tdSql.execute("drop table if exists db.state2;")
        tdSql.execute("create table db.state2 (ts timestamp, c1 int) tags (t binary(20));")
        tdSql.query("create table db.test2 using db.state2 tags('tt');")
        tdSql.error("create table db.test22 using db.test2 tags('tt');")
Exemplo n.º 25
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "create table st (ts timestamp, voltage int) tags (loc nchar(30))")
        tdSql.execute(
            "insert into t0 using st tags('beijing') values(%d, 220) (%d, 221) (%d, 225) (%d, 228) (%d, 222)"
            % (self.ts, self.ts + 1000000000, self.ts + 2000000000,
               self.ts + 3000000000, self.ts + 6000000000))
        tdSql.execute(
            "insert into t1 using st tags('shanghai') values(%d, 220) (%d, 221) (%d, 225) (%d, 228) (%d, 222)"
            % (self.ts, self.ts + 2000000000, self.ts + 4000000000,
               self.ts + 5000000000, self.ts + 7000000000))

        tdSql.query("select avg(voltage) from st interval(1n)")
        tdSql.checkRows(3)
        tdSql.checkData(0, 0, "2020-07-01 00:00:00")
        tdSql.checkData(0, 1, 221.4)
        tdSql.checkData(1, 0, "2020-08-01 00:00:00")
        tdSql.checkData(1, 1, 227.0)
        tdSql.checkData(2, 0, "2020-09-01 00:00:00")
        tdSql.checkData(2, 1, 222.0)

        tdSql.query("select avg(voltage) from st interval(1n, 15d)")
        tdSql.checkRows(4)
        tdSql.checkData(0, 0, "2020-06-16 00:00:00")
        tdSql.checkData(0, 1, 220.333333)
        tdSql.checkData(1, 0, "2020-07-16 00:00:00")
        tdSql.checkData(1, 1, 224.666666)
        tdSql.checkData(2, 0, "2020-08-16 00:00:00")
        tdSql.checkData(2, 1, 225.0)
        tdSql.checkData(3, 0, "2020-09-16 00:00:00")
        tdSql.checkData(3, 1, 222.0)

        tdSql.query(
            "select avg(voltage) from st interval(1n, 15d) group by loc")
        tdSql.checkRows(7)
        tdSql.checkData(0, 0, "2020-06-16 00:00:00")
        tdSql.checkData(0, 1, 220.5)
        tdSql.checkData(1, 0, "2020-07-16 00:00:00")
        tdSql.checkData(1, 1, 226.5)
        tdSql.checkData(2, 0, "2020-08-16 00:00:00")
        tdSql.checkData(2, 1, 222.0)
        tdSql.checkData(3, 0, "2020-06-16 00:00:00")
        tdSql.checkData(3, 1, 220.0)
        tdSql.checkData(4, 0, "2020-07-16 00:00:00")
        tdSql.checkData(4, 1, 221.0)
        tdSql.checkData(5, 0, "2020-08-16 00:00:00")
        tdSql.checkData(5, 1, 226.5)
        tdSql.checkData(6, 0, "2020-09-16 00:00:00")
        tdSql.checkData(6, 1, 222.0)
Exemplo n.º 26
0
 def run(self):
     tdSql.prepare()
     self.checkTbColTypeOperator()
     self.checkStbColTypeOperator()
     self.checkTbMultiExpression()
     self.checkStbMultiExpression()
     self.checkTbMultiIn()
     self.checkStbMultiIn()
     self.checkTbMultiLike()
     self.checkStbMultiLike()
     self.checkTbPreCal()
     self.checkStbPreCal()
     self.checkMultiTb()
     self.checkMultiStb()
Exemplo n.º 27
0
    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute(
            "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(5))"
        )
        tdSql.error(
            'CREATE TABLE if not exists dev_001 using st tags("dev_001")')
        tdSql.execute(
            'CREATE TABLE if not exists dev_002 using st tags("dev")')

        print("==============step2")
        tdSql.query("show tables")
        tdSql.checkRows(1)
Exemplo n.º 28
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)
Exemplo n.º 29
0
    def run(self):
        tdSql.prepare()

        tdSql.execute(
            "create table stb(ts timestamp,i int) tags (p_id nchar(20));")
        tdSql.execute(
            "insert into tb using stb tags('11231') values (%d, %d) (%d, %d) (%d, %d) (%d, %d)"
            % (self.ts, 12, self.ts + 1, 15, self.ts + 2, 15, self.ts + 3, 12))

        tdSql.query(
            ''' select last(ts) p_time,i from stb where p_id='11231' and ts>=%d and ts <=%d 
            group by i order by time desc limit 100 ''' %
            (self.ts, self.ts + 4))
        tdSql.checkRows(2)
        tdSql.checkData(0, 0, "2018-09-17 09:00:00.003000")
        tdSql.checkData(1, 0, "2018-09-17 09:00:00.002000")
Exemplo n.º 30
0
    def run(self):
        # tdSql.execute("drop database db ")
        tdSql.prepare()
        tdSql.execute("create table st (ts timestamp, num int,  value int) tags (loc nchar(30))")
        for i in range(self.tables):
            for j in range(self.rowsPerTable): 
                args1=(i, i, self.ts + i * self.rowsPerTable + j * 10000, i, random.randint(1, 100))              
                tdSql.execute("insert into t%d using st tags('beijing%d')  values(%d, %d, %d)" % args1)
                
        tdSql.query("select * from (select * from st)")
        tdSql.checkRows(self.tables * self.rowsPerTable)

        tdSql.query("select * from (select * from st limit 10)")
        tdSql.checkRows(10)

        tdSql.query("select * from (select * from st order by ts desc limit 10)")
        tdSql.checkRows(10)

        # bug: https://jira.taosdata.com:18080/browse/TD-5043
        tdSql.query("select * from (select * from st order by ts desc limit 10 offset 1000)")
        tdSql.checkRows(0)

        tdSql.query("select avg(value), sum(value) from st group by tbname")
        tdSql.checkRows(self.tables)

        tdSql.query("select * from (select avg(value), sum(value) from st group by tbname)")
        tdSql.checkRows(self.tables)

        tdSql.query("select avg(value), sum(value) from st group by tbname slimit 5")
        tdSql.checkRows(5)

        tdSql.query("select * from (select avg(value), sum(value) from st group by tbname slimit 5)")
        tdSql.checkRows(5)

        tdSql.query("select avg(value), sum(value) from st group by tbname slimit 5 soffset 7")
        tdSql.checkRows(3)

        tdSql.query("select * from (select avg(value), sum(value) from st group by tbname slimit 5 soffset 7)")
        tdSql.checkRows(3)

        # https://jira.taosdata.com:18080/browse/TD-5497
        tdSql.execute("create table tt(ts timestamp ,i int)")
        tdSql.execute("insert into tt values(now, 11)(now + 1s, -12)")
        tdSql.query("select * from (select max(i),0-min(i) from tt)")
        tdSql.checkRows(1);
        tdSql.checkData(0, 0, 11);
        tdSql.checkData(0, 1, 12.0);