To_unixtimestamp.py 3.5 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
from time import sleep

from util.log import *
from util.sql import *
from util.cases import *




class TDTestCase:

    def init(self, conn, logSql):
        tdLog.debug(f"start to excute {__file__}")
        tdSql.init(conn.cursor())
J
jiacy-jcy 已提交
15
        # name of normal table
G
Ganlin Zhao 已提交
16
        self.ntbname = 'ntb'
J
jiacy-jcy 已提交
17
        # name of stable
G
Ganlin Zhao 已提交
18
        self.stbname = 'stb'
J
jiacy-jcy 已提交
19
        # structure of column
G
Ganlin Zhao 已提交
20
        self.column_dict = {
J
jiacy-jcy 已提交
21 22 23 24 25 26 27
            'ts':'timestamp',
            'c1':'int',
            'c2':'float',
            'c3':'binary(20)',
            'c4':'nchar(20)'
        }
        # structure of tag
G
Ganlin Zhao 已提交
28
        self.tag_dict = {
J
jiacy-jcy 已提交
29 30 31
            't0':'int'
        }
        # number of child tables
G
Ganlin Zhao 已提交
32
        self.tbnum = 2
J
jiacy-jcy 已提交
33
        # values of tag,the number of values should equal to tbnum
G
Ganlin Zhao 已提交
34
        self.tag_values = [
J
jiacy-jcy 已提交
35 36 37 38 39 40 41
            f'10',
            f'100'
        ]
        # values of rows, structure should be same as column
        self.values_list = [
            f'now,10,99.99,"2020-1-1 00:00:00"',
            f'today(),100,11.111,22.222222'
J
jiacy-jcy 已提交
42

J
jiacy-jcy 已提交
43 44
        ]
        self.error_param = [1,'now()']
G
Ganlin Zhao 已提交
45

J
jiacy-jcy 已提交
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    def run(self):  # sourcery skip: extract-duplicate-method
        tdSql.prepare()
        tdLog.printNoPrefix("==========step1:create tables==========")
        tdSql.execute(
            '''create table if not exists ntb
            (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp)
            '''
        )
        tdSql.execute(
            '''create table if not exists stb
            (ts timestamp, c1 int, c2 float,c3 double,c4 timestamp) tags(t0 int)
            '''
        )
        tdSql.execute(
            '''create table if not exists stb_1 using stb tags(100)
            '''
        )
        tdLog.printNoPrefix("==========step2:insert data into ntb==========")

J
jiacy-jcy 已提交
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        # RFC3339:2020-01-01T00:00:00+8:00
        # ISO8601:2020-01-01T00:00:00.000+0800
        tdSql.execute(
            'insert into ntb values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
        tdSql.execute(
            'insert into stb_1 values(now,1,1.55,100.555555,today())("2020-1-1 00:00:00",10,11.11,99.999999,now())(today(),3,3.333,333.333333,now())')
        tdSql.query("select to_unixtimestamp('1970-01-01T08:00:00+0800') from ntb")
        tdSql.checkData(0,0,0)
        tdSql.checkData(1,0,0)
        tdSql.checkData(2,0,0)
        tdSql.checkRows(3)
        tdSql.query("select to_unixtimestamp('1970-01-01T08:00:00+08:00') from ntb")
        tdSql.checkData(0,0,0)
        tdSql.checkRows(3)
        tdSql.query("select to_unixtimestamp('1900-01-01T08:00:00+08:00') from ntb")
        tdSql.checkRows(3)
        tdSql.query("select to_unixtimestamp('2020-01-32T08:00:00') from ntb")
        tdSql.checkRows(3)
        tdSql.checkData(0,0,None)
        tdSql.query("select to_unixtimestamp('2020-13-32T08:00:00') from ntb")
        tdSql.checkRows(3)
        tdSql.checkData(0,0,None)
        tdSql.query("select to_unixtimestamp('acd') from ntb")
        tdSql.checkRows(3)
        tdSql.checkData(0,0,None)
        tdSql.error("select to_unixtimestamp(1) from ntb")
        tdSql.error("select to_unixtimestamp(1.5) from ntb")
        tdSql.error("select to_unixtimestamp(ts) from ntb")

        tdSql.query("select ts from ntb where to_unixtimestamp('1970-01-01T08:00:00+08:00')=0")
        tdSql.checkRows(3)
G
Ganlin Zhao 已提交
96

J
jiacy-jcy 已提交
97 98 99 100 101 102

    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")

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