count.py 8.3 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
from util.log import *
from util.sql import *
from util.cases import *

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

        self.rowNum = 10
        self.ts = 1537146000000

    def run(self):
        tdSql.prepare()

G
Ganlin Zhao 已提交
16
        tdSql.execute('''create table stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
17 18
                    col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
        tdSql.execute("create table stb_1 using stb tags('beijing')")
J
jiacy-jcy 已提交
19
        tdSql.execute("create table stb_2 using stb tags('shanghai')")
J
jiacy-jcy 已提交
20

G
Ganlin Zhao 已提交
21
        tdSql.execute('''create table ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
22
                    col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''')
G
Ganlin Zhao 已提交
23

J
jiacy-jcy 已提交
24
        for i in range(self.rowNum):
G
Ganlin Zhao 已提交
25
            tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
26
                        % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
G
Ganlin Zhao 已提交
27
            tdSql.execute("insert into stb_2 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
28
                        % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
G
Ganlin Zhao 已提交
29

J
jiacy-jcy 已提交
30
        for i in range(self.rowNum):
G
Ganlin Zhao 已提交
31
            tdSql.execute("insert into ntb values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
32
                        % (self.ts + i, i + 1, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
G
Ganlin Zhao 已提交
33

J
jiacy-jcy 已提交
34
        tdSql.query("select count(*) from stb")
J
jiacy-jcy 已提交
35
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
36
        tdSql.query("select count(*) from db.stb")
J
jiacy-jcy 已提交
37
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
38
        tdSql.query("select count(ts) from stb")
J
jiacy-jcy 已提交
39
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
40
        tdSql.query("select count(ts) from db.stb")
J
jiacy-jcy 已提交
41
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
42
        tdSql.query("select count(col1) from stb")
J
jiacy-jcy 已提交
43
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
44
        tdSql.query("select count(col1) from db.stb")
J
jiacy-jcy 已提交
45
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
46
        tdSql.query("select count(col2) from stb")
J
jiacy-jcy 已提交
47
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
48
        tdSql.query("select count(col2) from db.stb")
J
jiacy-jcy 已提交
49
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
50
        tdSql.query("select count(col3) from stb")
J
jiacy-jcy 已提交
51
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
52
        tdSql.query("select count(col3) from db.stb")
J
jiacy-jcy 已提交
53
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
54
        tdSql.query("select count(col4) from stb")
J
jiacy-jcy 已提交
55
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
56
        tdSql.query("select count(col4) from db.stb")
J
jiacy-jcy 已提交
57
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
58
        tdSql.query("select count(col5) from stb")
J
jiacy-jcy 已提交
59
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
60
        tdSql.query("select count(col5) from db.stb")
J
jiacy-jcy 已提交
61
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
62
        tdSql.query("select count(col6) from stb")
J
jiacy-jcy 已提交
63
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
64
        tdSql.query("select count(col6) from db.stb")
J
jiacy-jcy 已提交
65
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
66
        tdSql.query("select count(col7) from stb")
J
jiacy-jcy 已提交
67
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
68
        tdSql.query("select count(col7) from db.stb")
J
jiacy-jcy 已提交
69
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
70
        tdSql.query("select count(col8) from stb")
J
jiacy-jcy 已提交
71
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
72
        tdSql.query("select count(col8) from db.stb")
J
jiacy-jcy 已提交
73
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
74
        tdSql.query("select count(col9) from stb")
J
jiacy-jcy 已提交
75
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
76
        tdSql.query("select count(col9) from db.stb")
J
jiacy-jcy 已提交
77
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
78
        tdSql.query("select count(col11) from stb")
J
jiacy-jcy 已提交
79
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
80
        tdSql.query("select count(col11) from db.stb")
J
jiacy-jcy 已提交
81
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
82
        tdSql.query("select count(col12) from stb")
J
jiacy-jcy 已提交
83
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
84
        tdSql.query("select count(col12) from db.stb")
J
jiacy-jcy 已提交
85
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
86
        tdSql.query("select count(col13) from stb")
J
jiacy-jcy 已提交
87
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
88
        tdSql.query("select count(col13) from db.stb")
J
jiacy-jcy 已提交
89
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
90
        tdSql.query("select count(col14) from stb")
J
jiacy-jcy 已提交
91
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
92
        tdSql.query("select count(col14) from db.stb")
J
jiacy-jcy 已提交
93 94 95 96
        tdSql.checkData(0,0,20)



J
jiacy-jcy 已提交
97
        tdSql.query("select count(ts) from db.stb_1")
G
Ganlin Zhao 已提交
98
        tdSql.checkData(0,0,10)
J
jiacy-jcy 已提交
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
        tdSql.query("select count(ts) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col1) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col1) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col2) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col2) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col3) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col3) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col4) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col4) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col5) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col5) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col6) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col6) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col7) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col7) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col8) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col8) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col9) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col9) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col11) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col11) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col12) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col12) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col13) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col13) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col14) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col14) from db.stb_1")
        tdSql.checkData(0,0,10)
J
jiacy-jcy 已提交
153 154
        tdSql.query("select count(col1) from stb_1 group by col7")
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

        tdSql.execute("insert into stb_1 values(now,null,null,null,null,null,null,null,null,null,null,null,null,null)")
        tdSql.query("select count(col1) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col1),count(ts) from stb_1")
        tdSql.checkData(0,0,10)
        tdSql.checkData(0,1,11)

        tdSql.query("select count(col1) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.query("select count(col1),count(ts) from db.stb_1")
        tdSql.checkData(0,0,10)
        tdSql.checkData(0,1,11)

        tdSql.query("select count(col1) from stb")
J
jiacy-jcy 已提交
170
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
171
        tdSql.query("select count(col1),count(ts) from stb")
J
jiacy-jcy 已提交
172 173
        tdSql.checkData(0,0,20)
        tdSql.checkData(0,1,21)
G
Ganlin Zhao 已提交
174

J
jiacy-jcy 已提交
175
        tdSql.query("select count(col1) from db.stb")
J
jiacy-jcy 已提交
176
        tdSql.checkData(0,0,20)
J
jiacy-jcy 已提交
177
        tdSql.query("select count(col1),count(ts) from db.stb")
J
jiacy-jcy 已提交
178 179 180 181 182 183 184 185
        tdSql.checkData(0,0,20)
        tdSql.checkData(0,1,21)
        tdSql.query("select count(col1) from stb_1 group by col7")
        tdSql.checkRows(3)
        tdSql.query("select count(col1) from stb_2 group by col7")
        tdSql.checkRows(2)
        tdSql.query("select count(col1) from stb group by col7")
        tdSql.checkRows(3)
J
jiacy-jcy 已提交
186

G
Ganlin Zhao 已提交
187

J
jiacy-jcy 已提交
188 189 190 191 192 193 194 195


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


tdCases.addWindows(__file__, TDTestCase())
G
Ganlin Zhao 已提交
196
tdCases.addLinux(__file__, TDTestCase())