diff.py 5.3 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()
J
jiacy-jcy 已提交
21 22 23 24
        tdSql.execute(
            "create table ntb(ts timestamp,c1 int,c2 double,c3 float)")
        tdSql.execute(
            "insert into 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 已提交
25 26 27

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

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

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

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

        # diff verifacation
J
update  
jiacy-jcy 已提交
60 61
        tdSql.query("select diff(col1) from stb_1")
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
62

J
update  
jiacy-jcy 已提交
63 64
        tdSql.query("select diff(col2) from stb_1")
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
65

J
update  
jiacy-jcy 已提交
66 67
        tdSql.query("select diff(col3) from stb_1")
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
68

J
update  
jiacy-jcy 已提交
69 70
        tdSql.query("select diff(col4) from stb_1")
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
71

J
update  
jiacy-jcy 已提交
72 73
        tdSql.query("select diff(col5) from stb_1")
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
74

J
update  
jiacy-jcy 已提交
75 76
        tdSql.query("select diff(col6) from stb_1")
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
77

J
jiacy-jcy 已提交
78 79 80
        tdSql.query("select diff(col7) from stb_1")
        tdSql.checkRows(0)

J
jiacy-jcy 已提交
81
        for i in range(self.rowNum):
J
jiacy-jcy 已提交
82 83 84 85
            tdSql.execute("insert into stb_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
                          % (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))

        tdSql.error("select diff(ts) from stb")
J
jiacy-jcy 已提交
86
        tdSql.error("select diff(ts) from stb_1")
J
jiacy-jcy 已提交
87 88 89 90

        # tdSql.error("select diff(col7) from stb")

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

J
jiacy-jcy 已提交
100 101
        tdSql.query("select diff(col1) from stb_1")
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
102

J
jiacy-jcy 已提交
103 104
        tdSql.query("select diff(col2) from stb_1")
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
105

J
jiacy-jcy 已提交
106 107
        tdSql.query("select diff(col3) from stb_1")
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
108

J
jiacy-jcy 已提交
109 110
        tdSql.query("select diff(col4) from stb_1")
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
111

J
jiacy-jcy 已提交
112 113
        tdSql.query("select diff(col5) from stb_1")
        tdSql.checkRows(10)
J
update  
jiacy-jcy 已提交
114

J
jiacy-jcy 已提交
115 116
        tdSql.query("select diff(col6) from stb_1")
        tdSql.checkRows(10)
J
jiacy-jcy 已提交
117

G
Ganlin Zhao 已提交
118
        tdSql.execute('''create table stb1(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
J
jiacy-jcy 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
                    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 stb1_1 using stb tags('shanghai')")

        for i in range(self.rowNum):
            tdSql.execute("insert into stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
                          % (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):
            tdSql.execute("insert into stb1_1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
                          % (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))
        tdSql.query("select diff(col1,0) from stb1_1")
        tdSql.checkRows(19)
        tdSql.query("select diff(col1,1) from stb1_1")
        tdSql.checkRows(19)
        tdSql.checkData(0,0,None)

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

J
jiacy-jcy 已提交
138

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