filter.py 4.2 KB
Newer Older
P
Ping Xiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
###################################################################
#           Copyright (c) 2016 by TAOS Technologies, Inc.
#                     All rights reserved.
#
#  This file is proprietary and confidential to TAOS Technologies.
#  No part of this file may be reproduced, stored, transmitted,
#  disclosed or used in any form or by any means other than as
#  expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-

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


class TDTestCase:
22
    def init(self, conn, logSql):
P
Ping Xiao 已提交
23 24 25 26 27 28 29 30
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())

    def run(self):
        tdSql.prepare()

        print("==============step1")
        tdSql.execute(
31
            "create table if not exists st (ts timestamp, tagtype int, name nchar(16), col4 binary(16)) tags(dev nchar(50), tag2 binary(16))")
P
Ping Xiao 已提交
32
        tdSql.execute(
33
            'CREATE TABLE if not exists dev_001 using st tags("dev_01", "tag_01")')
P
Ping Xiao 已提交
34
        tdSql.execute(
35
            'CREATE TABLE if not exists dev_002 using st tags("dev_02", "tag_02")')
P
Ping Xiao 已提交
36 37 38 39

        print("==============step2")

        tdSql.execute(
40 41 42
            """INSERT INTO dev_001 VALUES('2020-05-13 10:00:00.000', 1, 'first', 'binary1'),('2020-05-13 10:00:00.001', 2, 'second', 'binary2'),
            ('2020-05-13 10:00:00.002', 3, 'third' , 'binary3') dev_002 VALUES('2020-05-13 10:00:00.003', 1, 'first', 'binary4'), ('2020-05-13 10:00:00.004', 2, 'second', 'binary5'),
            ('2020-05-13 10:00:00.005', 3, 'third', 'binary6')""")
P
Ping Xiao 已提交
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

        # > for timestamp type
        tdSql.query("select * from db.st where ts > '2020-05-13 10:00:00.002'")
        tdSql.checkRows(3)

        # > for numeric type
        tdSql.query("select * from db.st where tagtype > 2")
        tdSql.checkRows(2)

        # < for timestamp type
        tdSql.query("select * from db.st where ts < '2020-05-13 10:00:00.002'")
        tdSql.checkRows(2)

        # < for numeric type
        tdSql.query("select * from db.st where tagtype < 2")
        tdSql.checkRows(2)

        # >= for timestamp type
        tdSql.query("select * from db.st where ts >= '2020-05-13 10:00:00.002'")
        tdSql.checkRows(4)

        # >= for numeric type
        tdSql.query("select * from db.st where tagtype >= 2")
        tdSql.checkRows(4)

        # <= for timestamp type
        tdSql.query("select * from db.st where ts <= '2020-05-13 10:00:00.002'")
        tdSql.checkRows(3)

        # <= for numeric type
        tdSql.query("select * from db.st where tagtype <= 2")
        tdSql.checkRows(4)

        # = for timestamp type
        tdSql.query("select * from db.st where ts = '2020-05-13 10:00:00.002'")
        tdSql.checkRows(1)

        # = for numeric type
        tdSql.query("select * from db.st where tagtype = 2")
        tdSql.checkRows(2)

        # = for nchar type
        tdSql.query("select * from db.st where name = 'first'")
        tdSql.checkRows(2)

P
Ping Xiao 已提交
88 89 90 91 92
        tdSql.query("select * from db.st where col4 = 1231231")
        tdSql.checkRows(0)

        tdSql.query("select * from db.st where name = 1231231")
        tdSql.checkRows(0)
93

94
        # <> for timestamp type not supported on primary timestamp
95
        tdSql.error("select * from db.st where ts <> '2020-05-13 10:00:00.002'")
96
        # tdSql.checkRows(4)
P
Ping Xiao 已提交
97 98 99 100 101 102 103 104

        # <> for numeric type
        tdSql.query("select * from db.st where tagtype <> 2")
        tdSql.checkRows(4)

        # <> for nchar type
        tdSql.query("select * from db.st where name <> 'first'")
        tdSql.checkRows(4)
105

P
Ping Xiao 已提交
106 107 108 109 110 111 112 113
        # % for nchar type
        tdSql.query("select * from db.st where name like 'fi%'")
        tdSql.checkRows(2)

        # - for nchar type
        tdSql.query("select * from db.st where name like '_econd'")
        tdSql.checkRows(2)

114
        # for tag
P
Ping Xiao 已提交
115 116 117 118 119
        tdSql.query("select * from db.st where dev=1")
        tdSql.checkRows(0)

        tdSql.query("select * from db.st where tag2=1")
        tdSql.checkRows(0)
120

P
Ping Xiao 已提交
121 122 123 124 125 126 127
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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