diff.py 5.8 KB
Newer Older
J
update  
jiacy-jcy 已提交
1
from wsgiref.headers import tspecials
J
jiacy-jcy 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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
        self.perfix = 'dev'
        self.tables = 10


    def run(self):
        tdSql.prepare()
C
cpwu 已提交
21
        dbname = "db"
J
jiacy-jcy 已提交
22
        tdSql.execute(
C
cpwu 已提交
23
            f"create table {dbname}.ntb(ts timestamp,c1 int,c2 double,c3 float)")
J
jiacy-jcy 已提交
24
        tdSql.execute(
C
cpwu 已提交
25
            f"insert into {dbname}.ntb values(now,1,1.0,10.5)(now+1s,10,-100.0,5.1)(now+10s,-1,15.1,5.0)")
J
update  
jiacy-jcy 已提交
26

C
cpwu 已提交
27
        tdSql.query(f"select diff(c1,0) from {dbname}.ntb")
J
update  
jiacy-jcy 已提交
28
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
29 30
        tdSql.checkData(0, 0, 9)
        tdSql.checkData(1, 0, -11)
C
cpwu 已提交
31
        tdSql.query(f"select diff(c1,1) from {dbname}.ntb")
J
update  
jiacy-jcy 已提交
32
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
33 34 35
        tdSql.checkData(0, 0, 9)
        tdSql.checkData(1, 0, None)

C
cpwu 已提交
36
        tdSql.query(f"select diff(c2,0) from {dbname}.ntb")
J
update  
jiacy-jcy 已提交
37
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
38 39
        tdSql.checkData(0, 0, -101)
        tdSql.checkData(1, 0, 115.1)
C
cpwu 已提交
40
        tdSql.query(f"select diff(c2,1) from {dbname}.ntb")
J
update  
jiacy-jcy 已提交
41
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
42 43
        tdSql.checkData(0, 0, None)
        tdSql.checkData(1, 0, 115.1)
J
update  
jiacy-jcy 已提交
44

C
cpwu 已提交
45
        tdSql.query(f"select diff(c3,0) from {dbname}.ntb")
J
update  
jiacy-jcy 已提交
46
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
47 48
        tdSql.checkData(0, 0, -5.4)
        tdSql.checkData(1, 0, -0.1)
C
cpwu 已提交
49
        tdSql.query(f"select diff(c3,1) from {dbname}.ntb")
J
update  
jiacy-jcy 已提交
50
        tdSql.checkRows(2)
J
jiacy-jcy 已提交
51 52
        tdSql.checkData(0, 0, None)
        tdSql.checkData(1, 0, None)
J
jiacy-jcy 已提交
53

C
cpwu 已提交
54
        tdSql.execute(f'''create table {dbname}.stb(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
55
                    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 已提交
56
        tdSql.execute(f"create table {dbname}.stb_1 using {dbname}.stb tags('beijing')")
J
jiacy-jcy 已提交
57
        tdSql.execute(
C
cpwu 已提交
58
            f"insert into {dbname}.stb_1 values(%d, 0, 0, 0, 0, 0.0, 0.0, False, ' ', ' ', 0, 0, 0, 0)" % (self.ts - 1))
J
jiacy-jcy 已提交
59 60

        # diff verifacation
C
cpwu 已提交
61
        tdSql.query(f"select diff(col1) from {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
62
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
63

C
cpwu 已提交
64
        tdSql.query(f"select diff(col2) from {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
65
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
66

C
cpwu 已提交
67
        tdSql.query(f"select diff(col3) from {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
68
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
69

C
cpwu 已提交
70
        tdSql.query(f"select diff(col4) from {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
71
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
72

C
cpwu 已提交
73
        tdSql.query(f"select diff(col5) from {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
74
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
75

C
cpwu 已提交
76
        tdSql.query(f"select diff(col6) from {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
77
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
78

C
cpwu 已提交
79
        tdSql.query(f"select diff(col7) from {dbname}.stb_1")
J
jiacy-jcy 已提交
80 81
        tdSql.checkRows(0)

J
jiacy-jcy 已提交
82
        for i in range(self.rowNum):
C
cpwu 已提交
83
            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 已提交
84 85
                          % (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))

C
cpwu 已提交
86 87
        tdSql.error(f"select diff(ts) from {dbname}.stb")
        tdSql.error(f"select diff(ts) from {dbname}.stb_1")
J
jiacy-jcy 已提交
88

C
cpwu 已提交
89
        # tdSql.error(f"select diff(col7) from  {dbname}.stb")
J
jiacy-jcy 已提交
90

C
cpwu 已提交
91 92 93 94 95 96 97 98
        tdSql.error(f"select diff(col8) from {dbname}.stb")
        tdSql.error(f"select diff(col8) from {dbname}.stb_1")
        tdSql.error(f"select diff(col9) from {dbname}.stb")
        tdSql.error(f"select diff(col9) from {dbname}.stb_1")
        tdSql.error(f"select diff(col11) from  {dbname}.stb_1")
        tdSql.error(f"select diff(col12) from  {dbname}.stb_1")
        tdSql.error(f"select diff(col13) from  {dbname}.stb_1")
        tdSql.error(f"select diff(col14) from  {dbname}.stb_1")
C
cpwu 已提交
99
        tdSql.query(f"select ts,diff(col1),ts from  {dbname}.stb_1")
J
update  
jiacy-jcy 已提交
100

C
cpwu 已提交
101
        tdSql.query(f"select diff(col1) from  {dbname}.stb_1")
J
jiacy-jcy 已提交
102
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
103

C
cpwu 已提交
104
        tdSql.query(f"select diff(col2) from  {dbname}.stb_1")
J
jiacy-jcy 已提交
105
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
106

C
cpwu 已提交
107
        tdSql.query(f"select diff(col3) from  {dbname}.stb_1")
J
jiacy-jcy 已提交
108
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
109

C
cpwu 已提交
110
        tdSql.query(f"select diff(col4) from  {dbname}.stb_1")
J
jiacy-jcy 已提交
111
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
112

C
cpwu 已提交
113
        tdSql.query(f"select diff(col5) from  {dbname}.stb_1")
J
jiacy-jcy 已提交
114
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
115

C
cpwu 已提交
116
        tdSql.query(f"select diff(col6) from  {dbname}.stb_1")
J
jiacy-jcy 已提交
117
        tdSql.checkRows(10)
J
jiacy-jcy 已提交
118

C
cpwu 已提交
119
        tdSql.execute(f'''create table  {dbname}.stb1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
120
                    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 已提交
121
        tdSql.execute(f"create table  {dbname}.stb1_1 using  {dbname}.stb tags('shanghai')")
J
jiacy-jcy 已提交
122 123

        for i in range(self.rowNum):
C
cpwu 已提交
124
            tdSql.execute(f"insert into  {dbname}.stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
125 126
                          % (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))
        for i in range(self.rowNum):
C
cpwu 已提交
127
            tdSql.execute(f"insert into  {dbname}.stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
J
jiacy-jcy 已提交
128
                          % (self.ts - i-1, 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))
C
cpwu 已提交
129
        tdSql.query(f"select diff(col1,0) from  {dbname}.stb1_1")
J
jiacy-jcy 已提交
130
        tdSql.checkRows(19)
C
cpwu 已提交
131
        tdSql.query(f"select diff(col1,1) from  {dbname}.stb1_1")
J
jiacy-jcy 已提交
132 133 134
        tdSql.checkRows(19)
        tdSql.checkData(0,0,None)

J
jiacy-jcy 已提交
135 136 137 138
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)

J
jiacy-jcy 已提交
139

J
jiacy-jcy 已提交
140
tdCases.addWindows(__file__, TDTestCase())
J
jiacy-jcy 已提交
141
tdCases.addLinux(__file__, TDTestCase())