From 29d0e5e28ff8a2790a29064d859a11e21179e8cb Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 14 Jan 2022 14:34:40 +0800 Subject: [PATCH] [TD-12945](query): taos shell crash when constant comparison cause crash --- .../develop-test/2-query/constant_compare.py | 573 ++++++++++++++++++ 1 file changed, 573 insertions(+) create mode 100644 tests/develop-test/2-query/constant_compare.py diff --git a/tests/develop-test/2-query/constant_compare.py b/tests/develop-test/2-query/constant_compare.py new file mode 100644 index 0000000000..e2a67e323c --- /dev/null +++ b/tests/develop-test/2-query/constant_compare.py @@ -0,0 +1,573 @@ +################################################################### +# 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: [TD-12945] : taos shell crash when constant comparison cause crash + ''' + 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, 123);") + + ##operator: = + tdSql.query('select 1 = 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 = 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 = 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 = 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 = 1.0001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 = 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 = 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 = 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 = 1.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 = 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + ##operator: != + tdSql.query('select 1 != 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 != 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 != 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 != 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 != 1.0001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 != 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 != 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 != 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 != 1.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 != 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + ##operator: <> + tdSql.query('select 1 <> 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 <> 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <> 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 <> 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <> 1.0001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <> 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 <> 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 <> 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 <> 1.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 <> 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + ##operator: < + tdSql.query('select 1 < 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 0 < 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 < 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 0.0 < 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 < 1.0001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 < 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 < 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 0.0 < 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 < 1.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 < 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + ##operator: > + tdSql.query('select 1 > 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 > 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 > 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 > 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0001 > 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 > 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 > 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 > 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.001 > 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0000000001 > 1.0 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + ##operator: <= + tdSql.query('select 1 <= 2 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <= 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <= 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 <= 2.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <= 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <= 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 <= 1.0001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 <= 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 <= 2.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 <= 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 <= 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 <= 1.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 <= 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + ##operator: >= + tdSql.query('select 1 >= 2 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 >= 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 >= 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 >= 2.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 >= 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 >= 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0001 >= 1 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 >= 1.0000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 >= 2.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 >= 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0 >= 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.001 >= 1.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1.0000000001 >= 1.0 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + + ##operator: between and + tdSql.query('select 1 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 3 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 2 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 4 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 between 2.0 and 4.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1.0 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 3 between 2.0 and 4.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 3.0 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 2 between 2.0 and 4.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 4 between 2.0 and 4.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 2.0 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 4.0 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 2.0001 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 2.0000000001 between 2 and 4 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 2 between 2.0001 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 2 between 2.000000001 and 4 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + + tdSql.query('select 4 between 2 and 4.0001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 4 between 2 and 4.000000001 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 4.0001 between 2 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 4.000000001 between 2 and 4 from tb;') ##DBL_EPSILON is used in floating number comparison + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + ##operator: and + tdSql.query('select 10 and 10 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 10.0 and 10 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 10.0 and 10.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 10 and 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 10.0 and 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 10.0 and 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 10.0 and 0.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 10.0 and 0.000000000000000001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 and 2 and 3 and 10.1 and -20.02 and 22.03 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 and 2 and 3 and 0 and 20.02 and 22.03 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 and 2 and 3 and 0.0 and 20.02 and 22.03 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + ##operator: or + tdSql.query('select 10 or 10 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 10.0 or 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 10 or 0.0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 0.0 or 0 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 0.0 or 0.001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 0.0 or 0.000000000000000001 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 or 2 or 3 or 0.0 or -20.02 or 22.03 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 0 or 0.0 or 0.00 or 0.000 or 0.0000 or 0.00000 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + ##operator: multiple operations + tdSql.query('select 1 and 1 != 2 and 1 < 2 and 2 between 1 and 3 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 0 or 1 = 2 or 1 >= 2 or 2 between 3 and 5 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 0 and 1 != 2 and 1 < 2 and 2 between 1 and 3 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 or 1 = 2 or 1 >= 2 or 2 between 3 and 5 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 1 != 2 and 1 < 2 and 1 >= 2 and 2 between 1 and 3 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 = 2 or 1 >= 2 or 1<>3 or 2 between 3 and 5 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.query('select 0 or 1 != 2 and 1 <= 2 and 2 between 3 and 4 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 0 or 1 = 2 and 1 <= 2 and 2 between 3 and 5 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + tdSql.query('select 1 != 2 and 1 < 2 or 1 >= 2 or 2 between 4 and 5 from tb;') + tdSql.checkRows(1) + tdSql.checkData(0, 0, 1) + + tdSql.execute('drop database db') + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) -- GitLab