queryQnode.py 20.7 KB
Newer Older
haoranc's avatar
haoranc 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
###################################################################
#           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 os
import threading as thd
import multiprocessing as mp
from numpy.lib.function_base import insert
import taos
haoranc's avatar
haoranc 已提交
20 21
from util.dnodes import TDDnode
from util.dnodes import *
haoranc's avatar
haoranc 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34
from util.log import *
from util.cases import *
from util.sql import *
import numpy as np
import datetime as dt
import time
# constant define
WAITS = 5 # wait seconds

class TDTestCase:
    #
    # --------------- main frame -------------------
    #
35
    clientCfgDict = {'queryPolicy': '1','debugFlag': 143}
haoranc's avatar
haoranc 已提交
36
    clientCfgDict["queryPolicy"] = '1'
37
    clientCfgDict["debugFlag"] = 143
haoranc's avatar
haoranc 已提交
38 39 40 41 42 43 44 45 46 47

    updatecfgDict = {'clientCfg': {}}
    updatecfgDict = {'debugFlag': 143}
    updatecfgDict["clientCfg"]  = clientCfgDict
    def caseDescription(self):
        '''
        limit and offset keyword function test cases;
        case1: limit offset base function test
        case2: offset return valid
        '''
G
Ganlin Zhao 已提交
48
        return
haoranc's avatar
haoranc 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

    def getBuildPath(self):
        selfPath = os.path.dirname(os.path.realpath(__file__))

        if ("community" in selfPath):
            projPath = selfPath[:selfPath.find("community")]
        else:
            projPath = selfPath[:selfPath.find("tests")]

        for root, dirs, files in os.walk(projPath):
            if ("taosd" in files or "taosd.exe" in files):
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
                    buildPath = root[:len(root)-len("/build/bin")]
                    break
        return buildPath

    # init
haoranc's avatar
haoranc 已提交
67
    def init(self, conn, logSql=True):
haoranc's avatar
haoranc 已提交
68 69 70 71 72 73
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())
        # tdSql.prepare()
        # self.create_tables();
        self.ts = 1500000000000

G
Ganlin Zhao 已提交
74
    # stop
haoranc's avatar
haoranc 已提交
75 76 77 78 79 80 81 82 83 84
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


    # --------------- case  -------------------

    def newcur(self,host,cfg):
        user = "root"
        password = "taosdata"
G
Ganlin Zhao 已提交
85
        port =6030
haoranc's avatar
haoranc 已提交
86 87 88 89 90 91 92 93 94
        con=taos.connect(host=host, user=user, password=password, config=cfg ,port=port)
        cur=con.cursor()
        print(cur)
        return cur

    # create tables
    def create_tables(self,host,dbname,stbname,count):
        buildPath = self.getBuildPath()
        config = buildPath+ "../sim/dnode1/cfg/"
G
Ganlin Zhao 已提交
95

haoranc's avatar
haoranc 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
        tsql=self.newcur(host,config)
        tsql.execute("use %s" %dbname)

        pre_create = "create table"
        sql = pre_create
        count=int(count)

        tdLog.debug("doing create one  stable %s and %d  child table in %s  ..." %(stbname, count ,dbname))
        # print(time.time())
        exeStartTime=time.time()
        # print(type(tcountStop),type(tcountStart))
        for i in range(0,count):
            sql += " %s_%d using %s tags(%d)"%(stbname,i,stbname,i+1)
            if i >0 and i%20000 == 0:
                # print(sql)
                tsql.execute(sql)
                sql = pre_create
        # print(time.time())
G
Ganlin Zhao 已提交
114
        # end sql
haoranc's avatar
haoranc 已提交
115 116 117 118 119 120 121 122 123 124 125 126
        if sql != pre_create:
            # print(sql)
            tsql.execute(sql)
        exeEndTime=time.time()
        spendTime=exeEndTime-exeStartTime
        speedCreate=count/spendTime
        # tdLog.debug("spent %.2fs to create 1 stable and %d table, create speed is %.2f table/s... [OK]"% (spendTime,count,speedCreate))
        return

    def mutiThread_create_tables(self,host,dbname,stbname,vgroups,threadNumbers,childcount):
        buildPath = self.getBuildPath()
        config = buildPath+ "../sim/dnode1/cfg/"
G
Ganlin Zhao 已提交
127

haoranc's avatar
haoranc 已提交
128 129 130 131 132 133 134 135 136
        tsql=self.newcur(host,config)
        tdLog.debug("create database %s"%dbname)
        tsql.execute("drop database if exists %s"%dbname)
        tsql.execute("create database %s vgroups %d"%(dbname,vgroups))
        tsql.execute("use %s" %dbname)
        count=int(childcount)
        threads = []
        for i in range(threadNumbers):
            tsql.execute("create stable %s%d(ts timestamp, c1 int, c2 binary(10)) tags(t1 int)"%(stbname,i))
G
Ganlin Zhao 已提交
137
            threads.append(thd.Thread(target=self.create_tables, args=(host, dbname, stbname+"%d"%i, count,)))
haoranc's avatar
haoranc 已提交
138 139 140 141 142 143 144 145 146
        start_time = time.time()
        for tr in threads:
            tr.start()
        for tr in threads:
            tr.join()
        end_time = time.time()
        spendTime=end_time-start_time
        speedCreate=threadNumbers*count/spendTime
        tdLog.debug("spent %.2fs to create %d stable and %d table, create speed is %.2f table/s... [OK]"% (spendTime,threadNumbers,threadNumbers*count,speedCreate))
G
Ganlin Zhao 已提交
147

haoranc's avatar
haoranc 已提交
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
        return

    # def create_tables(self,host,dbname,stbname,vgroups,tcountStart,tcountStop):


    # insert data
    def insert_data(self, host, dbname, stbname, chilCount, ts_start, rowCount):
        buildPath = self.getBuildPath()
        config = buildPath+ "../sim/dnode1/cfg/"
        tsql=self.newcur(host,config)
        tdLog.debug("ready to inser data")
        tsql.execute("use %s" %dbname)
        pre_insert = "insert into "
        sql = pre_insert
        chilCount=int(chilCount)
        allRows=chilCount*rowCount
        tdLog.debug("doing insert data into stable-index:%s rows:%d ..."%(stbname, allRows))
        exeStartTime=time.time()
        for i in range(0,chilCount):
            sql += " %s_%d values "%(stbname,i)
            for j in range(rowCount):
                sql += "(%d, %d, 'taos_%d') "%(ts_start + j*1000, j, j)
                if j >0 and j%4000 == 0:
                    # print(sql)
                    tsql.execute(sql)
                    sql = "insert into %s_%d values " %(stbname,i)
G
Ganlin Zhao 已提交
174
        # end sql
haoranc's avatar
haoranc 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188
        if sql != pre_insert:
            # print(sql)
            print(len(sql))
            tsql.execute(sql)
        exeEndTime=time.time()
        spendTime=exeEndTime-exeStartTime
        speedInsert=allRows/spendTime
        tdLog.debug("spent %.2fs to INSERT  %d rows into %s , insert rate is  %.2f rows/s... [OK]"% (spendTime,allRows,stbname,speedInsert))
        # tdLog.debug("INSERT TABLE DATA ............ [OK]")
        return

    def mutiThread_insert_data(self, host, dbname, stbname, threadNumbers, chilCount, ts_start, childrowcount):
        buildPath = self.getBuildPath()
        config = buildPath+ "../sim/dnode1/cfg/"
G
Ganlin Zhao 已提交
189

haoranc's avatar
haoranc 已提交
190 191 192 193 194 195 196 197
        tsql=self.newcur(host,config)
        tdLog.debug("ready to inser data")

        tsql.execute("use %s" %dbname)
        chilCount=int(chilCount)
        threads = []
        for i in range(threadNumbers):
            # tsql.execute("create stable %s%d(ts timestamp, c1 int, c2 binary(10)) tags(t1 int)"%(stbname,i))
G
Ganlin Zhao 已提交
198
            threads.append(thd.Thread(target=self.insert_data, args=(host, dbname, stbname+"%d"%i, chilCount, ts_start, childrowcount,)))
haoranc's avatar
haoranc 已提交
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
        start_time = time.time()
        for tr in threads:
            tr.start()
        for tr in threads:
            tr.join()
        end_time = time.time()
        spendTime=end_time-start_time
        tableCounts=threadNumbers*chilCount
        stableRows=chilCount*childrowcount
        allRows=stableRows*threadNumbers
        speedInsert=allRows/spendTime

        for i in range(threadNumbers):
            tdSql.execute("use %s" %dbname)
            tdSql.query("select count(*) from %s%d"%(stbname,i))
            tdSql.checkData(0,0,stableRows)
        tdLog.debug("spent %.2fs to insert %d rows  into %d stable and %d table,  speed is %.2f table/s... [OK]"% (spendTime,allRows,threadNumbers,tableCounts,speedInsert))
        tdLog.debug("INSERT TABLE DATA ............ [OK]")

        return


    def taosBench(self,jsonFile):
        buildPath = self.getBuildPath()
        if (buildPath == ""):
            tdLog.exit("taosd not found!")
        else:
            tdLog.info("taosd found in %s" % buildPath)
        taosBenchbin = buildPath+ "/build/bin/taosBenchmark"
        os.system("%s -f %s -y " %(taosBenchbin,jsonFile))
G
Ganlin Zhao 已提交
229

haoranc's avatar
haoranc 已提交
230 231
        return
    def taosBenchCreate(self,host,dropdb,dbname,stbname,vgroups,processNumbers,count):
G
Ganlin Zhao 已提交
232

haoranc's avatar
haoranc 已提交
233 234 235 236 237 238 239 240 241 242 243 244 245
        # count=50000
        buildPath = self.getBuildPath()
        config = buildPath+ "../sim/dnode1/cfg/"
        tsql=self.newcur(host,config)

        # insert: create one  or mutiple tables per sql and insert multiple rows per sql
        tsql.execute("drop database if exists %s"%dbname)

        tsql.execute("create database %s vgroups %d"%(dbname,vgroups))
        print("db has been created")
        # tsql.getResult("show databases")
        # print(tdSql.queryResult)
        tsql.execute("use %s" %dbname)
G
Ganlin Zhao 已提交
246

haoranc's avatar
haoranc 已提交
247 248 249 250 251 252 253 254 255 256
        threads = []
        for i in range(processNumbers):
            jsonfile="1-insert/Vgroups%d%d.json"%(vgroups,i)
            os.system("cp -f 1-insert/manyVgroups.json   %s"%(jsonfile))
            os.system("sed -i 's/\"name\": \"db\",/\"name\": \"%s\",/g' %s"%(dbname,jsonfile))
            os.system("sed -i 's/\"drop\": \"no\",/\"drop\": \"%s\",/g' %s"%(dropdb,jsonfile))
            os.system("sed -i 's/\"host\": \"127.0.0.1\",/\"host\": \"%s\",/g' %s"%(host,jsonfile))
            os.system("sed -i 's/\"childtable_count\": 10000,/\"childtable_count\": %d,/g' %s "%(count,jsonfile))
            os.system("sed -i 's/\"name\": \"stb1\",/\"name\":  \"%s%d\",/g' %s "%(stbname,i,jsonfile))
            os.system("sed -i 's/\"childtable_prefix\": \"stb1_\",/\"childtable_prefix\": \"%s%d_\",/g' %s "%(stbname,i,jsonfile))
G
Ganlin Zhao 已提交
257
            threads.append(mp.Process(target=self.taosBench, args=("%s"%jsonfile,)))
haoranc's avatar
haoranc 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
        start_time = time.time()
        for tr in threads:
            tr.start()
        for tr in threads:
            tr.join()
        end_time = time.time()

        spendTime=end_time-start_time
        speedCreate=count/spendTime
        tdLog.debug("spent %.2fs to create 1 stable and %d table, create speed is %.2f table/s... [OK]"% (spendTime,count,speedCreate))
        return

    def checkData(self,dbname,stbname,stableCount,CtableCount,rowsPerSTable,):
        tdSql.execute("use %s"%dbname)
        tdSql.query("show stables")
        tdSql.checkRows(stableCount)
        tdSql.query("show tables")
        tdSql.checkRows(CtableCount)
        for i in range(stableCount):
            tdSql.query("select count(*) from %s%d"%(stbname,i))
            tdSql.checkData(0,0,rowsPerSTable)
G
Ganlin Zhao 已提交
279 280
        return

haoranc's avatar
haoranc 已提交
281
    # test case : Switch back and forth among the three queryPolicy(1\2\3)
haoranc's avatar
haoranc 已提交
282
    def test_case1(self):
haoranc's avatar
haoranc 已提交
283 284 285 286 287
        self.taosBenchCreate("127.0.0.1","no","db1", "stb1", 1, 2, 1*10)
        tdSql.execute("use db1;")
        tdSql.query("show dnodes;")
        dnodeId=tdSql.getData(0,0)
        print(dnodeId)
haoranc's avatar
haoranc 已提交
288
        tdLog.debug("create qnode on dnode %s"%dnodeId)
haoranc's avatar
haoranc 已提交
289 290 291 292 293 294 295 296 297 298 299 300
        tdSql.execute("create qnode on dnode %s"%dnodeId)
        tdSql.query("select max(c1) from stb10;")
        maxQnode=tdSql.getData(0,0)
        tdSql.query("select min(c1) from stb11;")
        minQnode=tdSql.getData(0,0)
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        unionQnode=tdSql.queryResult
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
        unionallQnode=tdSql.queryResult

        # tdSql.query("show qnodes;")
        # qnodeId=tdSql.getData(0,0)
haoranc's avatar
haoranc 已提交
301
        tdLog.debug("drop qnode on dnode %s"%dnodeId)
haoranc's avatar
haoranc 已提交
302 303 304 305
        tdSql.execute("drop qnode on dnode %s"%dnodeId)
        tdSql.execute("reset query cache")
        tdSql.query("select max(c1) from stb10;")
        tdSql.checkData(0, 0, "%s"%maxQnode)
G
Ganlin Zhao 已提交
306
        tdSql.query("select min(c1) from stb11;")
haoranc's avatar
haoranc 已提交
307 308 309 310 311 312 313 314
        tdSql.checkData(0, 0, "%s"%minQnode)
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        unionVnode=tdSql.queryResult
        assert unionQnode == unionVnode
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
        unionallVnode=tdSql.queryResult
        assert unionallQnode == unionallVnode

haoranc's avatar
haoranc 已提交
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
        queryPolicy=2
        simClientCfg="%s/taos.cfg"%tdDnodes.getSimCfgPath()
        cmd='sed -i "s/^queryPolicy.*/queryPolicy 2/g" %s'%simClientCfg
        os.system(cmd)
        # tdDnodes.stop(1)
        # tdDnodes.start(1)
        tdSql.execute("reset query cache")
        tdSql.execute('alter local  "queryPolicy" "%d"'%queryPolicy)
        tdSql.query("show local variables;")
        for i in range(tdSql.queryRows):
            if tdSql.queryResult[i][0] == "queryPolicy" :
                if int(tdSql.queryResult[i][1]) == int(queryPolicy):
                    tdLog.success('alter queryPolicy to %d successfully'%queryPolicy)
                else :
                    tdLog.debug(tdSql.queryResult)
                    tdLog.exit("alter queryPolicy to  %d failed"%queryPolicy)
        tdSql.execute("reset query cache")

        tdSql.execute("use db1;")
        tdSql.query("show dnodes;")
        dnodeId=tdSql.getData(0,0)
        tdLog.debug("create qnode on dnode %s"%dnodeId)

        tdSql.execute("create qnode on dnode %s"%dnodeId)
        tdSql.query("select max(c1) from stb10;")
        assert maxQnode==tdSql.getData(0,0)
        tdSql.query("select min(c1) from stb11;")
        assert minQnode==tdSql.getData(0,0)
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        assert unionQnode==tdSql.queryResult
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
        assert unionallQnode==tdSql.queryResult

        # tdSql.query("show qnodes;")
        # qnodeId=tdSql.getData(0,0)
        tdLog.debug("drop qnode on dnode %s"%dnodeId)
        tdSql.execute("drop qnode on dnode %s"%dnodeId)
        tdSql.execute("reset query cache")
        tdSql.query("select max(c1) from stb10;")
        assert maxQnode==tdSql.getData(0,0)
G
Ganlin Zhao 已提交
355 356
        tdSql.query("select min(c1) from stb11;")
        assert minQnode==tdSql.getData(0,0)
haoranc's avatar
haoranc 已提交
357 358
        tdSql.error("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        tdSql.error("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
haoranc's avatar
haoranc 已提交
359 360 361

        # tdSql.execute("create qnode on dnode %s"%dnodeId)

haoranc's avatar
haoranc 已提交
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
        queryPolicy=3
        simClientCfg="%s/taos.cfg"%tdDnodes.getSimCfgPath()
        cmd='sed -i "s/^queryPolicy.*/queryPolicy 2/g" %s'%simClientCfg
        os.system(cmd)
        # tdDnodes.stop(1)
        # tdDnodes.start(1)
        tdSql.execute("reset query cache")
        tdSql.execute('alter local  "queryPolicy" "%d"'%queryPolicy)
        tdSql.query("show local variables;")
        for i in range(tdSql.queryRows):
            if tdSql.queryResult[i][0] == "queryPolicy" :
                if int(tdSql.queryResult[i][1]) == int(queryPolicy):
                    tdLog.success('alter queryPolicy to %d successfully'%queryPolicy)
                else :
                    tdLog.debug(tdSql.queryResult)
                    tdLog.exit("alter queryPolicy to  %d failed"%queryPolicy)
        tdSql.execute("reset query cache")

        tdSql.execute("use db1;")
        tdSql.query("show dnodes;")
        dnodeId=tdSql.getData(0,0)
        tdLog.debug("create qnode on dnode %s"%dnodeId)

        tdSql.execute("create qnode on dnode %s"%dnodeId)
        tdSql.query("select max(c1) from stb10;")
        assert maxQnode==tdSql.getData(0,0)
        tdSql.query("select min(c1) from stb11;")
        assert minQnode==tdSql.getData(0,0)
haoranc's avatar
haoranc 已提交
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
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        assert unionQnode==tdSql.queryResult
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
        assert unionallQnode==tdSql.queryResult

        queryPolicy=1

        tdSql.execute('alter local  "queryPolicy" "%d"'%queryPolicy)
        tdSql.query("show local variables;")
        for i in range(tdSql.queryRows):
            if tdSql.queryResult[i][0] == "queryPolicy" :
                if int(tdSql.queryResult[i][1]) == int(queryPolicy):
                    tdLog.success('alter queryPolicy to %d successfully'%queryPolicy)
                else :
                    tdLog.debug(tdSql.queryResult)
                    tdLog.exit("alter queryPolicy to  %d failed"%queryPolicy)
        tdSql.execute("reset query cache")

        tdSql.execute("use db1;")
        tdSql.query("show dnodes;")
        dnodeId=tdSql.getData(0,0)
        tdSql.query("select max(c1) from stb10;")
        assert maxQnode==tdSql.getData(0,0)
        tdSql.query("select min(c1) from stb11;")
        assert minQnode==tdSql.getData(0,0)
haoranc's avatar
haoranc 已提交
415 416 417 418 419
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        assert unionQnode==tdSql.queryResult
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
        assert unionallQnode==tdSql.queryResult

haoranc's avatar
haoranc 已提交
420
    # test case : queryPolicy = 2
haoranc's avatar
haoranc 已提交
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444
    def test_case2(self):
        self.taosBenchCreate("127.0.0.1","no","db1", "stb1", 10, 2, 1*10)
        tdSql.query("show qnodes")
        if tdSql.queryRows == 1 :
            tdLog.debug("drop qnode on dnode 1")
            tdSql.execute("drop qnode on dnode 1")
        queryPolicy=2
        simClientCfg="%s/taos.cfg"%tdDnodes.getSimCfgPath()
        cmd='sed -i "s/^queryPolicy.*/queryPolicy 2/g" %s'%simClientCfg
        os.system(cmd)
        # tdDnodes.stop(1)
        # tdDnodes.start(1)
        tdSql.execute("reset query cache")
        tdSql.execute('alter local  "queryPolicy" "%d"'%queryPolicy)
        tdSql.query("show local variables;")
        for i in range(tdSql.queryRows):
            if tdSql.queryResult[i][0] == "queryPolicy" :
                if int(tdSql.queryResult[i][1]) == int(queryPolicy):
                    tdLog.success('alter queryPolicy to %d successfully'%queryPolicy)
                else :
                    tdLog.debug(tdSql.queryResult)
                    tdLog.exit("alter queryPolicy to  %d failed"%queryPolicy)
        tdSql.execute("use db1;")
        tdSql.error("select max(c1) from stb10;")
G
Ganlin Zhao 已提交
445
        tdSql.error("select min(c1) from stb11;")
haoranc's avatar
haoranc 已提交
446 447 448 449 450 451
        tdSql.error("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        tdSql.error("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")

        tdSql.query("select max(c1) from stb10_0;")
        tdSql.query("select min(c1) from stb11_0;")

haoranc's avatar
haoranc 已提交
452
    # test case : queryPolicy = 3
haoranc's avatar
haoranc 已提交
453

haoranc's avatar
haoranc 已提交
454
    def test_case3(self):
haoranc's avatar
haoranc 已提交
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
        tdSql.execute('alter local  "queryPolicy" "3"')
        tdLog.debug("create qnode on dnode 1")
        tdSql.execute("create qnode on dnode 1")
        tdSql.execute("use db1;")
        tdSql.query("show dnodes;")
        dnodeId=tdSql.getData(0,0)
        print(dnodeId)

        tdSql.query("select max(c1) from stb10;")
        maxQnode=tdSql.getData(0,0)
        tdSql.query("select min(c1) from stb11;")
        minQnode=tdSql.getData(0,0)
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        unionQnode=tdSql.queryResult
        tdSql.query("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")
        unionallQnode=tdSql.queryResult

        # tdSql.query("show qnodes;")
        # qnodeId=tdSql.getData(0,0)
        tdLog.debug("drop qnode on dnode %s"%dnodeId)

        tdSql.execute("drop qnode on dnode %s"%dnodeId)
        tdSql.execute("reset query cache")

        tdSql.error("select max(c1) from stb10;")
G
Ganlin Zhao 已提交
480
        tdSql.error("select min(c1) from stb11;")
haoranc's avatar
haoranc 已提交
481 482 483
        tdSql.error("select c0,c1 from stb11_1 where (c0>1000) union select c0,c1 from stb11_1 where c0>2000;")
        tdSql.error("select c0,c1 from stb11_1 where (c0>1000) union all  select c0,c1 from stb11_1 where c0>2000;")

G
Ganlin Zhao 已提交
484
    # run case
haoranc's avatar
haoranc 已提交
485 486
    def run(self):
        # test qnode
G
Ganlin Zhao 已提交
487
        tdLog.debug(" test_case1 ............ [start]")
haoranc's avatar
haoranc 已提交
488
        self.test_case1()
haoranc's avatar
haoranc 已提交
489
        tdLog.debug(" test_case1 ............ [OK]")
G
Ganlin Zhao 已提交
490
        tdLog.debug(" test_case2 ............ [start]")
haoranc's avatar
haoranc 已提交
491
        self.test_case2()
haoranc's avatar
haoranc 已提交
492
        tdLog.debug(" test_case2 ............ [OK]")
G
Ganlin Zhao 已提交
493
        tdLog.debug(" test_case3 ............ [start]")
haoranc's avatar
haoranc 已提交
494
        self.test_case3()
haoranc's avatar
haoranc 已提交
495 496
        tdLog.debug(" test_case3 ............ [OK]")

haoranc's avatar
haoranc 已提交
497
        # tdLog.debug(" LIMIT test_case3 ............ [OK]")
haoranc's avatar
haoranc 已提交
498

haoranc's avatar
haoranc 已提交
499 500 501
    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")
haoranc's avatar
haoranc 已提交
502

G
Ganlin Zhao 已提交
503
        return
haoranc's avatar
haoranc 已提交
504 505 506 507
#
# add case with filename
#
tdCases.addWindows(__file__, TDTestCase())
508
tdCases.addLinux(__file__, TDTestCase())