max_partition.py 10.7 KB
Newer Older
W
update  
wenzhouwww@live.cn 已提交
1 2 3 4 5 6
# author : wenzhouwww
from util.log import *
from util.sql import *
from util.cases import *

class TDTestCase:
7
    def init(self, conn, logSql, replicaVar=1):
W
update  
wenzhouwww@live.cn 已提交
8 9 10 11 12 13
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())

        self.row_nums = 10
        self.tb_nums = 10
        self.ts = 1537146000000
G
Ganlin Zhao 已提交
14

C
cpwu 已提交
15 16
    def prepare_datas(self, stb_name , tb_nums , row_nums, dbname="db" ):
        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,\
W
update  
wenzhouwww@live.cn 已提交
17 18
            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 ) ")
G
Ganlin Zhao 已提交
19

W
update  
wenzhouwww@live.cn 已提交
20
        for i in range(tb_nums):
C
cpwu 已提交
21
            tbname = f"{dbname}.sub_{stb_name}_{i}"
W
update  
wenzhouwww@live.cn 已提交
22
            ts = self.ts + i*10000
C
cpwu 已提交
23
            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 )")
W
update  
wenzhouwww@live.cn 已提交
24 25 26 27 28 29 30 31

            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 )")
G
Ganlin Zhao 已提交
32

C
cpwu 已提交
33 34
    def basic_query(self, dbname="db"):
        tdSql.query(f"select count(*) from {dbname}.stb")
W
update  
wenzhouwww@live.cn 已提交
35
        tdSql.checkData(0,0,(self.row_nums + 5 )*self.tb_nums)
C
cpwu 已提交
36
        tdSql.query(f"select max(c1) from {dbname}.stb")
W
update  
wenzhouwww@live.cn 已提交
37
        tdSql.checkData(0,0,(self.row_nums -1))
C
cpwu 已提交
38
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by tbname ")
W
update  
wenzhouwww@live.cn 已提交
39
        tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
40
        tdSql.query(f"select max(c1) from {dbname}.stb group by t1 order by t1 ")
W
update  
wenzhouwww@live.cn 已提交
41
        tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
42 43 44
        tdSql.query(f"select max(c1) from {dbname}.stb group by c1 order by t1 ")
        tdSql.query(f"select max(t2) from {dbname}.stb group by c1 order by t1 ")
        tdSql.query(f"select max(c1) from {dbname}.stb group by tbname order by tbname ")
W
update  
wenzhouwww@live.cn 已提交
45
        tdSql.checkRows(self.tb_nums)
G
Ganlin Zhao 已提交
46
        # bug need fix
C
cpwu 已提交
47
        tdSql.query(f"select max(t2) from {dbname}.stb group by t2 order by t2 ")
48
        tdSql.checkRows(self.tb_nums)
C
cpwu 已提交
49
        tdSql.query(f"select max(c1) from {dbname}.stb group by c1 order by c1 ")
W
update  
wenzhouwww@live.cn 已提交
50 51
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
52
        tdSql.query(f"select c1 , max(c1) from {dbname}.stb group by c1 order by c1 ")
W
update  
wenzhouwww@live.cn 已提交
53 54 55
        tdSql.checkRows(self.row_nums+1)

        # support selective functions
C
cpwu 已提交
56
        tdSql.query(f"select c1 ,c2 ,c3 , max(c1)  ,c4 ,c5 ,t11 from {dbname}.stb group by c1 order by c1 desc ")
W
update  
wenzhouwww@live.cn 已提交
57 58
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
59
        tdSql.query(f"select c1, tbname , max(c1)  ,c4 ,c5 ,t11 from {dbname}.stb group by c1 order by c1 desc ")
W
update  
wenzhouwww@live.cn 已提交
60 61 62
        tdSql.checkRows(self.row_nums+1)

        # bug need fix
C
cpwu 已提交
63 64 65
        tdSql.query(f"select tbname , max(c1)  from {dbname}.sub_stb_1 where c1 is null group by c1 order by c1 desc ")
        tdSql.checkRows(1)
        tdSql.checkData(0,0,"sub_stb_1")
W
update  
wenzhouwww@live.cn 已提交
66

C
cpwu 已提交
67
        tdSql.query(f"select max(c1) ,c2 ,t2,tbname from {dbname}.stb group by abs(c1) order by abs(c1)")
W
update  
wenzhouwww@live.cn 已提交
68
        tdSql.checkRows(self.row_nums+1)
C
cpwu 已提交
69
        tdSql.query(f"select abs(c1+c3), count(c1+c3) ,max(c1+t2) from {dbname}.stb group by abs(c1+c3) order by abs(c1+c3)")
W
update  
wenzhouwww@live.cn 已提交
70
        tdSql.checkRows(self.row_nums+1)
C
cpwu 已提交
71
        tdSql.query(f"select max(c1+c3)+min(c2) ,abs(c1) from {dbname}.stb group by abs(c1) order by abs(c1)")
W
update  
wenzhouwww@live.cn 已提交
72
        tdSql.checkRows(self.row_nums+1)
C
cpwu 已提交
73 74 75
        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)+max(c2) from {dbname}.stb group by abs(c1+c3)+abs(c2) order by abs(c1+c3)+abs(c2)")
W
update  
wenzhouwww@live.cn 已提交
76 77
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
78
        tdSql.query(f"select max(c1) , max(t2) from {dbname}.stb where abs(c1+t2)=1 partition by tbname ")
W
update  
wenzhouwww@live.cn 已提交
79
        tdSql.checkRows(2)
C
cpwu 已提交
80
        tdSql.query(f"select max(c1) from {dbname}.stb where abs(c1+t2)=1 partition by tbname ")
W
update  
wenzhouwww@live.cn 已提交
81
        tdSql.checkRows(2)
G
Ganlin Zhao 已提交
82

C
cpwu 已提交
83
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by tbname order by tbname ")
W
update  
wenzhouwww@live.cn 已提交
84 85 86
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,1,self.row_nums-1)

C
cpwu 已提交
87 88 89
        tdSql.query(f"select tbname , max(c2) from {dbname}.stb partition by t1 order by t1")
        tdSql.query(f"select tbname , max(t2) from {dbname}.stb partition by t1 order by t1")
        tdSql.query(f"select tbname , max(t2) from {dbname}.stb partition by t2 order by t2")
W
update  
wenzhouwww@live.cn 已提交
90

G
Ganlin Zhao 已提交
91
        # # bug need fix
C
cpwu 已提交
92
        tdSql.query(f"select t2 , max(t2) from {dbname}.stb partition by t2 order by t2")
93
        tdSql.checkRows(self.tb_nums)
W
update  
wenzhouwww@live.cn 已提交
94

C
cpwu 已提交
95
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by tbname order by tbname")
W
update  
wenzhouwww@live.cn 已提交
96 97 98
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,1,self.row_nums-1)

G
Ganlin Zhao 已提交
99

C
cpwu 已提交
100
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by t2 order by t2")
W
update  
wenzhouwww@live.cn 已提交
101

C
cpwu 已提交
102
        tdSql.query(f"select c2, max(c1) from {dbname}.stb partition by c2 order by c2 desc")
W
update  
wenzhouwww@live.cn 已提交
103 104 105
        tdSql.checkRows(self.tb_nums+1)
        tdSql.checkData(0,1,self.row_nums-1)

C
cpwu 已提交
106
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by c1 order by c2")
W
update  
wenzhouwww@live.cn 已提交
107 108


C
cpwu 已提交
109
        tdSql.query(f"select tbname , abs(t2) from {dbname}.stb partition by c2 order by t2")
W
update  
wenzhouwww@live.cn 已提交
110 111
        tdSql.checkRows(self.tb_nums*(self.row_nums+5))

C
cpwu 已提交
112
        tdSql.query(f"select max(c1) , count(t2) from {dbname}.stb partition by c2 ")
W
update  
wenzhouwww@live.cn 已提交
113 114 115
        tdSql.checkRows(self.row_nums+1)
        tdSql.checkData(0,1,self.row_nums)

C
cpwu 已提交
116
        tdSql.query(f"select count(c1) , max(t2) ,c2 from {dbname}.stb partition by c2 order by c2")
W
update  
wenzhouwww@live.cn 已提交
117 118
        tdSql.checkRows(self.row_nums+1)

C
cpwu 已提交
119
        tdSql.query(f"select count(c1) , count(t1) ,max(c2) ,tbname  from {dbname}.stb partition by tbname order by tbname")
W
update  
wenzhouwww@live.cn 已提交
120 121 122
        tdSql.checkRows(self.tb_nums)
        tdSql.checkCols(4)

C
cpwu 已提交
123
        tdSql.query(f"select count(c1) , max(t2) ,t1  from {dbname}.stb partition by t1 order by t1")
W
update  
wenzhouwww@live.cn 已提交
124 125 126
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,0,self.row_nums)

G
Ganlin Zhao 已提交
127
        # bug need fix
C
cpwu 已提交
128
        tdSql.query(f"select count(c1) , max(t2) ,abs(c1) from {dbname}.stb partition by abs(c1) order by abs(c1)")
129
        tdSql.checkRows(self.row_nums+1)
G
Ganlin Zhao 已提交
130

W
update  
wenzhouwww@live.cn 已提交
131

C
cpwu 已提交
132
        tdSql.query(f"select max(ceil(c2)) , max(floor(t2)) ,max(floor(c2)) from {dbname}.stb partition by abs(c2) order by abs(c2)")
W
update  
wenzhouwww@live.cn 已提交
133 134 135
        tdSql.checkRows(self.row_nums+1)


C
cpwu 已提交
136
        tdSql.query(f"select max(ceil(c1-2)) , max(floor(t2+1)) ,max(c2-c1) from {dbname}.stb partition by abs(floor(c1)) order by abs(floor(c1))")
W
update  
wenzhouwww@live.cn 已提交
137
        tdSql.checkRows(self.row_nums+1)
138

C
cpwu 已提交
139
        tdSql.query(f"select tbname , max(c1) ,c1 from {dbname}.stb partition by tbname order by tbname")
140 141 142 143 144
        tdSql.checkRows(self.tb_nums)
        tdSql.checkData(0,0,'sub_stb_0')
        tdSql.checkData(0,1,9)
        tdSql.checkData(0,2,9)

C
cpwu 已提交
145
        tdSql.query(f"select tbname ,top(c1,1) ,c1 from {dbname}.stb partition by tbname order by tbname")
146 147
        tdSql.checkRows(self.tb_nums)

C
cpwu 已提交
148
        tdSql.query(f"select c1 , sample(c1,2) from {dbname}.stb partition by tbname order by tbname ")
149
        tdSql.checkRows(self.tb_nums*2)
W
update  
wenzhouwww@live.cn 已提交
150

G
Ganlin Zhao 已提交
151 152

        # interval
C
cpwu 已提交
153
        tdSql.query(f"select max(c1) from {dbname}.stb interval(2s) sliding(1s)")
W
update  
wenzhouwww@live.cn 已提交
154 155 156

        # bug need fix

C
cpwu 已提交
157
        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)')
G
Ganlin Zhao 已提交
158

C
cpwu 已提交
159
        tdSql.query(f"select tbname , count(c1) from {dbname}.stb partition by tbname interval(10s) slimit 5 soffset 1 ")
W
update  
wenzhouwww@live.cn 已提交
160

C
cpwu 已提交
161
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by tbname interval(10s)")
W
update  
wenzhouwww@live.cn 已提交
162 163
        tdSql.checkRows(self.row_nums*2)

C
cpwu 已提交
164
        tdSql.query(f"select unique(c1) from {dbname}.stb partition  by tbname order by tbname")
W
wenzhouwww@live.cn 已提交
165

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

C
cpwu 已提交
170
        tdSql.query(f"select c1 , mavg(c1 ,2 ) from {dbname}.stb partition by c1")
S
shenglian zhou 已提交
171
        tdSql.checkRows(90)
W
wenzhouwww@live.cn 已提交
172

C
cpwu 已提交
173
        tdSql.query(f"select c1 , diff(c1 , 0) from {dbname}.stb partition by c1")
S
shenglian zhou 已提交
174
        tdSql.checkRows(90)
W
wenzhouwww@live.cn 已提交
175

C
cpwu 已提交
176
        tdSql.query(f"select c1 , csum(c1) from {dbname}.stb partition by c1")
S
shenglian zhou 已提交
177
        tdSql.checkRows(100)
W
wenzhouwww@live.cn 已提交
178

C
cpwu 已提交
179
        tdSql.query(f"select c1 , sample(c1,2) from {dbname}.stb partition by c1 order by c1")
W
wenzhouwww@live.cn 已提交
180
        tdSql.checkRows(21)
G
Ganlin Zhao 已提交
181
        # bug need fix
C
cpwu 已提交
182
        tdSql.checkData(0,1,None)
W
wenzhouwww@live.cn 已提交
183

G
Ganlin Zhao 已提交
184
        tdSql.query(f"select c1 , twa(c1) from {dbname}.sub_stb_1 partition by c1 order by c1")
W
wenzhouwww@live.cn 已提交
185
        tdSql.checkRows(11)
G
Ganlin Zhao 已提交
186
        tdSql.checkData(0,1,None)
W
wenzhouwww@live.cn 已提交
187

C
cpwu 已提交
188
        tdSql.query(f"select c1 , irate(c1) from {dbname}.stb partition by c1 order by c1")
W
wenzhouwww@live.cn 已提交
189 190 191
        tdSql.checkRows(11)
        tdSql.checkData(0,1,None)

C
cpwu 已提交
192
        tdSql.query(f"select c1 , DERIVATIVE(c1,2,1) from {dbname}.stb partition by c1 order by c1")
S
shenglian zhou 已提交
193
        tdSql.checkRows(90)
G
Ganlin Zhao 已提交
194
        # bug need fix
W
wenzhouwww@live.cn 已提交
195
        tdSql.checkData(0,1,None)
W
wenzhouwww@live.cn 已提交
196

G
Ganlin Zhao 已提交
197

C
cpwu 已提交
198
        tdSql.query(f"select tbname , max(c1) from {dbname}.stb partition by tbname order by tbname slimit 5 soffset 0 ")
W
wenzhouwww@live.cn 已提交
199
        tdSql.checkRows(10)
G
Ganlin Zhao 已提交
200

C
cpwu 已提交
201
        tdSql.query(f"select tbname , max(c1) from {dbname}.sub_stb_1 partition by tbname interval(10s) sliding(5s) ")
G
Ganlin Zhao 已提交
202

C
cpwu 已提交
203 204
        tdSql.query(f'select max(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+1000 interval(50s) sliding(30s)')
        tdSql.query(f'select tbname , max(c1) from {dbname}.stb where ts>={self.ts} and ts < {self.ts}+1000 interval(50s) sliding(30s)')
W
update  
wenzhouwww@live.cn 已提交
205 206 207


    def run(self):
C
cpwu 已提交
208
        dbname = "db"
W
update  
wenzhouwww@live.cn 已提交
209 210 211 212
        tdSql.prepare()
        self.prepare_datas("stb",self.tb_nums,self.row_nums)
        self.basic_query()

G
Ganlin Zhao 已提交
213
        # # coverage case for taosd crash about bug fix
C
cpwu 已提交
214 215 216 217 218
        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 ")
W
update  
wenzhouwww@live.cn 已提交
219

G
Ganlin Zhao 已提交
220

W
update  
wenzhouwww@live.cn 已提交
221 222 223 224 225 226
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
G
Ganlin Zhao 已提交
227
tdCases.addLinux(__file__, TDTestCase())