stream2.py 5.1 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 26 27 28 29 30 31 32 33 34
###################################################################
#           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 time
import taos
from util.log import tdLog
from util.cases import tdCases
from util.sql import tdSql


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

    def run(self):
        tbNum = 10
        rowNum = 20
        totalNum = tbNum * rowNum

        tdSql.prepare()

        tdLog.info("===== step1 =====")
S
Shuduo Sang 已提交
35 36
        tdSql.execute(
            "create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)")
37 38 39
        for i in range(tbNum):
            tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i))
            for j in range(rowNum):
S
Shuduo Sang 已提交
40 41 42
                tdSql.execute(
                    "insert into tb%d values (now - %dm, %d, %d)" %
                    (i, 1440 - j, j, j))
43 44 45 46 47 48 49
        time.sleep(0.1)

        tdLog.info("===== step2 =====")
        tdSql.query("select count(col1) from tb0 interval(1d)")
        tdSql.checkData(0, 1, rowNum)
        tdSql.query("show tables")
        tdSql.checkRows(tbNum)
S
Shuduo Sang 已提交
50 51
        tdSql.execute(
            "create table s0 as select count(col1) from tb0 interval(1d)")
52 53 54 55
        tdSql.query("show tables")
        tdSql.checkRows(tbNum + 1)

        tdLog.info("===== step3 =====")
56
        tdSql.waitedQuery("select * from s0", 1, 120)
S
Shuduo Sang 已提交
57 58 59 60
        try:
            tdSql.checkData(0, 1, rowNum)
        except Exception as e:
            tdLog.info(repr(e))
61 62 63 64

        tdLog.info("===== step4 =====")
        tdSql.execute("drop table s0")
        tdSql.query("show tables")
S
Shuduo Sang 已提交
65 66 67 68
        try:
            tdSql.checkRows(tbNum)
        except Exception as e:
            tdLog.info(repr(e))
69 70 71 72 73

        tdLog.info("===== step5 =====")
        tdSql.error("select * from s0")

        tdLog.info("===== step6 =====")
S
Shuduo Sang 已提交
74 75
        tdSql.execute(
            "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)")
76
        tdSql.query("show tables")
S
Shuduo Sang 已提交
77 78 79 80
        try:
            tdSql.checkRows(tbNum + 1)
        except Exception as e:
            tdLog.info(repr(e))
81 82

        tdLog.info("===== step7 =====")
83
        tdSql.waitedQuery("select * from s0", 1, 120)
S
Shuduo Sang 已提交
84 85 86 87 88 89
        try:
            tdSql.checkData(0, 1, rowNum)
            tdSql.checkData(0, 2, rowNum)
            tdSql.checkData(0, 3, rowNum)
        except Exception as e:
            tdLog.info(repr(e))
90
        
D
dapan1121 已提交
91 92
        
        time.sleep(5)
93 94 95
        tdSql.query("show streams")
        tdSql.checkRows(1)
        tdSql.checkData(0, 2, 's0')
96 97

        tdLog.info("===== step8 =====")
S
Shuduo Sang 已提交
98 99
        tdSql.query(
            "select count(*), count(col1), count(col2) from stb0 interval(1d)")
S
Shuduo Sang 已提交
100 101 102 103 104 105
        try:
            tdSql.checkData(0, 1, totalNum)
            tdSql.checkData(0, 2, totalNum)
            tdSql.checkData(0, 3, totalNum)
        except Exception as e:
            tdLog.info(repr(e))
106 107
        tdSql.query("show tables")
        tdSql.checkRows(tbNum + 1)
S
Shuduo Sang 已提交
108 109
        tdSql.execute(
            "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)")
110 111 112 113
        tdSql.query("show tables")
        tdSql.checkRows(tbNum + 2)

        tdLog.info("===== step9 =====")
114
        tdSql.waitedQuery("select * from s1", 1, 120)
S
Shuduo Sang 已提交
115 116 117 118 119 120
        try:
            tdSql.checkData(0, 1, totalNum)
            tdSql.checkData(0, 2, totalNum)
            tdSql.checkData(0, 3, totalNum)
        except Exception as e:
            tdLog.info(repr(e))
121 122 123 124

        tdLog.info("===== step10 =====")
        tdSql.execute("drop table s1")
        tdSql.query("show tables")
S
Shuduo Sang 已提交
125 126 127 128
        try:
            tdSql.checkRows(tbNum + 1)
        except Exception as e:
            tdLog.info(repr(e))
129 130 131 132 133

        tdLog.info("===== step11 =====")
        tdSql.error("select * from s1")

        tdLog.info("===== step12 =====")
S
Shuduo Sang 已提交
134 135
        tdSql.execute(
            "create table s1 as select count(col1) from stb0 interval(1d)")
136
        tdSql.query("show tables")
S
Shuduo Sang 已提交
137 138 139 140
        try:
            tdSql.checkRows(tbNum + 2)
        except Exception as e:
            tdLog.info(repr(e))
141 142

        tdLog.info("===== step13 =====")
143
        tdSql.waitedQuery("select * from s1", 1, 120)
S
Shuduo Sang 已提交
144 145 146 147 148 149
        try:
            tdSql.checkData(0, 1, totalNum)
            #tdSql.checkData(0, 2, None)
            #tdSql.checkData(0, 3, None)
        except Exception as e:
            tdLog.info(repr(e))
150

D
dapan1121 已提交
151
        time.sleep(5)
152 153 154 155 156 157
        tdSql.query("show streams")
        tdSql.checkRows(2)
        tdSql.checkData(0, 2, 's1')
        tdSql.checkData(1, 2, 's0')
        

158 159 160 161 162 163 164
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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