smaTest.py 3.8 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 20 21 22 23 24 25 26 27 28 29
###################################################################
#           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 numpy.lib.function_base import insert
import taos
from util.log import *
from util.cases import *
from util.sql import *
import numpy as np

# constant define
WAITS = 5 # wait seconds

class TDTestCase:
    #
    # --------------- main frame -------------------
    #
haoranc's avatar
haoranc 已提交
30 31 32
    # updatecfgDict = {'debugFlag': 135}
    # updatecfgDict = {'fqdn': 135}

haoranc's avatar
haoranc 已提交
33
    # init
34
    def init(self, conn, logSql, replicaVar=1):
35
        self.replicaVar = int(replicaVar)
haoranc's avatar
haoranc 已提交
36 37 38 39 40 41 42
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())
        tdSql.prepare()
        self.create_tables();
        self.ts = 1500000000000


C
cpwu 已提交
43
    # run case
haoranc's avatar
haoranc 已提交
44 45
    def run(self):
        # insert data
C
cpwu 已提交
46
        dbname = "db"
S
Shengliang Guan 已提交
47 48
        self.insert_data1(f"{dbname}.t1", self.ts, 10*10000)
        self.insert_data1(f"{dbname}.t4", self.ts, 10*10000)
haoranc's avatar
haoranc 已提交
49 50 51 52 53 54 55
        # test base case
        # self.test_case1()
        tdLog.debug(" LIMIT test_case1 ............ [OK]")
        # test advance case
        # self.test_case2()
        tdLog.debug(" LIMIT test_case2 ............ [OK]")

C
cpwu 已提交
56
    # stop
haoranc's avatar
haoranc 已提交
57 58 59 60 61 62 63 64 65
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)

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

    # create table
C
cpwu 已提交
66
    def create_tables(self, dbname="db"):
haoranc's avatar
haoranc 已提交
67
        # super table
C
cpwu 已提交
68
        tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int) tags(area int)")
haoranc's avatar
haoranc 已提交
69
        # child table
C
cpwu 已提交
70
        tdSql.execute(f"create table {dbname}.t1 using {dbname}.st tags(1)")
haoranc's avatar
haoranc 已提交
71

C
cpwu 已提交
72 73
        tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int) tags(area int) sma(i2) ")
        tdSql.execute(f"create table {dbname}.t4 using {dbname}.st1 tags(1)")
haoranc's avatar
haoranc 已提交
74

C
cpwu 已提交
75
        return
haoranc's avatar
haoranc 已提交
76 77 78

    # insert data1
    def insert_data(self, tbname, ts_start, count):
S
Shengliang Guan 已提交
79
        pre_insert = "insert into %s values" % tbname
haoranc's avatar
haoranc 已提交
80
        sql = pre_insert
S
Shengliang Guan 已提交
81
        tdLog.debug("insert table %s rows=%d ..." % (tbname, count))
haoranc's avatar
haoranc 已提交
82
        for i in range(count):
S
Shengliang Guan 已提交
83 84 85
            sql += " (%d,%d)" % (ts_start + i*1000, i)
            if i > 0 and i % 20000 == 0:
                tdLog.info("%d rows inserted" % i)
haoranc's avatar
haoranc 已提交
86 87
                tdSql.execute(sql)
                sql = pre_insert
C
cpwu 已提交
88
        # end sql
S
Shengliang Guan 已提交
89
        tdLog.info("insert_data end")
haoranc's avatar
haoranc 已提交
90 91 92 93 94 95 96
        if sql != pre_insert:
            tdSql.execute(sql)

        tdLog.debug("INSERT TABLE DATA ............ [OK]")
        return

    def insert_data1(self, tbname, ts_start, count):
S
Shengliang Guan 已提交
97
        pre_insert = "insert into %s values" % tbname
haoranc's avatar
haoranc 已提交
98
        sql = pre_insert
S
Shengliang Guan 已提交
99
        tdLog.debug("insert table %s rows=%d ..." % (tbname, count))
haoranc's avatar
haoranc 已提交
100
        for i in range(count):
S
Shengliang Guan 已提交
101 102 103
            sql += " (%d,%d,%d)" % (ts_start + i*1000, i, i+1)
            if i > 0 and i % 20000 == 0:
                tdLog.info("%d rows inserted" % i)
haoranc's avatar
haoranc 已提交
104 105
                tdSql.execute(sql)
                sql = pre_insert
C
cpwu 已提交
106
        # end sql
S
Shengliang Guan 已提交
107
        tdLog.info("insert_data1 end")
haoranc's avatar
haoranc 已提交
108 109 110 111 112 113
        if sql != pre_insert:
            tdSql.execute(sql)

        tdLog.debug("INSERT TABLE DATA ............ [OK]")
        return

C
cpwu 已提交
114
    # test case1 base
haoranc's avatar
haoranc 已提交
115
    # def test_case1(self):
C
cpwu 已提交
116
    #     #
haoranc's avatar
haoranc 已提交
117 118 119 120 121 122 123 124 125 126 127 128
    #     # limit base function
    #     #
    #     # base no where
    #     sql = "select * from t1 limit 10"
    #     tdSql.waitedQuery(sql, 10, WAITS)


#
# add case with filename
#
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())