queryRegex.py 3.8 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
###################################################################
#           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 tdLog
from util.cases import tdCases
from util.sql import tdSql
from util.dnodes import tdDnodes


class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)

    def run(self):
        tdSql.prepare()
        print("==============step1")
        ##2021-09-17 For jira: https://jira.taosdata.com:18080/browse/TD-6585
        tdSql.execute(
J
jiacy-jcy 已提交
32
            "create stable if not exists stb_test(ts timestamp,c0 binary(32),c1 int) tags(t0 binary(32))"
J
jiacy-jcy 已提交
33 34 35 36
        )
        tdSql.execute(
            'create table if not exists stb_1 using stb_test tags("abcdefgasdfg12346")'
        )
J
jiacy-jcy 已提交
37
        tdLog.info('insert into stb_1 values("2021-09-13 10:00:00.001","abcefdasdqwerxasdazx12345",15')
J
jiacy-jcy 已提交
38 39


J
jiacy-jcy 已提交
40 41 42 43 44
        tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.002","abcefdasdqwerxasdazx12345",15)')
        tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.003","aaaaafffwwqqxzz",16)')
        tdSql.execute('insert into stb_1 values("2021-09-13 10:00:00.004","fffwwqqxzz",17)')
        tdSql.execute('insert into stb_1 values("2020-10-13 10:00:00.001","abcd\\\efgh",100)')

J
jiacy-jcy 已提交
45 46 47
        tdSql.query('select * from stb_test where tbname match "asd"')
        tdSql.checkRows(0)
        tdSql.query('select * from stb_test where tbname nmatch "asd"')
J
jiacy-jcy 已提交
48
        tdSql.checkRows(4)
J
jiacy-jcy 已提交
49 50

        tdSql.query('select * from stb_test where c0 match "abc"')
J
jiacy-jcy 已提交
51 52 53 54 55 56 57
        tdSql.checkRows(2)
        tdSql.query('select * from stb_test where c0 nmatch "abc"')
        tdSql.checkRows(2)

        tdSql.query('select * from stb_test where c0 match "^a"')
        tdSql.checkRows(3)
        tdSql.query('select * from stb_test where c0 nmatch "^a"')
J
jiacy-jcy 已提交
58
        tdSql.checkRows(1)
J
jiacy-jcy 已提交
59 60
    
        tdSql.query('select * from stb_test where c0 match "5$"')
J
jiacy-jcy 已提交
61
        tdSql.checkData(0,1,"abcefdasdqwerxasdazx12345")
J
jiacy-jcy 已提交
62 63 64 65 66 67 68 69
        tdSql.query('select * from stb_test where c0 nmatch "5$"')
        tdSql.checkRows(3)
        
        
        tdSql.query('select * from stb_test where c0 match "a*"')
        tdSql.checkRows(4)
        tdSql.query('select * from stb_test where c0 nmatch "a*"')
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
70

J
jiacy-jcy 已提交
71 72 73 74 75 76 77 78 79

        tdSql.query('select * from stb_test where c0 match "a+"')
        tdSql.checkRows(3)
        tdSql.query('select * from stb_test where c0 nmatch "a+"')
        tdSql.checkRows(1)

        tdSql.query('select * from stb_test where c0 match "a?"')
        tdSql.checkRows(4)
        tdSql.query('select * from stb_test where c0 nmatch "a?"')
J
jiacy-jcy 已提交
80
        tdSql.checkRows(0)
J
jiacy-jcy 已提交
81 82 83 84 85 86 87 88
        

        tdSql.query('select last(c1) from stb_test where c0 match "a"')
        tdSql.checkData(0,0,16)


        tdSql.query('select count(c1) from stb_test where t0 match "a"')
        tdSql.checkData(0,0,4)
J
jiacy-jcy 已提交
89 90 91 92 93

        tdSql.error('select * from stb_test where c0 match abc')

        tdSql.error('select * from stb_test where c0 nmatch abc')

J
jiacy-jcy 已提交
94
        
J
jiacy-jcy 已提交
95 96 97
        tdSql.query("select * from stb_1 where c0 match '\\\\'")
        tdSql.checkRows(1)

J
jiacy-jcy 已提交
98 99 100
        tdSql.query("select * from stb_1 where c0 nmatch '\\\\'")
        tdSql.checkRows(3)

J
jiacy-jcy 已提交
101 102 103 104 105 106 107 108 109 110 111 112





    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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