filter.py 13.8 KB
Newer Older
S
Shuduo Sang 已提交
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 28 29 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 211 212 213 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
###################################################################
#           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
from util.log import *
from util.cases import *
from util.sql import *


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

    def run(self):
        tdSql.prepare()

        #TSIM: system sh/stop_dnodes.sh
        #TSIM: system sh/deploy.sh -n dnode1 -i 1
        #TSIM: system sh/exec.sh -n dnode1 -s start
        #TSIM: 
        #TSIM: sleep 3000
        #TSIM: sql connect
        #TSIM: 
        #TSIM: print ======================== dnode1 start
        tdLog.info('======================== dnode1 start')
        #TSIM: 
        dbPrefix = "ta_fi_db"
        tbPrefix = "ta_fi_tb"
        mtPrefix = "ta_fi_mt"
        #TSIM: $tbNum = 10
        rowNum = 20
        #TSIM: $totalNum = 200
        #TSIM: 
        #TSIM: print =============== step1
        tdLog.info('=============== step1')
        i = 0
        #TSIM: $db = $dbPrefix . $i
        mt = "%s%d" % (mtPrefix, i)
        #TSIM: 
        #TSIM: sql create database $db
        #TSIM: sql use $db
        #TSIM: sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol binary(10))
        tdLog.info("create table %s (ts timestamp, tbcol int) TAGS(tgcol binary(10))" % mt)
        tdSql.execute('create table %s (ts timestamp, tbcol int) TAGS(tgcol binary(10))' % mt)
        #TSIM: 
        i = 0
        while (i < 5):
            tb = "tbPrefix%d" % i
            tdLog.info("create table %s using %s tags( '0' )" % (tb, mt))
            tdSql.execute("create table %s using %s tags( '0' )" % (tb, mt))

            x = 0
            while (x < rowNum):
                ms = "%dm" % x
                tdLog.info("insert into %s values (now + %s , %d)" % (tb, ms, x))
                tdSql.execute("insert into %s values (now + %s , %d)" % (tb, ms, x))
                x = x + 1
            i = i + 1

        while (i < 10):
            tb = "%s%d" % (tbPrefix , i)
        #TSIM: sql create table $tb using $mt tags( '1' )
            tdLog.info("create table %s using %s tags( '1' )" % (tb, mt))
            tdSql.execute("create table %s using %s tags( '1' )" % (tb, mt))
            x = 0
            while (x < rowNum):
                ms = "%dm" % x
        #TSIM: sql insert into $tb values (now + $ms , $x )
                tdLog.info("insert into %s values (now + %s, %d )" % (tb, ms, x))
                tdSql.execute("insert into %s values (now + %s, %d )" % (tb, ms, x))
                x = x + 1
            i = i + 1
        #TSIM: 
        #TSIM: print =============== step2
        tdLog.info('=============== step2')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tgcol = '1'
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where tgcol = '1'" % mt)
        tdSql.query("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where tgcol = '1'" % mt)
        #TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06
        tdLog.info("%s %s %s %s %s %s %s" % (tdSql.getData(0, 0), tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4), tdSql.getData(0, 5), tdSql.getData(0, 6)))
        #TSIM: if $data00 != 100 then
        tdLog.info('tdSql.checkData(0, 0, 100)')
        tdSql.checkData(0, 0, 100)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tg = '1' -x step2
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where tg = '1' -x step2" % mt)
        tdSql.error("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where tg = '1'" % mt)
        #TSIM: return -1
        #TSIM: step2:
        #TSIM: 
        #TSIM: print =============== step3
        tdLog.info('=============== step3')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where noexist = '1' -x step3
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where noexist = '1' -x step3" % mt)
        tdSql.error("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where noexist = '1'" % mt)
        #TSIM: return -1
        #TSIM: step3:
        #TSIM: 
        #TSIM: print =============== step4
        tdLog.info('=============== step4')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt where tbcol = '1'
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where tbcol = '1'" % mt)
        tdSql.query("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s where tbcol = '1'" % mt)
        #TSIM: if $rows != 1 then
        tdLog.info('tdSql.checkRow(1)')
        tdSql.checkRows(1)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: if $data00 != 10 then
        tdLog.info('tdSql.checkData(0, 0, 10)')
        tdSql.checkData(0, 0, 10)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: print =============== step5
        tdLog.info('=============== step5')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s" % mt)
        tdSql.query("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s" % mt)
        #TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06
        tdLog.info("%s %s %s %s %s %s %s" % (tdSql.getData(0,0), tdSql.getData(0,1), tdSql.getData(0,2), tdSql.getData(0, 3), tdSql.getData(0, 4), tdSql.getData(0,5 ), tdSql.getData(0, 6)))
        #TSIM: if $data00 != 200 then
        tdLog.info('tdSql.checkData(0, 0, 200)')
        tdSql.checkData(0, 0, 200)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: print =============== step6
        tdLog.info('=============== step6')
        #TSIM: sql select count(tbcol), avg(cc), sum(xx), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt -x step6
        tdLog.info("select count(tbcol), avg(cc), sum(xx), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s -x step6" % mt)
        tdSql.error("select count(tbcol), avg(cc), sum(xx), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s" % mt)
        #TSIM: return -1
        #TSIM: step6:
        #TSIM: 
        #TSIM: print =============== step7
        tdLog.info('=============== step7')
        #TSIM: sql select count(tgcol), avg(tgcol), sum(tgcol), min(tgcol), max(tgcol), first(tgcol), last(tgcol) from $mt -x step7
        tdLog.info("select count(tgcol), avg(tgcol), sum(tgcol), min(tgcol), max(tgcol), first(tgcol), last(tgcol) from %s -x step7" % mt)
        tdSql.error("select count(tgcol), avg(tgcol), sum(tgcol), min(tgcol), max(tgcol), first(tgcol), last(tgcol) from %s" % mt)
        #TSIM: return -1
        #TSIM: step7:
        #TSIM: 
        #TSIM: print =============== step8
        tdLog.info('=============== step8')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt group by tbcol
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s by tbcol" % mt)
        tdSql.query("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s group by tbcol" % mt)
        #TSIM: 
        #TSIM: print =============== step9
        tdLog.info('=============== step9')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt group by noexist  -x step9
        tdLog.info("select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s group by noexist  -x step9" % mt)
        tdSql.error('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s group by noexist ' % mt)
        #TSIM: return -1
        #TSIM: step9:
        #TSIM: 
        #TSIM: print =============== step10
        tdLog.info('=============== step10')
        #TSIM: sql select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from $mt group by tgcol
        tdLog.info('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s group by tgcol' % mt)
        tdSql.query('select count(tbcol), avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from %s group by tgcol' % mt)
        #TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06
        tdLog.info('$data00 $data01 $data02 $data03 $data04 $data05 $data06')
        #TSIM: if $data00 != 100 then
        tdLog.info('tdSql.checkData(0, 0, 100)')
        tdSql.checkData(0, 0, 100)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: print =============== step11
        tdLog.info('=============== step11')
        #TSIM: sql select count(tbcol) as c from $mt group by tbcol
        tdLog.info('select count(tbcol) as c from %s group by tbcol' % mt)
        tdSql.query('select count(tbcol) as c from %s group by tbcol' % mt)
        #TSIM: 
        #TSIM: print =============== step12
        tdLog.info('=============== step12')
        #TSIM: sql select count(tbcol) as c from $mt group by noexist -x step12
        tdLog.info('select count(tbcol) as c from %s group by noexist -x step12' % mt)
        tdSql.error('select count(tbcol) as c from %s group by noexist2' % mt)
        #TSIM: return -1
        #TSIM: step12:
        #TSIM: 
        #TSIM: print =============== step13
        tdLog.info('=============== step13')
        #TSIM: sql select count(tbcol) as c from $mt group by tgcol
        tdLog.info('select count(tbcol) as c from %s group by tgcol' % mt)
        tdSql.query('select count(tbcol) as c from %s group by tgcol' % mt)
        #TSIM: print $data00
        tdLog.info('$data00')
        #TSIM: if $data00 != 100 then
        tdLog.info('tdSql.checkData(0, 0, 100)')
        tdSql.checkData(0, 0, 100)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: print =============== step14
        tdLog.info('=============== step14')
        #TSIM: sql select count(tbcol) as c from $mt where ts > 1000 group by tgcol
        tdLog.info('select count(tbcol) as c from %s where ts > 1000 group by tgcol' % mt)
        tdSql.query('select count(tbcol) as c from %s where ts > 1000 group by tgcol' % mt)
        #TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06
#        tdLog.info("%s %s %s %s %s %s %s" % (tdSql.getData(0, 0), tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4), tdSql.getData(0, 5), tdSql.getData(0, 6)))
        #TSIM: if $data00 != 100 then
        tdLog.info('tdSql.checkData(0, 0, 100)')
        tdSql.checkData(0, 0, 100)
        #TSIM: print expect 100, actual $data00
        tdLog.info('expect 100, actual $data00')
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: print =============== step15
        tdLog.info('=============== step15')
        #TSIM: sql select count(tbcol) as c from $mt where noexist < 1  group by tgcol -x step15
        tdLog.info('select count(tbcol) as c from %s where noexist < 1  group by tgcol -x step15' % mt)
        tdSql.error('select count(tbcol) as c from %s where noexist < 1  group by tgcol5' % mt)
        #TSIM: return -1
        #TSIM: step15:
        #TSIM: 
        #TSIM: print =============== step16
        tdLog.info('=============== step16')
        #TSIM: sql select count(tbcol) as c from $mt where tgcol = '1' group by tgcol
        tdLog.info("select count(tbcol) as c from %s where tgcol = '1' group by tgcol" % mt)
        tdSql.query("select count(tbcol) as c from %s where tgcol = '1' group by tgcol" % mt)
        #TSIM: print $data00 $data01 $data02 $data03 $data04 $data05 $data06
#        tdLog.info("%s %s %s %s %s %s %s" % (tdSql.getData(0, 0), tdSql.getData(0, 1), tdSql.getData(0, 2), tdSql.getData(0, 3), tdSql.getData(0, 4), tdSql.getData(0, 5), tdSql.getData(0, 6)))
        #TSIM: if $data00 != 100 then
        tdLog.info('tdSql.checkData(0, 0, 100)')
        tdSql.checkData(0, 0, 100)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: print =============== clear
        tdLog.info('=============== clear')
        #TSIM: sql drop database $db
        tdLog.info('drop database db')
        tdSql.execute('drop database db')
        #TSIM: sql show databases
        tdLog.info('show databases')
        tdSql.query('show databases')
        #TSIM: if $rows != 0 then
        tdLog.info('tdSql.checkRow(0)')
        tdSql.checkRows(0)
        #TSIM: return -1
        #TSIM: endi
        #TSIM: 
        #TSIM: system sh/exec.sh -n dnode1 -s stop -x SIGINT
# convert end

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


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