elapsed.py 83.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
###################################################################
#           Copyright (c) 2020 by TAOS Technologies, Inc.
#                     All rights reserved.
#
#  This file is proprietary and confidential to TAOS Technologies.
#  No part of this file may be reproduced, stored, transmitted,
#  disclosed or used in any form or by any means other than as
#  expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-

import sys
import os

from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *

class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)
G
Ganlin Zhao 已提交
26

27 28 29 30 31 32
        self.ts = 1420041600000 # 2015-01-01 00:00:00  this is begin time for first record
        self.num = 10

    def caseDescription(self):

        '''
G
Ganlin Zhao 已提交
33 34 35
        case1 <wenzhouwww>: [TD-11804]  test case for elapsed function :

        this test case is for aggregate function elapsed , elapsed function can only used for the timestamp primary key column (ts) ,
36
        it has two input parameters,  the first parameter is necessary, basic SQL as follow:
G
Ganlin Zhao 已提交
37

38 39 40 41 42 43 44 45 46 47 48 49 50 51
        ===================================================================================================================================
        SELECT ELAPSED(field_name[, time_unit]) FROM { tb_name | stb_name } [WHERE clause] [INTERVAL(interval [, offset]) [SLIDING sliding]];
        ===================================================================================================================================

        elapsed function can acting on ordinary tables and super tables , notice that this function is related to the timeline.
        If it acts on a super table , it must be group by tbname . by the way ,this function support nested query.

        The scenarios covered by the test cases are as follows:

        ====================================================================================================================================

        case: select * from table|stable[group by tbname]|regular_table

        case:select elapsed(ts) from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
G
Ganlin Zhao 已提交
52

53
        case:select elapsed(ts) , elapsed(ts,unit_time1)*regular_num1 , elapsed(ts,unit_time1)+regular_num2 from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
G
Ganlin Zhao 已提交
54

55 56
        //mixup with all functions only once query (it's different with nest query)
        case:select elapsed(ts), count(*), avg(col), twa(col), irate(col), sum(col), stddev(col), leastsquares(col, 1, 1),min(col), max(col), first(col), last(col), percentile(col, 20), apercentile(col, 30), last_row(col), spread(col)from table|stable where clause interval (units)  [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
G
Ganlin Zhao 已提交
57 58

        //mixup with ordinary col
59
        case:select ts ,elapsed(ts)*10 ,col+5 from table|stable where clause interval (units) [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
G
Ganlin Zhao 已提交
60

61 62
        //nest query
        case:select elapsed(ts) from (select elapsed(ts), count(*), avg(col), twa(col), irate(col), sum(col), stddev(col), leastsquares(col, 1, 1),min(col), max(col), first(col), last(col), percentile(col, 20), apercentile(col, 30), last_row(col), spread(col)from table|stable where clause interval (units)  [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc]) where clause interval (units)  [fill(LINEAR,NEXT,PREV,VALUE,NULL)] [group by tbname] order [by ts desc asc|desc];
G
Ganlin Zhao 已提交
63

64 65 66 67 68 69 70 71 72 73 74 75 76
        //clause about filter condition
        case:select  elapsed(ts) from table|stable[group by tbname] where [ts|col|tag >|<|=|>=|<=|=|<>|!= value] | [between ... and ...] |[in] |[is null|not null] interval (unit_time) ;
        case:select  elapsed(ts) from table|stable[group by tbname] where clause1 and clause 2 and clause3  interval (unit_time)  ;

        //JOIN query
        case:select elapsed(ts) from TABLE1 as tb1 , TABLE2 as tb2 where join_condition [TABLE1 and TABLE2 can be stable|table|sub_table|empty_table]

        //UNION ALL query
       case:select elapsed(ts) from TABLE1 union all select elapsed(ts) from TABLE2 [TABLE1 and TABLE2 can be stable|table|sub_table|empty_table]

        // Window aggregation

        case:select elapsed(ts) from t1 where  clause session(ts, time_units) ;
G
Ganlin Zhao 已提交
77
        case:select elapsed(ts) from t1 where  clause state_window(regular_nums);
78 79 80 81 82 83 84 85

        // Continuous query
        case:create table select elapsed(ts)  ,avg(col) from (select elapsed(ts) ts_inter ,avg(col) col from stable|table interval (unit_time) [fill(LINEAR,NEXT,PREV,VALUE,NULL)][group by tbname])  interval (unit_time) [fill(LINEAR,NEXT,PREV,VALUE,NULL) sliding(unit_time_windows);

        ========================================================================================================================================

        this test case notice successful execution and correctness of results.

G
Ganlin Zhao 已提交
86 87
        '''
        return
88 89 90 91

    def prepare_data(self):

        tdLog.info (" ====================================== prepare data ==================================================")
G
Ganlin Zhao 已提交
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        tdSql.execute('drop database if exists testdb ;')
        tdSql.execute('create database testdb keep 36500;')
        tdSql.execute('use testdb;')

        tdSql.execute('create stable stable_1(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\
             q_double double , bin_chars binary(20)) tags(loc nchar(20) ,ind int,tstag timestamp);')
        tdSql.execute('create stable stable_2(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\
             q_double double, bin_chars binary(20) ) tags(loc nchar(20),ind int,tstag timestamp);')
        # create empty stables
        tdSql.execute('create stable stable_empty(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\
             q_double double, bin_chars binary(20) ) tags(loc nchar(20),ind int,tstag timestamp);')
        tdSql.execute('create stable stable_sub_empty(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\
             q_double double, bin_chars binary(20) ) tags(loc nchar(20),ind int,tstag timestamp);')

        # create empty sub_talbes and regular tables
        tdSql.execute('create table sub_empty_1 using stable_sub_empty tags("sub_empty_1",3,"2015-01-01 00:02:00")')
        tdSql.execute('create table sub_empty_2 using stable_sub_empty tags("sub_empty_2",3,"2015-01-01 00:02:00")')
        tdSql.execute('create table regular_empty (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;')

        tdSql.execute('create table sub_table1_1 using stable_1 tags("sub1_1",1,"2015-01-01 00:00:00")')
        tdSql.execute('create table sub_table1_2 using stable_1 tags("sub1_2",2,"2015-01-01 00:01:00")')
        tdSql.execute('create table sub_table1_3 using stable_1 tags("sub1_3",3,"2015-01-01 00:02:00")')

        tdSql.execute('create table sub_table2_1 using stable_2 tags("sub2_1",1,"2015-01-01 00:00:00")')
        tdSql.execute('create table sub_table2_2 using stable_2 tags("sub2_2",2,"2015-01-01 00:01:00")')
        tdSql.execute('create table sub_table2_3 using stable_2 tags("sub2_3",3,"2015-01-01 00:02:00")')

        tdSql.execute('create table regular_table_1 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double, bin_chars binary(20)) ;')
        tdSql.execute('create table regular_table_2 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;')
        tdSql.execute('create table regular_table_3 (ts timestamp , tscol timestamp ,q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , bin_chars binary(20)) ;')
G
Ganlin Zhao 已提交
123

124 125 126 127 128 129
        tablenames = ["sub_table1_1","sub_table1_2","sub_table1_3","sub_table2_1","sub_table2_2","sub_table2_3","regular_table_1","regular_table_2","regular_table_3"]

        tdLog.info("insert into records ")

        for tablename in tablenames:

G
Ganlin Zhao 已提交
130
            for i in range(self.num):
131 132 133 134 135 136 137 138 139 140 141 142 143
                sql= 'insert into %s values(%d, %d,%d, %d, %d, %d, %f, %f, "%s")' % (tablename,self.ts + i*10000, self.ts + i*10,2147483647-i, 9223372036854775807-i, 32767-i, 127-i, i, i,("bintest"+str(i)))
                print(sql)
                tdSql.execute(sql)

        tdLog.info("=============================================data prepared done!=========================")

    def abnormal_common_test(self):

        tdLog.info (" ====================================== elapsed illeagal params ==================================================")

        tablenames = ["sub_table1_1","sub_table1_2","sub_table1_3","sub_table2_1","sub_table2_2","sub_table2_3","regular_table_1","regular_table_2","regular_table_3"]

        abnormal_list = ["()","(NULL)","(*)","(abc)","( , )","(NULL,*)","( ,NULL)","(%)","(+)","(*,)","(*, /)","(ts,*)" "(ts,tbname*10)","(ts,tagname)",
144
        "(ts,2d+3m-2s,NULL)","(ts+10d,NULL)" ,"(ts,now -1m%1d)","(ts+10d,_c0)","(ts+10d,)","(ts,%)","(ts, , m)","(ts,abc)","(ts,/)","(ts,*)","(ts,1s,100)",
145 146
        "(ts,1s,abc)","(ts,1s,_c0)","(ts,1s,*)","(ts,1s,NULL)","(ts,,_c0)","(ts,tbname,ts)","(ts,0,tbname)","('2021-11-18 00:00:10')","('2021-11-18 00:00:10', 1s)",
        "('2021-11-18T00:00:10+0800', '1s')","('2021-11-18T00:00:10Z', '1s')","('2021-11-18T00:00:10+0800', 10000000d,)","('ts', ,2021-11-18T00:00:10+0800, )"]
G
Ganlin Zhao 已提交
147

148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
        for tablename in tablenames:
            for abnormal_param in abnormal_list:

                if tablename.startswith("stable"):
                    basic_sql= "select elapsed" + abnormal_param + " from " + tablename + " group by tbname ,ind order by tbname;"  #stables
                else:
                    basic_sql= "select elapsed" + abnormal_param + " from " + tablename + ";"  # regular table
                tdSql.error(basic_sql)

    def abnormal_use_test(self):

        tdLog.info (" ====================================== elapsed use abnormal ==================================================")

        sqls_list = ["select elapsed(ts) from regular_empty group by tbname,ind order by desc; ",
                    "select elapsed(ts) from regular_empty group by tbname,ind order by desc; ",
                    "select elapsed(ts) from regular_table_1 group by tbname,ind order by desc; ",
                    "select elapsed(ts) from sub_table1_1  group by tbname,ind order by desc; ",
                    "select elapsed(ts) from sub_table1_1  group by tbname,ind order by desc; ",
166 167 168 169 170 171
                    # "select elapsed(ts,1s) from stable_empty group by ts order by ts;",
                    "select elapsed(ts,1s) from stable_1 group by ind order by ts;",
                    "select elapsed(ts,1s) from stable_2 group by tstag order by ts;",
                    "select elapsed(ts,1s) from stable_1 group by tbname,tstag,tscol order by ts;",
                    "select elapsed(ts,1s),ts from stable_1 group by tbname ,ind order by ts;",
                    "select ts,elapsed(ts,1s),tscol*100 from stable_1 group by tbname ,ind order by ts;",
172 173 174 175 176 177 178 179 180
                    "select elapsed(ts) from stable_1 group by tstag order by ts;",
                    "select elapsed(ts) from sub_empty_1 group by tbname,ind ,tscol order by ts desc;",
                    "select tbname, tscol,elapsed(ts) from sub_table1_1 group by tbname ,ind order by ts desc;",
                    "select elapsed(tscol) from sub_table1_1 order by ts desc;",
                    "select elapsed(tstag) from sub_table1_1 order by ts desc;",
                    "select elapsed(ind) from sub_table1_1 order by ts desc;",
                    "select elapsed(tscol) from sub_empty_1 order by ts desc;",
                    "select elapsed(tstag) from sub_empty_1 order by ts desc;",
                    "select elapsed(ind) from sub_table1_1 order by ts desc;",
181 182 183 184 185 186 187
                    "select elapsed(ind,1s) from sub_table1_1 order by ts desc;",
                    "select elapsed(tscol,1s) from sub_table1_1 order by ts desc;",
                    "select elapsed(tstag,1s) from sub_table1_1 order by ts desc;",
                    "select elapsed(q_int,1s) from sub_table1_1 order by ts desc;",
                    "select elapsed(loc,1s) from sub_table1_1 order by ts desc;",
                    "select elapsed(q_bigint,1s) from sub_table1_1 order by ts desc;",
                    "select elapsed(bin_chars,1s) from sub_table1_1 order by ts desc;"]
188 189 190 191 192 193
        for sql in sqls_list :
            tdSql.error(sql)

    def query_filter(self):

        tdLog.info (" ====================================== elapsed query filter ==================================================")
G
Ganlin Zhao 已提交
194

195 196 197 198 199 200 201
        for i in range(self.num):
            ts_start_time = self.ts + i*10000
            ts_col_start_time = self.ts + i*10
            ts_tag_time = "2015-01-01 00:01:00"
            ts_end_time = self.ts + (self.num-1-i)*10000
            ts_col_end_time = self.ts + (self.num-1-i)*10

202
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts >= %d group by tbname " %(ts_start_time)
203 204
            tdSql.query(filter_sql)
            tdSql.checkRows(3)
205 206 207
            tdSql.checkData(0,0,float((self.num -i-1)*10))
            tdSql.checkData(1,0,float((self.num -i-1)*10))
            tdSql.checkData(2,0,float((self.num -i-1)*10))
208

209
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts >= %d  " %(ts_start_time)
210 211
            tdSql.query(filter_sql)
            tdSql.checkRows(1)
212
            tdSql.checkData(0,0,float((self.num -i-1)*10))
G
Ganlin Zhao 已提交
213

214

215
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts >= %d  and tscol >= %d and tstag='2015-01-01 00:01:00'group by tbname " %(ts_start_time,ts_col_start_time)
216 217
            tdSql.query(filter_sql)
            tdSql.checkRows(1)
218
            tdSql.checkData(0,0,float((self.num -i-1)*10))
219

220
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts >= %d  and tscol >= %d  " %(ts_start_time,ts_col_start_time)
221 222
            tdSql.query(filter_sql)
            tdSql.checkRows(1)
223
            tdSql.checkData(0,0,float((self.num -i-1)*10))
224

225
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts >= %d  and tscol > %d and tstag='2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time)
226
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
227

228 229 230 231
            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
232
                tdSql.checkData(0,0,float((self.num -i-2)*10))
233

234
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts >= %d  and tscol > %d " %(ts_start_time,ts_col_start_time)
235
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
236

237 238 239 240
            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
241
                tdSql.checkData(0,0,float((self.num -i-2)*10))
242

243
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts > %d  and tscol > %d and tstag < '2015-01-01 00:01:00' group by tbname " %(ts_start_time,ts_col_start_time)
244 245 246 247 248 249
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
250
                tdSql.checkData(0,0,float((self.num -i-2)*10))
251

252
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts > %d  and tscol > %d  " %(ts_start_time,ts_col_start_time)
253 254 255 256 257 258
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
259
                tdSql.checkData(0,0,float((self.num -i-2)*10))
260

261
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts > %d  and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_start_time,ts_col_start_time)
262 263 264
            tdSql.query(filter_sql)
            tdSql.checkRows(0)

265
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts > %d  and tscol <= %d " %(ts_start_time,ts_col_start_time)
266 267 268
            tdSql.query(filter_sql)
            tdSql.checkRows(0)

269
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts < %d  and tscol <= %d and tstag < '2015-01-01 00:01:00' group by tbname" %(ts_end_time,ts_col_end_time)
270
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
271

272 273 274 275
            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
276
                tdSql.checkData(0,0,float((self.num -i-2)*10))
277

278
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts < %d  and tscol <= %d " %(ts_end_time,ts_col_end_time)
279
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
280

281 282 283 284
            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
285
                tdSql.checkData(0,0,float((self.num -i-2)*10))
286

287
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts < %d  and tscol <= %d  group by tbname " %(ts_end_time,ts_col_end_time)
288 289 290 291 292 293
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(3)
294 295 296
                tdSql.checkData(0,0,float((self.num -i-2)*10))
                tdSql.checkData(1,0,float((self.num -i-2)*10))
                tdSql.checkData(2,0,float((self.num -i-2)*10))
297

298
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts < %d  and tscol <= %d   " %(ts_end_time,ts_col_end_time)
299 300 301 302 303 304
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
305
                tdSql.checkData(0,0,float((self.num -i-2)*10))
G
Ganlin Zhao 已提交
306

307
            filter_sql = "select elapsed(ts,1s) from stable_1 where  ts = %d  and tscol < %d  group by tbname " %(ts_end_time,ts_col_end_time)
308 309 310
            tdSql.query(filter_sql)
            tdSql.checkRows(0)

311
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts = %d  and tscol < %d  " %(ts_end_time,ts_col_end_time)
312 313 314
            tdSql.query(filter_sql)
            tdSql.checkRows(0)

315
            filter_sql = "select elapsed(ts,1s) from stable_1 where  q_tinyint != %d  and tscol < %d  group by tbname " %(i,ts_col_end_time)
316 317 318 319 320 321
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(3)
322 323 324
                tdSql.checkData(0,0,float((self.num -i-2)*10))
                tdSql.checkData(1,0,float((self.num -i-2)*10))
                tdSql.checkData(2,0,float((self.num -i-2)*10))
325

326
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  q_tinyint != %d  and tscol < %d   " %(i,ts_col_end_time)
327 328 329 330 331 332
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
333
                tdSql.checkData(0,0,float((self.num -i-2)*10))
G
Ganlin Zhao 已提交
334

335
            filter_sql = "select elapsed(ts,1s) from stable_1 where  q_tinyint != %d  and tscol <= %d  group by tbname " %(i,ts_col_end_time)
336
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
337

338 339 340 341
            if i == self.num:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(3)
342 343 344
                tdSql.checkData(0,0,float((self.num -i-1)*10))
                tdSql.checkData(1,0,float((self.num -i-1)*10))
                tdSql.checkData(2,0,float((self.num -i-1)*10))
345

346
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  q_tinyint != %d  and tscol <= %d   " %(i,ts_col_end_time)
347
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
348

349 350 351 352
            if i == self.num:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
353
                tdSql.checkData(0,0,float((self.num -i-1)*10))
354

355
            filter_sql = "select elapsed(ts,1s) from stable_1 where  q_tinyint <> %d  and tscol < %d  group by tbname " %(i,ts_col_end_time)
356 357 358 359 360 361
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(3)
362 363 364
                tdSql.checkData(0,0,float((self.num -i-2)*10))
                tdSql.checkData(1,0,float((self.num -i-2)*10))
                tdSql.checkData(2,0,float((self.num -i-2)*10))
365

366
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  q_tinyint <> %d  and tscol < %d   " %(i,ts_col_end_time)
367 368 369 370 371 372
            tdSql.query(filter_sql)

            if i == self.num-1:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
373
                tdSql.checkData(0,0,float((self.num -i-2)*10))
374

375
            filter_sql = "select elapsed(ts,1s) from stable_1 where  q_tinyint <> %d  and tscol <= %d  group by tbname " %(i,ts_col_end_time)
376
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
377

378 379 380 381
            if i == self.num:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(3)
382 383 384
                tdSql.checkData(0,0,float((self.num -i-1)*10))
                tdSql.checkData(1,0,float((self.num -i-1)*10))
                tdSql.checkData(2,0,float((self.num -i-1)*10))
385

386
            filter_sql = "select elapsed(ts,1s) from sub_table1_1 where  q_tinyint <> %d  and tscol <= %d  " %(i,ts_col_end_time)
387
            tdSql.query(filter_sql)
G
Ganlin Zhao 已提交
388

389 390 391 392
            if i == self.num:
                tdSql.checkRows(0)
            else:
                tdSql.checkRows(1)
393
                tdSql.checkData(0,0,float((self.num -i-1)*10))
394

G
Ganlin Zhao 已提交
395
            # filter between and
396 397 398
            tdSql.query("select elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000'  ")
            tdSql.checkData(0,0,20)
            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and \
399
            q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
400 401 402
            tdSql.checkData(0,0,20)
            tdSql.checkData(1,0,20)
            tdSql.checkData(2,0,20)
403

G
Ganlin Zhao 已提交
404
            # filter in and or
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
            tdSql.query("select elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000'  ")
            tdSql.checkData(0,0,20)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and q_tinyint between 125 and 127 and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
            tdSql.checkData(0,0,20)
            tdSql.checkData(1,0,20)
            tdSql.checkData(2,0,20)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and q_tinyint in (125,126,127) and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
            tdSql.checkData(0,0,20)
            tdSql.checkData(1,0,20)
            tdSql.checkData(2,0,20)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
            tdSql.checkData(0,0,10)
            tdSql.checkData(1,0,10)
            tdSql.checkData(2,0,10)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars in ('bintest0','bintest1') and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
            tdSql.checkData(0,0,10)
            tdSql.checkData(1,0,10)
            tdSql.checkData(2,0,10)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
            tdSql.checkData(0,0,60)
            tdSql.checkData(1,0,60)
            tdSql.checkData(2,0,60)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars like 'bintest_' and tscol <= '2015-01-01 00:01:00.000' group by tbname ")
            tdSql.checkData(0,0,60)
            tdSql.checkData(1,0,60)
            tdSql.checkData(2,0,60)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars is not null  and tscol <= '2015-01-01 00:01:00.000' group by tbname; ")
            tdSql.checkData(0,0,60)
            tdSql.checkData(1,0,60)
            tdSql.checkData(2,0,60)

            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars is null  and tscol <= '2015-01-01 00:01:00.000' group by tbname; ")
444 445
            tdSql.checkRows(0)

446
            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars match '^b'  and tscol <= '2015-01-01 00:01:00.000' group by tbname; ")
447
            tdSql.checkRows(3)
448 449 450
            tdSql.checkData(0,0,60)
            tdSql.checkData(1,0,60)
            tdSql.checkData(2,0,60)
451

452
            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars nmatch '^a'  and tscol <= '2015-01-01 00:01:00.000' group by tbname; ")
453
            tdSql.checkRows(3)
454 455 456
            tdSql.checkData(0,0,60)
            tdSql.checkData(1,0,60)
            tdSql.checkData(2,0,60)
457

458
            tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and bin_chars ='bintest1' or bin_chars ='bintest2' and tscol <= '2015-01-01 00:01:00.000' group by tbname; ")
459
            tdSql.checkRows(3)
460
            tdSql.query("select elapsed(ts,1s) from stable_1 where (ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000')  or (ts between '2015-01-01 00:01:00.000'  and '2015-01-01 00:02:00.000') group by tbname; ")
461
            tdSql.checkRows(3)
462 463 464
            tdSql.checkData(0,0,90)
            tdSql.checkData(1,0,90)
            tdSql.checkData(2,0,90)
465 466 467 468 469 470 471 472 473 474 475

    def query_interval(self):

        tdLog.info (" ====================================== elapsed interval sliding fill ==================================================")

        # empty interval
        tdSql.query("select max(q_int)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);")
        tdSql.checkRows(0)
        tdSql.query("select max(q_int)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);")
        tdSql.checkRows(0)

476
        tdSql.query("select elapsed(ts,1s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;")
477
        tdSql.checkRows(0)
478
        tdSql.query("select elapsed(ts,1s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);")
479
        tdSql.checkRows(0)
G
Ganlin Zhao 已提交
480

481 482 483 484 485 486 487
        for i in range(self.num):
            ts_start_time = self.ts + i*10000
            ts_col_start_time = self.ts + i*10
            ts_tag_time = "2015-01-01 00:01:00"
            ts_end_time = self.ts + (self.num-1-i)*10000
            ts_col_end_time = self.ts + (self.num-1-i)*10

G
Ganlin Zhao 已提交
488 489

            # only interval
490
            interval_sql = "select elapsed(ts,1s) from stable_1 where  ts <=%d interval(10s) group by tbname " %(ts_start_time)
491 492 493
            tdSql.query(interval_sql)
            tdSql.checkRows(3*(i+1))

494
            interval_sql = "select elapsed(ts,1s) from sub_table1_1 where  ts <=%d interval(10s) " %(ts_start_time)
495 496 497 498 499 500
            tdSql.query(interval_sql)
            tdSql.checkRows(i+1)
            for x in range(i+1):
                if x == i:
                    tdSql.checkData(x,1,0)
                else :
501
                    tdSql.checkData(x,1,10)
G
Ganlin Zhao 已提交
502

503 504
        # interval and fill , fill_type =  ["NULL","value,100","prev","next","linear"]

505
        # interval (1s)  and time range is outer records
506

507
        tdSql.query("select elapsed(ts,1s)*10 from stable_empty where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;")
508 509
        tdSql.checkRows(0)

510
        tdSql.query("select elapsed(ts,1s)*10 from sub_empty_2 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev);")
511 512
        tdSql.checkRows(0)

513
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(prev) group by tbname;")
514
        tdSql.checkRows(180)
515
        tdSql.checkData(0,1,100)
516 517
        tdSql.checkData(9,1,0)
        tdSql.checkData(59,1,0)
518
        tdSql.checkData(60,1,100)
519

520
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(next) group by tbname;")
521
        tdSql.checkRows(180)
522
        tdSql.checkData(0,1,100)
523 524 525
        tdSql.checkData(9,1,0)
        tdSql.checkData(10,1,None)
        tdSql.checkData(59,1,None)
526 527
        tdSql.checkData(60,1,100)
        tdSql.checkData(61,1,100)
528

529
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(linear) group by tbname;")
530
        tdSql.checkRows(180)
531
        tdSql.checkData(0,1,100)
532 533 534
        tdSql.checkData(9,1,0)
        tdSql.checkData(10,1,None)
        tdSql.checkData(59,1,None)
535 536
        tdSql.checkData(60,1,100)
        tdSql.checkData(61,1,100)
537

538
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(NULL) group by tbname;")
539
        tdSql.checkRows(180)
540
        tdSql.checkData(0,1,100)
541 542 543
        tdSql.checkData(9,1,0)
        tdSql.checkData(10,1,None)
        tdSql.checkData(59,1,None)
544 545
        tdSql.checkData(60,1,100)
        tdSql.checkData(61,1,100)
546

547
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(10s) fill(value ,2) group by tbname;")
548
        tdSql.checkRows(180)
549
        tdSql.checkData(0,1,100)
550
        tdSql.checkData(9,1,0)
551 552
        tdSql.checkData(10,1,20)
        tdSql.checkData(59,1,20)
553
        tdSql.checkData(60,1,10)
554
        tdSql.checkData(61,1,100)
G
Ganlin Zhao 已提交
555 556

        # interval (20s)  and time range is outer records
557
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(prev) group by tbname,ind ;")
558
        tdSql.checkRows(90)
559 560 561 562 563 564 565 566
        tdSql.checkData(0,1,200)
        tdSql.checkData(4,1,100)
        tdSql.checkData(5,1,100)
        tdSql.checkData(29,1,100)
        tdSql.checkData(30,1,200)
        tdSql.checkData(31,1,200)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(next) group by tbname,ind ;")
567
        tdSql.checkRows(90)
568 569
        tdSql.checkData(0,1,200)
        tdSql.checkData(4,1,100)
570 571
        tdSql.checkData(5,1,None)
        tdSql.checkData(29,1,None)
572 573
        tdSql.checkData(30,1,200)
        tdSql.checkData(31,1,200)
574

575
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(linear) group by tbname,ind ;")
576
        tdSql.checkRows(90)
577 578
        tdSql.checkData(0,1,200)
        tdSql.checkData(4,1,100)
579 580
        tdSql.checkData(5,1,None)
        tdSql.checkData(29,1,None)
581 582
        tdSql.checkData(30,1,200)
        tdSql.checkData(31,1,200)
583

584
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(NULL) group by tbname,ind ;")
585
        tdSql.checkRows(90)
586 587
        tdSql.checkData(0,1,200)
        tdSql.checkData(4,1,100)
588 589
        tdSql.checkData(5,1,None)
        tdSql.checkData(29,1,None)
590 591
        tdSql.checkData(30,1,200)
        tdSql.checkData(31,1,200)
G
Ganlin Zhao 已提交
592

593
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:10:00.000' interval(20s) fill(value ,2) group by tbname,ind ;")
594
        tdSql.checkRows(90)
595 596 597 598 599 600
        tdSql.checkData(0,1,200)
        tdSql.checkData(4,1,100)
        tdSql.checkData(5,1,20)
        tdSql.checkData(29,1,20)
        tdSql.checkData(30,1,200)
        tdSql.checkData(31,1,200)
601

G
Ganlin Zhao 已提交
602
        # interval (20s)  and time range is in records
603

604
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(prev) group by tbname,ind ;")
605
        tdSql.checkRows(9)
606 607 608 609 610 611 612 613
        tdSql.checkData(0,1,200)
        tdSql.checkData(2,1,100)
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
        tdSql.checkData(7,1,200)
        tdSql.checkData(8,1,100)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(next) group by tbname,ind ;")
614
        tdSql.checkRows(9)
615 616 617 618 619 620 621 622
        tdSql.checkData(0,1,200)
        tdSql.checkData(2,1,100)
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
        tdSql.checkData(7,1,200)
        tdSql.checkData(8,1,100)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(linear) group by tbname,ind ;")
623
        tdSql.checkRows(9)
624 625 626 627 628 629 630 631
        tdSql.checkData(0,1,200)
        tdSql.checkData(2,1,100)
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
        tdSql.checkData(7,1,200)
        tdSql.checkData(8,1,100)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;")
632
        tdSql.checkRows(9)
633 634 635 636 637 638 639 640
        tdSql.checkData(0,1,200)
        tdSql.checkData(2,1,100)
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
        tdSql.checkData(7,1,200)
        tdSql.checkData(8,1,100)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(value ,2 ) group by tbname,ind ;")
641
        tdSql.checkRows(9)
642 643 644 645 646 647 648 649
        tdSql.checkData(0,1,200)
        tdSql.checkData(2,1,100)
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
        tdSql.checkData(7,1,200)
        tdSql.checkData(8,1,100)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2015-01-01 00:00:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) group by tbname,ind ;")
650
        tdSql.checkRows(9)
651 652 653 654 655 656 657 658
        tdSql.checkData(0,1,200)
        tdSql.checkData(2,1,100)
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
        tdSql.checkData(7,1,200)
        tdSql.checkData(8,1,100)

        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) fill(NULL) group by tbname,ind ;")
659 660 661
        tdSql.checkRows(18)
        tdSql.checkData(0,1,None)
        tdSql.checkData(2,1,None)
662 663
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
664 665
        tdSql.checkData(7,1,None)
        tdSql.checkData(8,1,None)
666
        tdSql.checkData(9,1,200)
667 668 669

        # interval sliding

670
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(20s) fill(NULL) group by tbname,ind ;")
671 672 673
        tdSql.checkRows(18)
        tdSql.checkData(0,1,None)
        tdSql.checkData(2,1,None)
674 675
        tdSql.checkData(3,1,200)
        tdSql.checkData(5,1,100)
676 677
        tdSql.checkData(7,1,None)
        tdSql.checkData(8,1,None)
678
        tdSql.checkData(9,1,200)
679

680
        tdSql.query("select elapsed(ts,1s)*10 from stable_1 where ts >= '2014-12-31 23:59:00.000' and ts <'2015-01-01 00:01:00.000' interval(20s) sliding(10s) fill(NULL) group by tbname,ind ;")
681 682 683
        tdSql.checkRows(39)
        tdSql.checkData(0,1,None)
        tdSql.checkData(2,1,None)
684 685
        tdSql.checkData(6,1,100)
        tdSql.checkData(7,1,200)
686 687 688
        tdSql.checkData(12,1,0)
        tdSql.checkData(13,1,None)
        tdSql.checkData(15,1,None)
689 690
        tdSql.checkData(19,1,100)
        tdSql.checkData(20,1,200)
691
        tdSql.checkData(25,1,0)
G
Ganlin Zhao 已提交
692

693 694 695 696
    def query_mix_common(self):

        tdLog.info (" ======================================elapsed mixup with common col, it will not support =======================================")

697
        tdSql.query("select elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  and ind =1  group by tbname; ")
698
        tdSql.checkRows(1)
699
        tdSql.checkData(0,0,60)
700

701
        tdSql.query("select elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  ; ")
702
        tdSql.checkRows(1)
703
        tdSql.checkData(0,0,60)
704

705 706
        tdSql.error("select ts,elapsed(ts,1s) from sub_empty_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000' ; ")
        tdSql.error("select ts,elapsed(ts,1s) from stable_empty where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  group by tbname; ")
707

708 709
        tdSql.error("select ts,elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000' ; ")
        tdSql.error("select ts,elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  group by tbname; ")
710

711 712
        tdSql.error("select q_int,elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000' ; ")
        tdSql.error("select q_int,elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  group by tbname; ")
713

714 715
        tdSql.error("select ts,q_int,elapsed(ts,1s) from sub_table1_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000' ; ")
        tdSql.error("select ts,q_int,elapsed(ts,1s) from stable_1 where ts between '2015-01-01 00:00:00.000'  and '2015-01-01 00:01:00.000'  group by tbname; ")
716 717 718 719 720

    def query_mix_Aggregate(self):

        tdLog.info (" ====================================== elapsed mixup with aggregate ==================================================")

721
        tdSql.query("select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) from sub_table1_1 ; ")
722

723
        data = tdSql.getResult("select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) from sub_table1_1 ; ")
724

725
        querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)", "elapsed(ts,1s)"]
726 727 728 729 730 731

        for index , query in enumerate(querys):
            sql = "select %s from sub_table1_1 " %(query)
            tdSql.query(sql)
            tdSql.checkData(0,0,data[0][index])

732
        tdSql.query("select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) from stable_1  group by tbname; ")
G
Ganlin Zhao 已提交
733

734 735 736
        # Arithmetic with elapsed for common table

        operators = ["+" ,"-" , "*" ,"/" ,"%"]
737
        querys_oper = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)", "elapsed(ts,1s)"]
738 739 740 741 742 743 744 745

        for operator in operators:

            query_datas=[]

            sql_common= "select "

            for index , query in enumerate(querys_oper):
G
Ganlin Zhao 已提交
746

747
                query_data = tdSql.getResult("select %s from sub_table1_1;"%query)
G
Ganlin Zhao 已提交
748

749 750 751 752 753 754 755
                query_datas.append(query_data[0][0])
                sql_common += " %s %s " %(query,operator)
            sql_common=sql_common[:-2] + " from sub_table1_1;"

            tdSql.query(sql_common)
            results= query_datas[0]
            if operator == "+":
G
Ganlin Zhao 已提交
756
                for data in query_datas[1:]:
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
                    results += data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "-":
                for data in query_datas[1:]:
                    results -= data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "*":
                for data in query_datas[1:]:
                    results *= data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "/":
                for data in query_datas[1:]:
                    results /= data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "%":
                for data in query_datas[1:]:
                    results %= data
                tdSql.checkData(0,0,results)


        # Arithmetic with elapsed for super table

        operators = ["+" ,"-" , "*" ,"/" ,"%"]
788
        querys_oper = ["count(*)","avg(q_int)",  "sum(q_double)","stddev(q_float)", "elapsed(ts,1s)"]
789 790 791 792 793 794 795 796

        for operator in operators:

            query_datas=[]

            sql_common= "select "

            for index , query in enumerate(querys_oper):
G
Ganlin Zhao 已提交
797

798
                query_data = tdSql.getResult("select %s from stable_1 group by tbname;"%query)
G
Ganlin Zhao 已提交
799

800 801 802 803 804 805 806
                query_datas.append(query_data[0][0])
                sql_common += " %s %s " %(query,operator)
            sql_common=sql_common[:-2] + " from stable_1 group by tbname;"

            tdSql.query(sql_common)
            results= query_datas[0]
            if operator == "+":
G
Ganlin Zhao 已提交
807
                for data in query_datas[1:]:
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
                    results += data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)


            results= query_datas[0]
            if operator == "-":
                for data in query_datas[1:]:
                    results -= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

            results= query_datas[0]
            if operator == "*":
                for data in query_datas[1:]:
                    results *= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

            results= query_datas[0]
            if operator == "/":
                for data in query_datas[1:]:
                    results /= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

            results= query_datas[0]
            if operator == "%":
                for data in query_datas[1:]:
                    results %= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

    def query_mix_select(self):

        tdLog.info (" ====================================== elapsed mixup with select function =================================================")

850
        querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,1s)"]
851

G
Ganlin Zhao 已提交
852

853
        querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)","elapsed(ts,1s)"]
G
Ganlin Zhao 已提交
854

855
        tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,1s) from sub_table1_1 ; ")
856

857
        data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),PERCENTILE(q_int,10),APERCENTILE(q_int,10) ,elapsed(ts,1s) from sub_table1_1 ; ")
858 859 860 861 862 863

        for index , query in enumerate(querys_mix):
            sql = "select %s from sub_table1_1 " %(query)
            tdSql.query(sql)
            tdSql.checkData(0,0,data[0][index])

864
        tdSql.query("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,1s) from stable_1 group by tbname ; ")
865

866
        data = tdSql.getResult("select max(q_int),min(q_int) , first(q_tinyint), first(q_int),last(q_int),APERCENTILE(q_int,10) ,elapsed(ts,1s) from stable_1 group by tbname ; ")
867

868
        querys_mix = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(q_int)","last(q_int)","APERCENTILE(q_int,10)","elapsed(ts,1s)"]
869 870 871 872 873 874 875

        for index , query in enumerate(querys_mix):
            sql = "select %s from stable_1 group by tbname " %(query)
            tdSql.query(sql)
            tdSql.checkData(0,0,data[0][index])
            tdSql.checkData(1,0,data[0][index])
            tdSql.checkData(2,0,data[0][index])
G
Ganlin Zhao 已提交
876

877 878 879 880 881 882 883 884 885 886
        operators = ["+" ,"-" , "*" ,"/" ,"%"]
        querys_oper = querys_mix

        for operator in operators:

            query_datas=[]

            sql_common= "select "

            for index , query in enumerate(querys_oper):
G
Ganlin Zhao 已提交
887

888
                query_data = tdSql.getResult("select %s from sub_table1_1;"%query)
G
Ganlin Zhao 已提交
889

890 891 892 893 894 895 896
                query_datas.append(query_data[0][0])
                sql_common += " %s %s " %(query,operator)
            sql_common=sql_common[:-2] + " from sub_table1_1;"

            tdSql.query(sql_common)
            results= query_datas[0]
            if operator == "+":
G
Ganlin Zhao 已提交
897
                for data in query_datas[1:]:
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937
                    results += data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "-":
                for data in query_datas[1:]:
                    results -= data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "*":
                for data in query_datas[1:]:
                    results *= data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "/":
                for data in query_datas[1:]:
                    results /= data
                tdSql.checkData(0,0,results)

            results= query_datas[0]
            if operator == "%":
                for data in query_datas[1:]:
                    results %= data
                tdSql.checkData(0,0,results)


        # Arithmetic with elapsed for super table

        operators = ["+" ,"-" , "*" ,"/" ,"%"]
        querys_oper = querys_mix

        for operator in operators:

            query_datas=[]

            sql_common= "select "

            for index , query in enumerate(querys_oper):
G
Ganlin Zhao 已提交
938

939
                query_data = tdSql.getResult("select %s from stable_1 group by tbname;"%query)
G
Ganlin Zhao 已提交
940

941 942 943 944 945 946 947
                query_datas.append(query_data[0][0])
                sql_common += " %s %s " %(query,operator)
            sql_common=sql_common[:-2] + " from stable_1 group by tbname;"

            tdSql.query(sql_common)
            results= query_datas[0]
            if operator == "+":
G
Ganlin Zhao 已提交
948
                for data in query_datas[1:]:
949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985
                    results += data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)


            results= query_datas[0]
            if operator == "-":
                for data in query_datas[1:]:
                    results -= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

            results= query_datas[0]
            if operator == "*":
                for data in query_datas[1:]:
                    results *= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

            results= query_datas[0]
            if operator == "/":
                for data in query_datas[1:]:
                    results /= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)

            results= query_datas[0]
            if operator == "%":
                for data in query_datas[1:]:
                    results %= data
                tdSql.checkData(0,0,results)
                tdSql.checkData(1,0,results)
                tdSql.checkData(2,0,results)
G
Ganlin Zhao 已提交
986

987 988 989 990 991 992 993 994
    def query_mix_compute(self):

        tdLog.info (" ====================================== elapsed mixup with compute function =================================================")

        querys = ["diff(q_int)","DERIVATIVE(q_int,1s,1)","spread(ts)","spread(q_tinyint)","ceil(q_float)","floor(q_float)","round(q_float)"]

        for index , query in enumerate(querys):

995 996
            sql1 = "select elapsed(ts,1s),%s from sub_table1_1 " %(query)
            sql2 = "select elapsed(ts,1s),%s from stable_1  group by tbname" %(query)
997 998 999 1000 1001 1002
            if query in ["diff(q_int)","DERIVATIVE(q_int,1s,1)","ceil(q_float)","floor(q_float)","round(q_float)"]:
                tdSql.error(sql1)
                tdSql.error(sql2)
                continue
            tdSql.query(sql1)
            tdSql.query(sql2)
G
Ganlin Zhao 已提交
1003 1004

        # only support mixup with spread
1005

1006
        sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,1s) from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\"  ;"
1007 1008 1009 1010
        tdSql.execute(sql)

        data = tdSql.getResult(sql)

1011
        sql = "select spread(ts)*10,spread(q_tinyint)-10,elapsed(ts,1s) from stable_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" ;"
1012 1013
        tdSql.execute(sql)

1014
        querys_mix = ["spread(ts)","spread(q_tinyint)-10","elapsed(ts,1s)"]
1015 1016 1017 1018

        for index , query in enumerate(querys_mix):
            sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" ; " %(query)
            tdSql.query(sql)
G
Ganlin Zhao 已提交
1019

1020 1021 1022 1023 1024 1025 1026 1027
        operators = ["+" ,"-" , "*" ,"/" ,"%"]
        querys_oper = querys_mix

        for operator in operators:

            sql_common= "select "

            for index , query in enumerate(querys_oper):
G
Ganlin Zhao 已提交
1028

1029 1030 1031 1032 1033 1034 1035 1036
                sql_common += " %s %s " %(query,operator)
            sql_common=sql_common[:-2] + " from stable_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" ;"

            tdSql.query(sql_common)

        for index , query in enumerate(querys_mix):
            sql = "select %s from stable_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\"  ; " %(query)
            tdSql.query(sql)
G
Ganlin Zhao 已提交
1037

1038 1039 1040 1041 1042 1043 1044 1045
        operators = ["+" ,"-" , "*" ,"/" ,"%"]
        querys_oper = querys_mix

        for operator in operators:

            sql_common= "select "

            for index , query in enumerate(querys_oper):
G
Ganlin Zhao 已提交
1046

1047 1048 1049 1050
                sql_common += " %s %s " %(query,operator)
            sql_common=sql_common[:-2] + " from stable_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" ;"

            tdSql.query(sql_common)
G
Ganlin Zhao 已提交
1051

1052
    def query_mix_arithmetic(self):
G
Ganlin Zhao 已提交
1053

1054
        tdLog.info (" ====================================== elapsed mixup with arithmetic =================================================")
G
Ganlin Zhao 已提交
1055

1056 1057
        tdSql.execute("select elapsed(ts,1s)+1 ,elapsed(ts,1s)-2,elapsed(ts,1s)*3,elapsed(ts,1s)/4,elapsed(ts,1s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" ; ")
        tdSql.execute("select elapsed(ts,1s)+1 ,elapsed(ts,1s)-2,elapsed(ts,1s)*3,elapsed(ts,1s)/4,elapsed(ts,1s)%5 from stable_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" ; ")
G
Ganlin Zhao 已提交
1058

1059
        # queries = ["elapsed(ts,1s)+1" ,"elapsed(ts,1s)-2","elapsed(ts,1s)*3","elapsed(ts,1s)/4","elapsed(ts,1s)%5" ]
G
Ganlin Zhao 已提交
1060

1061 1062 1063
        # for index ,query in enumerate(queries):
        #     sql = "select %s from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ;" % (query)
        #     data =  tdSql.getResult(sql)
1064
        #     tdSql.query("select elapsed(ts,1s)+1 ,elapsed(ts,1s)-2,elapsed(ts,1s)*3,elapsed(ts,1s)/4,elapsed(ts,1s)%5 from sub_table1_1 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev) ; ")
1065 1066 1067 1068 1069
        #     tdSql.checkData(0,index+1,data[0][1])

    def query_with_join(self):

        tdLog.info (" ====================================== elapsed mixup with join =================================================")
G
Ganlin Zhao 已提交
1070

1071 1072
        tdSql.error("select elapsed(ts,1s) from stable_empty TABLE1 , stable_empty TABLE2  where TABLE1.ts =TABLE2.ts; ")
        tdSql.error("select elapsed(ts,1s) from stable_empty TABLE1 , stable_empty TABLE2  where TABLE1.ts =TABLE2.ts group by tbname; ")
1073

1074 1075 1076
        tdSql.execute("select elapsed(ts,1s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2  where TABLE1.ts =TABLE2.ts; ")
        tdSql.error("select elapsed(ts,1s) from stable_1 TABLE1 , stable_2 TABLE2  where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind; ")
        tdSql.error("select elapsed(ts,1s) from stable_1 TABLE1 , stable_2 TABLE2  where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind group by tbname,ind; ") # join not support group by
1077

1078 1079
        tdSql.error("select elapsed(ts,1s) from sub_empty_1 TABLE1 , stable_2 TABLE2  where TABLE1.ts =TABLE2.ts and TABLE1.ind =TABLE2.ind ; ")
        tdSql.execute("select elapsed(ts,1s) from sub_empty_1 TABLE1 , sub_empty_2 TABLE2  where TABLE1.ts =TABLE2.ts ; ")
1080

1081 1082
        tdSql.query("select elapsed(ts,1s) from sub_table1_1 TABLE1 , sub_table1_2 TABLE2  where TABLE1.ts =TABLE2.ts ; ")
        tdSql.checkData(0,0,90)
1083

1084
        tdSql.query("select elapsed(ts,1s) from sub_empty_1 TABLE1 , sub_table1_2 TABLE2  where TABLE1.ts =TABLE2.ts ; ")
1085 1086
        tdSql.checkRows(0)

1087
        tdSql.query("select elapsed(ts,1s) from sub_empty_1 TABLE1 , regular_empty  TABLE2  where TABLE1.ts =TABLE2.ts ; ")
1088 1089
        tdSql.checkRows(0)

1090
        tdSql.query("select elapsed(ts,1s) from sub_empty_1 TABLE1 , regular_table_1  TABLE2  where TABLE1.ts =TABLE2.ts ; ")
1091 1092
        tdSql.checkRows(0)

1093
        tdSql.query("select elapsed(ts,1s) from sub_table1_3 TABLE1 , regular_table_1  TABLE2  where TABLE1.ts =TABLE2.ts ; ")
1094
        tdSql.checkRows(1)
1095
        tdSql.checkData(0,0,90)
1096

1097
        tdSql.query("select elapsed(ts,1s) from regular_table_1 ; ")
1098
        tdSql.checkRows(1)
1099
        tdSql.checkData(0,0,90)
1100 1101 1102 1103 1104

    def query_with_union(self):

        tdLog.info (" ====================================== elapsed mixup with union all =================================================")

G
Ganlin Zhao 已提交
1105
        # union all with empty
1106

1107
        tdSql.query("select elapsed(ts,1s) from regular_table_1  union all  select elapsed(ts,1s) from regular_table_2;")
1108

1109 1110
        tdSql.query("select elapsed(ts,1s) from regular_table_1  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)  union all \
        select elapsed(ts,1s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);")
1111
        tdSql.checkRows(1200)
1112
        tdSql.checkData(0,1,1)
1113 1114
        tdSql.checkData(500,1,0)

1115 1116
        tdSql.query("select elapsed(ts,1s) from sub_empty_1  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)  union all \
        select elapsed(ts,1s) from regular_table_2 where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);")
1117
        tdSql.checkRows(600)
1118
        tdSql.checkData(0,1,1)
1119
        tdSql.checkData(500,0,0)
G
Ganlin Zhao 已提交
1120

1121
        tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from sub_empty_2;')
1122 1123
        tdSql.checkRows(0)

1124
        tdSql.query('select elapsed(ts,1s) from regular_table_1 union all select elapsed(ts,1s) from sub_empty_1;')
1125
        tdSql.checkRows(1)
1126
        tdSql.checkData(0,0,90)
1127

1128
        tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from regular_table_1;')
1129
        tdSql.checkRows(1)
1130
        tdSql.checkData(0,0,90)
1131

1132
        tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from sub_table1_1;')
1133
        tdSql.checkRows(1)
1134
        tdSql.checkData(0,0,90)
1135

1136
        tdSql.query('select elapsed(ts,1s) from sub_table1_1 union all select elapsed(ts,1s) from sub_empty_1;')
1137
        tdSql.checkRows(1)
1138
        tdSql.checkData(0,0,90)
1139

1140
        tdSql.query('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from regular_table_1;')
1141
        tdSql.checkRows(1)
1142
        tdSql.checkData(0,0,90)
1143

1144
        tdSql.error('select elapsed(ts,1s) from sub_empty_1 union all select elapsed(ts,1s) from stable_sub_empty group by tbname;')
1145

1146
        tdSql.error('select elapsed(ts,1s) from regular_table_1 union all select elapsed(ts,1s) from stable_sub_empty group by tbname;')
1147

1148
        tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,1s) from sub_empty_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev);')
1149 1150
        tdSql.checkRows(0)

1151
        tdSql.error('select elapsed(ts,1s) from sub_empty_1   union all select elapsed(ts,1s) from stable_empty  group by tbname;')
G
Ganlin Zhao 已提交
1152

1153
        tdSql.error('select elapsed(ts,1s) from sub_empty_1  interval(1s)  union all select elapsed(ts,1s) from stable_empty interval(1s)  group by tbname;')
G
Ganlin Zhao 已提交
1154

1155
        # tdSql.error('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) union all select elapsed(ts,1s) from stable_empty where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(1s) fill(prev) group by tbname;')
G
Ganlin Zhao 已提交
1156

1157
        tdSql.query("select elapsed(ts,1s) from stable_empty  group by tbname union all select elapsed(ts,1s) from stable_empty group by tbname ;")
1158 1159 1160
        tdSql.checkRows(0)

        # case : TD-12229
1161
        tdSql.query("select elapsed(ts,1s) from stable_empty  group by tbname union all select elapsed(ts,1s) from stable_1 group by tbname ;")
1162 1163
        tdSql.checkRows(3)

1164
        tdSql.query("select elapsed(ts,1s) from stable_1  group by tbname union all select elapsed(ts,1s) from stable_1 group by tbname ;")
1165
        tdSql.checkRows(6)
1166 1167
        tdSql.checkData(0,0,90)
        tdSql.checkData(5,0,90)
1168

1169
        tdSql.query("select elapsed(ts,1s) from stable_1  group by tbname union all select elapsed(ts,1s) from stable_2 group by tbname ;")
1170
        tdSql.checkRows(6)
1171 1172
        tdSql.checkData(0,0,90)
        tdSql.checkData(5,0,90)
1173

1174 1175
        tdSql.query('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\
             select elapsed(ts,1s) from stable_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;')
1176
        tdSql.checkRows(360)
1177
        tdSql.checkData(0,1,10)
1178
        tdSql.checkData(50,1,0)
G
Ganlin Zhao 已提交
1179

1180
        #case : TD-12229
1181
        tdSql.query('select elapsed(ts,1s) from stable_empty group by tbname union all  select elapsed(ts,1s) from stable_2 group by tbname ;')
1182 1183
        tdSql.checkRows(3)

1184
        tdSql.query('select elapsed(ts,1s) from stable_1 group by tbname union all  select elapsed(ts,1s) from stable_empty group by tbname ;')
1185 1186 1187
        tdSql.checkRows(3)


1188 1189
        tdSql.query('select elapsed(ts,1s) from stable_empty where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\
             select elapsed(ts,1s) from stable_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;')
1190 1191
        tdSql.checkRows(180)

1192 1193
        tdSql.query('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname union all\
             select elapsed(ts,1s) from stable_empty where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname ;')
1194 1195 1196 1197
        tdSql.checkRows(180)

        # union all with sub table and regular table

G
Ganlin Zhao 已提交
1198
        # sub_table with sub_table
1199

1200 1201
        tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from sub_table2_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1202
        tdSql.checkRows(120)
1203
        tdSql.checkData(0,1,10)
1204 1205
        tdSql.checkData(12,1,0)

1206 1207
        tdSql.query('select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1208
        tdSql.checkRows(120)
1209
        tdSql.checkData(0,1,10)
1210 1211
        tdSql.checkData(12,1,0)

1212 1213
        tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from sub_table1_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1214
        tdSql.checkRows(120)
1215
        tdSql.checkData(0,1,10)
1216 1217
        tdSql.checkData(12,1,0)

1218 1219
        tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1220
        tdSql.checkRows(120)
1221
        tdSql.checkData(0,1,10)
1222 1223
        tdSql.checkData(12,1,0)

1224 1225
        tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1226
        tdSql.checkRows(120)
1227
        tdSql.checkData(0,1,10)
1228 1229
        tdSql.checkData(12,1,0)

1230 1231
        tdSql.query('select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1232
        tdSql.checkRows(120)
1233
        tdSql.checkData(0,1,10)
1234
        tdSql.checkData(12,1,0)
G
Ganlin Zhao 已提交
1235

1236 1237
        tdSql.query('select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1238
        tdSql.checkRows(60)
1239
        tdSql.checkData(0,1,10)
1240 1241
        tdSql.checkData(12,1,0)

1242 1243
        tdSql.query('select elapsed(ts,1s) from regular_table_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  union all\
             select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1244
        tdSql.checkRows(60)
1245
        tdSql.checkData(0,1,10)
1246 1247
        tdSql.checkData(12,1,0)

G
Ganlin Zhao 已提交
1248
        # stable with stable
1249

1250 1251
        tdSql.query('select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev)  group by tbname union all\
             select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) group by tbname;')
1252
        tdSql.checkRows(360)
1253
        tdSql.checkData(0,1,10)
1254 1255
        tdSql.checkData(12,1,0)

1256
        tdSql.query('select elapsed(ts,1s) from regular_table_2  interval(10s)  union all  select elapsed(ts,1s) from sub_empty_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev);')
1257
        tdSql.checkRows(10)
1258
        tdSql.checkData(0,1,10)
1259 1260
        tdSql.checkData(9,1,0)

1261
        tdSql.query('select elapsed(ts,1s) from regular_table_2  interval(10s)  union all  select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(10s) fill(prev) ;')
1262
        tdSql.checkRows(70)
1263
        tdSql.checkData(0,1,10)
1264 1265
        tdSql.checkData(9,1,0)

1266
        tdSql.query('select elapsed(ts,1s) from regular_table_2  interval(10s) order by ts desc union all  select elapsed(ts,1s) from regular_table_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  interval(10s) fill(prev) order by ts asc;')
1267 1268
        tdSql.checkRows(70)
        tdSql.checkData(0,1,0)
1269 1270
        tdSql.checkData(1,1,10)
        tdSql.checkData(9,1,10)
1271

1272
        tdSql.query('select elapsed(ts,1s) from stable_1 group by tbname, ind  order by ts desc union all  select elapsed(ts,1s) from stable_2 group by tbname, ind  order by ts asc ;')
1273
        tdSql.checkRows(6)
1274
        tdSql.checkData(0,0,90)
1275

1276
        tdSql.query('select elapsed(ts,1s) from stable_1 group by tbname, ind  order by ts desc union all  select elapsed(ts,1s) from stable_1 group by tbname, ind  order by ts asc ;')
1277
        tdSql.checkRows(6)
1278
        tdSql.checkData(0,0,90)
1279

1280
        tdSql.query('select elapsed(ts,1s) from stable_1  interval(10s) group by tbname,ind order by ts desc union all  select elapsed(ts,1s) from stable_2 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  interval(10s) fill(prev) group by tbname,ind order by ts asc ;')
1281 1282
        tdSql.checkRows(210)
        tdSql.checkData(0,1,0)
1283
        tdSql.checkData(1,1,10)
1284 1285
        tdSql.checkData(9,1,1)

1286
        tdSql.query('select elapsed(ts,1s) from stable_2  interval(10s) group by tbname,ind order by ts desc union all  select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  interval(10s) fill(prev) group by tbname,ind order by ts asc ;')
1287 1288
        tdSql.checkRows(210)
        tdSql.checkData(0,1,0)
1289 1290
        tdSql.checkData(1,1,10)
        tdSql.checkData(9,1,10)
1291

1292
        tdSql.query('select elapsed(ts,1s) from stable_1  interval(10s) group by tbname,ind order by ts desc union all  select elapsed(ts,1s) from stable_1 where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  interval(10s) fill(prev) group by tbname,ind order by ts asc ;')
1293 1294
        tdSql.checkRows(210)
        tdSql.checkData(0,1,0)
1295 1296
        tdSql.checkData(1,1,10)
        tdSql.checkData(9,1,10)
1297 1298 1299 1300 1301 1302

    def query_nest(self):

        tdLog.info (" ====================================== elapsed query for nest =================================================")

        # ===============================================outer nest============================================
G
Ganlin Zhao 已提交
1303

1304 1305 1306 1307
        # regular table

        # ts can't be used at outer query

1308
        tdSql.query("select elapsed(ts,1s) from (select ts from regular_table_1 );")
1309

G
Ganlin Zhao 已提交
1310
        # case : TD-12164
1311

1312 1313
        tdSql.error("select elapsed(ts,1s) from (select qint ts from regular_table_1 );")
        tdSql.error("select elapsed(tbname ,1s) from (select qint tbname from regular_table_1 );")
1314 1315 1316
        tdSql.error("select elapsed(tsc ,1s) from (select q_int tsc from regular_table_1) ;")
        tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from regular_table_1);")
        tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1);")
G
Ganlin Zhao 已提交
1317
        # # bug fix
1318
        tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;")
G
Ganlin Zhao 已提交
1319

1320
        # case TD-12276
1321 1322
        tdSql.query("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts asc );")
        tdSql.checkData(0,0,90.000000000)
1323

1324 1325
        tdSql.query("select elapsed(ts,1s) from (select ts,tbname  from regular_table_1 order by ts desc );")
        tdSql.checkData(0,0,90.000000000)
1326

1327
        tdSql.query("select elapsed(ts,1s) from (select ts ,max(q_int),tbname  from regular_table_1 order by ts  ) interval(1s);")
1328

1329
        tdSql.query("select elapsed(ts,1s) from (select ts ,q_int,tbname  from regular_table_1 order by ts  ) interval(10s);")
1330 1331 1332

        # sub table

1333
        tdSql.query("select elapsed(ts,1s) from (select ts from sub_table1_1  );")
1334

1335
        tdSql.query("select elapsed(ts,1s) from (select ts ,max(q_int),tbname  from sub_table1_1 order by ts  ) interval(1s);")
1336

1337
        tdSql.query("select elapsed(ts,1s) from (select ts ,q_int,tbname  from sub_table1_1 order by ts  ) interval(10s);")
G
Ganlin Zhao 已提交
1338

1339
        tdSql.query("select elapsed(ts,1s) from (select ts ,tbname,top(q_int,3)  from sub_table1_1   ) interval(10s);")
G
Ganlin Zhao 已提交
1340

1341
        tdSql.query("select elapsed(ts,1s) from (select ts ,tbname,bottom(q_int,3)  from sub_table1_1   ) interval(10s);")
G
Ganlin Zhao 已提交
1342

1343
        tdSql.query("select elapsed(ts,1s) from (select ts ,tbname from sub_table1_1   ) interval(10s);")
1344

1345
        tdSql.query("select elapsed(ts,1s) from (select ts ,tbname from sub_table1_1   ) interval(10s);")
1346

1347
        tdSql.error("select elapsed(ts,1s) from (select ts ,count(*),tbname  from sub_table1_1 order by ts  ) interval(1s);")
1348

1349
        querys = ["count(*)","avg(q_int)", "sum(q_double)","stddev(q_float)","LEASTSQUARES(q_int,0,1)","elapsed(ts,1s)"]
G
Ganlin Zhao 已提交
1350

1351
        for query in querys:
1352 1353 1354 1355 1356
            sql1 = "select elapsed(ts,1s) from (select %s from regular_table_1 order by ts  ) interval(1s); " % query
            sql2 = "select elapsed(ts,1s) from (select ts , tbname ,%s from regular_table_1 order by ts  ) interval(1s); " % query
            sql3 = "select elapsed(ts,1s) from (select ts , tbname ,%s from stable_1 group by tbname, ind order by ts  ) interval(1s); " % query
            sql4 = "select elapsed(ts,1s) from (select %s from sub_table2_1  order by ts  ) interval(1s); " % query
            sql5 = "select elapsed(ts,1s) from (select ts , tbname ,%s from sub_table2_1  order by ts  ) interval(1s); " % query
1357 1358 1359 1360 1361 1362 1363

            tdSql.error(sql1)
            tdSql.error(sql2)
            tdSql.error(sql3)
            tdSql.error(sql4)
            tdSql.error(sql5)

G
Ganlin Zhao 已提交
1364

1365 1366 1367
        # case TD-12164
        tdSql.error( "select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from regular_table_1) ; " )
        tdSql.error( "select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1) ; " )
G
Ganlin Zhao 已提交
1368

1369 1370 1371 1372
        tdSql.error( "select elapsed(ts00 ,1s) from (select elapsed(ts,1s) ts00 from stable_1 group by tbname ) ; " )
        tdSql.error( "select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from stable_1 group by tbname) ; " )


G
Ganlin Zhao 已提交
1373
        # stable
1374

1375
        tdSql.error("select elapsed(ts,1s) from (select ts from stable_1 ) group by tbname ;")
1376

1377
        tdSql.error("select elapsed(ts,1s) from (select ts ,max(q_int),tbname  from stable_1 group by tbname order by ts ) interval(1s) group by tbname;")
1378

1379
        tdSql.error("select elapsed(ts,1s) from (select ts ,q_int,tbname  from stable_1 order by ts ) interval(1s) group by tbname;")
1380

G
Ganlin Zhao 已提交
1381
        # mixup with aggregate
1382 1383

        querys = ["max(q_int)","min(q_int)" , "first(q_tinyint)", "first(*)","last(q_int)","last(*)","top(q_double,1)",
1384
        "bottom(q_float,1)","PERCENTILE(q_int,10)","APERCENTILE(q_int,10)" ,"elapsed(ts,1s)"]
1385 1386 1387

        for index , query in enumerate(querys):

1388 1389 1390
            sql1 = "select elapsed(ts,1s) from (select %s from sub_table1_1) where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev) ;  " %(query)
            sql2 = "select elapsed(ts,1s) from (select %s from stable_1 ) where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev)  group by tbname; " %(query)
            sql3 = "select elapsed(ts,1s) from (select %s from stable_1 group by tbname) where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(10s) fill(prev)  group by tbname; " %(query)
1391

G
Ganlin Zhao 已提交
1392
            if query in ["interp(q_int)"  ]:
1393 1394 1395 1396 1397 1398 1399 1400 1401
                # print(sql1 )
                # print(sql2)
                tdSql.query(sql1)
                tdSql.error(sql2)
            else:
                tdSql.error(sql1)
                tdSql.error(sql2)
                tdSql.error(sql3)

1402
        tdSql.query("select elapsed(ts,1s) from (select ts,tbname  from regular_table_1 order by ts  ) where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);")
1403

1404
        tdSql.query("select elapsed(ts,1s) from (select ts ,max(q_int),tbname  from regular_table_1 order by ts  ) where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev);")
1405 1406 1407 1408 1409

        # ===============================================inner nest============================================

        # sub table

1410 1411
        tdSql.query("select data from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from sub_table1_1 ); ")
        tdSql.checkData(0,0,90)
1412

1413
        # tdSql.query("select data from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from sub_table1_1 \
1414 1415
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)
1416
        # tdSql.checkData(0,0,1)
1417

1418 1419
        tdSql.query("select * from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 ); ")
        tdSql.checkData(0,5,90)
1420

1421
        # tdSql.query("select * from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1422 1423
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)
1424
        # tdSql.checkData(0,0,1)
1425

1426 1427
        tdSql.query("select max(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 ); ")
        tdSql.checkData(0,0,90)
1428

1429
        # tdSql.query("select max(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1430 1431
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(1)
1432
        # tdSql.checkData(0,0,1)
1433

1434
        # tdSql.query("select max(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from sub_empty_2 \
1435 1436 1437
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(0)

1438
        # tdSql.query("select max(data),min(data),avg(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1439 1440 1441
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(1)

1442
        # tdSql.query("select ceil(data),floor(data),round(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1443 1444 1445
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)

1446
        # tdSql.query("select spread(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1447 1448
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(1)
G
Ganlin Zhao 已提交
1449

1450
        # tdSql.query("select diff(data) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1451 1452 1453 1454 1455 1456 1457
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(599)

        # tdSql.query("select DERIVATIVE(data ,1s ,1) from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,10s) data from regular_table_3 \
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(598)

1458
        # tdSql.query("select ceil(data)from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1459 1460 1461
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)

1462
        # tdSql.query("select floor(data)from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1463 1464 1465
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)

1466
        # tdSql.query("select round(data)from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1467 1468 1469
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)

1470
        # tdSql.query("select data*10+2 from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1471 1472 1473
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)

1474
        # tdSql.query("select data*10+2 from (select count(*),avg(q_int) ,  sum(q_double),stddev(q_float),LEASTSQUARES(q_int,0,1), elapsed(ts,1s) data from regular_table_3 \
1475 1476 1477 1478
        #  where ts>=\"2015-01-01 00:00:00.000\"  and ts < \"2015-01-01 00:10:00.000\" interval(1s) fill(prev)); ")
        # tdSql.checkRows(600)

    def query_session_windows(self):
G
Ganlin Zhao 已提交
1479 1480

        # case TD-12344
1481
        # session not support stable
1482
        tdSql.error('select elapsed(ts,1s) from stable_1  where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  session(ts ,1s) group by tbname,ind order by ts asc ')
1483

1484
        tdSql.query('select elapsed(ts,1s) from sub_table1_1  session(ts,1w) ; ')
1485
        tdSql.checkRows(1)
1486 1487
        tdSql.checkData(0,0,90)
        tdSql.query('select elapsed(ts,1s) from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" session(ts,1w) ; ')
1488
        tdSql.checkRows(1)
1489
        tdSql.checkData(0,0,90)
1490

1491
        tdSql.query('select elapsed(ts,1s) from  ( select * from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ')
1492

1493 1494
        tdSql.query('select elapsed(ts,1s) from  ( select ts ,q_int from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000") session(ts,1w) ; ')
        # tdSql.query('select elapsed(ts,1s) from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) session(ts,1w) ; ')
G
Ganlin Zhao 已提交
1495

1496
        tdSql.query('select elapsed(ts,1s) from sub_empty_1  where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  session(ts,1w) ; ')
1497 1498 1499 1500 1501
        tdSql.checkRows(0)

        # windows state
        # not support stable

1502
        tdSql.error('select elapsed(ts,1s) from stable_1  where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  state_window(q_int) group by tbname,ind order by ts asc ')
1503

1504
        tdSql.query('select elapsed(ts,1s) from sub_table1_1  state_window(q_int) ; ')
1505 1506
        tdSql.checkRows(10)
        tdSql.checkData(0,0,0)
1507
        tdSql.query('select elapsed(ts,1s) from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" state_window(q_int) ; ')
1508 1509 1510
        tdSql.checkRows(10)
        tdSql.checkData(0,0,0)

1511
        tdSql.query('select elapsed(ts,1s) from  ( select * from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ')
1512

1513
        tdSql.query('select elapsed(ts,1s) from  ( select ts ,q_int from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000") state_window(q_int) ; ')
1514

1515
        tdSql.error('select elapsed(ts,1s) from sub_table1_1   where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000" interval(20s) fill (next) state_window(q_int) ; ')
G
Ganlin Zhao 已提交
1516

1517 1518
        tdSql.query('select elapsed(ts,1s) from sub_empty_1  where ts>="2015-01-01 00:00:00.000"  and ts < "2015-01-01 00:10:00.000"  state_window(q_int); ')
        tdSql.checkRows(0)
1519

G
Ganlin Zhao 已提交
1520

1521 1522 1523
    def continuous_query(self):
        tdSql.error('create table elapsed_t as select elapsed(ts) from sub_table1_1  interval(1m) sliding(30s);')
        tdSql.error('create table elapsed_tb as select elapsed(ts) from stable_1  interval(1m) sliding(30s) group by tbname;')
1524
        tdSql.error('create table elapsed_tc as select elapsed(ts) from stable_1  interval(1s) sliding(5s) interval(1m) sliding(30s) group by tbname;')
G
Ganlin Zhao 已提交
1525

1526 1527
    def query_precision(self):
        def generate_data(precision="ms"):
G
Ganlin Zhao 已提交
1528

1529 1530 1531 1532 1533
            tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision))
            tdSql.execute("use db_%s;" %precision)
            tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision)
            tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision)
            tdSql.execute("create table db_%s.tb2 using st tags(2);"%precision)
G
Ganlin Zhao 已提交
1534

1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553
            if precision == "ms":
                start_ts = self.ts
                step = 10000
            elif precision == "us":
                start_ts = self.ts*1000
                step = 10000000
            elif precision == "ns":
                start_ts = self.ts*1000000
                step = 10000000000
            else:
                pass

            for i in range(10):

                sql1 = "insert into db_%s.tb1 values (%d,%d)"%(precision ,start_ts+i*step,i)
                sql2 = "insert into db_%s.tb1 values (%d,%d)"%(precision, start_ts+i*step,i)
                tdSql.execute(sql1)
                tdSql.execute(sql2)

1554
        time_units = ["1s","1a","1u","1b"]
1555 1556 1557 1558 1559 1560 1561 1562

        precision_list = ["ms","us","ns"]
        for pres in precision_list:
            generate_data(pres)

            for index,unit in enumerate(time_units):

                if pres == "ms":
1563
                    if unit in ["1u","1b"]:
W
wenzhouwww@live.cn 已提交
1564
                        tdSql.error("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres))
1565 1566 1567
                        pass
                    else:
                        tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres))
1568 1569
                elif pres == "us" and unit in ["1b"]:
                    if unit in ["1b"]:
W
wenzhouwww@live.cn 已提交
1570
                        tdSql.error("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres))
1571 1572 1573 1574 1575 1576
                        pass
                    else:
                        tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres))
                else:

                    tdSql.query("select elapsed(ts,%s) from db_%s.st group by tbname "%(unit,pres))
1577
                    basic_result = 90
1578
                    tdSql.checkData(0,0,basic_result*pow(1000,index))
W
wenzhouwww@live.cn 已提交
1579

1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
    def run(self):
        tdSql.prepare()
        self.prepare_data()
        self.abnormal_common_test()
        self.abnormal_use_test()
        self.query_filter()
        # self.query_interval()
        self.query_mix_common()
        self.query_mix_Aggregate()
        self.query_mix_select()
        self.query_mix_compute()
        self.query_mix_arithmetic()
        # self.query_with_join()
        # self.query_with_union()
        self.query_nest()
        self.query_session_windows()
        self.continuous_query()
        self.query_precision()
G
Ganlin Zhao 已提交
1598

1599 1600 1601 1602 1603 1604
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)

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