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


class TDTestCase:
    def init(self, conn, logSql):
        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
C
cpwu 已提交
40 41 42 43 44 45
        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 已提交
46

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

70
        tdSql.query(f"select min(now()) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
71 72
        tdSql.checkRows(1)

73
        tdSql.query(f"select first(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
74
        firstTs = tdSql.getData(0, 0)
75
        tdSql.query(f"select min(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
76 77
        tdSql.checkData(0, 0, firstTs)

78
        tdSql.query(f"select first(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
79
        firstTs = tdSql.getData(0, 0)
80
        tdSql.query(f"select min(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
81 82
        tdSql.checkData(0, 0, firstTs)

J
jiacy-jcy 已提交
83

C
cpwu 已提交
84 85 86 87 88 89
        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 已提交
90

C
cpwu 已提交
91
        tdSql.query(f"select min(col1) from {dbname}.stb")
J
jiacy-jcy 已提交
92
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
93
        tdSql.query(f"select min(col2) from {dbname}.stb")
J
jiacy-jcy 已提交
94
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
95
        tdSql.query(f"select min(col3) from {dbname}.stb")
J
jiacy-jcy 已提交
96
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
97
        tdSql.query(f"select min(col4) from {dbname}.stb")
J
jiacy-jcy 已提交
98
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
99
        tdSql.query(f"select min(col11) from {dbname}.stb")
J
jiacy-jcy 已提交
100
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
101
        tdSql.query(f"select min(col12) from {dbname}.stb")
J
jiacy-jcy 已提交
102
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
103
        tdSql.query(f"select min(col13) from {dbname}.stb")
J
jiacy-jcy 已提交
104
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
105
        tdSql.query(f"select min(col14) from {dbname}.stb")
J
jiacy-jcy 已提交
106
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
107
        tdSql.query(f"select min(col5) from {dbname}.stb")
J
jiacy-jcy 已提交
108
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
109
        tdSql.query(f"select min(col6) from {dbname}.stb")
J
jiacy-jcy 已提交
110
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
111
        tdSql.query(f"select min(col1) from {dbname}.stb where col2>=5")
J
jiacy-jcy 已提交
112 113
        tdSql.checkData(0,0,5)

114
        tdSql.query(f"select min(now()) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
115 116
        tdSql.checkRows(1)

117
        tdSql.query(f"select first(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
118
        firstTs = tdSql.getData(0, 0)
119
        tdSql.query(f"select min(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
120 121
        tdSql.checkData(0, 0, firstTs)

122
        tdSql.query(f"select first(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
123
        firstTs = tdSql.getData(0, 0)
124
        tdSql.query(f"select min(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
125 126
        tdSql.checkData(0, 0, firstTs)

C
cpwu 已提交
127 128 129 130 131 132
        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 已提交
133

C
cpwu 已提交
134
        tdSql.query(f"select min(col1) from {dbname}.ntb")
J
jiacy-jcy 已提交
135
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
136
        tdSql.query(f"select min(col2) from {dbname}.ntb")
J
jiacy-jcy 已提交
137
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
138
        tdSql.query(f"select min(col3) from {dbname}.ntb")
J
jiacy-jcy 已提交
139
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
140
        tdSql.query(f"select min(col4) from {dbname}.ntb")
J
jiacy-jcy 已提交
141
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
142
        tdSql.query(f"select min(col11) from {dbname}.ntb")
J
jiacy-jcy 已提交
143
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
144
        tdSql.query(f"select min(col12) from {dbname}.ntb")
J
jiacy-jcy 已提交
145
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
146
        tdSql.query(f"select min(col13) from {dbname}.ntb")
J
jiacy-jcy 已提交
147
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
148
        tdSql.query(f"select min(col14) from {dbname}.ntb")
J
jiacy-jcy 已提交
149
        tdSql.checkData(0, 0, np.min(intData))
C
cpwu 已提交
150
        tdSql.query(f"select min(col5) from {dbname}.ntb")
J
jiacy-jcy 已提交
151
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
152
        tdSql.query(f"select min(col6) from {dbname}.ntb")
J
jiacy-jcy 已提交
153
        tdSql.checkData(0, 0, np.min(floatData))
C
cpwu 已提交
154
        tdSql.query(f"select min(col1) from {dbname}.ntb where col2>=5")
J
jiacy-jcy 已提交
155 156
        tdSql.checkData(0,0,5)

157
        tdSql.query(f"select min(now()) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
158 159
        tdSql.checkRows(1)

160
        tdSql.query(f"select first(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
161
        firstTs = tdSql.getData(0, 0)
162
        tdSql.query(f"select min(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
163 164
        tdSql.checkData(0, 0, firstTs)

165
        tdSql.query(f"select first(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
166
        firstTs = tdSql.getData(0, 0)
167
        tdSql.query(f"select min(ts) from {dbname}.stb_1")
G
Ganlin Zhao 已提交
168 169
        tdSql.checkData(0, 0, firstTs)

G
Ganlin Zhao 已提交
170

J
jiacy-jcy 已提交
171 172 173 174 175 176
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)

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