count_partition.py 8.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# author : wenzhouwww
from util.log import *
from util.sql import *
from util.cases import *

class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())

        self.row_nums = 10
        self.tb_nums = 10
        self.ts = 1537146000000
C
cpwu 已提交
14 15 16 17

    def prepare_datas(self, stb_name , tb_nums , row_nums, dbname="db" ):
        tdSql.execute(f" use {dbname} ")
        tdSql.execute(f" create stable {dbname}.{stb_name} (ts timestamp , c1 int , c2 bigint , c3 float , c4 double , c5 smallint , c6 tinyint , c7 bool , c8 binary(36) , c9 nchar(36) , uc1 int unsigned,\
18 19
            uc2 bigint unsigned ,uc3 smallint unsigned , uc4 tinyint unsigned ) tags(t1 timestamp , t2 int , t3 bigint , t4 float , t5 double , t6 smallint , t7 tinyint , t8 bool , t9 binary(36)\
                , t10 nchar(36) , t11 int unsigned , t12 bigint unsigned ,t13 smallint unsigned , t14 tinyint unsigned ) ")
C
cpwu 已提交
20

21
        for i in range(tb_nums):
C
cpwu 已提交
22
            tbname = f"{dbname}.sub_{stb_name}_{i}"
23
            ts = self.ts + i*10000
C
cpwu 已提交
24
            tdSql.execute(f"create table {tbname} using {dbname}.{stb_name} tags ({ts} , {i} , {i}*10 ,{i}*1.0,{i}*1.0 , 1 , 2, 'true', 'binary_{i}' ,'nchar_{i}',{i},{i},10,20 )")
25 26 27 28 29 30 31 32

            for row in range(row_nums):
                ts = self.ts + row*1000
                tdSql.execute(f"insert into {tbname} values({ts} , {row} , {row} , {row} , {row} , 1 , 2 , 'true' , 'binary_{row}' , 'nchar_{row}' , {row} , {row} , 1 ,2 )")

            for null in range(5):
                ts =  self.ts + row_nums*1000 + null*1000
                tdSql.execute(f"insert into {tbname} values({ts} , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL )")
C
cpwu 已提交
33 34 35

    def basic_query(self, dbname="db"):
        tdSql.query(f"select count(*) from {dbname}.stb")
36
        tdSql.checkData(0,0,(self.row_nums + 5 )*self.tb_nums)
C
cpwu 已提交
37
        tdSql.query(f"select count(c1) from {dbname}.stb")
38
        tdSql.checkData(0,0,(self.row_nums )*self.tb_nums)
C
cpwu 已提交
39
        tdSql.query(f"select tbname , count(*) from {dbname}.stb partition by tbname ")
40
        tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
41
        tdSql.query(f"select count(c1) from {dbname}.stb group by t1 order by t1 ")
42
        tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
43 44 45
        tdSql.error(f"select count(c1) from {dbname}.stb group by c1 order by t1 ")
        tdSql.error(f"select count(t1) from {dbname}.stb group by c1 order by t1 ")
        tdSql.query(f"select count(c1) from {dbname}.stb group by tbname order by tbname ")
46
        tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
47 48
        # bug need fix
        # tdSql.query(f"select count(t1) from {dbname}.stb group by t2 order by t2 ")
49
        # tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
50
        tdSql.query(f"select count(c1) from {dbname}.stb group by c1 order by c1 ")
51 52
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
53
        tdSql.query(f"select c1 , count(c1) from {dbname}.stb group by c1 order by c1 ")
54 55
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
56
        tdSql.query(f"select count(c1) from {dbname}.stb group by abs(c1) order by abs(c1)")
57
        tdSql.checkRows(self.row_nums+1)
C
cpwu 已提交
58
        tdSql.query(f"select abs(c1+c3), count(c1+c3) from {dbname}.stb group by abs(c1+c3) order by abs(c1+c3)")
59
        tdSql.checkRows(self.row_nums+1)
C
cpwu 已提交
60
        tdSql.query(f"select count(c1+c3)+max(c2) ,abs(c1) from {dbname}.stb group by abs(c1) order by abs(c1)")
61
        tdSql.checkRows(self.row_nums+1)
C
cpwu 已提交
62 63 64
        tdSql.error(f"select count(c1+c3)+max(c2) ,abs(c1) ,abs(t1) from {dbname}.stb group by abs(c1) order by abs(t1)+c2")
        tdSql.error(f"select count(c1+c3)+max(c2) ,abs(c1) from {dbname}.stb group by abs(c1) order by abs(c1)+c2")
        tdSql.query(f"select abs(c1+c3)+abs(c2) , count(c1+c3)+count(c2) from {dbname}.stb group by abs(c1+c3)+abs(c2) order by abs(c1+c3)+abs(c2)")
65 66
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
67
        tdSql.query(f"select count(c1) , count(t2) from {dbname}.stb where abs(c1+t2)=1 partition by tbname")
68
        tdSql.checkRows(2)
C
cpwu 已提交
69
        tdSql.query(f"select count(c1) from {dbname}.stb where abs(c1+t2)=1 partition by tbname")
70
        tdSql.checkRows(2)
C
cpwu 已提交
71 72

        tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname")
73 74 75
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,1,self.row_nums)

C
cpwu 已提交
76 77 78
        tdSql.error(f"select tbname , count(c1) from {dbname}.stb partition by t1 order by t1")
        tdSql.error(f"select tbname , count(t1) from {dbname}.stb partition by t1 order by t1")
        tdSql.error(f"select tbname , count(t1) from {dbname}.stb partition by t2 order by t2")
79

C
cpwu 已提交
80 81
        # # bug need fix
        # tdSql.query(f"select t2 , count(t1) from {dbname}.stb partition by t2 order by t2")
82 83
        # tdSql.checkRows(self.tb_nums)

C
cpwu 已提交
84
        tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname")
85 86 87 88
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,1,self.row_nums)


C
cpwu 已提交
89 90 91
        tdSql.error(f"select tbname , count(c1) from {dbname}.stb partition by t2 order by t2")

        tdSql.query(f"select c2, count(c1) from {dbname}.stb partition by c2 order by c2 desc")
92 93 94
        tdSql.checkRows(self.tb_nums+1)
        tdSql.checkData(0,1,self.tb_nums)

C
cpwu 已提交
95
        tdSql.error(f"select tbname , count(c1) from {dbname}.stb partition by c1 order by c2")
96 97


C
cpwu 已提交
98
        tdSql.query(f"select tbname , abs(t2) from {dbname}.stb partition by c2 order by t2")
99 100
        tdSql.checkRows(self.tb_nums*(self.row_nums+5))

C
cpwu 已提交
101
        tdSql.query(f"select count(c1) , count(t2) from {dbname}.stb partition by c2 ")
102 103 104
        tdSql.checkRows(self.row_nums+1)
        tdSql.checkData(0,1,self.row_nums)

C
cpwu 已提交
105
        tdSql.query(f"select count(c1) , count(t2) ,c2 from {dbname}.stb partition by c2 order by c2")
106 107
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
108
        tdSql.query(f"select count(c1) , count(t1) ,max(c2) ,tbname  from {dbname}.stb partition by tbname order by tbname")
109 110 111
        tdSql.checkRows(self.tb_nums)
        tdSql.checkCols(4)

C
cpwu 已提交
112
        tdSql.query(f"select count(c1) , count(t2) ,t1  from {dbname}.stb partition by t1 order by t1")
113 114 115
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,0,self.row_nums)

C
cpwu 已提交
116 117
        # bug need fix
        # tdSql.query(f"select count(c1) , count(t1) ,abs(c1) from {dbname}.stb partition by abs(c1) order by abs(c1)")
W
update  
wenzhouwww@live.cn 已提交
118
        # tdSql.checkRows(self.row_nums+1)
119

C
cpwu 已提交
120 121

        tdSql.query(f"select count(ceil(c2)) , count(floor(t2)) ,count(floor(c2)) from {dbname}.stb partition by abs(c2) order by abs(c2)")
122 123 124
        tdSql.checkRows(self.row_nums+1)


C
cpwu 已提交
125
        tdSql.query(f"select count(ceil(c1-2)) , count(floor(t2+1)) ,max(c2-c1) from {dbname}.stb partition by abs(floor(c1)) order by abs(floor(c1))")
126 127
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
128 129 130

        # interval
        tdSql.query(f"select count(c1) from {dbname}.stb interval(2s) sliding(1s)")
131 132 133

        # bug need fix

C
cpwu 已提交
134
        tdSql.query(f'select max(c1) from {dbname}.stb where ts>="2022-07-06 16:00:00.000 " and ts < "2022-07-06 17:00:00.000 " interval(50s) sliding(30s) fill(NULL)')
135

C
cpwu 已提交
136
        tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname interval(10s) slimit 5 soffset 1 ")
137

C
cpwu 已提交
138
        tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname interval(10s)")
139

C
cpwu 已提交
140
        tdSql.query(f"select tbname , count(c1) from {dbname}.sub_stb_1 partition by tbname interval(10s)")
W
update  
wenzhouwww@live.cn 已提交
141 142
        tdSql.checkData(0,0,'sub_stb_1')
        tdSql.checkData(0,1,self.row_nums)
143

C
cpwu 已提交
144 145 146 147
        # tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname slimit 5 soffset 0 ")
        # tdSql.checkRows(5)

        # tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname order by tbname slimit 5 soffset 1 ")
148
        # tdSql.checkRows(5)
C
cpwu 已提交
149 150 151 152 153 154

        tdSql.query(f"select tbname , count(c1) from {dbname}.sub_stb_1 partition by tbname interval(10s) sliding(5s) ")

        tdSql.query(f'select max(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)')
        tdSql.query(f'select max(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+10000 interval(50s) sliding(30s)')
        tdSql.query(f'select tbname , count(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+10000 partition by tbname interval(50s) sliding(30s)')
155 156 157 158 159 160


    def run(self):
        tdSql.prepare()
        self.prepare_datas("stb",self.tb_nums,self.row_nums)
        self.basic_query()
C
cpwu 已提交
161 162 163 164 165 166 167 168
        dbname="db"

        # # coverage case for taosd crash about bug fix
        tdSql.query(f"select sum(c1) from {dbname}.stb where t2+10 >1 ")
        tdSql.query(f"select count(c1),count(t1) from {dbname}.stb where -t2<1 ")
        tdSql.query(f"select tbname ,max(ceil(c1)) from {dbname}.stb group by tbname ")
        tdSql.query(f"select avg(abs(c1)) , tbname from {dbname}.stb group by tbname ")
        tdSql.query(f"select t1,c1 from {dbname}.stb where abs(t2+c1)=1 ")
169 170 171 172 173 174 175 176 177


    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())