min.py 7.0 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8
from wsgiref.headers import tspecials
from util.log import *
from util.cases import *
from util.sql import *
import numpy as np


class TDTestCase:
9
    def init(self, conn, logSql, replicaVar=1):
J
jiacy-jcy 已提交
10 11 12 13 14
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())

        self.rowNum = 10
        self.ts = 1537146000000
G
Ganlin Zhao 已提交
15

J
jiacy-jcy 已提交
16
    def run(self):
C
cpwu 已提交
17
        dbname = "db"
J
jiacy-jcy 已提交
18 19
        tdSql.prepare()

G
Ganlin Zhao 已提交
20
        intData = []
J
jiacy-jcy 已提交
21 22
        floatData = []

C
cpwu 已提交
23
        tdSql.execute(f'''create table {dbname}.stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
24
                    col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
C
cpwu 已提交
25 26
        tdSql.execute(f"create table {dbname}.stb_1 using {dbname}.stb tags('beijing')")
        tdSql.execute(f'''create table {dbname}.ntb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
27 28
                    col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned)''')
        for i in range(self.rowNum):
C
cpwu 已提交
29
            tdSql.execute(f"insert into {dbname}.ntb values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
30
                        % (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 已提交
31
            intData.append(i + 1)
J
jiacy-jcy 已提交
32 33
            floatData.append(i + 0.1)
        for i in range(self.rowNum):
C
cpwu 已提交
34
            tdSql.execute(f"insert into {dbname}.stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
35
                        % (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 已提交
36 37
            intData.append(i + 1)
            floatData.append(i + 0.1)
J
jiacy-jcy 已提交
38

G
Ganlin Zhao 已提交
39
        # max verifacation
G
Ganlin Zhao 已提交
40 41
        tdSql.error(f"select min(now()) from {dbname}.stb_1")
        tdSql.error(f"select min(ts) from {dbname}.stb_1")
C
cpwu 已提交
42 43 44 45 46 47
        tdSql.error(f"select min(col7) from {dbname}.stb_1")
        tdSql.error(f"select min(col8) from {dbname}.stb_1")
        tdSql.error(f"select min(col9) from {dbname}.stb_1")
        tdSql.error(f"select min(a) from {dbname}.stb_1")
        tdSql.query(f"select min(1) from {dbname}.stb_1")
        tdSql.error(f"select min(count(c1),count(c2)) from {dbname}.stb_1")
J
jiacy-jcy 已提交
48

C
cpwu 已提交
49
        tdSql.query(f"select min(col1) from {dbname}.stb_1")
J
jiacy-jcy 已提交
50
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
51
        tdSql.query(f"select min(col2) from {dbname}.stb_1")
J
jiacy-jcy 已提交
52
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
53
        tdSql.query(f"select min(col3) from {dbname}.stb_1")
J
jiacy-jcy 已提交
54
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
55
        tdSql.query(f"select min(col4) from {dbname}.stb_1")
J
jiacy-jcy 已提交
56
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
57
        tdSql.query(f"select min(col11) from {dbname}.stb_1")
J
jiacy-jcy 已提交
58
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
59
        tdSql.query(f"select min(col12) from {dbname}.stb_1")
J
jiacy-jcy 已提交
60
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
61
        tdSql.query(f"select min(col13) from {dbname}.stb_1")
J
jiacy-jcy 已提交
62
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
63
        tdSql.query(f"select min(col14) from {dbname}.stb_1")
J
jiacy-jcy 已提交
64
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
65
        tdSql.query(f"select min(col5) from {dbname}.stb_1")
J
jiacy-jcy 已提交
66
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
67
        tdSql.query(f"select min(col6) from {dbname}.stb_1")
J
jiacy-jcy 已提交
68
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
69
        tdSql.query(f"select min(col1) from {dbname}.stb_1 where col2>=5")
J
jiacy-jcy 已提交
70 71 72
        tdSql.checkData(0,0,5)


G
Ganlin Zhao 已提交
73 74
        tdSql.error(f"select min(now()) from {dbname}.stb_1")
        tdSql.error(f"select min(ts) from {dbname}.stb_1")
C
cpwu 已提交
75 76 77 78 79 80
        tdSql.error(f"select min(col7) from {dbname}.stb_1")
        tdSql.error(f"select min(col8) from {dbname}.stb_1")
        tdSql.error(f"select min(col9) from {dbname}.stb_1")
        tdSql.error(f"select min(a) from {dbname}.stb_1")
        tdSql.query(f"select min(1) from {dbname}.stb_1")
        tdSql.error(f"select min(count(c1),count(c2)) from {dbname}.stb_1")
J
jiacy-jcy 已提交
81

C
cpwu 已提交
82
        tdSql.query(f"select min(col1) from {dbname}.stb")
J
jiacy-jcy 已提交
83
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
84
        tdSql.query(f"select min(col2) from {dbname}.stb")
J
jiacy-jcy 已提交
85
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
86
        tdSql.query(f"select min(col3) from {dbname}.stb")
J
jiacy-jcy 已提交
87
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
88
        tdSql.query(f"select min(col4) from {dbname}.stb")
J
jiacy-jcy 已提交
89
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
90
        tdSql.query(f"select min(col11) from {dbname}.stb")
J
jiacy-jcy 已提交
91
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
92
        tdSql.query(f"select min(col12) from {dbname}.stb")
J
jiacy-jcy 已提交
93
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
94
        tdSql.query(f"select min(col13) from {dbname}.stb")
J
jiacy-jcy 已提交
95
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
96
        tdSql.query(f"select min(col14) from {dbname}.stb")
J
jiacy-jcy 已提交
97
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
98
        tdSql.query(f"select min(col5) from {dbname}.stb")
J
jiacy-jcy 已提交
99
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
100
        tdSql.query(f"select min(col6) from {dbname}.stb")
J
jiacy-jcy 已提交
101
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
102
        tdSql.query(f"select min(col1) from {dbname}.stb where col2>=5")
J
jiacy-jcy 已提交
103 104
        tdSql.checkData(0,0,5)

G
Ganlin Zhao 已提交
105 106
        tdSql.error(f"select min(now()) from {dbname}.stb_1")
        tdSql.error(f"select min(ts) from {dbname}.stb_1")
C
cpwu 已提交
107 108 109 110 111 112
        tdSql.error(f"select min(col7) from {dbname}.ntb")
        tdSql.error(f"select min(col8) from {dbname}.ntb")
        tdSql.error(f"select min(col9) from {dbname}.ntb")
        tdSql.error(f"select min(a) from {dbname}.ntb")
        tdSql.query(f"select min(1) from {dbname}.ntb")
        tdSql.error(f"select min(count(c1),count(c2)) from {dbname}.ntb")
J
jiacy-jcy 已提交
113

C
cpwu 已提交
114
        tdSql.query(f"select min(col1) from {dbname}.ntb")
J
jiacy-jcy 已提交
115
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
116
        tdSql.query(f"select min(col2) from {dbname}.ntb")
J
jiacy-jcy 已提交
117
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
118
        tdSql.query(f"select min(col3) from {dbname}.ntb")
J
jiacy-jcy 已提交
119
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
120
        tdSql.query(f"select min(col4) from {dbname}.ntb")
J
jiacy-jcy 已提交
121
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
122
        tdSql.query(f"select min(col11) from {dbname}.ntb")
J
jiacy-jcy 已提交
123
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
124
        tdSql.query(f"select min(col12) from {dbname}.ntb")
J
jiacy-jcy 已提交
125
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
126
        tdSql.query(f"select min(col13) from {dbname}.ntb")
J
jiacy-jcy 已提交
127
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
128
        tdSql.query(f"select min(col14) from {dbname}.ntb")
J
jiacy-jcy 已提交
129
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
130
        tdSql.query(f"select min(col5) from {dbname}.ntb")
J
jiacy-jcy 已提交
131
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
132
        tdSql.query(f"select min(col6) from {dbname}.ntb")
J
jiacy-jcy 已提交
133
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
134
        tdSql.query(f"select min(col1) from {dbname}.ntb where col2>=5")
J
jiacy-jcy 已提交
135 136
        tdSql.checkData(0,0,5)

G
Ganlin Zhao 已提交
137

J
jiacy-jcy 已提交
138 139 140 141 142 143
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)

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