operator_cost.py 32.2 KB
Newer Older
H
happyguoxy 已提交
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 26 27
###################################################################
#           Copyright (c) 2016 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 taos
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql
import random
import time


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

28 29
        now = time.time()
        self.ts = int(round(now * 1000))
H
happyguoxy 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
        self.num = 10

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

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

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

        tdLog.info("========== operator=1(OP_TableScan) ==========")
        tdLog.info("========== operator=7(OP_Project) ==========")
        sql = '''select * from stable_1'''
        tdSql.query(sql)
        tdSql.checkRows(6*self.num)    
        sql = '''select * from regular_table_1'''
        tdSql.query(sql)
        tdSql.checkRows(6*self.num)    

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

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

        tdLog.info("========== operator=9(OP_Limit) ==========")
        sql = '''select * from stable_1 where loc = 'table_0' limit 5;'''
        tdSql.query(sql)
        tdSql.checkRows(5)
        sql = '''select last_row(*) from (select * from stable_1 where loc = 'table_0');'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        sql = '''select * from regular_table_1 ;'''
        tdSql.query(sql)
        tdSql.checkRows(6*self.num)
        sql = '''select last_row(*) from (select * from regular_table_1);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        tdSql.checkData(0,1,self.num-1)


        sql = '''select last_row(*) from 
                ((select * from table_0) union all
                 (select * from table_1) union all
                 (select * from table_2));'''
        tdSql.error(sql)

        tdLog.info("========== operator=16(OP_DummyInput) ==========")
        sql = '''select last_row(*) from 
                ((select last_row(*) from table_0) union all
                 (select last_row(*) from table_1) union all
                 (select last_row(*) from table_2));'''
        tdSql.error(sql)

        sql = '''select last_row(*) from 
                ((select * from table_0 limit 5 offset 5) union all
                 (select * from table_1 limit 5 offset 5) union all
                 (select * from regular_table_1 limit 5 offset 5));'''
        tdSql.error(sql)

        tdLog.info("========== operator=10(OP_SLimit) ==========")
        sql = '''select count(*) from stable_1 group by loc slimit 3 soffset 2 ;'''
        tdSql.query(sql)
        tdSql.checkRows(3)

        sql = '''select last_row(*) from 
                ((select * from table_0) union all
                 (select * from table_1) union all
                 (select * from table_2));'''
        tdSql.error(sql)

        tdLog.info("========== operator=20(OP_Distinct) ==========")
        tdLog.info("========== operator=4(OP_TagScan) ==========")
        sql = '''select distinct(t_bool) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(2)
        sql = '''select distinct(loc) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_int) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_bigint) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_smallint) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_tinyint) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_nchar) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_float) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_double) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(6)
        sql = '''select distinct(t_ts) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(3)
H
happyguoxy 已提交
211 212 213
        # sql = '''select distinct(tbname) from stable_1;'''
        # tdSql.query(sql)
        # tdSql.checkRows(6)
H
happyguoxy 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 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 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537

        tdLog.info("========== operator=2(OP_DataBlocksOptScan) ==========")
        sql = '''select last(q_int),first(q_int) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_bigint),first(q_bigint) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_smallint),first(q_smallint) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_tinyint),first(q_tinyint) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_bool),first(q_bool) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_binary),first(q_binary) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_nchar),first(q_nchar) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_float),first(q_float) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_double),first(q_double) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_ts),first(q_ts) from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_int),last(q_bigint), last(q_smallint),last(q_tinyint),last(q_bool),last(q_binary),last(q_nchar),
                last(q_float),last(q_double),last(q_ts),first(q_int),first(q_bigint),first(q_smallint),first(q_tinyint),
                first(q_bool),first(q_binary),first(q_nchar),first(q_float),first(q_float),first(q_double),first(q_ts)  from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_int),last(q_bigint), last(q_smallint),last(q_tinyint),last(q_bool),last(q_binary),last(q_nchar),
                last(q_float),last(q_double),last(q_ts),first(q_int),first(q_bigint),first(q_smallint),first(q_tinyint),first(q_bool),
                first(q_binary),first(q_nchar),first(q_float),first(q_float),first(q_double),first(q_ts) from regular_table_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("========== operator=8(OP_Groupby) ==========")
        sql = '''select stddev(q_int) from table_0 group by q_int;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select stddev(q_int),stddev(q_bigint),stddev(q_smallint),stddev(q_tinyint),stddev(q_float),stddev(q_double) from stable_1 group by q_int;'''
        tdSql.query(sql)
        sql = '''select stddev(q_int),stddev(q_bigint),stddev(q_smallint),stddev(q_tinyint),stddev(q_float),stddev(q_double) from table_1 group by q_bigint;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select stddev(q_int),stddev(q_bigint),stddev(q_smallint),stddev(q_tinyint),stddev(q_float),stddev(q_double) from regular_table_1 group by q_smallint;'''
        tdSql.query(sql)

        tdLog.info("========== operator=11(OP_TimeWindow) ==========")
        sql = '''select last(q_int) from table_0 interval(1m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_int),last(q_bigint), last(q_smallint),last(q_tinyint), 
                first(q_int),first(q_bigint),first(q_smallint),first(q_tinyint) from table_1 interval(1m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_int),last(q_bigint), last(q_smallint),last(q_tinyint), 
                first(q_int),first(q_bigint),first(q_smallint),first(q_tinyint) from stable_1 interval(1m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select last(q_int),last(q_bigint), last(q_smallint),last(q_tinyint), 
                first(q_int),first(q_bigint),first(q_smallint),first(q_tinyint) from regular_table_1 interval(1m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("========== operator=12(OP_SessionWindow) ==========")
        sql = '''select count(*) from table_1 session(ts,1s);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select count(*) from regular_table_1 session(ts,1s);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select count(*),sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from table_1 session(ts,1s);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select count(*),sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from regular_table_1 session(ts,1s);'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("========== operator=13(OP_Fill) ==========")
        sql = '''select sum(q_int) from table_0 
                where ts >='1970-10-01 00:00:00' and ts <=now  interval(1n) fill(NULL);'''
        tdSql.query(sql)
        tdSql.checkData(0,1,'None')
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 where ts >='1970-10-01 00:00:00' and ts <=now  interval(1n) fill(NULL);'''
        tdSql.query(sql)
        tdSql.checkData(0,1,'None')
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from regular_table_1 where ts >='1970-10-01 00:00:00' and ts <=now  interval(1n) fill(NULL);'''
        tdSql.query(sql)
        tdSql.checkData(0,1,'None')
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from table_0 where ts >='1970-10-01 00:00:00' and ts <=now  interval(1n) fill(NULL);'''
        tdSql.query(sql)
        tdSql.checkData(0,1,'None')
        #TD-5190
        sql = '''select sum(q_tinyint),stddev(q_float)  from stable_1 
                where ts >='1970-10-01 00:00:00' and ts <=now  interval(1n) fill(NULL);'''
        tdSql.query(sql)
        tdSql.checkData(0,1,'None')

        tdLog.info("========== operator=15(OP_MultiTableTimeInterval) ==========")
        sql = '''select avg(q_int) from stable_1 where ts<now interval(10m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double) 
                from table_1 where ts<now interval(10m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double) 
                from stable_1 where ts<now interval(10m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double) 
                from regular_table_1 where ts<now interval(10m);'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("========== operator=3(OP_TableSeqScan) ==========")
        tdLog.info("========== operator=6(OP_Aggregate) ==========")
        sql = '''select * from table_1,table_2 
                where table_1.ts = table_2.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        #TD-5206
        sql = '''select * from stable_1,stable_2  
                where stable_1.t_nchar = stable_2.t_nchar and stable_1.ts = stable_2.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        #TD-5139
        sql = '''select * from table_1,regular_table_1 
                where table_1.ts = regular_table_1.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)

        tdLog.info("========== operator=5(OP_TableBlockInfoScan) ==========")
        sql = '''select _block_dist() from stable_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select _block_dist() from table_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)
        sql = '''select _block_dist() from regular_table_1;'''
        tdSql.query(sql)
        tdSql.checkRows(1)

        tdLog.info("========== operator=17(OP_MultiwayMergeSort) ==========")
        tdLog.info("========== operator=18(OP_GlobalAggregate) ==========")
        tdLog.info("========== operator=19(OP_Filter) ==========")
        sql = '''select loc,sum(q_int) from stable_1 
                group by loc having sum(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')
        sql = '''select loc, sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 group by loc having sum(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')
        sql = '''select loc, sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 group by loc having avg(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')
        sql = '''select loc, sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 group by loc having min(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')
        sql = '''select loc, sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 group by loc having max(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')
        sql = '''select loc, sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 group by loc having first(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')
        sql = '''select loc, sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from stable_1 group by loc having last(q_int)>=0;'''
        tdSql.query(sql)
        tdSql.checkData(0,0,'table_0')

        tdLog.info("========== operator=21(OP_Join) ==========")
        sql = '''select t1.q_int,t2.q_int from
                (select ts,q_int from table_1) t1 , (select ts,q_int from table_2) t2
                where t2.ts = t1.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select t1.*,t2.* from
                (select * from table_1) t1 , (select * from table_2) t2
                where t2.ts = t1.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select t1.*,t2.* from
                (select * from regular_table_1) t1 , (select * from table_0) t2
                where t2.ts = t1.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select t1.*,t2.* from
                (select * from stable_1) t1 , (select * from table_2) t2
                where t2.ts = t1.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select t1.*,t2.* from
                (select * from regular_table_1) t1 , (select * from stable_1) t2
                where t2.ts = t1.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select t1.*,t2.*,t3.* from
                (select * from regular_table_1) t1 , (select * from stable_1) t2, (select * from table_0) t3
                where t2.ts = t1.ts and t3.ts = t1.ts and t2.ts = t3.ts;'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)

        tdLog.info("========== operator=22(OP_StateWindow) ==========")
        sql = '''select avg(q_int),sum(q_smallint) from table_1 state_window(q_int);'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double) 
                from table_1 state_window(q_bigint);'''
        tdSql.query(sql)
        tdSql.checkRows(self.num)
        sql = '''select sum(q_int), avg(q_int), min(q_int), max(q_int), first(q_int), last(q_int),
                sum(q_bigint), avg(q_bigint), min(q_bigint), max(q_bigint), first(q_bigint), last(q_bigint),
                sum(q_smallint), avg(q_smallint), min(q_smallint), max(q_smallint), first(q_smallint), last(q_smallint),
                sum(q_tinyint), avg(q_tinyint), min(q_tinyint), max(q_tinyint), first(q_tinyint), last(q_tinyint),
                sum(q_float), avg(q_float), min(q_float), max(q_float), first(q_float), last(q_float),
                sum(q_double), avg(q_double), min(q_double), max(q_double), first(q_double), last(q_double)
                from regular_table_1 state_window(q_smallint);'''
        tdSql.query(sql)
        tdSql.checkRows(6*self.num)

        endTime = time.time()
        print("total time %ds" % (endTime - startTime))  


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


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