func_compare.py 20.3 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
###################################################################
#           Copyright (c) 2021 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
from util.log import *
from util.cases import *
from util.sql import *


class TDTestCase:
    def caseDescription(self):
        '''
        case1<Ganlin Zhao>: [TD-12861] : taoshell crash coredump for such as "select first(c1)==max(c1) from st"
        '''
        return

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

    def getBuildPath(self):
        selfPath = os.path.dirname(os.path.realpath(__file__))

        if ("community" in selfPath):
            projPath = selfPath[:selfPath.find("community")]
        else:
            projPath = selfPath[:selfPath.find("tests")]

        for root, dirs, files in os.walk(projPath):
            if ("taosd" in files):
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
                    buildPath = root[:len(root) - len("/build/bin")]
                    break
        return buildPath

    def run(self):
        print("running {}".format(__file__))
        tdSql.execute("drop database if exists db")
        tdSql.execute("create database if not exists db")
        tdSql.execute('use db')

        #Prepare data
        tdSql.execute("create table tb (ts timestamp, value int);")
        tdSql.execute("insert into tb values (now, 1);")
        tdSql.execute("insert into tb values (now, 2);")
        tdSql.execute("insert into tb values (now, 3);")
        tdSql.execute("insert into tb values (now, 4);")

        ##operator: =
        tdSql.error('select count(*) = 4 from tb;')
        tdSql.error('select avg(value) = 2.5 from tb')
        tdSql.error('select twa(value) = 3.03 from tb')
        tdSql.error('select sum(value) = 10 from tb')
        tdSql.error('select stddev(value) = 2.0 from tb')
        tdSql.error('select min(value) = 1 from tb')
        tdSql.error('select max(value) = 4 from tb')
        tdSql.error('select first(*) = 3 from tb')
        tdSql.error('select last(*) = 3 from tb')
        tdSql.error('select top(value, 3) = 3 from tb')
        tdSql.error('select bottom(value, 3) = 3 from tb')
        tdSql.error('select percentile(value, 50) = 3 from tb')
        tdSql.error('select apercentile(value, 50) = 3 from tb')
        tdSql.error('select last_row(*) = 3 from tb')
        tdSql.error('select diff(value) = 3 from tb')
        tdSql.error('select ceil(value) = 12 from tb')
        tdSql.error('select floor(3.5) = 3 from tb')
        tdSql.error('select round(3.5) = 3 from tb')

        tdSql.error('select count(*) = max(value) from tb')
        tdSql.error('select avg(value) = min(value) from tb')
        tdSql.error('select first(value) = last(value) from tb')
        tdSql.error('select round(value) = round(value) from tb')

        ##operator: !=
        tdSql.error('select count(*) != 4 from tb;')
        tdSql.error('select avg(value) != 2.5 from tb')
        tdSql.error('select twa(value) != 3.03 from tb')
        tdSql.error('select sum(value) != 10 from tb')
        tdSql.error('select stddev(value) != 2.0 from tb')
        tdSql.error('select min(value) != 1 from tb')
        tdSql.error('select max(value) != 4 from tb')
        tdSql.error('select first(*) != 3 from tb')
        tdSql.error('select last(*) != 3 from tb')
        tdSql.error('select top(value, 3) != 3 from tb')
        tdSql.error('select bottom(value, 3) != 3 from tb')
        tdSql.error('select percentile(value, 50) != 3 from tb')
        tdSql.error('select apercentile(value, 50) != 3 from tb')
        tdSql.error('select last_row(*) != 3 from tb')
        tdSql.error('select diff(value) != 3 from tb')
        tdSql.error('select ceil(value) != 12 from tb')
        tdSql.error('select floor(3.5) != 3 from tb')
        tdSql.error('select round(3.5) != 3 from tb')

        tdSql.error('select count(*) != max(value) from tb')
        tdSql.error('select avg(value) != min(value) from tb')
        tdSql.error('select first(value) != last(value) from tb')
        tdSql.error('select round(value) != round(value) from tb')

        ##operator: <>
        tdSql.error('select count(*) <> 4 from tb;')
        tdSql.error('select avg(value) <> 2.5 from tb')
        tdSql.error('select twa(value) <> 3.03 from tb')
        tdSql.error('select sum(value) <> 10 from tb')
        tdSql.error('select stddev(value) <> 2.0 from tb')
        tdSql.error('select min(value) <> 1 from tb')
        tdSql.error('select max(value) <> 4 from tb')
        tdSql.error('select first(*) <> 3 from tb')
        tdSql.error('select last(*) <> 3 from tb')
        tdSql.error('select top(value, 3) <> 3 from tb')
        tdSql.error('select bottom(value, 3) <> 3 from tb')
        tdSql.error('select percentile(value, 50) <> 3 from tb')
        tdSql.error('select apercentile(value, 50) <> 3 from tb')
        tdSql.error('select last_row(*) <> 3 from tb')
        tdSql.error('select diff(value) <> 3 from tb')
        tdSql.error('select ceil(value) <> 12 from tb')
        tdSql.error('select floor(3.5) <> 3 from tb')
        tdSql.error('select round(3.5) <> 3 from tb')

        tdSql.error('select count(*) <> max(value) from tb')
        tdSql.error('select avg(value) <> min(value) from tb')
        tdSql.error('select first(value) <> last(value) from tb')
        tdSql.error('select round(value) <> round(value) from tb')

        ##operator: <
        tdSql.error('select count(*) < 4 from tb;')
        tdSql.error('select avg(value) < 2.5 from tb')
        tdSql.error('select twa(value) < 3.03 from tb')
        tdSql.error('select sum(value) < 10 from tb')
        tdSql.error('select stddev(value) < 2.0 from tb')
        tdSql.error('select min(value) < 1 from tb')
        tdSql.error('select max(value) < 4 from tb')
        tdSql.error('select first(*) < 3 from tb')
        tdSql.error('select last(*) < 3 from tb')
        tdSql.error('select top(value, 3) < 3 from tb')
        tdSql.error('select bottom(value, 3) < 3 from tb')
        tdSql.error('select percentile(value, 50) < 3 from tb')
        tdSql.error('select apercentile(value, 50) < 3 from tb')
        tdSql.error('select last_row(*) < 3 from tb')
        tdSql.error('select diff(value) < 3 from tb')
        tdSql.error('select ceil(value) < 12 from tb')
        tdSql.error('select floor(3.5) < 3 from tb')
        tdSql.error('select round(3.5) < 3 from tb')

        tdSql.error('select count(*) < max(value) from tb')
        tdSql.error('select avg(value) < min(value) from tb')
        tdSql.error('select first(value) < last(value) from tb')
        tdSql.error('select round(value) < round(value) from tb')

        ##operator: >
        tdSql.error('select count(*) > 4 from tb;')
        tdSql.error('select avg(value) > 2.5 from tb')
        tdSql.error('select twa(value) > 3.03 from tb')
        tdSql.error('select sum(value) > 10 from tb')
        tdSql.error('select stddev(value) > 2.0 from tb')
        tdSql.error('select min(value) > 1 from tb')
        tdSql.error('select max(value) > 4 from tb')
        tdSql.error('select first(*) > 3 from tb')
        tdSql.error('select last(*) > 3 from tb')
        tdSql.error('select top(value, 3) > 3 from tb')
        tdSql.error('select bottom(value, 3) > 3 from tb')
        tdSql.error('select percentile(value, 50) > 3 from tb')
        tdSql.error('select apercentile(value, 50) > 3 from tb')
        tdSql.error('select last_row(*) > 3 from tb')
        tdSql.error('select diff(value) > 3 from tb')
        tdSql.error('select ceil(value) > 12 from tb')
        tdSql.error('select floor(3.5) > 3 from tb')
        tdSql.error('select round(3.5) > 3 from tb')

        tdSql.error('select count(*) > max(value) from tb')
        tdSql.error('select avg(value) > min(value) from tb')
        tdSql.error('select first(value) > last(value) from tb')
        tdSql.error('select round(value) > round(value) from tb')

        ##operator: <=
        tdSql.error('select count(*) <= 4 from tb;')
        tdSql.error('select avg(value) <= 2.5 from tb')
        tdSql.error('select twa(value) <= 3.03 from tb')
        tdSql.error('select sum(value) <= 10 from tb')
        tdSql.error('select stddev(value) <= 2.0 from tb')
        tdSql.error('select min(value) <= 1 from tb')
        tdSql.error('select max(value) <= 4 from tb')
        tdSql.error('select first(*) <= 3 from tb')
        tdSql.error('select last(*) <= 3 from tb')
        tdSql.error('select top(value, 3) <= 3 from tb')
        tdSql.error('select bottom(value, 3) <= 3 from tb')
        tdSql.error('select percentile(value, 50) <= 3 from tb')
        tdSql.error('select apercentile(value, 50) <= 3 from tb')
        tdSql.error('select last_row(*) <= 3 from tb')
        tdSql.error('select diff(value) <= 3 from tb')
        tdSql.error('select ceil(value) <= 12 from tb')
        tdSql.error('select floor(3.5) <= 3 from tb')
        tdSql.error('select round(3.5) <= 3 from tb')

        tdSql.error('select count(*) <= max(value) from tb')
        tdSql.error('select avg(value) <= min(value) from tb')
        tdSql.error('select first(value) <= last(value) from tb')
        tdSql.error('select round(value) <= round(value) from tb')

        ##operator: >=
        tdSql.error('select count(*) >= 4 from tb;')
        tdSql.error('select avg(value) >= 2.5 from tb')
        tdSql.error('select twa(value) >= 3.03 from tb')
        tdSql.error('select sum(value) >= 10 from tb')
        tdSql.error('select stddev(value) >= 2.0 from tb')
        tdSql.error('select min(value) >= 1 from tb')
        tdSql.error('select max(value) >= 4 from tb')
        tdSql.error('select first(*) >= 3 from tb')
        tdSql.error('select last(*) >= 3 from tb')
        tdSql.error('select top(value, 3) >= 3 from tb')
        tdSql.error('select bottom(value, 3) >= 3 from tb')
        tdSql.error('select percentile(value, 50) >= 3 from tb')
        tdSql.error('select apercentile(value, 50) >= 3 from tb')
        tdSql.error('select last_row(*) >= 3 from tb')
        tdSql.error('select diff(value) >= 3 from tb')
        tdSql.error('select ceil(value) >= 12 from tb')
        tdSql.error('select floor(3.5) >= 3 from tb')
        tdSql.error('select round(3.5) >= 3 from tb')

        tdSql.error('select count(*) >= max(value) from tb')
        tdSql.error('select avg(value) >= min(value) from tb')
        tdSql.error('select first(value) >= last(value) from tb')
        tdSql.error('select round(value) >= round(value) from tb')

        ##operator: between and
        tdSql.error('select count(*) between 3 and 4 from tb;')
        tdSql.error('select avg(value) between 1.5 and 2.5 from tb')
        tdSql.error('select twa(value) between 3.0 and 3.03 from tb')
        tdSql.error('select sum(value) between 1 and 10 from tb')
        tdSql.error('select stddev(value) between 1 and 2.0 from tb')
        tdSql.error('select min(value) between 2 and 5 from tb')
        tdSql.error('select max(value) between 1 and 10 from tb')
        tdSql.error('select first(*) between 1 and 3 from tb')
        tdSql.error('select last(*) between 0 and 3 from tb')
        tdSql.error('select top(value, 3) between 0.0 and 3 from tb')
        tdSql.error('select bottom(value, 3) between 0.0 and 3 from tb')
        tdSql.error('select percentile(value, 50) between 1 and 3 from tb')
        tdSql.error('select apercentile(value, 50) between 2 and 3 from tb')
        tdSql.error('select last_row(*) between 2 and 3 from tb')
        tdSql.error('select diff(value) between 1 and 3 from tb')
        tdSql.error('select ceil(value) between 5 and 12 from tb')
        tdSql.error('select floor(3.5) between 12 and 3 from tb')
        tdSql.error('select round(3.5) between true and 3 from tb')

        tdSql.error('select count(*) between min(value) and max(value) from tb')
        tdSql.error('select avg(*) between min(value) and 3 from tb')
        tdSql.error('select avg(value) between 1 and max(value) from tb')
        tdSql.error('select first(value) between first(value) and last(value) from tb')
        tdSql.error('select round(value) between ceil(value) and floor(value) from tb')

        ##operator: and
        tdSql.error('select count(*) and 1 from tb;')
        tdSql.error('select avg(value) and 0.0 from tb')
        tdSql.error('select twa(value) and true from tb')
        tdSql.error('select sum(value) and false from tb')
        tdSql.error('select 1 and stddev(value) from tb')
        tdSql.error('select 0.0 and min(value) from tb')
        tdSql.error('select true and max(value) from tb')
        tdSql.error('select false and first(*) from tb')
        tdSql.error('select last(*) and first(value) from tb')
        tdSql.error('select top(value, 3) and bottom(value, 3) from tb')
        tdSql.error('select percentile(value, 50) and apercentile(value, 50) from tb')
        tdSql.error('select diff(value) and ceil(value) from tb')
        tdSql.error('select floor(3.5) and round(3.5) and ceil(3.5) from tb')
        tdSql.error('select true and round(3.5) and 3 from tb')

        ##operator: or
        tdSql.error('select count(*) or 1 from tb;')
        tdSql.error('select avg(value) or 0.0 from tb')
        tdSql.error('select twa(value) or true from tb')
        tdSql.error('select sum(value) or false from tb')
        tdSql.error('select 1 or stddev(value) from tb')
        tdSql.error('select 0.0 or min(value) from tb')
        tdSql.error('select true or max(value) from tb')
        tdSql.error('select false or first(*) from tb')
        tdSql.error('select last(*) or first(value) from tb')
        tdSql.error('select top(value, 3) or bottom(value, 3) from tb')
        tdSql.error('select percentile(value, 50) or apercentile(value, 50) from tb')
        tdSql.error('select diff(value) or ceil(value) from tb')
        tdSql.error('select floor(3.5) or round(3.5) or ceil(3.5) from tb')
        tdSql.error('select true or round(3.5) or 3 from tb')

        ##operator: multiple operations
        tdSql.error('select count(*) <> avg(value) or twa(value) and sum(value) or 1 from tb;')
        tdSql.error('select 1 and stddev(value) <= min(value) or max(value) and first(*) or 0.0 from tb')
        tdSql.error('select last(*) and first(value) or top(value, 3) and 3 between 4.0 and bottom(value, 3)from tb')
        tdSql.error('select percentile(value, 50) or diff(value) = ceil(value) and apercentile(value, 50) from tb')
        tdSql.error('select floor(3.5) or round(3.5) and ceil(3.5) > true and round(3.5) or 3 from tb')

        #operator: is NULL
        tdSql.error('select count(*) is NULL from tb;')
        tdSql.error('select avg(value) is NULL from tb;')
        tdSql.error('select twa(value) is NULL from tb;')
        tdSql.error('select sum(value) is NULL from tb;')
        tdSql.error('select stddev(value) is NULL from tb;')
        tdSql.error('select min(value) is NULL from tb;')
        tdSql.error('select max(value) is NULL from tb;')
        tdSql.error('select first(*) is NULL from tb;')
        tdSql.error('select last(*) is NULL from tb;')
        tdSql.error('select top(value, 3) is NULL or bottom(value,3) is NULL from tb;')
        tdSql.error('select percentile(value, 50) is NULL or apercentile(value, 50) is NULL from tb')
        tdSql.error('select diff(value) is NULL or ceil(value) is NULL from tb')
        tdSql.error('select floor(3.5) is NULL or round(3.5) is NULL or ceil(3.5) is NULL from tb')

        #operator: is not NULL
        tdSql.error('select count(*) is not NULL from tb;')
        tdSql.error('select avg(value) is not NULL from tb;')
        tdSql.error('select twa(value) is not NULL from tb;')
        tdSql.error('select sum(value) is not NULL from tb;')
        tdSql.error('select stddev(value) is not NULL from tb;')
        tdSql.error('select min(value) is not NULL from tb;')
        tdSql.error('select max(value) is not NULL from tb;')
        tdSql.error('select first(*) is not NULL from tb;')
        tdSql.error('select last(*) is not NULL from tb;')
        tdSql.error('select top(value, 3) is not NULL or bottom(value,3) is not NULL from tb;')
        tdSql.error('select percentile(value, 50) is not NULL or apercentile(value, 50) is not NULL from tb')
        tdSql.error('select diff(value) is not NULL or ceil(value) is not NULL from tb')
        tdSql.error('select floor(3.5) is not NULL or round(3.5) is not NULL or ceil(3.5) is not NULL from tb')

        #operator: like
        tdSql.error('select count(*) like "abc" from tb;')
        tdSql.error('select avg(value) like "abc" from tb;')
        tdSql.error('select twa(value) like "abc" from tb;')
        tdSql.error('select sum(value) like "abc" from tb;')
        tdSql.error('select stddev(value) like "abc" from tb;')
        tdSql.error('select min(value) like "abc" from tb;')
        tdSql.error('select max(value) like "abc" from tb;')
        tdSql.error('select first(*) like "abc" from tb;')
        tdSql.error('select last(*) like "abc" from tb;')
        tdSql.error('select top(value, 3) like "abc" or bottom(value,3) like "abc" from tb;')
        tdSql.error('select percentile(value, 50) like "abc" or apercentile(value, 50) like "abc" from tb')
        tdSql.error('select diff(value) like "abc" or ceil(value) like "abc" from tb')
        tdSql.error('select floor(3.5) like "abc" or round(3.5) like "abc" or ceil(3.5) like "abc" from tb')

        #operator: match
        tdSql.error('select count(*) match "abc" from tb;')
        tdSql.error('select avg(value) match "abc" from tb;')
        tdSql.error('select twa(value) match "abc" from tb;')
        tdSql.error('select sum(value) match "abc" from tb;')
        tdSql.error('select stddev(value) match "abc" from tb;')
        tdSql.error('select min(value) match "abc" from tb;')
        tdSql.error('select max(value) match "abc" from tb;')
        tdSql.error('select first(*) match "abc" from tb;')
        tdSql.error('select last(*) match "abc" from tb;')
        tdSql.error('select top(value, 3) match "abc" or bottom(value,3) match "abc" from tb;')
        tdSql.error('select percentile(value, 50) match "abc" or apercentile(value, 50) match "abc" from tb')
        tdSql.error('select diff(value) match "abc" or ceil(value) match "abc" from tb')
        tdSql.error('select floor(3.5) match "abc" or round(3.5) match "abc" or ceil(3.5) match "abc" from tb')

        #operator: nmatch
        tdSql.error('select count(*) nmatch "abc" from tb;')
        tdSql.error('select avg(value) nmatch "abc" from tb;')
        tdSql.error('select twa(value) nmatch "abc" from tb;')
        tdSql.error('select sum(value) nmatch "abc" from tb;')
        tdSql.error('select stddev(value) nmatch "abc" from tb;')
        tdSql.error('select min(value) nmatch "abc" from tb;')
        tdSql.error('select max(value) nmatch "abc" from tb;')
        tdSql.error('select first(*) nmatch "abc" from tb;')
        tdSql.error('select last(*) nmatch "abc" from tb;')
        tdSql.error('select top(value, 3) nmatch "abc" or bottom(value,3) nmatch "abc" from tb;')
        tdSql.error('select percentile(value, 50) nmatch "abc" or apercentile(value, 50) nmatch "abc" from tb')
        tdSql.error('select diff(value) nmatch "abc" or ceil(value) nmatch "abc" from tb')
        tdSql.error('select floor(3.5) nmatch "abc" or round(3.5) nmatch "abc" or ceil(3.5) nmatch "abc" from tb')

        #operator: in
        tdSql.error('select count(*) in 1 from tb;')
        tdSql.error('select avg(value) in (1, 2, 3) from tb;')
        tdSql.error('select twa(value) in 1.0 from tb;')
        tdSql.error('select sum(value) in (1.0, 2.0, 3.0) from tb;')
        tdSql.error('select min(value) in (true, false, true) from tb;')
        tdSql.error('select tbname in (\'acd\', \'bce\') from tb;')
        tdSql.error('select t in ("acd", "bce") from tb;')
        tdSql.error('select top(value, 3) in (1,2,3) and ceil(value) in (1.0,2.0,3.0) or last(*) in ("abc","cde") from tb;')

        tdSql.execute('drop database db')

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


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