filterOtherTypes.py 12.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
###################################################################
#           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:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
S
Shuduo Sang 已提交
24 25
        tdSql.init(conn.cursor())

26
        self.ts = 1537146000000
S
Shuduo Sang 已提交
27

28 29
    def run(self):
        tdSql.prepare()
S
Shuduo Sang 已提交
30

31 32
        print("======= Verify filter for bool, nchar and binary type =========")
        tdLog.debug(
33
            "create table st(ts timestamp, tbcol1 bool, tbcol2 binary(10), tbcol3 nchar(20)) tags(tagcol1 bool, tagcol2 binary(10), tagcol3 nchar(10))")
34
        tdSql.execute(
35
            "create table st(ts timestamp, tbcol1 bool, tbcol2 binary(10), tbcol3 nchar(20)) tags(tagcol1 bool, tagcol2 binary(10), tagcol3 nchar(10))")
36 37

        tdSql.execute("create table st1 using st tags(true, 'table1', '水表')")
S
Shuduo Sang 已提交
38 39 40 41 42
        for i in range(1, 6):
            tdSql.execute(
                "insert into st1 values(%d, %d, 'taosdata%d', '涛思数据%d')" %
                (self.ts + i, i %
                 2, i, i))
43 44

        tdSql.execute("create table st2 using st tags(false, 'table2', '电表')")
S
Shuduo Sang 已提交
45 46 47 48 49
        for i in range(6, 11):
            tdSql.execute(
                "insert into st2 values(%d, %d, 'taosdata%d', '涛思数据%d')" %
                (self.ts + i, i %
                 2, i, i))
50 51 52 53 54 55

        # =============Verify stable columns====================
        # > for bool type on column
        tdSql.error("select * from st where tbcol1 > false")

        # >= for bool type on column
S
Shuduo Sang 已提交
56
        tdSql.error("select * from st where tbcol1 >= false")
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

        # = for bool type on column
        tdSql.query("select * from st where tbcol1 = false")
        tdSql.checkRows(5)

        # <> for bool type on column
        tdSql.query("select * from st where tbcol1 <> true")
        tdSql.checkRows(5)

        # != for bool type on column
        tdSql.query("select * from st where tbcol1 != true")
        tdSql.checkRows(5)

        # > for bool type on column
        tdSql.error("select * from st where tbcol1 < true")

        # >= for bool type on column
        tdSql.error("select * from st where tbcol1 <= true")

        # % for bool type on column
        tdSql.error("select * from st where tbcol1 like '%'")

        # _ for bool type on column
        tdSql.error("select * from st where tbcol1 like '____'")

        # > for nchar type on column
        tdSql.error("select * from st where tbcol2 > 'taosdata'")

        # >= for nchar type on column
S
Shuduo Sang 已提交
86
        tdSql.error("select * from st where tbcol2 >= 'taosdata'")
87 88 89 90 91 92

        # = for nchar type on column
        tdSql.query("select * from st where tbcol2 = 'taosdata1'")
        tdSql.checkRows(1)

        # <> for nchar type on column
S
Shuduo Sang 已提交
93
        tdSql.query("select * from st where tbcol2 <> 'taosdata1'")
94 95 96
        tdSql.checkRows(9)

        # != for nchar type on column
S
Shuduo Sang 已提交
97
        tdSql.query("select * from st where tbcol2 != 'taosdata1'")
98 99 100 101 102 103 104 105 106
        tdSql.checkRows(9)

        # > for nchar type on column
        tdSql.error("select * from st where tbcol2 < 'taodata'")

        # >= for nchar type on column
        tdSql.error("select * from st where tbcol2 <= 'taodata'")

        # % for nchar type on column case 1
S
Shuduo Sang 已提交
107
        tdSql.query("select * from st where tbcol2 like '%'")
108 109 110
        tdSql.checkRows(10)

        # % for nchar type on column case 2
S
Shuduo Sang 已提交
111
        tdSql.query("select * from st where tbcol2 like 'a%'")
112 113 114
        tdSql.checkRows(0)

        # % for nchar type on column case 3
S
Shuduo Sang 已提交
115
        tdSql.query("select * from st where tbcol2 like 't%_'")
116 117 118
        tdSql.checkRows(10)

        # % for nchar type on column case 4
S
Shuduo Sang 已提交
119
        tdSql.query("select * from st where tbcol2 like '%1'")
120 121 122
        # tdSql.checkRows(2)

        # _ for nchar type on column case 1
S
Shuduo Sang 已提交
123 124
        tdSql.query("select * from st where tbcol2 like '____________'")
        tdSql.checkRows(0)
125 126

        # _ for nchar type on column case 2
S
Shuduo Sang 已提交
127
        tdSql.query("select * from st where tbcol2 like '__________'")
128 129 130
        tdSql.checkRows(1)

        # _ for nchar type on column case 3
S
Shuduo Sang 已提交
131
        tdSql.query("select * from st where tbcol2 like '_________'")
132 133 134
        tdSql.checkRows(9)

        # _ for nchar type on column case 4
S
Shuduo Sang 已提交
135
        tdSql.query("select * from st where tbcol2 like 't________'")
136 137 138
        tdSql.checkRows(9)

        # _ for nchar type on column case 5
S
Shuduo Sang 已提交
139
        tdSql.query("select * from st where tbcol2 like '%________'")
140 141 142 143 144 145
        tdSql.checkRows(10)

        # > for binary type on column
        tdSql.error("select * from st where tbcol3 > '涛思数据'")

        # >= for binary type on column
S
Shuduo Sang 已提交
146
        tdSql.error("select * from st where tbcol3 >= '涛思数据'")
147 148 149 150 151 152

        # = for binary type on column
        tdSql.query("select * from st where tbcol3 = '涛思数据1'")
        tdSql.checkRows(1)

        # <> for binary type on column
S
Shuduo Sang 已提交
153
        tdSql.query("select * from st where tbcol3 <> '涛思数据1'")
154 155 156
        tdSql.checkRows(9)

        # != for binary type on column
S
Shuduo Sang 已提交
157
        tdSql.query("select * from st where tbcol3 != '涛思数据1'")
158 159 160 161 162 163 164 165 166
        tdSql.checkRows(9)

        # > for binary type on column
        tdSql.error("select * from st where tbcol3 < '涛思数据'")

        # >= for binary type on column
        tdSql.error("select * from st where tbcol3 <= '涛思数据'")

        # % for binary type on column case 1
S
Shuduo Sang 已提交
167
        tdSql.query("select * from st where tbcol3 like '%'")
168 169 170
        tdSql.checkRows(10)

        # % for binary type on column case 2
S
Shuduo Sang 已提交
171
        tdSql.query("select * from st where tbcol3 like '陶%'")
172 173 174
        tdSql.checkRows(0)

        # % for binary type on column case 3
S
Shuduo Sang 已提交
175
        tdSql.query("select * from st where tbcol3 like '涛%_'")
176 177 178
        tdSql.checkRows(10)

        # % for binary type on column case 4
S
Shuduo Sang 已提交
179
        tdSql.query("select * from st where tbcol3 like '%1'")
180 181 182
        tdSql.checkRows(1)

        # _ for binary type on column case 1
S
Shuduo Sang 已提交
183 184
        tdSql.query("select * from st where tbcol3 like '_______'")
        tdSql.checkRows(0)
185 186

        # _ for binary type on column case 2
S
Shuduo Sang 已提交
187
        tdSql.query("select * from st where tbcol3 like '______'")
188 189 190
        tdSql.checkRows(1)

        # _ for binary type on column case 2
S
Shuduo Sang 已提交
191
        tdSql.query("select * from st where tbcol3 like '_____'")
192 193 194
        tdSql.checkRows(9)

        # _ for binary type on column case 3
S
Shuduo Sang 已提交
195
        tdSql.query("select * from st where tbcol3 like '____'")
196 197 198
        tdSql.checkRows(0)

        # _ for binary type on column case 4
S
Shuduo Sang 已提交
199
        tdSql.query("select * from st where tbcol3 like 't____'")
200 201 202 203 204 205 206
        tdSql.checkRows(0)

        # =============Verify stable tags====================
        # > for bool type on tag
        tdSql.error("select * from st where tagcol1 > false")

        # >= for bool type on tag
S
Shuduo Sang 已提交
207
        tdSql.error("select * from st where tagcol1 >= false")
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233

        # = for bool type on tag
        tdSql.query("select * from st where tagcol1 = false")
        tdSql.checkRows(5)

        # <> for bool type on tag
        tdSql.query("select * from st where tagcol1 <> true")
        tdSql.checkRows(5)

        # != for bool type on tag
        tdSql.query("select * from st where tagcol1 != true")
        tdSql.checkRows(5)

        # > for bool type on tag
        tdSql.error("select * from st where tagcol1 < true")

        # >= for bool type on tag
        tdSql.error("select * from st where tagcol1 <= true")

        # % for bool type on tag
        tdSql.error("select * from st where tagcol1 like '%'")

        # _ for bool type on tag
        tdSql.error("select * from st where tagcol1 like '____'")

        # > for nchar type on tag
P
Ping Xiao 已提交
234 235
        tdSql.query("select * from st where tagcol2 > 'table1'")
        tdSql.checkRows(5)
236 237

        # >= for nchar type on tag
P
Ping Xiao 已提交
238 239
        tdSql.query("select * from st where tagcol2 >= 'table1'")
        tdSql.checkRows(10)
240 241 242 243 244 245

        # = for nchar type on tag
        tdSql.query("select * from st where tagcol2 = 'table1'")
        tdSql.checkRows(5)

        # <> for nchar type on tag
S
Shuduo Sang 已提交
246
        tdSql.query("select * from st where tagcol2 <> 'table1'")
247 248 249
        tdSql.checkRows(5)

        # != for nchar type on tag
S
Shuduo Sang 已提交
250
        tdSql.query("select * from st where tagcol2 != 'table'")
251 252 253
        tdSql.checkRows(10)

        # > for nchar type on tag
P
Ping Xiao 已提交
254 255
        tdSql.query("select * from st where tagcol2 < 'table'")
        tdSql.checkRows(0)
256 257

        # >= for nchar type on tag
P
Ping Xiao 已提交
258 259
        tdSql.query("select * from st where tagcol2 <= 'table'")
        tdSql.checkRows(0)
260 261

        # % for nchar type on tag case 1
S
Shuduo Sang 已提交
262
        tdSql.query("select * from st where tagcol2 like '%'")
263 264 265
        tdSql.checkRows(10)

        # % for nchar type on tag case 2
S
Shuduo Sang 已提交
266
        tdSql.query("select * from st where tagcol2 like 'a%'")
267 268 269
        tdSql.checkRows(0)

        # % for nchar type on tag case 3
S
Shuduo Sang 已提交
270
        tdSql.query("select * from st where tagcol2 like 't%_'")
271 272 273
        tdSql.checkRows(10)

        # % for nchar type on tag case 4
S
Shuduo Sang 已提交
274
        tdSql.query("select * from st where tagcol2 like '%1'")
275 276 277
        tdSql.checkRows(5)

        # _ for nchar type on tag case 1
S
Shuduo Sang 已提交
278 279
        tdSql.query("select * from st where tagcol2 like '_______'")
        tdSql.checkRows(0)
280 281

        # _ for nchar type on tag case 2
S
Shuduo Sang 已提交
282
        tdSql.query("select * from st where tagcol2 like '______'")
283 284 285
        tdSql.checkRows(10)

        # _ for nchar type on tag case 3
S
Shuduo Sang 已提交
286
        tdSql.query("select * from st where tagcol2 like 't_____'")
287 288 289
        tdSql.checkRows(10)

        # _ for nchar type on tag case 4
S
Shuduo Sang 已提交
290
        tdSql.query("select * from st where tagcol2 like 's________'")
291 292 293
        tdSql.checkRows(0)

        # _ for nchar type on tag case 5
S
Shuduo Sang 已提交
294
        tdSql.query("select * from st where tagcol2 like '%__'")
295 296 297
        tdSql.checkRows(10)

        # > for binary type on tag
P
Ping Xiao 已提交
298 299
        tdSql.query("select * from st where tagcol3 > '表'")
        tdSql.checkRows(10)
300 301

        # >= for binary type on tag
P
Ping Xiao 已提交
302 303
        tdSql.query("select * from st where tagcol3 >= '表'")
        tdSql.checkRows(10)
304 305 306 307 308 309

        # = for binary type on tag
        tdSql.query("select * from st where tagcol3 = '水表'")
        tdSql.checkRows(5)

        # <> for binary type on tag
S
Shuduo Sang 已提交
310
        tdSql.query("select * from st where tagcol3 <> '水表'")
311 312 313
        tdSql.checkRows(5)

        # != for binary type on tag
S
Shuduo Sang 已提交
314
        tdSql.query("select * from st where tagcol3 != '水表'")
315 316 317
        tdSql.checkRows(5)

        # > for binary type on tag
P
Ping Xiao 已提交
318 319
        tdSql.query("select * from st where tagcol3 < '水表'")
        tdSql.checkRows(0)
320 321

        # >= for binary type on tag
P
Ping Xiao 已提交
322 323
        tdSql.query("select * from st where tagcol3 <= '水表'")
        tdSql.checkRows(5)
324 325

        # % for binary type on tag case 1
S
Shuduo Sang 已提交
326
        tdSql.query("select * from st where tagcol3 like '%'")
327 328 329
        tdSql.checkRows(10)

        # % for binary type on tag case 2
S
Shuduo Sang 已提交
330
        tdSql.query("select * from st where tagcol3 like '水%'")
331 332 333
        tdSql.checkRows(5)

        # % for binary type on tag case 3
S
Shuduo Sang 已提交
334
        tdSql.query("select * from st where tagcol3 like '数%_'")
335 336 337
        tdSql.checkRows(0)

        # % for binary type on tag case 4
S
Shuduo Sang 已提交
338
        tdSql.query("select * from st where tagcol3 like '%表'")
339 340 341
        tdSql.checkRows(10)

        # % for binary type on tag case 5
S
Shuduo Sang 已提交
342
        tdSql.query("select * from st where tagcol3 like '%据'")
343 344 345
        tdSql.checkRows(0)

        # _ for binary type on tag case 1
S
Shuduo Sang 已提交
346 347
        tdSql.query("select * from st where tagcol3 like '__'")
        tdSql.checkRows(10)
348 349

        # _ for binary type on tag case 2
S
Shuduo Sang 已提交
350
        tdSql.query("select * from st where tagcol3 like '水_'")
351 352 353
        tdSql.checkRows(5)

        # _ for binary type on tag case 2
S
Shuduo Sang 已提交
354
        tdSql.query("select * from st where tagcol3 like '_表'")
355 356 357
        tdSql.checkRows(10)

        # _ for binary type on tag case 3
S
Shuduo Sang 已提交
358
        tdSql.query("select * from st where tagcol3 like '___'")
359 360 361
        tdSql.checkRows(0)

        # _ for binary type on tag case 4
S
Shuduo Sang 已提交
362
        tdSql.query("select * from st where tagcol3 like '数_'")
363 364 365
        tdSql.checkRows(0)

        # _ for binary type on tag case 5
S
Shuduo Sang 已提交
366
        tdSql.query("select * from st where tagcol3 like '_据'")
367
        tdSql.checkRows(0)
S
Shuduo Sang 已提交
368

369 370
    def stop(self):
        tdSql.close()
S
Shuduo Sang 已提交
371
        tdLog.success("%s successfully executed" % __file__)
372 373 374 375


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