From af1726d866edd7990bfcfc3b35404e722a4fa61c Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Fri, 6 May 2022 20:42:49 +0800 Subject: [PATCH 01/18] update single type of col --- tests/pytest/query/queryDiffColsTagsAndOr.py | 1670 ++++++++++++++++++ 1 file changed, 1670 insertions(+) create mode 100644 tests/pytest/query/queryDiffColsTagsAndOr.py diff --git a/tests/pytest/query/queryDiffColsTagsAndOr.py b/tests/pytest/query/queryDiffColsTagsAndOr.py new file mode 100644 index 0000000000..4fe62d8dba --- /dev/null +++ b/tests/pytest/query/queryDiffColsTagsAndOr.py @@ -0,0 +1,1670 @@ +################################################################### +# 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 -*- +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.common import tdCom +class TDTestCase: + def init(self, conn, logSql): + ## add for TD-6672 + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def insertData(self, tb_name): + # insert_sql_list = [f'insert into {tb_name} values ("2021-01-01 12:00:00", 1, 1, 1, 3, 1.1, 1.1, "binary", "nchar", true, 1)', + # f'insert into {tb_name} values ("2021-01-05 12:00:00", 2, 2, 1, 3, 1.1, 1.1, "binary", "nchar", true, 2)', + # f'insert into {tb_name} values ("2021-01-07 12:00:00", 1, 3, 1, 2, 1.1, 1.1, "binary", "nchar", true, 3)', + # f'insert into {tb_name} values ("2021-01-09 12:00:00", 1, 2, 4, 3, 1.1, 1.1, "binary", "nchar", true, 4)', + # f'insert into {tb_name} values ("2021-01-11 12:00:00", 1, 2, 5, 5, 1.1, 1.1, "binary", "nchar", true, 5)', + # f'insert into {tb_name} values ("2021-01-13 12:00:00", 1, 2, 1, 3, 6.6, 1.1, "binary", "nchar", true, 6)', + # f'insert into {tb_name} values ("2021-01-15 12:00:00", 1, 2, 1, 3, 1.1, 7.7, "binary", "nchar", true, 7)', + # f'insert into {tb_name} values ("2021-01-17 12:00:00", 1, 2, 1, 3, 1.1, 1.1, "binary8", "nchar", true, 8)', + # f'insert into {tb_name} values ("2021-01-19 12:00:00", 1, 2, 1, 3, 1.1, 1.1, "binary", "nchar9", true, 9)', + # f'insert into {tb_name} values ("2021-01-21 12:00:00", 1, 2, 1, 3, 1.1, 1.1, "binary", "nchar", false, 10)', + # f'insert into {tb_name} values ("2021-01-23 12:00:00", 1, 3, 1, 3, 1.1, 1.1, Null, Null, false, 11)' + # ] + insert_sql_list = [f'insert into {tb_name} values ("2021-01-01 12:00:00", 1, 1, 1, 3, 1.1, 1.1, "binary", "nchar", true, 1, 2, 3, 4)', + f'insert into {tb_name} values ("2021-01-05 12:00:00", 2, 2, 1, 3, 1.1, 1.1, "binary", "nchar", true, 2, 3, 4, 5)', + f'insert into {tb_name} values ("2021-01-07 12:00:00", 1, 3, 1, 2, 1.1, 1.1, "binary", "nchar", true, 3, 4, 5, 6)', + f'insert into {tb_name} values ("2021-01-09 12:00:00", 1, 2, 4, 3, 1.1, 1.1, "binary", "nchar", true, 4, 5, 6, 7)', + f'insert into {tb_name} values ("2021-01-11 12:00:00", 1, 2, 5, 5, 1.1, 1.1, "binary", "nchar", true, 5, 6, 7, 8)', + f'insert into {tb_name} values ("2021-01-13 12:00:00", 1, 2, 1, 3, 6.6, 1.1, "binary", "nchar", true, 6, 7, 8, 9)', + f'insert into {tb_name} values ("2021-01-15 12:00:00", 1, 2, 1, 3, 1.1, 7.7, "binary", "nchar", true, 7, 9, 9, 10)', + f'insert into {tb_name} values ("2021-01-17 12:00:00", 1, 2, 1, 3, 1.1, 1.1, "binary8", "nchar", true, 8, 9, 10, 11)', + f'insert into {tb_name} values ("2021-01-19 12:00:00", 1, 2, 1, 3, 1.1, 1.1, "binary", "nchar9", true, 9, 10, 11, 12)', + f'insert into {tb_name} values ("2021-01-21 12:00:00", 1, 2, 1, 3, 1.1, 1.1, "binary", "nchar", false, 10, 11, 12, 13)', + f'insert into {tb_name} values ("2021-01-23 12:00:00", 1, 3, 1, 3, 1.1, 1.1, Null, Null, false, 11, 12, 13, 14)' + ] + for sql in insert_sql_list: + tdSql.execute(sql) + + def initTb(self): + tdCom.cleanTb() + tb_name = tdCom.getLongName(8, "letters") + tdSql.execute( + f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned)") + # f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 int)") + self.insertData(tb_name) + return tb_name + + def initStb(self): + tdCom.cleanTb() + tb_name = tdCom.getLongName(8, "letters") + tdSql.execute( + f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 int) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 int)") + for i in range(1, 6): + tdSql.execute( + f'CREATE TABLE {tb_name}_sub_{i} using {tb_name} tags ({i}, {i}, {i}, {i}, {i}.{i}, {i}.{i}, "binary{i}", "nchar{i}", true, {i})') + self.insertData(f'{tb_name}_sub_{i}') + return tb_name + + def initTwoStb(self): + tdCom.cleanTb() + tb_name = tdCom.getLongName(8, "letters") + tb_name1 = f'{tb_name}1' + tb_name2 = f'{tb_name}2' + tdSql.execute( + f"CREATE TABLE {tb_name1} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 int) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 int)") + tdSql.execute( + f"CREATE TABLE {tb_name2} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 int) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 int)") + tdSql.execute( + f'CREATE TABLE {tb_name1}_sub using {tb_name1} tags (1, 1, 1, 1, 1.1, 1.1, "binary1", "nchar1", true, 1)') + tdSql.execute( + f'CREATE TABLE {tb_name2}_sub using {tb_name2} tags (1, 1, 1, 1, 1.1, 1.1, "binary1", "nchar1", true, 1)') + self.insertData(f'{tb_name1}_sub') + self.insertData(f'{tb_name2}_sub') + return tb_name + + def queryLastC10(self, query_sql, multi=False): + if multi: + res = tdSql.query(query_sql.replace('c10', 'last(*)'), True) + else: + res = tdSql.query(query_sql.replace('*', 'last(*)'), True) + return int(res[0][-4]) + + def queryTsCol(self, tb_name): + # ts and ts + query_sql = f'select * from {tb_name} where ts > "2021-01-11 12:00:00" or ts < "2021-01-13 12:00:00"' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and ts <= "2021-01-13 12:00:00"' + tdSql.query(query_sql) + # tdSql.checkRows(2) + # tdSql.checkEqual(self.queryLastC10(query_sql), 6) + + ## ts or and tinyint col + query_sql = f'select * from {tb_name} where ts > "2021-01-11 12:00:00" or c1 = 2' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and c1 != 2' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + ## ts or and smallint col + query_sql = f'select * from {tb_name} where ts <> "2021-01-11 12:00:00" or c2 = 10' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and c2 <= 1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + + ## ts or and int col + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" or c3 = 4' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and c3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## ts or and big col + query_sql = f'select * from {tb_name} where ts is Null or c4 = 5' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts is not Null and c4 = 2' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) + + ## ts or and float col + query_sql = f'select * from {tb_name} where ts between "2021-01-17 12:00:00" and "2021-01-23 12:00:00" or c5 = 6.6' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and c5 = 1.1' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## ts or and double col + query_sql = f'select * from {tb_name} where ts between "2021-01-17 12:00:00" and "2021-01-23 12:00:00" or c6 = 7.7' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and c6 = 1.1' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## ts or and binary col + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" or c7 like "binary_"' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and c7 in ("binary")' + tdSql.query(query_sql) + tdSql.checkRows(5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + ## ts or and nchar col + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" or c8 like "nchar%"' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and c8 is Null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## ts or and bool col + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" or c9=false' + tdSql.error(query_sql) + + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and c9=true' + tdSql.query(query_sql) + tdSql.checkRows(5) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + + ## multi cols + query_sql = f'select * from {tb_name} where ts > "2021-01-03 12:00:00" and c1 != 2 and c2 >= 2 and c3 <> 4 and c4 < 4 and c5 > 1 and c6 >= 1.1 and c7 is not Null and c8 = "nchar" and c9=false' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + + def queryTsTag(self, tb_name): + ## ts and tinyint col + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and t1 != 2' + tdSql.query(query_sql) + tdSql.checkRows(20) + + ## ts and smallint col + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and t2 <= 1' + tdSql.query(query_sql) + tdSql.checkRows(5) + + ## ts or and int col + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and t3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(4) + + ## ts or and big col + query_sql = f'select * from {tb_name} where ts is not Null and t4 = 2' + tdSql.query(query_sql) + tdSql.checkRows(11) + + ## ts or and float col + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and t5 = 1.1' + tdSql.query(query_sql) + tdSql.checkRows(4) + + ## ts or and double col + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and t6 = 1.1' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## ts or and binary col + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and t7 in ("binary1")' + tdSql.query(query_sql) + tdSql.checkRows(5) + + ## ts or and nchar col + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and t8 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(35) + + ## ts or and bool col + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(35) + + ## multi cols + query_sql = f'select * from {tb_name} where ts > "2021-01-03 12:00:00" and t1 != 2 and t2 >= 2 and t3 <> 4 and t4 < 4 and t5 > 1 and t6 >= 1.1 and t7 is not Null and t8 = "nchar3" and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(10) + + def queryTsColTag(self, tb_name): + ## ts and tinyint col tag + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and c1 >= 2 and t1 != 2' + tdSql.query(query_sql) + tdSql.checkRows(4) + + ## ts and smallint col tag + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and c2 >=3 and t2 <= 1' + tdSql.query(query_sql) + tdSql.checkRows(1) + + ## ts or and int col tag + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and c3 < 3 and t3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(3) + + ## ts or and big col tag + query_sql = f'select * from {tb_name} where ts is not Null and c4 <> 1 and t4 = 2' + tdSql.query(query_sql) + tdSql.checkRows(11) + + ## ts or and float col tag + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00" and c5 is not Null and t5 = 1.1' + tdSql.query(query_sql) + tdSql.checkRows(4) + + ## ts or and double col tag + query_sql = f'select * from {tb_name} where ts < "2021-01-11 12:00:00"and c6 = 1.1 and t6 = 1.1' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## ts or and binary col tag + query_sql = f'select * from {tb_name} where ts <= "2021-01-11 12:00:00" and c7 is Null and t7 in ("binary1")' + tdSql.query(query_sql) + tdSql.checkRows(0) + + ## ts or and nchar col tag + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and c8 like "nch%" and t8 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(30) + + ## ts or and bool col tag + query_sql = f'select * from {tb_name} where ts >= "2021-01-11 12:00:00" and c9=false and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(10) + + ## multi cols tag + query_sql = f'select * from {tb_name} where ts > "2021-01-03 12:00:00" and c1 = 1 and c2 != 3 and c3 <= 2 and c4 >= 2 and c5 in (1.2, 1.1) and c6 < 2.2 and c7 like "bina%" and c8 is not Null and c9 = true and t1 != 2 and t2 >= 2 and t3 <> 4 and t4 < 4 and t5 > 1 and t6 >= 1.1 and t7 is not Null and t8 = "nchar3" and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(2) + + def queryTinyintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c1 > 1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # >= + query_sql = f'select * from {tb_name} where c1 >= 2' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # < + query_sql = f'select * from {tb_name} where c1 < 2' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <= + query_sql = f'select * from {tb_name} where c1 <= 2' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # = + query_sql = f'select * from {tb_name} where c1 = 2' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # != + query_sql = f'select * from {tb_name} where c1 != 1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # <> + query_sql = f'select * from {tb_name} where c1 <> 2' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c1 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c1 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c1 between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # not between and + query_sql = f'select * from {tb_name} where c1 not between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c1 in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # not in + query_sql = f'select * from {tb_name} where c1 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c1 > 0 and c1 >= 1 and c1 < 2 and c1 <= 3 and c1 =1 and c1 != 5 and c1 <> 4 and c1 is not null and c1 between 1 and 2 and c1 not between 2 and 3 and c1 in (1,2) and c1 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # or + query_sql = f'select * from {tb_name} where c1 > 2 or c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 or c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # and or + query_sql = f'select * from {tb_name} where c1 > 2 and c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 and c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + + def querySmallintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c2 > 2' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # >= + query_sql = f'select * from {tb_name} where c2 >= 3' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c2 < 3' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # <= + query_sql = f'select * from {tb_name} where c2 <= 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # = + query_sql = f'select * from {tb_name} where c2 = 3' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # != + query_sql = f'select * from {tb_name} where c2 != 1' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <> + query_sql = f'select * from {tb_name} where c2 <> 2' + tdSql.query(query_sql) + tdSql.checkRows(3) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c2 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c2 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c2 between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # not between and + query_sql = f'select * from {tb_name} where c2 not between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # in + query_sql = f'select * from {tb_name} where c2 in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # not in + query_sql = f'select * from {tb_name} where c2 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # and + query_sql = f'select * from {tb_name} where c2 > 0 and c2 >= 1 and c2 < 4 and c2 <= 3 and c2 != 2 and c2 <> 2 and c2 = 3 and c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # or + query_sql = f'select * from {tb_name} where c2 > 4 or c2 >= 3 or c2 < 1 or c2 <= 0 or c2 != 2 or c2 <> 2 or c2 = 3 or c2 is null or c2 between 3 and 4 or c2 not between 1 and 3 or c2 in (3,4) or c2 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(3) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and or + query_sql = f'select * from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryIntCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c3 > 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # >= + query_sql = f'select * from {tb_name} where c3 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # < + query_sql = f'select * from {tb_name} where c3 < 4' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <= + query_sql = f'select * from {tb_name} where c3 <= 4' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # = + query_sql = f'select * from {tb_name} where c3 = 5' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # != + query_sql = f'select * from {tb_name} where c3 != 5' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <> + query_sql = f'select * from {tb_name} where c3 <> 1' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # is null + query_sql = f'select * from {tb_name} where c3 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c3 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c3 between 1 and 2' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # not between and + query_sql = f'select * from {tb_name} where c3 not between 1 and 2' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # in + query_sql = f'select * from {tb_name} where c3 in (1, 2)' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # not in + query_sql = f'select * from {tb_name} where c3 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c3 > 0 and c3 >= 1 and c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 and c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + # or + query_sql = f'select * from {tb_name} where c3 > 4 or c3 >= 3 or c3 < 1 or c3 <= 0 or c3 != 1 or c3 <> 1 or c3 = 4 or c3 is null or c3 between 3 and 4 or c3 not between 1 and 3 or c3 in (3,4) or c3 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # and or + query_sql = f'select * from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryBigintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c4 > 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # >= + query_sql = f'select * from {tb_name} where c4 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # < + query_sql = f'select * from {tb_name} where c4 < 4' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <= + query_sql = f'select * from {tb_name} where c4 <= 3' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # = + query_sql = f'select * from {tb_name} where c4 = 5' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # != + query_sql = f'select * from {tb_name} where c4 != 5' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <> + query_sql = f'select * from {tb_name} where c4 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # is null + query_sql = f'select * from {tb_name} where c4 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c4 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c4 between 4 and 5' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # not between and + query_sql = f'select * from {tb_name} where c4 not between 1 and 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # in + query_sql = f'select * from {tb_name} where c4 in (1, 5)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # not in + query_sql = f'select * from {tb_name} where c4 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # and + query_sql = f'select * from {tb_name} where c4 > 0 and c4 >= 1 and c4 < 6 and c4 <= 5 and c4 != 2 and c4 <> 2 and c4 = 5 and c4 is not null and c4 between 2 and 5 and c4 not between 1 and 2 and c4 in (2,5) and c4 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # or + query_sql = f'select * from {tb_name} where c4 > 5 or c4 >= 4 or c4 < 1 or c4 <= 0 or c4 != 3 or c4 <> 3 or c4 = 5 or c4 is null or c4 between 4 and 5 or c4 not between 1 and 3 or c4 in (4,5) or c4 not in (1,3)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + # and or + query_sql = f'select * from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryFloatCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c5 > 1.1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # >= + query_sql = f'select * from {tb_name} where c5 >= 1.1' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c5 < 1.2' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <= + query_sql = f'select * from {tb_name} where c5 <= 6.6' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # = + query_sql = f'select * from {tb_name} where c5 = 6.6' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # != + query_sql = f'select * from {tb_name} where c5 != 1.1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # <> + query_sql = f'select * from {tb_name} where c5 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c5 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c5 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c5 between 4 and 6.6' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # not between and + query_sql = f'select * from {tb_name} where c5 not between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c5 in (1, 6.6)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # not in + query_sql = f'select * from {tb_name} where c5 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c5 > 0 and c5 >= 1 and c5 < 7 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 6.6 and c5 is not null and c5 between 2 and 6.6 and c5 not between 1 and 2 and c5 in (2,6.6) and c5 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # or + query_sql = f'select * from {tb_name} where c5 > 6 or c5 >= 6.6 or c5 < 1 or c5 <= 0 or c5 != 1.1 or c5 <> 1.1 or c5 = 5 or c5 is null or c5 between 4 and 5 or c5 not between 1 and 3 or c5 in (4,5) or c5 not in (1.1,3)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) + # and or + query_sql = f'select * from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryDoubleCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c6 > 1.1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # >= + query_sql = f'select * from {tb_name} where c6 >= 1.1' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c6 < 1.2' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <= + query_sql = f'select * from {tb_name} where c6 <= 7.7' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # = + query_sql = f'select * from {tb_name} where c6 = 7.7' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # != + query_sql = f'select * from {tb_name} where c6 != 1.1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # <> + query_sql = f'select * from {tb_name} where c6 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c6 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c6 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c6 between 4 and 7.7' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # not between and + query_sql = f'select * from {tb_name} where c6 not between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c6 in (1, 7.7)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # not in + query_sql = f'select * from {tb_name} where c6 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c6 > 0 and c6 >= 1 and c6 < 8 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 7.7 and c6 is not null and c6 between 2 and 7.7 and c6 not between 1 and 2 and c6 in (2,7.7) and c6 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # or + query_sql = f'select * from {tb_name} where c6 > 7 or c6 >= 7.7 or c6 < 1 or c6 <= 0 or c6 != 1.1 or c6 <> 1.1 or c6 = 5 or c6 is null or c6 between 4 and 5 or c6 not between 1 and 3 or c6 in (4,5) or c6 not in (1.1,3)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + # and or + query_sql = f'select * from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryBinaryCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c7 > "binary"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # >= + query_sql = f'select * from {tb_name} where c7 >= "binary8"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # < + query_sql = f'select * from {tb_name} where c7 < "binary8"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # <= + query_sql = f'select * from {tb_name} where c7 <= "binary8"' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # = + query_sql = f'select * from {tb_name} where c7 = "binary8"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # != + query_sql = f'select * from {tb_name} where c7 != "binary"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # <> + query_sql = f'select * from {tb_name} where c7 <> "binary8"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # is null + query_sql = f'select * from {tb_name} where c7 is null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is not null + query_sql = f'select * from {tb_name} where c7 is not null' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # between and + query_sql = f'select * from {tb_name} where c7 between "bi" and "binary7"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # not between and + query_sql = f'select * from {tb_name} where c7 not between "bi" and "binary7"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # in + query_sql = f'select * from {tb_name} where c7 in ("binar", "binary8")' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # not in + query_sql = f'select * from {tb_name} where c7 not in ("bi", "binary8")' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # ! bug TD-15324 not in + # query_sql = f'select * from {tb_name} where c7 not in (1, "binary8")' + # tdSql.query(query_sql) + # tdSql.checkRows(9) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" and c7 < "binary9" and c7 <= "binary8" and c7 != "binary" and c7 <> "333" and c7 = "binary8" and c7 is not null and c7 between "binary" and "binary8" and c7 not between 1 and 2 and c7 in ("binary","binary8") and c7 not in ("binary")' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # or + query_sql = f'select * from {tb_name} where c7 > "binary" or c7 >= "binary8" or c7 < "binary" or c7 <= "binar" or c7 != "binary" or c7 <> "binary" or c7 = 5 or c7 is null or c7 between 4 and 5 or c7 not between "binary" and "binary7" or c7 in ("binary2222") or c7 not in ("binary")' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and or + query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryNcharCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c8 > "nchar"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # >= + query_sql = f'select * from {tb_name} where c8 >= "nchar9"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # < + query_sql = f'select * from {tb_name} where c8 < "nchar9"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # <= + query_sql = f'select * from {tb_name} where c8 <= "nchar9"' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # = + query_sql = f'select * from {tb_name} where c8 = "nchar9"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # != + query_sql = f'select * from {tb_name} where c8 != "nchar"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # <> + query_sql = f'select * from {tb_name} where c8 <> "nchar9"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # is null + query_sql = f'select * from {tb_name} where c8 is null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is not null + query_sql = f'select * from {tb_name} where c8 is not null' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # between and + query_sql = f'select * from {tb_name} where c8 between "na" and "nchar8"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # not between and + query_sql = f'select * from {tb_name} where c8 not between "na" and "nchar8"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # ! bug TD-15240 in + # query_sql = f'select * from {tb_name} where c8 in ("ncha", "nchar9")' + # tdSql.query(query_sql) + # tdSql.checkRows(1) + # tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # not in + # query_sql = f'select * from {tb_name} where c8 not in ("na", "nchar9")' + # tdSql.query(query_sql) + # tdSql.checkRows(9) + # tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # ! bug TD-15324 not in + # query_sql = f'select * from {tb_name} where c8 not in (1, "nchar9")' + # tdSql.query(query_sql) + # tdSql.checkRows(9) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + # query_sql = f'select * from {tb_name} where c8 > "nchar" and c8 >= "nchar8" and c8 < "nchar9" and c8 <= "nchar8" and c8 != "nchar" and c8 <> "333" and c8 = "nchar8" and c8 is not null and c8 between "nchar" and "nchar8" and c8 not between 1 and 2 and c8 in ("nchar","nchar8") and c8 not in ("nchar")' + # tdSql.query(query_sql) + # tdSql.checkRows(1) + # tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # # or + # query_sql = f'select * from {tb_name} where c8 > "nchar" or c8 >= "nchar8" or c8 < "nchar" or c8 <= "binar" or c8 != "nchar" or c8 <> "nchar" or c8 = 5 or c8 is null or c8 between 4 and 5 or c8 not between "nchar" and "nchar7" or c8 in ("nchar2222") or c8 not in ("nchar")' + # tdSql.query(query_sql) + # tdSql.checkRows(2) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # # and or + # query_sql = f'select * from {tb_name} where c8 > "nchar" and c8 >= "nchar8" or c8 < "nchar9" and c8 <= "nchar" and c8 != 2 and c8 <> 2 and c8 = 4 or c8 is not null and c8 between 2 and 4 and c8 not between 1 and 2 and c8 in (2,4) and c8 not in (1,2)' + # tdSql.query(query_sql) + # tdSql.checkRows(11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryFullColType(self, tb_name): + ## != or and + query_sql = f'select * from {tb_name} where c1 != 1 or c2 = 3' + tdSql.query(query_sql) + tdSql.checkRows(3) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c1 != 1 and c2 = 2' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + + ## <> or and + query_sql = f'select * from {tb_name} where c1 <> 1 or c3 = 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + + query_sql = f'select * from {tb_name} where c1 <> 2 and c3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## >= or and + query_sql = f'select * from {tb_name} where c1 >= 2 or c3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + query_sql = f'select * from {tb_name} where c1 >= 2 and c3 = 1' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + + ## <= or and + query_sql = f'select * from {tb_name} where c1 <= 1 or c3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c1 <= 1 and c3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + + ## <> or and is Null + query_sql = f'select * from {tb_name} where c1 <> 1 or c7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c1 <> 2 and c7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## > or and is not Null + query_sql = f'select * from {tb_name} where c2 > 2 or c8 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c2 > 2 and c8 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) + + ## > or < or >= or <= or != or <> or = Null + query_sql = f'select * from {tb_name} where c1 > 1 or c2 < 2 or c3 >= 4 or c4 <= 2 or c5 != 1.1 or c6 <> 1.1 or c7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(8) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c1 = 1 and c2 > 1 and c3 >= 1 and c4 <= 5 and c5 != 6.6 and c6 <> 7.7 and c7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## tiny small int big or + query_sql = f'select * from {tb_name} where c1 = 2 or c2 = 3 or c3 = 4 or c4 = 5' + tdSql.query(query_sql) + tdSql.checkRows(5) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c1 = 1 and c2 = 2 and c3 = 1 and c4 = 3' + tdSql.query(query_sql) + tdSql.checkRows(5) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + + ## float double binary nchar bool or + query_sql = f'select * from {tb_name} where c5=6.6 or c6=7.7 or c7="binary8" or c8="nchar9" or c9=false' + tdSql.query(query_sql) + tdSql.checkRows(6) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c5=1.1 and c6=7.7 and c7="binary" and c8="nchar" and c9=true' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + + ## all types or + query_sql = f'select * from {tb_name} where c1=2 or c2=3 or c3=4 or c4=5 or c5=6.6 or c6=7.7 or c7 nmatch "binary[134]" or c8="nchar9" or c9=false' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where c1=1 and c2=2 and c3=1 and c4=3 and c5=1.1 and c6=1.1 and c7 match "binary[28]" and c8 in ("nchar") and c9=true' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + + query_sql = f'select * from {tb_name} where c1=1 and c2=2 or c3=1 and c4=3 and c5=1.1 and c6=1.1 and c7 match "binary[28]" and c8 in ("nchar") and c9=true' + tdSql.query(query_sql) + tdSql.checkRows(7) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + + def queryFullTagType(self, tb_name): + ## != or and + query_sql = f'select * from {tb_name} where t1 != 1 or t2 = 3' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 != 1 and t2 = 2' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## <> or and + query_sql = f'select * from {tb_name} where t1 <> 1 or t3 = 3' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 <> 2 and t3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## >= or and + query_sql = f'select * from {tb_name} where t1 >= 2 or t3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 >= 1 and t3 = 1' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## <= or and + query_sql = f'select * from {tb_name} where t1 <= 1 or t3 = 4' + tdSql.query(query_sql) + tdSql.checkRows(22) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 <= 3 and t3 = 2' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## <> or and is Null + query_sql = f'select * from {tb_name} where t1 <> 1 or t7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 <> 2 and t7 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## > or and is not Null + query_sql = f'select * from {tb_name} where t2 > 2 or t8 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(55) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t2 > 2 and t8 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(33) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## > or < or >= or <= or != or <> or = Null + query_sql = f'select * from {tb_name} where t1 > 1 or t2 < 2 or t3 >= 4 or t4 <= 2 or t5 != 1.1 or t6 <> 1.1 or t7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(55) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 >= 1 and t2 > 1 and t3 >= 1 and t4 <= 5 and t5 != 6.6 and t6 <> 7.7 and t7 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## tiny small int big or and + query_sql = f'select * from {tb_name} where t1 = 2 or t2 = 3 or t3 = 4 or t4 = 5' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1 = 1 and t2 = 2 and t3 = 1 and t4 = 3' + tdSql.query(query_sql) + tdSql.checkRows(0) + + ## float double binary nchar bool or and + query_sql = f'select * from {tb_name} where t5=2.2 or t6=7.7 or t7="binary8" or t8="nchar9" or t9=false' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t5=2.2 and t6=2.2 and t7="binary2" and t8="nchar2" and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## all types or and + query_sql = f'select * from {tb_name} where t1=2 or t2=3 or t3=4 or t4=5 or t5=6.6 or t6=7.7 or t7 nmatch "binary[134]" or t8="nchar9" or t9=false' + tdSql.query(query_sql) + tdSql.checkRows(44) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1=1 and t2=1 and t3>=1 and t4!=2 and t5=1.1 and t6=1.1 and t7 match "binary[18]" and t8 in ("nchar1") and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + query_sql = f'select * from {tb_name} where t1=1 and t2=1 or t3>=1 and t4!=2 and t5=1.1 and t6=1.1 and t7 match "binary[18]" and t8 in ("nchar1") and t9=true' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + def queryColMultiExpression(self, tb_name): + ## condition_A and condition_B or condition_C (> < >=) + query_sql = f'select * from {tb_name} where c1 > 2 and c2 < 4 or c3 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + ## (condition_A and condition_B) or condition_C (<= != <>) + query_sql = f'select * from {tb_name} where (c1 <= 1 and c2 != 2) or c4 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## condition_A and (condition_B or condition_C) (Null not Null) + query_sql = f'select * from {tb_name} where c1 is not Null and (c6 = 7.7 or c8 is Null)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## condition_A or condition_B and condition_C (> < >=) + query_sql = f'select * from {tb_name} where c1 > 2 or c2 < 4 and c3 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + ## (condition_A or condition_B) and condition_C (<= != <>) + query_sql = f'select * from {tb_name} where (c1 <= 1 or c2 != 2) and c4 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + ## condition_A or (condition_B and condition_C) (Null not Null) + query_sql = f'select * from {tb_name} where c6 >= 7.7 or (c1 is not Null and c3 =5)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + + ## condition_A or (condition_B and condition_C) or condition_D (> != < Null) + query_sql = f'select * from {tb_name} where c1 != 1 or (c2 >2 and c3 < 1) or c7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## condition_A and (condition_B or condition_C) and condition_D (>= = <= not Null) + query_sql = f'select * from {tb_name} where c4 >= 4 and (c1 = 2 or c5 <= 1.1) and c7 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + ## (condition_A and condition_B) or (condition_C or condition_D) (Null >= > =) + query_sql = f'select * from {tb_name} where (c8 is Null and c1 >= 1) or (c3 > 3 or c4 =2)' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + + ## (condition_A or condition_B) or condition_C or (condition_D and condition_E) (>= <= = not Null <>) + query_sql = f'select * from {tb_name} where (c1 >= 2 or c2 <= 1) or c3 = 4 or (c7 is not Null and c6 <> 1.1)' + tdSql.query(query_sql) + tdSql.checkRows(4) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) + + ## condition_A or (condition_B and condition_C) or (condition_D and condition_E) and condition_F + query_sql = f'select * from {tb_name} where c1 != 1 or (c2 <= 1 and c3 <4) or (c3 >= 4 or c7 is not Null) and c9 <> true' + tdSql.query(query_sql) + tdSql.checkRows(3) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + + ## (condition_A or (condition_B and condition_C) or (condition_D and condition_E)) and condition_F + query_sql = f'select * from {tb_name} where (c1 != 1 or (c2 <= 2 and c3 >= 4) or (c3 >= 4 or c7 is not Null)) and c9 != false' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + + ## (condition_A or condition_B) or (condition_C or condition_D) and (condition_E or condition_F or condition_G) + query_sql = f'select * from {tb_name} where c1 != 1 or (c2 <= 3 and c3 > 4) and c3 <= 5 and (c7 is not Null and c9 != false)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) + + def queryTagMultiExpression(self, tb_name): + ## condition_A and condition_B or condition_C (> < >=) + query_sql = f'select * from {tb_name} where t1 > 2 and t2 < 4 or t3 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(33) + + ## (condition_A and condition_B) or condition_C (<= != <>) + query_sql = f'select * from {tb_name} where (t1 <= 1 and t2 != 2) or t4 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(44) + + ## condition_A and (condition_B or condition_C) (Null not Null) + query_sql = f'select * from {tb_name} where t1 is not Null and (t6 = 7.7 or t8 is not Null)' + tdSql.query(query_sql) + tdSql.checkRows(55) + + ## condition_A or condition_B and condition_C (> < >=) + query_sql = f'select * from {tb_name} where t1 > 2 or t2 < 4 and t3 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(33) + + ## (condition_A or condition_B) and condition_C (<= != <>) + query_sql = f'select * from {tb_name} where (t1 <= 1 or t2 != 2) and t4 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(33) + + ## condition_A or (condition_B and condition_C) (Null not Null) + query_sql = f'select * from {tb_name} where t6 >= 7.7 or (t1 is not Null and t3 =5)' + tdSql.query(query_sql) + tdSql.checkRows(11) + + ## condition_A or (condition_B and condition_C) or condition_D (> != < Null) + query_sql = f'select * from {tb_name} where t1 != 1 or (t2 >2 and t3 < 1) or t7 is Null' + tdSql.query(query_sql) + tdSql.checkRows(44) + + ## condition_A and (condition_B or condition_C) and condition_D (>= = <= not Null) + query_sql = f'select * from {tb_name} where t4 >= 2 and (t1 = 2 or t5 <= 1.1) and t7 is not Null' + tdSql.query(query_sql) + tdSql.checkRows(11) + + ## (condition_A and condition_B) or (condition_C or condition_D) (Null >= > =) + query_sql = f'select * from {tb_name} where (t8 is Null and t1 >= 1) or (t3 > 3 or t4 =2)' + tdSql.query(query_sql) + tdSql.checkRows(33) + + ## (condition_A or condition_B) or condition_C or (condition_D and condition_E) (>= <= = not Null <>) + query_sql = f'select * from {tb_name} where (t1 >= 2 or t2 <= 1) or t3 = 4 or (t7 is not Null and t6 <> 1.1)' + tdSql.query(query_sql) + tdSql.checkRows(55) + + ## condition_A or (condition_B and condition_C) or (condition_D and condition_E) and condition_F + query_sql = f'select * from {tb_name} where t1 != 1 or (t2 <= 1 and t3 <4) or (t3 >= 4 or t7 is not Null) and t9 <> true' + tdSql.query(query_sql) + tdSql.checkRows(55) + + ## (condition_A or (condition_B and condition_C) or (condition_D and condition_E)) and condition_F + query_sql = f'select * from {tb_name} where (t1 != 1 or (t2 <= 2 and t3 >= 4) or (t3 >= 4 or t7 is not Null)) and t9 != false' + tdSql.query(query_sql) + tdSql.checkRows(55) + + ## (condition_A or condition_B) or (condition_C or condition_D) and (condition_E or condition_F or condition_G) + query_sql = f'select * from {tb_name} where t1 != 1 or (t2 <= 3 and t3 > 4) and t3 <= 5 and (t7 is not Null and t9 != false)' + tdSql.query(query_sql) + tdSql.checkRows(44) + + def queryColPreCal(self, tb_name): + ## avg sum condition_A or/and condition_B + query_sql = f'select avg(c3), sum(c3) from {tb_name} where c10 = 5 or c8 is Null' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[0]), 3) + tdSql.checkEqual(int(res[1]), 6) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where c6 = 1.1 and c8 is not Null' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[1]), 16) + + ## avg sum condition_A or/and condition_B or/and condition_C + query_sql = f'select avg(c3), sum(c3) from {tb_name} where c10 = 4 or c8 is Null or c9 = false ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[0]), 2) + tdSql.checkEqual(int(res[1]), 6) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where c6 = 1.1 and c8 is not Null and c9 = false ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[0]), 1) + tdSql.checkEqual(int(res[1]), 1) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where c6 = 1.1 and c8 is not Null or c9 = false ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[1]), 17) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where c6 = 1.1 or c8 is not Null and c9 = false ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[1]), 17) + + ## count avg sum condition_A or/and condition_B or/and condition_C interval + query_sql = f'select count(*), avg(c3), sum(c3) from {tb_name} where c10 = 4 or c8 is Null or c9 = false interval(16d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[0][1]), 1) + tdSql.checkEqual(int(res[0][2]), 4) + tdSql.checkEqual(int(res[0][3]), 4) + tdSql.checkEqual(int(res[1][1]), 2) + tdSql.checkEqual(int(res[1][2]), 1) + tdSql.checkEqual(int(res[1][3]), 2) + query_sql = f'select count(*), avg(c3), sum(c3) from {tb_name} where c6 = 1.1 and c8 is not Null and c9 = false interval(16d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(1) + tdSql.checkEqual(int(res[0][1]), 1) + tdSql.checkEqual(int(res[0][2]), 1) + tdSql.checkEqual(int(res[0][3]), 1) + + ## count avg sum condition_A or condition_B or in and like or condition_C interval + query_sql = f'select count(*), sum(c3) from {tb_name} where c10 = 4 or c8 is Null or c2 in (1, 2) and c7 like "binary_" or c1 <> 1 interval(16d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[0][1]), 2) + tdSql.checkEqual(int(res[0][2]), 5) + tdSql.checkEqual(int(res[1][1]), 2) + tdSql.checkEqual(int(res[1][2]), 2) + + def queryTagPreCal(self, tb_name): + ## avg sum condition_A or/and condition_B + query_sql = f'select avg(c3), sum(c3) from {tb_name} where t10 = 5 or t8 is Null' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[0]), 1) + tdSql.checkEqual(int(res[1]), 18) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where t6 = 1.1 and t8 is not Null' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[1]), 18) + + ## avg sum condition_A or/and condition_B or/and condition_C + query_sql = f'select avg(c3), sum(c3) from {tb_name} where t10 = 4 or t8 is Null or t9 = true ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[0]), 1) + tdSql.checkEqual(int(res[1]), 90) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where t6 = 1.1 and t8 is not Null and t9 = true ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[0]), 1) + tdSql.checkEqual(int(res[1]), 18) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where t6 = 1.1 and t8 is not Null or t9 = true ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[1]), 90) + query_sql = f'select avg(c3), sum(c3) from {tb_name} where t6 = 1.1 or t8 is not Null and t9 = true ' + res = tdSql.query(query_sql, True)[0] + tdSql.checkEqual(int(res[1]), 90) + + ## count avg sum condition_A or/and condition_B or/and condition_C interval + query_sql = f'select count(*), avg(c3), sum(c3) from {tb_name} where t10 = 4 or t8 is Null or t9 = true interval(16d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[0][1]), 25) + tdSql.checkEqual(int(res[0][2]), 2) + tdSql.checkEqual(int(res[0][3]), 60) + tdSql.checkEqual(int(res[1][1]), 30) + tdSql.checkEqual(int(res[1][2]), 1) + tdSql.checkEqual(int(res[1][3]), 30) + query_sql = f'select count(*), avg(c3), sum(c3) from {tb_name} where t6 = 1.1 and t8 is not Null and t9 = true interval(16d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[0][1]), 5) + tdSql.checkEqual(int(res[0][2]), 2) + tdSql.checkEqual(int(res[0][3]), 12) + tdSql.checkEqual(int(res[1][1]), 6) + tdSql.checkEqual(int(res[1][2]), 1) + tdSql.checkEqual(int(res[1][3]), 6) + + ## count avg sum condition_A or condition_B or in and like or condition_C interval + query_sql = f'select count(*), sum(c3) from {tb_name} where t10 = 4 or t8 is Null or t2 in (1, 2) and t7 like "binary_" or t1 <> 1 interval(16d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[0][1]), 25) + tdSql.checkEqual(int(res[0][2]), 60) + tdSql.checkEqual(int(res[1][1]), 30) + tdSql.checkEqual(int(res[1][2]), 30) + + def queryMultiTb(self, tb_name): + ## select from (condition_A or condition_B) + query_sql = f'select c10 from (select * from {tb_name} where c1 >1 or c2 >=3)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(3) + tdSql.checkEqual(int(res[2][0]), 11) + + ## select from (condition_A or condition_B) where condition_A or condition_B + query_sql = f'select c10 from (select * from {tb_name} where c1 >1 or c2 >=3) where c1 =2 or c4 = 2' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[1][0]), 3) + + ## select from (condition_A or condition_B and like and in) where condition_A or condition_B or like and in + query_sql = f'select c10 from (select * from {tb_name} where c1 >1 or c2 = 2 and c7 like "binar_" and c4 in (3, 5)) where c1 != 2 or c3 = 1 or c8 like "ncha_" and c9 in (true)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(7) + tdSql.checkEqual(int(res[6][0]), 10) + + ## select count avg sum from (condition_A or condition_B and like and in) where condition_A or condition_B or like and in interval + query_sql = f'select count(*), avg(c6), sum(c3) from (select * from {tb_name} where c1 >1 or c2 = 2 and c7 like "binar_" and c4 in (3, 5)) where c1 != 2 or c3 = 1 or c8 like "ncha_" and c9 in (true) interval(8d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(3) + tdSql.checkEqual(int(res[0][1]), 3) + tdSql.checkEqual(int(res[0][2]), 1) + tdSql.checkEqual(int(res[0][3]), 10) + tdSql.checkEqual(int(res[1][1]), 3) + tdSql.checkEqual(int(res[1][2]), 3) + tdSql.checkEqual(int(res[1][3]), 3) + tdSql.checkEqual(int(res[2][1]), 1) + tdSql.checkEqual(int(res[2][2]), 1) + tdSql.checkEqual(int(res[2][3]), 1) + + ## cname + query_sql = f'select c10 from (select * from {tb_name} where c1 >1 or c2 = 2 and c7 like "binar_" and c4 in (3, 5)) a where a.c1 != 2 or a.c3 = 1 or a.c8 like "ncha_" and a.c9 in (true)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(7) + tdSql.checkEqual(int(res[6][0]), 10) + + ## multi cname + query_sql = f'select b.c10 from (select * from {tb_name} where c9 = true or c2 = 2) a, (select * from {tb_name} where c7 like "binar_" or c4 in (3, 5)) b where a.ts = b.ts' + res = tdSql.query(query_sql, True) + tdSql.checkRows(10) + tdSql.checkEqual(int(res[9][0]), 10) + + def queryMultiTbWithTag(self, tb_name): + ## select count avg sum from (condition_A or condition_B and like and in) where condition_A or condition_B or condition_tag_C or condition_tag_D or like and in interval + query_sql = f'select count(*), avg(c6), sum(c3) from (select * from {tb_name} where c1 >1 or c2 = 2 and c7 like "binar_" and c4 in (3, 5)) where c1 != 2 or c3 = 1 or t1=2 or t1=3 or c8 like "ncha_" and c9 in (true) interval(8d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(3) + tdSql.checkEqual(int(res[0][1]), 17) + tdSql.checkEqual(int(res[0][2]), 1) + tdSql.checkEqual(int(res[0][3]), 38) + tdSql.checkEqual(int(res[1][1]), 10) + tdSql.checkEqual(int(res[1][2]), 2) + tdSql.checkEqual(int(res[1][3]), 17) + tdSql.checkEqual(int(res[2][1]), 8) + tdSql.checkEqual(int(res[2][2]), 1) + tdSql.checkEqual(int(res[2][3]), 15) + + ## select count avg sum from (condition_A and condition_B and and line and in and ts and condition_tag_A and condition_tag_B and between) where condition_C orr condition_D or condition_tag_C or condition_tag_D or like and in interval + query_sql = f'select count(*), avg(c6), sum(c3) from (select * from {tb_name} where c1 >= 1 and c2 = 2 and c7 like "binar_" and c4 in (3, 5) and ts > "2021-01-11 12:00:00" and t1 < 2 and t1 > 0 and c6 between 0 and 7) where c1 != 2 or c3 = 1 or t1=2 or t1=3 or c8 like "ncha_" and c9 in (true) interval(8d)' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(int(res[0][1]), 2) + tdSql.checkEqual(int(res[0][2]), 1) + tdSql.checkEqual(int(res[0][3]), 2) + tdSql.checkEqual(int(res[1][1]), 1) + tdSql.checkEqual(int(res[1][2]), 1) + tdSql.checkEqual(int(res[1][3]), 1) + + def queryJoin(self, tb_name): + ## between tss tag + query_sql = f'select stb1.ts, stb2.ts, stb1.t1, stb1.c10 from {tb_name}1 stb1, {tb_name}2 stb2 where stb1.ts = stb2.ts and stb1.ts <= "2021-01-07 12:00:00" and stb2.ts < "2021-01-07 12:00:00" and stb1.t1 = stb2.t1' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + tdSql.checkEqual(str(res[0][0]), "2021-01-01 12:00:00") + tdSql.checkEqual(str(res[1][1]), "2021-01-05 12:00:00") + ## between ts tag col + query_sql = f'select stb1.t1, stb2.t1, stb1.c1, stb2.c2 from {tb_name}1 stb1, {tb_name}2 stb2 where stb1.ts = stb2.ts and stb1.t1 = stb2.t1 and stb2.c2 <= 2 and stb1.c1 > 0' + res = tdSql.query(query_sql, True) + tdSql.checkRows(9) + ## between ts tags + query_sql = f'select stb1.t1, stb2.t1, stb1.c1, stb2.c2 from {tb_name}1 stb1, {tb_name}2 stb2 where stb1.ts = stb2.ts and stb1.t1 = stb2.t1 and stb1.t1 = 1 ' + res = tdSql.query(query_sql, True) + tdSql.checkRows(11) + ## between ts tag tbnames + query_sql = f'select stb1.t1, stb2.t1, stb1.c1, stb2.c2 from {tb_name}1 stb1, {tb_name}2 stb2 where stb1.ts = stb2.ts and stb1.t1 = stb2.t1 and stb1.tbname is not Null' + res = tdSql.query(query_sql, True) + tdSql.checkRows(11) + ## between ts col tag tbname + query_sql = f'select stb1.tbname, stb1.t1, stb2.t1, stb1.c1, stb2.c2 from {tb_name}1 stb1, {tb_name}2 stb2 where stb1.ts = stb2.ts and stb1.t1 = stb2.t1 and stb1.tbname is not Null and stb1.c2 = 3' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + query_sql = f'select stb1.tbname, stb1.*, stb2.tbname, stb1.* from {tb_name}1 stb1, {tb_name}2 stb2 where stb1.ts = stb2.ts and stb1.t1 = stb2.t1 and (stb1.t2 != 1 or stb1.t3 <= 1) and (stb2.tbname like "{tb_name}%" or stb2.tbname is Null ) and stb1.tbname is not Null and stb2.c2 = 3' + res = tdSql.query(query_sql, True) + tdSql.checkRows(2) + + def checkTbColTypeOperator(self): + ''' + Ordinary table full column type and operator + ''' + tb_name = self.initTb() + self.queryTinyintCol(tb_name) + self.querySmallintCol(tb_name) + self.queryIntCol(tb_name) + self.queryBigintCol(tb_name) + self.queryFloatCol(tb_name) + self.queryDoubleCol(tb_name) + self.queryBinaryCol(tb_name) + self.queryNcharCol(tb_name) + self.queryFullColType(tb_name) + + def checkStbColTypeOperator(self): + ''' + Super table full column type and operator + ''' + tb_name = self.initStb() + self.queryFullColType(f'{tb_name}_sub_1') + + + def checkStbTagTypeOperator(self): + ''' + Super table full tag type and operator + ''' + tb_name = self.initStb() + self.queryFullTagType(tb_name) + + def checkTbTsCol(self): + ''' + Ordinary table ts and col check + ''' + tb_name = self.initTb() + self.queryTsCol(tb_name) + + def checkStbTsTol(self): + tb_name = self.initStb() + self.queryTsCol(f'{tb_name}_sub_1') + + def checkStbTsTag(self): + tb_name = self.initStb() + self.queryTsTag(tb_name) + + def checkStbTsColTag(self): + tb_name = self.initStb() + self.queryTsColTag(tb_name) + + def checkTbMultiExpression(self): + ''' + Ordinary table multiExpression + ''' + tb_name = self.initTb() + self.queryColMultiExpression(tb_name) + + def checkStbMultiExpression(self): + ''' + Super table multiExpression + ''' + tb_name = self.initStb() + self.queryColMultiExpression(f'{tb_name}_sub_1') + self.queryTagMultiExpression(tb_name) + + def checkTbPreCal(self): + ''' + Ordinary table precal + ''' + tb_name = self.initTb() + self.queryColPreCal(tb_name) + + def checkStbPreCal(self): + ''' + Super table precal + ''' + tb_name = self.initStb() + self.queryColPreCal(f'{tb_name}_sub_1') + self.queryTagPreCal(tb_name) + + def checkMultiTb(self): + ''' + test "or" in multi ordinary table + ''' + tb_name = self.initTb() + self.queryMultiTb(tb_name) + + def checkMultiStb(self): + ''' + test "or" in multi super table + ''' + tb_name = self.initStb() + self.queryMultiTb(f'{tb_name}_sub_1') + + def checkMultiTbWithTag(self): + ''' + test Multi tb with tag + ''' + tb_name = self.initStb() + self.queryMultiTbWithTag(tb_name) + + def checkMultiStbJoin(self): + ''' + join test + ''' + tb_name = self.initTwoStb() + self.queryJoin(tb_name) + + def run(self): + tdSql.prepare() + self.checkTbColTypeOperator() + # self.checkStbColTypeOperator() + # self.checkStbTagTypeOperator() + # self.checkTbTsCol() + # self.checkStbTsTol() + # self.checkStbTsTag() + # self.checkStbTsColTag() + # self.checkTbMultiExpression() + # self.checkStbMultiExpression() + # self.checkTbPreCal() + # self.checkStbPreCal() + # self.checkMultiTb() + # self.checkMultiStb() + # self.checkMultiTbWithTag() + # self.checkMultiStbJoin() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From 1716bfb5dcbc23518001c949b9af3e05b9d32355 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Sat, 7 May 2022 00:34:47 +0800 Subject: [PATCH 02/18] test: finish tb select *|column --- tests/pytest/query/queryDiffColsTagsAndOr.py | 450 ++++++++++++++++++- 1 file changed, 447 insertions(+), 3 deletions(-) diff --git a/tests/pytest/query/queryDiffColsTagsAndOr.py b/tests/pytest/query/queryDiffColsTagsAndOr.py index 4fe62d8dba..5f22920d06 100644 --- a/tests/pytest/query/queryDiffColsTagsAndOr.py +++ b/tests/pytest/query/queryDiffColsTagsAndOr.py @@ -375,6 +375,93 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(1) tdSql.checkEqual(self.queryLastC10(query_sql), 2) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c1 > 2 and c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 and c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' + res = tdSql.query(query_sql) + tdSql.checkRows(1) + + def queryUtinyintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c10 > 10' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # >= + query_sql = f'select * from {tb_name} where c10 >= 10' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c10 < 2' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # <= + query_sql = f'select * from {tb_name} where c10 <= 2' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # = + query_sql = f'select * from {tb_name} where c10 = 2' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # != + query_sql = f'select * from {tb_name} where c10 != 11' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # <> + query_sql = f'select * from {tb_name} where c10 <> 2' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c10 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c10 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c10 between 2 and 4' + tdSql.query(query_sql) + tdSql.checkRows(3) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) + # not between and + query_sql = f'select * from {tb_name} where c10 not between 2 and 4' + tdSql.query(query_sql) + tdSql.checkRows(8) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c10 in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) + # not in + query_sql = f'select * from {tb_name} where c10 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c10 > 0 and c10 >= 1 and c10 < 2 and c10 <= 3 and c10 =1 and c10 != 5 and c10 <> 4 and c10 is not null and c10 between 1 and 2 and c10 not between 2 and 3 and c10 in (1,2) and c10 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # or + query_sql = f'select * from {tb_name} where c10 > 2 or c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 or c10 is null or c10 between 2 and 3 or c10 not between 1 and 1 or c10 in (2, 3) or c10 not in (1, 2)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and or + query_sql = f'select * from {tb_name} where c10 > 2 and c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 and c10 is null or c10 between 2 and 3 and c10 not between 1 and 1 and c10 in (2, 3) and c10 not in (1, 2)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c10 > 2 and c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 and c10 is null or c10 between 2 and 3 and c10 not between 1 and 1 and c10 in (2, 3) and c10 not in (1, 2)' + res = tdSql.query(query_sql) + tdSql.checkRows(10) def querySmallintCol(self, tb_name): # > @@ -456,6 +543,93 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(11) tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + + def queryUsmallintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c11 > 11' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # >= + query_sql = f'select * from {tb_name} where c11 >= 11' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c11 < 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # <= + query_sql = f'select * from {tb_name} where c11 <= 3' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # = + query_sql = f'select * from {tb_name} where c11 = 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # != + query_sql = f'select * from {tb_name} where c11 != 1' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <> + query_sql = f'select * from {tb_name} where c11 <> 2' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c11 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c11 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c11 between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # not between and + query_sql = f'select * from {tb_name} where c11 not between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c11 in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # not in + query_sql = f'select * from {tb_name} where c11 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c11 > 0 and c11 >= 1 and c11 < 4 and c11 <= 3 and c11 != 2 and c11 <> 2 and c11 = 3 and c11 is not null and c11 between 2 and 3 and c11 not between 1 and 2 and c11 in (2,3) and c11 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # or + query_sql = f'select * from {tb_name} where c11 > 4 or c11 >= 3 or c11 < 1 or c11 <= 0 or c11 != 2 or c11 <> 2 or c11 = 3 or c11 is null or c11 between 3 and 4 or c11 not between 1 and 3 or c11 in (3,4) or c11 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and or + query_sql = f'select * from {tb_name} where c11 > 0 and c11 >= 1 or c11 < 4 and c11 <= 3 and c11 != 1 and c11 <> 2 and c11 = 3 or c11 is not null and c11 between 2 and 3 and c11 not between 1 and 2 and c11 in (2,3) and c11 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryIntCol(self, tb_name): # > @@ -537,6 +711,93 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(11) tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + + def queryUintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c12 > 12' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # >= + query_sql = f'select * from {tb_name} where c12 >= 12' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c12 < 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # <= + query_sql = f'select * from {tb_name} where c12 <= 4' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # = + query_sql = f'select * from {tb_name} where c12 = 5' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) + # != + query_sql = f'select * from {tb_name} where c12 != 5' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <> + query_sql = f'select * from {tb_name} where c12 <> 1' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c12 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c12 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c12 between 2 and 3' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # not between and + query_sql = f'select * from {tb_name} where c12 not between 1 and 2' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c12 in (3, 2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # not in + query_sql = f'select * from {tb_name} where c12 not in (2, 3)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c12 > 0 and c12 >= 1 and c12 < 5 and c12 <= 4 and c12 != 2 and c12 <> 2 and c12 = 4 and c12 is not null and c12 between 2 and 4 and c12 not between 1 and 2 and c12 in (2,4) and c12 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # or + query_sql = f'select * from {tb_name} where c12 > 4 or c12 >= 3 or c12 < 1 or c12 <= 0 or c12 != 1 or c12 <> 1 or c12 = 4 or c12 is null or c12 between 3 and 4 or c12 not between 1 and 3 or c12 in (3,4) or c12 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and or + query_sql = f'select * from {tb_name} where c12 > 0 and c12 >= 1 or c12 < 5 and c12 <= 4 and c12 != 2 and c12 <> 2 and c12 = 4 or c12 is not null and c12 between 2 and 4 and c12 not between 1 and 2 and c12 in (2,4) and c12 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryBigintCol(self, tb_name): # > @@ -618,6 +879,93 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(11) tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + + def queryUbigintCol(self, tb_name): + # > + query_sql = f'select * from {tb_name} where c13 > 4' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # >= + query_sql = f'select * from {tb_name} where c13 >= 4' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # < + query_sql = f'select * from {tb_name} where c13 < 5' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # <= + query_sql = f'select * from {tb_name} where c13 <= 4' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) + # = + query_sql = f'select * from {tb_name} where c13 = 5' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # != + query_sql = f'select * from {tb_name} where c13 != 5' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # <> + query_sql = f'select * from {tb_name} where c13 <> 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c13 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c13 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # between and + query_sql = f'select * from {tb_name} where c13 between 4 and 5' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # not between and + query_sql = f'select * from {tb_name} where c13 not between 1 and 3' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c13 in (1, 5)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # not in + query_sql = f'select * from {tb_name} where c13 not in (2, 6)' + tdSql.query(query_sql) + tdSql.checkRows(10) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and + query_sql = f'select * from {tb_name} where c13 > 0 and c13 >= 1 and c13 < 6 and c13 <= 5 and c13 != 2 and c13 <> 2 and c13 = 5 and c13 is not null and c13 between 2 and 5 and c13 not between 1 and 2 and c13 in (2,5) and c13 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # or + query_sql = f'select * from {tb_name} where c13 > 5 or c13 >= 4 or c13 < 1 or c13 <= 0 or c13 != 3 or c13 <> 3 or c13 = 5 or c13 is null or c13 between 4 and 5 or c13 not between 1 and 3 or c13 in (4,5) or c13 not in (1,3)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # and or + query_sql = f'select * from {tb_name} where c13 > 0 and c13 >= 1 or c13 < 5 and c13 <= 4 and c13 != 2 and c13 <> 2 and c13 = 4 or c13 is not null and c13 between 2 and 4 and c13 not between 1 and 2 and c13 in (2,4) and c13 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryFloatCol(self, tb_name): # > @@ -699,6 +1047,9 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(11) tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryDoubleCol(self, tb_name): # > @@ -780,6 +1131,9 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(11) tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryBinaryCol(self, tb_name): # > @@ -847,26 +1201,40 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(9) tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # match + query_sql = f'select * from {tb_name} where c7 match "binary[28]"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # nmatch + query_sql = f'select * from {tb_name} where c7 nmatch "binary[28]"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # ! bug TD-15324 not in # query_sql = f'select * from {tb_name} where c7 not in (1, "binary8")' # tdSql.query(query_sql) # tdSql.checkRows(9) # tdSql.checkEqual(self.queryLastC10(query_sql), 11) # and - query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" and c7 < "binary9" and c7 <= "binary8" and c7 != "binary" and c7 <> "333" and c7 = "binary8" and c7 is not null and c7 between "binary" and "binary8" and c7 not between 1 and 2 and c7 in ("binary","binary8") and c7 not in ("binary")' + query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" and c7 < "binary9" and c7 <= "binary8" and c7 != "binary" and c7 <> "333" and c7 = "binary8" and c7 is not null and c7 between "binary" and "binary8" and c7 not between 1 and 2 and c7 in ("binary","binary8") and c7 not in ("binary") and c7 match "binary[28]" and c7 nmatch "binary[2]"' tdSql.query(query_sql) tdSql.checkRows(1) tdSql.checkEqual(self.queryLastC10(query_sql), 8) # or - query_sql = f'select * from {tb_name} where c7 > "binary" or c7 >= "binary8" or c7 < "binary" or c7 <= "binar" or c7 != "binary" or c7 <> "binary" or c7 = 5 or c7 is null or c7 between 4 and 5 or c7 not between "binary" and "binary7" or c7 in ("binary2222") or c7 not in ("binary")' + query_sql = f'select * from {tb_name} where c7 > "binary" or c7 >= "binary8" or c7 < "binary" or c7 <= "binar" or c7 != "binary" or c7 <> "binary" or c7 = 5 or c7 is null or c7 between 4 and 5 or c7 not between "binary" and "binary7" or c7 in ("binary2222") or c7 not in ("binary") or c7 match "binary[28]" or c7 nmatch "binary"' tdSql.query(query_sql) tdSql.checkRows(2) tdSql.checkEqual(self.queryLastC10(query_sql), 11) # and or - query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2)' + query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2) or c7 match "binary[28]" or c7 nmatch "binary"' tdSql.query(query_sql) tdSql.checkRows(11) tdSql.checkEqual(self.queryLastC10(query_sql), 11) + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2) or c7 match "binary[28]" or c7 nmatch "binary"' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryNcharCol(self, tb_name): # > @@ -939,6 +1307,17 @@ class TDTestCase: # tdSql.query(query_sql) # tdSql.checkRows(9) # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # match + query_sql = f'select * from {tb_name} where c8 match "nchar[19]"' + tdSql.query(query_sql) + tdSql.checkRows(1) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # nmatch + query_sql = f'select * from {tb_name} where c8 nmatch "nchar[19]"' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # and # query_sql = f'select * from {tb_name} where c8 > "nchar" and c8 >= "nchar8" and c8 < "nchar9" and c8 <= "nchar8" and c8 != "nchar" and c8 <> "333" and c8 = "nchar8" and c8 is not null and c8 between "nchar" and "nchar8" and c8 not between 1 and 2 and c8 in ("nchar","nchar8") and c8 not in ("nchar")' # tdSql.query(query_sql) @@ -954,6 +1333,66 @@ class TDTestCase: # tdSql.query(query_sql) # tdSql.checkRows(11) # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c8 > "nchar" and c8 >= "nchar8" or c8 < "nchar9" and c8 <= "nchar" and c8 != 2 and c8 <> 2 and c8 = 4 or c8 is not null and c8 between 2 and 4 and c8 not between 1 and 2 and c8 in (2,4) and c8 not in (1,2)' + # tdSql.query(query_sql) + # tdSql.checkRows(11) + + def queryBoolCol(self, tb_name): + # = + query_sql = f'select * from {tb_name} where c9 = false' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # != + query_sql = f'select * from {tb_name} where c9 != false' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # <> + query_sql = f'select * from {tb_name} where c9 <> true' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # is null + query_sql = f'select * from {tb_name} where c9 is null' + tdSql.query(query_sql) + tdSql.checkRows(0) + # is not null + query_sql = f'select * from {tb_name} where c9 is not null' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # in + query_sql = f'select * from {tb_name} where c9 in ("binar", false)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # # not in + # # ! bug TD-15327 + # query_sql = f'select * from {tb_name} where c9 not in ("true")' + # tdSql.query(query_sql) + # tdSql.checkRows(2) + # tdSql.checkEqual(self.queryLastC10(query_sql), 2) + + # # ! bug TD-15327 + # # and + # query_sql = f'select * from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 = "true" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' + # tdSql.query(query_sql) + # tdSql.checkRows(1) + # tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # # or + # query_sql = f'select * from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' + # tdSql.query(query_sql) + # tdSql.checkRows(2) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # # and or + # query_sql = f'select * from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' + # tdSql.query(query_sql) + # tdSql.checkRows(11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' + # tdSql.query(query_sql) + # tdSql.checkRows(11) def queryFullColType(self, tb_name): ## != or and @@ -1542,13 +1981,18 @@ class TDTestCase: ''' tb_name = self.initTb() self.queryTinyintCol(tb_name) + self.queryUtinyintCol(tb_name) self.querySmallintCol(tb_name) + self.queryUsmallintCol(tb_name) self.queryIntCol(tb_name) + self.queryUintCol(tb_name) self.queryBigintCol(tb_name) + self.queryUbigintCol(tb_name) self.queryFloatCol(tb_name) self.queryDoubleCol(tb_name) self.queryBinaryCol(tb_name) self.queryNcharCol(tb_name) + self.queryBoolCol(tb_name) self.queryFullColType(tb_name) def checkStbColTypeOperator(self): From 90ffb798ba470dbf89d4f871e92748e35deb453f Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Sat, 7 May 2022 00:43:17 +0800 Subject: [PATCH 03/18] test: finish sub_tb select *|column --- tests/pytest/query/queryDiffColsTagsAndOr.py | 29 ++++++++++++++------ 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/pytest/query/queryDiffColsTagsAndOr.py b/tests/pytest/query/queryDiffColsTagsAndOr.py index 5f22920d06..408d692b78 100644 --- a/tests/pytest/query/queryDiffColsTagsAndOr.py +++ b/tests/pytest/query/queryDiffColsTagsAndOr.py @@ -61,10 +61,10 @@ class TDTestCase: tdCom.cleanTb() tb_name = tdCom.getLongName(8, "letters") tdSql.execute( - f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 int) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 int)") + f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 tinyint unsigned, t11 smallint unsigned, t12 int unsigned, t13 bigint unsigned)") for i in range(1, 6): tdSql.execute( - f'CREATE TABLE {tb_name}_sub_{i} using {tb_name} tags ({i}, {i}, {i}, {i}, {i}.{i}, {i}.{i}, "binary{i}", "nchar{i}", true, {i})') + f'CREATE TABLE {tb_name}_sub_{i} using {tb_name} tags ({i}, {i}, {i}, {i}, {i}.{i}, {i}.{i}, "binary{i}", "nchar{i}", true, {i}, {i}, {i}, {i})') self.insertData(f'{tb_name}_sub_{i}') return tb_name @@ -1999,10 +1999,23 @@ class TDTestCase: ''' Super table full column type and operator ''' - tb_name = self.initStb() - self.queryFullColType(f'{tb_name}_sub_1') - - + stb_name = self.initStb() + tb_name = stb_name + "_sub_1" + self.queryTinyintCol(tb_name) + self.queryUtinyintCol(tb_name) + self.querySmallintCol(tb_name) + self.queryUsmallintCol(tb_name) + self.queryIntCol(tb_name) + self.queryUintCol(tb_name) + self.queryBigintCol(tb_name) + self.queryUbigintCol(tb_name) + self.queryFloatCol(tb_name) + self.queryDoubleCol(tb_name) + self.queryBinaryCol(tb_name) + self.queryNcharCol(tb_name) + self.queryBoolCol(tb_name) + self.queryFullColType(tb_name) + def checkStbTagTypeOperator(self): ''' Super table full tag type and operator @@ -2089,8 +2102,8 @@ class TDTestCase: def run(self): tdSql.prepare() - self.checkTbColTypeOperator() - # self.checkStbColTypeOperator() + # self.checkTbColTypeOperator() + self.checkStbColTypeOperator() # self.checkStbTagTypeOperator() # self.checkTbTsCol() # self.checkStbTsTol() From e841a70159280710714a76dcc65106c7180afce7 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Sat, 7 May 2022 20:01:20 +0800 Subject: [PATCH 04/18] test: finish sub_tb select *|column --- tests/pytest/query/queryDiffColsTagsAndOr.py | 996 ++++++++++--------- 1 file changed, 503 insertions(+), 493 deletions(-) diff --git a/tests/pytest/query/queryDiffColsTagsAndOr.py b/tests/pytest/query/queryDiffColsTagsAndOr.py index 408d692b78..0a74954f5a 100644 --- a/tests/pytest/query/queryDiffColsTagsAndOr.py +++ b/tests/pytest/query/queryDiffColsTagsAndOr.py @@ -14,6 +14,7 @@ from util.log import tdLog from util.cases import tdCases from util.sql import tdSql from util.common import tdCom +import random class TDTestCase: def init(self, conn, logSql): ## add for TD-6672 @@ -295,1220 +296,1234 @@ class TDTestCase: tdSql.query(query_sql) tdSql.checkRows(2) - def queryTinyintCol(self, tb_name): + def queryTinyintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c1 > 1' + query_sql = f'select {select_elm} from {tb_name} where c1 > 1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c1 >= 2' + query_sql = f'select {select_elm} from {tb_name} where c1 >= 2' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c1 < 2' + query_sql = f'select {select_elm} from {tb_name} where c1 < 2' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c1 <= 2' + query_sql = f'select {select_elm} from {tb_name} where c1 <= 2' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c1 = 2' + query_sql = f'select {select_elm} from {tb_name} where c1 = 2' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c1 != 1' + query_sql = f'select {select_elm} from {tb_name} where c1 != 1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c1 <> 2' + query_sql = f'select {select_elm} from {tb_name} where c1 <> 2' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c1 is null' + query_sql = f'select {select_elm} from {tb_name} where c1 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c1 is not null' + query_sql = f'select {select_elm} from {tb_name} where c1 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c1 between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c1 between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c1 not between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c1 not between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c1 in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c1 in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c1 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c1 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c1 > 0 and c1 >= 1 and c1 < 2 and c1 <= 3 and c1 =1 and c1 != 5 and c1 <> 4 and c1 is not null and c1 between 1 and 2 and c1 not between 2 and 3 and c1 in (1,2) and c1 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c1 > 0 and c1 >= 1 and c1 < 2 and c1 <= 3 and c1 =1 and c1 != 5 and c1 <> 4 and c1 is not null and c1 between 1 and 2 and c1 not between 2 and 3 and c1 in (1,2) and c1 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c1 > 2 or c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 or c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' + query_sql = f'select {select_elm} from {tb_name} where c1 > 2 or c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 or c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c1 > 2 and c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 and c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' + query_sql = f'select {select_elm} from {tb_name} where c1 > 2 and c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 and c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c1 > 2 and c1 >= 3 or c1 < 1 or c1 <= 0 or c1 =2 or c1 != 1 or c1 <> 1 and c1 is null or c1 between 2 and 3 and c1 not between 1 and 1 and c1 in (2, 3) and c1 not in (1, 2)' res = tdSql.query(query_sql) tdSql.checkRows(1) - def queryUtinyintCol(self, tb_name): + def queryUtinyintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c10 > 10' + query_sql = f'select {select_elm} from {tb_name} where c10 > 10' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c10 >= 10' + query_sql = f'select {select_elm} from {tb_name} where c10 >= 10' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c10 < 2' + query_sql = f'select {select_elm} from {tb_name} where c10 < 2' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c10 <= 2' + query_sql = f'select {select_elm} from {tb_name} where c10 <= 2' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c10 = 2' + query_sql = f'select {select_elm} from {tb_name} where c10 = 2' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c10 != 11' + query_sql = f'select {select_elm} from {tb_name} where c10 != 11' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c10 <> 2' + query_sql = f'select {select_elm} from {tb_name} where c10 <> 2' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c10 is null' + query_sql = f'select {select_elm} from {tb_name} where c10 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c10 is not null' + query_sql = f'select {select_elm} from {tb_name} where c10 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c10 between 2 and 4' + query_sql = f'select {select_elm} from {tb_name} where c10 between 2 and 4' tdSql.query(query_sql) tdSql.checkRows(3) - tdSql.checkEqual(self.queryLastC10(query_sql), 4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c10 not between 2 and 4' + query_sql = f'select {select_elm} from {tb_name} where c10 not between 2 and 4' tdSql.query(query_sql) tdSql.checkRows(8) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c10 in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c10 in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 3) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c10 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c10 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c10 > 0 and c10 >= 1 and c10 < 2 and c10 <= 3 and c10 =1 and c10 != 5 and c10 <> 4 and c10 is not null and c10 between 1 and 2 and c10 not between 2 and 3 and c10 in (1,2) and c10 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c10 > 0 and c10 >= 1 and c10 < 2 and c10 <= 3 and c10 =1 and c10 != 5 and c10 <> 4 and c10 is not null and c10 between 1 and 2 and c10 not between 2 and 3 and c10 in (1,2) and c10 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c10 > 2 or c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 or c10 is null or c10 between 2 and 3 or c10 not between 1 and 1 or c10 in (2, 3) or c10 not in (1, 2)' + query_sql = f'select {select_elm} from {tb_name} where c10 > 2 or c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 or c10 is null or c10 between 2 and 3 or c10 not between 1 and 1 or c10 in (2, 3) or c10 not in (1, 2)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c10 > 2 and c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 and c10 is null or c10 between 2 and 3 and c10 not between 1 and 1 and c10 in (2, 3) and c10 not in (1, 2)' + query_sql = f'select {select_elm} from {tb_name} where c10 > 2 and c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 and c10 is null or c10 between 2 and 3 and c10 not between 1 and 1 and c10 in (2, 3) and c10 not in (1, 2)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c10 > 2 and c10 >= 3 or c10 < 1 or c10 <= 0 or c10 =2 or c10 != 1 or c10 <> 1 and c10 is null or c10 between 2 and 3 and c10 not between 1 and 1 and c10 in (2, 3) and c10 not in (1, 2)' res = tdSql.query(query_sql) tdSql.checkRows(10) - def querySmallintCol(self, tb_name): + def querySmallintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c2 > 2' + query_sql = f'select {select_elm} from {tb_name} where c2 > 2' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c2 >= 3' + query_sql = f'select {select_elm} from {tb_name} where c2 >= 3' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c2 < 3' + query_sql = f'select {select_elm} from {tb_name} where c2 < 3' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c2 <= 3' + query_sql = f'select {select_elm} from {tb_name} where c2 <= 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c2 = 3' + query_sql = f'select {select_elm} from {tb_name} where c2 = 3' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c2 != 1' + query_sql = f'select {select_elm} from {tb_name} where c2 != 1' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c2 <> 2' + query_sql = f'select {select_elm} from {tb_name} where c2 <> 2' tdSql.query(query_sql) tdSql.checkRows(3) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c2 is null' + query_sql = f'select {select_elm} from {tb_name} where c2 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c2 is not null' + query_sql = f'select {select_elm} from {tb_name} where c2 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c2 between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c2 between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c2 not between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c2 not between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c2 in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c2 in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c2 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c2 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c2 > 0 and c2 >= 1 and c2 < 4 and c2 <= 3 and c2 != 2 and c2 <> 2 and c2 = 3 and c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c2 > 0 and c2 >= 1 and c2 < 4 and c2 <= 3 and c2 != 2 and c2 <> 2 and c2 = 3 and c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c2 > 4 or c2 >= 3 or c2 < 1 or c2 <= 0 or c2 != 2 or c2 <> 2 or c2 = 3 or c2 is null or c2 between 3 and 4 or c2 not between 1 and 3 or c2 in (3,4) or c2 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c2 > 4 or c2 >= 3 or c2 < 1 or c2 <= 0 or c2 != 2 or c2 <> 2 or c2 = 3 or c2 is null or c2 between 3 and 4 or c2 not between 1 and 3 or c2 in (3,4) or c2 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(3) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryUsmallintCol(self, tb_name): + def queryUsmallintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c11 > 11' + query_sql = f'select {select_elm} from {tb_name} where c11 > 11' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c11 >= 11' + query_sql = f'select {select_elm} from {tb_name} where c11 >= 11' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c11 < 3' + query_sql = f'select {select_elm} from {tb_name} where c11 < 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c11 <= 3' + query_sql = f'select {select_elm} from {tb_name} where c11 <= 3' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c11 = 3' + query_sql = f'select {select_elm} from {tb_name} where c11 = 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c11 != 1' + query_sql = f'select {select_elm} from {tb_name} where c11 != 1' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c11 <> 2' + query_sql = f'select {select_elm} from {tb_name} where c11 <> 2' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c11 is null' + query_sql = f'select {select_elm} from {tb_name} where c11 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c11 is not null' + query_sql = f'select {select_elm} from {tb_name} where c11 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c11 between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c11 between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c11 not between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c11 not between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c11 in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c11 in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c11 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c11 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c11 > 0 and c11 >= 1 and c11 < 4 and c11 <= 3 and c11 != 2 and c11 <> 2 and c11 = 3 and c11 is not null and c11 between 2 and 3 and c11 not between 1 and 2 and c11 in (2,3) and c11 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c11 > 0 and c11 >= 1 and c11 < 4 and c11 <= 3 and c11 != 2 and c11 <> 2 and c11 = 3 and c11 is not null and c11 between 2 and 3 and c11 not between 1 and 2 and c11 in (2,3) and c11 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c11 > 4 or c11 >= 3 or c11 < 1 or c11 <= 0 or c11 != 2 or c11 <> 2 or c11 = 3 or c11 is null or c11 between 3 and 4 or c11 not between 1 and 3 or c11 in (3,4) or c11 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c11 > 4 or c11 >= 3 or c11 < 1 or c11 <= 0 or c11 != 2 or c11 <> 2 or c11 = 3 or c11 is null or c11 between 3 and 4 or c11 not between 1 and 3 or c11 in (3,4) or c11 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c11 > 0 and c11 >= 1 or c11 < 4 and c11 <= 3 and c11 != 1 and c11 <> 2 and c11 = 3 or c11 is not null and c11 between 2 and 3 and c11 not between 1 and 2 and c11 in (2,3) and c11 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c11 > 0 and c11 >= 1 or c11 < 4 and c11 <= 3 and c11 != 1 and c11 <> 2 and c11 = 3 or c11 is not null and c11 between 2 and 3 and c11 not between 1 and 2 and c11 in (2,3) and c11 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c2 > 0 and c2 >= 1 or c2 < 4 and c2 <= 3 and c2 != 1 and c2 <> 2 and c2 = 3 or c2 is not null and c2 between 2 and 3 and c2 not between 1 and 2 and c2 in (2,3) and c2 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryIntCol(self, tb_name): + def queryIntCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c3 > 4' + query_sql = f'select {select_elm} from {tb_name} where c3 > 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c3 >= 4' + query_sql = f'select {select_elm} from {tb_name} where c3 >= 4' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c3 < 4' + query_sql = f'select {select_elm} from {tb_name} where c3 < 4' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c3 <= 4' + query_sql = f'select {select_elm} from {tb_name} where c3 <= 4' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c3 = 5' + query_sql = f'select {select_elm} from {tb_name} where c3 = 5' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c3 != 5' + query_sql = f'select {select_elm} from {tb_name} where c3 != 5' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c3 <> 1' + query_sql = f'select {select_elm} from {tb_name} where c3 <> 1' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c3 is null' + query_sql = f'select {select_elm} from {tb_name} where c3 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c3 is not null' + query_sql = f'select {select_elm} from {tb_name} where c3 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c3 between 1 and 2' + query_sql = f'select {select_elm} from {tb_name} where c3 between 1 and 2' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c3 not between 1 and 2' + query_sql = f'select {select_elm} from {tb_name} where c3 not between 1 and 2' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c3 in (1, 2)' + query_sql = f'select {select_elm} from {tb_name} where c3 in (1, 2)' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c3 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c3 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c3 > 0 and c3 >= 1 and c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 and c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c3 > 0 and c3 >= 1 and c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 and c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c3 > 4 or c3 >= 3 or c3 < 1 or c3 <= 0 or c3 != 1 or c3 <> 1 or c3 = 4 or c3 is null or c3 between 3 and 4 or c3 not between 1 and 3 or c3 in (3,4) or c3 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c3 > 4 or c3 >= 3 or c3 < 1 or c3 <= 0 or c3 != 1 or c3 <> 1 or c3 = 4 or c3 is null or c3 between 3 and 4 or c3 not between 1 and 3 or c3 in (3,4) or c3 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryUintCol(self, tb_name): + def queryUintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c12 > 12' + query_sql = f'select {select_elm} from {tb_name} where c12 > 12' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c12 >= 12' + query_sql = f'select {select_elm} from {tb_name} where c12 >= 12' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c12 < 4' + query_sql = f'select {select_elm} from {tb_name} where c12 < 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c12 <= 4' + query_sql = f'select {select_elm} from {tb_name} where c12 <= 4' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c12 = 5' + query_sql = f'select {select_elm} from {tb_name} where c12 = 5' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 3) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c12 != 5' + query_sql = f'select {select_elm} from {tb_name} where c12 != 5' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c12 <> 1' + query_sql = f'select {select_elm} from {tb_name} where c12 <> 1' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c12 is null' + query_sql = f'select {select_elm} from {tb_name} where c12 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c12 is not null' + query_sql = f'select {select_elm} from {tb_name} where c12 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c12 between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c12 between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c12 not between 1 and 2' + query_sql = f'select {select_elm} from {tb_name} where c12 not between 1 and 2' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c12 in (3, 2)' + query_sql = f'select {select_elm} from {tb_name} where c12 in (3, 2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c12 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c12 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c12 > 0 and c12 >= 1 and c12 < 5 and c12 <= 4 and c12 != 2 and c12 <> 2 and c12 = 4 and c12 is not null and c12 between 2 and 4 and c12 not between 1 and 2 and c12 in (2,4) and c12 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c12 > 0 and c12 >= 1 and c12 < 5 and c12 <= 4 and c12 != 2 and c12 <> 2 and c12 = 4 and c12 is not null and c12 between 2 and 4 and c12 not between 1 and 2 and c12 in (2,4) and c12 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c12 > 4 or c12 >= 3 or c12 < 1 or c12 <= 0 or c12 != 1 or c12 <> 1 or c12 = 4 or c12 is null or c12 between 3 and 4 or c12 not between 1 and 3 or c12 in (3,4) or c12 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c12 > 4 or c12 >= 3 or c12 < 1 or c12 <= 0 or c12 != 1 or c12 <> 1 or c12 = 4 or c12 is null or c12 between 3 and 4 or c12 not between 1 and 3 or c12 in (3,4) or c12 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c12 > 0 and c12 >= 1 or c12 < 5 and c12 <= 4 and c12 != 2 and c12 <> 2 and c12 = 4 or c12 is not null and c12 between 2 and 4 and c12 not between 1 and 2 and c12 in (2,4) and c12 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c12 > 0 and c12 >= 1 or c12 < 5 and c12 <= 4 and c12 != 2 and c12 <> 2 and c12 = 4 or c12 is not null and c12 between 2 and 4 and c12 not between 1 and 2 and c12 in (2,4) and c12 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c3 > 0 and c3 >= 1 or c3 < 5 and c3 <= 4 and c3 != 2 and c3 <> 2 and c3 = 4 or c3 is not null and c3 between 2 and 4 and c3 not between 1 and 2 and c3 in (2,4) and c3 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryBigintCol(self, tb_name): + def queryBigintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c4 > 4' + query_sql = f'select {select_elm} from {tb_name} where c4 > 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c4 >= 4' + query_sql = f'select {select_elm} from {tb_name} where c4 >= 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c4 < 4' + query_sql = f'select {select_elm} from {tb_name} where c4 < 4' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c4 <= 3' + query_sql = f'select {select_elm} from {tb_name} where c4 <= 3' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c4 = 5' + query_sql = f'select {select_elm} from {tb_name} where c4 = 5' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c4 != 5' + query_sql = f'select {select_elm} from {tb_name} where c4 != 5' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c4 <> 3' + query_sql = f'select {select_elm} from {tb_name} where c4 <> 3' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c4 is null' + query_sql = f'select {select_elm} from {tb_name} where c4 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c4 is not null' + query_sql = f'select {select_elm} from {tb_name} where c4 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c4 between 4 and 5' + query_sql = f'select {select_elm} from {tb_name} where c4 between 4 and 5' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c4 not between 1 and 3' + query_sql = f'select {select_elm} from {tb_name} where c4 not between 1 and 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c4 in (1, 5)' + query_sql = f'select {select_elm} from {tb_name} where c4 in (1, 5)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c4 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c4 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c4 > 0 and c4 >= 1 and c4 < 6 and c4 <= 5 and c4 != 2 and c4 <> 2 and c4 = 5 and c4 is not null and c4 between 2 and 5 and c4 not between 1 and 2 and c4 in (2,5) and c4 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c4 > 0 and c4 >= 1 and c4 < 6 and c4 <= 5 and c4 != 2 and c4 <> 2 and c4 = 5 and c4 is not null and c4 between 2 and 5 and c4 not between 1 and 2 and c4 in (2,5) and c4 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c4 > 5 or c4 >= 4 or c4 < 1 or c4 <= 0 or c4 != 3 or c4 <> 3 or c4 = 5 or c4 is null or c4 between 4 and 5 or c4 not between 1 and 3 or c4 in (4,5) or c4 not in (1,3)' + query_sql = f'select {select_elm} from {tb_name} where c4 > 5 or c4 >= 4 or c4 < 1 or c4 <= 0 or c4 != 3 or c4 <> 3 or c4 = 5 or c4 is null or c4 between 4 and 5 or c4 not between 1 and 3 or c4 in (4,5) or c4 not in (1,3)' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 5) + tdSql.checkEqual(self.queryLastC10(query_sql), 5) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryUbigintCol(self, tb_name): + def queryUbigintCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c13 > 4' + query_sql = f'select {select_elm} from {tb_name} where c13 > 4' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c13 >= 4' + query_sql = f'select {select_elm} from {tb_name} where c13 >= 4' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c13 < 5' + query_sql = f'select {select_elm} from {tb_name} where c13 < 5' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c13 <= 4' + query_sql = f'select {select_elm} from {tb_name} where c13 <= 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 1) + tdSql.checkEqual(self.queryLastC10(query_sql), 1) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c13 = 5' + query_sql = f'select {select_elm} from {tb_name} where c13 = 5' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c13 != 5' + query_sql = f'select {select_elm} from {tb_name} where c13 != 5' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c13 <> 3' + query_sql = f'select {select_elm} from {tb_name} where c13 <> 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c13 is null' + query_sql = f'select {select_elm} from {tb_name} where c13 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c13 is not null' + query_sql = f'select {select_elm} from {tb_name} where c13 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c13 between 4 and 5' + query_sql = f'select {select_elm} from {tb_name} where c13 between 4 and 5' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c13 not between 1 and 3' + query_sql = f'select {select_elm} from {tb_name} where c13 not between 1 and 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c13 in (1, 5)' + query_sql = f'select {select_elm} from {tb_name} where c13 in (1, 5)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c13 not in (2, 6)' + query_sql = f'select {select_elm} from {tb_name} where c13 not in (2, 6)' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c13 > 0 and c13 >= 1 and c13 < 6 and c13 <= 5 and c13 != 2 and c13 <> 2 and c13 = 5 and c13 is not null and c13 between 2 and 5 and c13 not between 1 and 2 and c13 in (2,5) and c13 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c13 > 0 and c13 >= 1 and c13 < 6 and c13 <= 5 and c13 != 2 and c13 <> 2 and c13 = 5 and c13 is not null and c13 between 2 and 5 and c13 not between 1 and 2 and c13 in (2,5) and c13 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c13 > 5 or c13 >= 4 or c13 < 1 or c13 <= 0 or c13 != 3 or c13 <> 3 or c13 = 5 or c13 is null or c13 between 4 and 5 or c13 not between 1 and 3 or c13 in (4,5) or c13 not in (1,3)' + query_sql = f'select {select_elm} from {tb_name} where c13 > 5 or c13 >= 4 or c13 < 1 or c13 <= 0 or c13 != 3 or c13 <> 3 or c13 = 5 or c13 is null or c13 between 4 and 5 or c13 not between 1 and 3 or c13 in (4,5) or c13 not in (1,3)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c13 > 0 and c13 >= 1 or c13 < 5 and c13 <= 4 and c13 != 2 and c13 <> 2 and c13 = 4 or c13 is not null and c13 between 2 and 4 and c13 not between 1 and 2 and c13 in (2,4) and c13 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c13 > 0 and c13 >= 1 or c13 < 5 and c13 <= 4 and c13 != 2 and c13 <> 2 and c13 = 4 or c13 is not null and c13 between 2 and 4 and c13 not between 1 and 2 and c13 in (2,4) and c13 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c4 > 0 and c4 >= 1 or c4 < 5 and c4 <= 4 and c4 != 2 and c4 <> 2 and c4 = 4 or c4 is not null and c4 between 2 and 4 and c4 not between 1 and 2 and c4 in (2,4) and c4 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryFloatCol(self, tb_name): + def queryFloatCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c5 > 1.1' + query_sql = f'select {select_elm} from {tb_name} where c5 > 1.1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c5 >= 1.1' + query_sql = f'select {select_elm} from {tb_name} where c5 >= 1.1' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c5 < 1.2' + query_sql = f'select {select_elm} from {tb_name} where c5 < 1.2' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c5 <= 6.6' + query_sql = f'select {select_elm} from {tb_name} where c5 <= 6.6' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c5 = 6.6' + query_sql = f'select {select_elm} from {tb_name} where c5 = 6.6' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c5 != 1.1' + query_sql = f'select {select_elm} from {tb_name} where c5 != 1.1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c5 <> 3' + query_sql = f'select {select_elm} from {tb_name} where c5 <> 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c5 is null' + query_sql = f'select {select_elm} from {tb_name} where c5 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c5 is not null' + query_sql = f'select {select_elm} from {tb_name} where c5 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c5 between 4 and 6.6' + query_sql = f'select {select_elm} from {tb_name} where c5 between 4 and 6.6' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c5 not between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c5 not between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c5 in (1, 6.6)' + query_sql = f'select {select_elm} from {tb_name} where c5 in (1, 6.6)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c5 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c5 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c5 > 0 and c5 >= 1 and c5 < 7 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 6.6 and c5 is not null and c5 between 2 and 6.6 and c5 not between 1 and 2 and c5 in (2,6.6) and c5 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c5 > 0 and c5 >= 1 and c5 < 7 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 6.6 and c5 is not null and c5 between 2 and 6.6 and c5 not between 1 and 2 and c5 in (2,6.6) and c5 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c5 > 6 or c5 >= 6.6 or c5 < 1 or c5 <= 0 or c5 != 1.1 or c5 <> 1.1 or c5 = 5 or c5 is null or c5 between 4 and 5 or c5 not between 1 and 3 or c5 in (4,5) or c5 not in (1.1,3)' + query_sql = f'select {select_elm} from {tb_name} where c5 > 6 or c5 >= 6.6 or c5 < 1 or c5 <= 0 or c5 != 1.1 or c5 <> 1.1 or c5 = 5 or c5 is null or c5 between 4 and 5 or c5 not between 1 and 3 or c5 in (4,5) or c5 not in (1.1,3)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 6) + tdSql.checkEqual(self.queryLastC10(query_sql), 6) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c5 > 0 and c5 >= 1 or c5 < 5 and c5 <= 6.6 and c5 != 2 and c5 <> 2 and c5 = 4 or c5 is not null and c5 between 2 and 4 and c5 not between 1 and 2 and c5 in (2,4) and c5 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryDoubleCol(self, tb_name): + def queryDoubleCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c6 > 1.1' + query_sql = f'select {select_elm} from {tb_name} where c6 > 1.1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c6 >= 1.1' + query_sql = f'select {select_elm} from {tb_name} where c6 >= 1.1' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c6 < 1.2' + query_sql = f'select {select_elm} from {tb_name} where c6 < 1.2' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c6 <= 7.7' + query_sql = f'select {select_elm} from {tb_name} where c6 <= 7.7' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c6 = 7.7' + query_sql = f'select {select_elm} from {tb_name} where c6 = 7.7' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c6 != 1.1' + query_sql = f'select {select_elm} from {tb_name} where c6 != 1.1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c6 <> 3' + query_sql = f'select {select_elm} from {tb_name} where c6 <> 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c6 is null' + query_sql = f'select {select_elm} from {tb_name} where c6 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c6 is not null' + query_sql = f'select {select_elm} from {tb_name} where c6 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c6 between 4 and 7.7' + query_sql = f'select {select_elm} from {tb_name} where c6 between 4 and 7.7' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c6 not between 2 and 3' + query_sql = f'select {select_elm} from {tb_name} where c6 not between 2 and 3' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c6 in (1, 7.7)' + query_sql = f'select {select_elm} from {tb_name} where c6 in (1, 7.7)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c6 not in (2, 3)' + query_sql = f'select {select_elm} from {tb_name} where c6 not in (2, 3)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c6 > 0 and c6 >= 1 and c6 < 8 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 7.7 and c6 is not null and c6 between 2 and 7.7 and c6 not between 1 and 2 and c6 in (2,7.7) and c6 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c6 > 0 and c6 >= 1 and c6 < 8 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 7.7 and c6 is not null and c6 between 2 and 7.7 and c6 not between 1 and 2 and c6 in (2,7.7) and c6 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c6 > 7 or c6 >= 7.7 or c6 < 1 or c6 <= 0 or c6 != 1.1 or c6 <> 1.1 or c6 = 5 or c6 is null or c6 between 4 and 5 or c6 not between 1 and 3 or c6 in (4,5) or c6 not in (1.1,3)' + query_sql = f'select {select_elm} from {tb_name} where c6 > 7 or c6 >= 7.7 or c6 < 1 or c6 <= 0 or c6 != 1.1 or c6 <> 1.1 or c6 = 5 or c6 is null or c6 between 4 and 5 or c6 not between 1 and 3 or c6 in (4,5) or c6 not in (1.1,3)' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' + query_sql = f'select {select_elm} from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c6 > 0 and c6 >= 1 or c6 < 5 and c6 <= 7.7 and c6 != 2 and c6 <> 2 and c6 = 4 or c6 is not null and c6 between 2 and 4 and c6 not between 1 and 2 and c6 in (2,4) and c6 not in (1,2)' tdSql.query(query_sql) tdSql.checkRows(11) - def queryBinaryCol(self, tb_name): + def queryBinaryCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c7 > "binary"' + query_sql = f'select {select_elm} from {tb_name} where c7 > "binary"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c7 >= "binary8"' + query_sql = f'select {select_elm} from {tb_name} where c7 >= "binary8"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c7 < "binary8"' + query_sql = f'select {select_elm} from {tb_name} where c7 < "binary8"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c7 <= "binary8"' + query_sql = f'select {select_elm} from {tb_name} where c7 <= "binary8"' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c7 = "binary8"' + query_sql = f'select {select_elm} from {tb_name} where c7 = "binary8"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c7 != "binary"' + query_sql = f'select {select_elm} from {tb_name} where c7 != "binary"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c7 <> "binary8"' + query_sql = f'select {select_elm} from {tb_name} where c7 <> "binary8"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c7 is null' + query_sql = f'select {select_elm} from {tb_name} where c7 is null' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is not null - query_sql = f'select * from {tb_name} where c7 is not null' + query_sql = f'select {select_elm} from {tb_name} where c7 is not null' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c7 between "bi" and "binary7"' + query_sql = f'select {select_elm} from {tb_name} where c7 between "bi" and "binary7"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c7 not between "bi" and "binary7"' + query_sql = f'select {select_elm} from {tb_name} where c7 not between "bi" and "binary7"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c7 in ("binar", "binary8")' + query_sql = f'select {select_elm} from {tb_name} where c7 in ("binar", "binary8")' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # not in - query_sql = f'select * from {tb_name} where c7 not in ("bi", "binary8")' + query_sql = f'select {select_elm} from {tb_name} where c7 not in ("bi", "binary8")' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # match - query_sql = f'select * from {tb_name} where c7 match "binary[28]"' + query_sql = f'select {select_elm} from {tb_name} where c7 match "binary[28]"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # nmatch - query_sql = f'select * from {tb_name} where c7 nmatch "binary[28]"' + query_sql = f'select {select_elm} from {tb_name} where c7 nmatch "binary[28]"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # ! bug TD-15324 not in - # query_sql = f'select * from {tb_name} where c7 not in (1, "binary8")' + # query_sql = f'select {select_elm} from {tb_name} where c7 not in (1, "binary8")' # tdSql.query(query_sql) # tdSql.checkRows(9) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and - query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" and c7 < "binary9" and c7 <= "binary8" and c7 != "binary" and c7 <> "333" and c7 = "binary8" and c7 is not null and c7 between "binary" and "binary8" and c7 not between 1 and 2 and c7 in ("binary","binary8") and c7 not in ("binary") and c7 match "binary[28]" and c7 nmatch "binary[2]"' + query_sql = f'select {select_elm} from {tb_name} where c7 > "binary" and c7 >= "binary8" and c7 < "binary9" and c7 <= "binary8" and c7 != "binary" and c7 <> "333" and c7 = "binary8" and c7 is not null and c7 between "binary" and "binary8" and c7 not between 1 and 2 and c7 in ("binary","binary8") and c7 not in ("binary") and c7 match "binary[28]" and c7 nmatch "binary[2]"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # or - query_sql = f'select * from {tb_name} where c7 > "binary" or c7 >= "binary8" or c7 < "binary" or c7 <= "binar" or c7 != "binary" or c7 <> "binary" or c7 = 5 or c7 is null or c7 between 4 and 5 or c7 not between "binary" and "binary7" or c7 in ("binary2222") or c7 not in ("binary") or c7 match "binary[28]" or c7 nmatch "binary"' + query_sql = f'select {select_elm} from {tb_name} where c7 > "binary" or c7 >= "binary8" or c7 < "binary" or c7 <= "binar" or c7 != "binary" or c7 <> "binary" or c7 = 5 or c7 is null or c7 between 4 and 5 or c7 not between "binary" and "binary7" or c7 in ("binary2222") or c7 not in ("binary") or c7 match "binary[28]" or c7 nmatch "binary"' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # and or - query_sql = f'select * from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2) or c7 match "binary[28]" or c7 nmatch "binary"' + query_sql = f'select {select_elm} from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2) or c7 match "binary[28]" or c7 nmatch "binary"' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c7 > "binary" and c7 >= "binary8" or c7 < "binary9" and c7 <= "binary" and c7 != 2 and c7 <> 2 and c7 = 4 or c7 is not null and c7 between 2 and 4 and c7 not between 1 and 2 and c7 in (2,4) and c7 not in (1,2) or c7 match "binary[28]" or c7 nmatch "binary"' tdSql.query(query_sql) tdSql.checkRows(11) - def queryNcharCol(self, tb_name): + def queryNcharCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # > - query_sql = f'select * from {tb_name} where c8 > "nchar"' + query_sql = f'select {select_elm} from {tb_name} where c8 > "nchar"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # >= - query_sql = f'select * from {tb_name} where c8 >= "nchar9"' + query_sql = f'select {select_elm} from {tb_name} where c8 >= "nchar9"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # < - query_sql = f'select * from {tb_name} where c8 < "nchar9"' + query_sql = f'select {select_elm} from {tb_name} where c8 < "nchar9"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # <= - query_sql = f'select * from {tb_name} where c8 <= "nchar9"' + query_sql = f'select {select_elm} from {tb_name} where c8 <= "nchar9"' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # = - query_sql = f'select * from {tb_name} where c8 = "nchar9"' + query_sql = f'select {select_elm} from {tb_name} where c8 = "nchar9"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c8 != "nchar"' + query_sql = f'select {select_elm} from {tb_name} where c8 != "nchar"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c8 <> "nchar9"' + query_sql = f'select {select_elm} from {tb_name} where c8 <> "nchar9"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c8 is null' + query_sql = f'select {select_elm} from {tb_name} where c8 is null' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is not null - query_sql = f'select * from {tb_name} where c8 is not null' + query_sql = f'select {select_elm} from {tb_name} where c8 is not null' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # between and - query_sql = f'select * from {tb_name} where c8 between "na" and "nchar8"' + query_sql = f'select {select_elm} from {tb_name} where c8 between "na" and "nchar8"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # not between and - query_sql = f'select * from {tb_name} where c8 not between "na" and "nchar8"' + query_sql = f'select {select_elm} from {tb_name} where c8 not between "na" and "nchar8"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # ! bug TD-15240 in - # query_sql = f'select * from {tb_name} where c8 in ("ncha", "nchar9")' + # query_sql = f'select {select_elm} from {tb_name} where c8 in ("ncha", "nchar9")' # tdSql.query(query_sql) # tdSql.checkRows(1) - # tdSql.checkEqual(self.queryLastC10(query_sql), 9) + # tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # not in - # query_sql = f'select * from {tb_name} where c8 not in ("na", "nchar9")' + # query_sql = f'select {select_elm} from {tb_name} where c8 not in ("na", "nchar9")' # tdSql.query(query_sql) # tdSql.checkRows(9) - # tdSql.checkEqual(self.queryLastC10(query_sql), 10) + # tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # ! bug TD-15324 not in - # query_sql = f'select * from {tb_name} where c8 not in (1, "nchar9")' + # query_sql = f'select {select_elm} from {tb_name} where c8 not in (1, "nchar9")' # tdSql.query(query_sql) # tdSql.checkRows(9) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # match - query_sql = f'select * from {tb_name} where c8 match "nchar[19]"' + query_sql = f'select {select_elm} from {tb_name} where c8 match "nchar[19]"' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # nmatch - query_sql = f'select * from {tb_name} where c8 nmatch "nchar[19]"' + query_sql = f'select {select_elm} from {tb_name} where c8 nmatch "nchar[19]"' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False # and - # query_sql = f'select * from {tb_name} where c8 > "nchar" and c8 >= "nchar8" and c8 < "nchar9" and c8 <= "nchar8" and c8 != "nchar" and c8 <> "333" and c8 = "nchar8" and c8 is not null and c8 between "nchar" and "nchar8" and c8 not between 1 and 2 and c8 in ("nchar","nchar8") and c8 not in ("nchar")' + # query_sql = f'select {select_elm} from {tb_name} where c8 > "nchar" and c8 >= "nchar8" and c8 < "nchar9" and c8 <= "nchar8" and c8 != "nchar" and c8 <> "333" and c8 = "nchar8" and c8 is not null and c8 between "nchar" and "nchar8" and c8 not between 1 and 2 and c8 in ("nchar","nchar8") and c8 not in ("nchar")' # tdSql.query(query_sql) # tdSql.checkRows(1) - # tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # # or - # query_sql = f'select * from {tb_name} where c8 > "nchar" or c8 >= "nchar8" or c8 < "nchar" or c8 <= "binar" or c8 != "nchar" or c8 <> "nchar" or c8 = 5 or c8 is null or c8 between 4 and 5 or c8 not between "nchar" and "nchar7" or c8 in ("nchar2222") or c8 not in ("nchar")' + # query_sql = f'select {select_elm} from {tb_name} where c8 > "nchar" or c8 >= "nchar8" or c8 < "nchar" or c8 <= "binar" or c8 != "nchar" or c8 <> "nchar" or c8 = 5 or c8 is null or c8 between 4 and 5 or c8 not between "nchar" and "nchar7" or c8 in ("nchar2222") or c8 not in ("nchar")' # tdSql.query(query_sql) # tdSql.checkRows(2) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # # and or - # query_sql = f'select * from {tb_name} where c8 > "nchar" and c8 >= "nchar8" or c8 < "nchar9" and c8 <= "nchar" and c8 != 2 and c8 <> 2 and c8 = 4 or c8 is not null and c8 between 2 and 4 and c8 not between 1 and 2 and c8 in (2,4) and c8 not in (1,2)' + # query_sql = f'select {select_elm} from {tb_name} where c8 > "nchar" and c8 >= "nchar8" or c8 < "nchar9" and c8 <= "nchar" and c8 != 2 and c8 <> 2 and c8 = 4 or c8 is not null and c8 between 2 and 4 and c8 not between 1 and 2 and c8 in (2,4) and c8 not in (1,2)' # tdSql.query(query_sql) # tdSql.checkRows(11) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c8 > "nchar" and c8 >= "nchar8" or c8 < "nchar9" and c8 <= "nchar" and c8 != 2 and c8 <> 2 and c8 = 4 or c8 is not null and c8 between 2 and 4 and c8 not between 1 and 2 and c8 in (2,4) and c8 not in (1,2)' # tdSql.query(query_sql) # tdSql.checkRows(11) - def queryBoolCol(self, tb_name): + def queryBoolCol(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm # = - query_sql = f'select * from {tb_name} where c9 = false' + query_sql = f'select {select_elm} from {tb_name} where c9 = false' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # != - query_sql = f'select * from {tb_name} where c9 != false' + query_sql = f'select {select_elm} from {tb_name} where c9 != false' tdSql.query(query_sql) tdSql.checkRows(9) - tdSql.checkEqual(self.queryLastC10(query_sql), 9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # <> - query_sql = f'select * from {tb_name} where c9 <> true' + query_sql = f'select {select_elm} from {tb_name} where c9 <> true' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # is null - query_sql = f'select * from {tb_name} where c9 is null' + query_sql = f'select {select_elm} from {tb_name} where c9 is null' tdSql.query(query_sql) tdSql.checkRows(0) # is not null - query_sql = f'select * from {tb_name} where c9 is not null' + query_sql = f'select {select_elm} from {tb_name} where c9 is not null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # in - query_sql = f'select * from {tb_name} where c9 in ("binar", false)' + query_sql = f'select {select_elm} from {tb_name} where c9 in ("binar", false)' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # # not in # # ! bug TD-15327 - # query_sql = f'select * from {tb_name} where c9 not in ("true")' + # query_sql = f'select {select_elm} from {tb_name} where c9 not in ("true")' # tdSql.query(query_sql) # tdSql.checkRows(2) - # tdSql.checkEqual(self.queryLastC10(query_sql), 2) + # tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False # # ! bug TD-15327 # # and - # query_sql = f'select * from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 = "true" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' + # query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 = "true" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' # tdSql.query(query_sql) # tdSql.checkRows(1) - # tdSql.checkEqual(self.queryLastC10(query_sql), 8) + # tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False # # or - # query_sql = f'select * from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' + # query_sql = f'select {select_elm} from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' # tdSql.query(query_sql) # tdSql.checkRows(2) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # # and or - # query_sql = f'select * from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' + # query_sql = f'select {select_elm} from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' # tdSql.query(query_sql) # tdSql.checkRows(11) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) + # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' # tdSql.query(query_sql) # tdSql.checkRows(11) - def queryFullColType(self, tb_name): + def queryFullColType(self, tb_name, check_elm=None): + select_elm = "*" if check_elm is None else check_elm ## != or and - query_sql = f'select * from {tb_name} where c1 != 1 or c2 = 3' + query_sql = f'select {select_elm} from {tb_name} where c1 != 1 or c2 = 3' tdSql.query(query_sql) tdSql.checkRows(3) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 != 1 and c2 = 2' + query_sql = f'select {select_elm} from {tb_name} where c1 != 1 and c2 = 2' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False ## <> or and - query_sql = f'select * from {tb_name} where c1 <> 1 or c3 = 3' + query_sql = f'select {select_elm} from {tb_name} where c1 <> 1 or c3 = 3' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 <> 2 and c3 = 4' + query_sql = f'select {select_elm} from {tb_name} where c1 <> 2 and c3 = 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) if select_elm == "*" else False ## >= or and - query_sql = f'select * from {tb_name} where c1 >= 2 or c3 = 4' + query_sql = f'select {select_elm} from {tb_name} where c1 >= 2 or c3 = 4' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 >= 2 and c3 = 1' + query_sql = f'select {select_elm} from {tb_name} where c1 >= 2 and c3 = 1' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 2) + tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False ## <= or and - query_sql = f'select * from {tb_name} where c1 <= 1 or c3 = 4' + query_sql = f'select {select_elm} from {tb_name} where c1 <= 1 or c3 = 4' tdSql.query(query_sql) tdSql.checkRows(10) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 <= 1 and c3 = 4' + query_sql = f'select {select_elm} from {tb_name} where c1 <= 1 and c3 = 4' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 4) + tdSql.checkEqual(self.queryLastC10(query_sql), 4) if select_elm == "*" else False ## <> or and is Null - query_sql = f'select * from {tb_name} where c1 <> 1 or c7 is Null' + query_sql = f'select {select_elm} from {tb_name} where c1 <> 1 or c7 is Null' tdSql.query(query_sql) tdSql.checkRows(2) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 <> 2 and c7 is Null' + query_sql = f'select {select_elm} from {tb_name} where c1 <> 2 and c7 is Null' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False ## > or and is not Null - query_sql = f'select * from {tb_name} where c2 > 2 or c8 is not Null' + query_sql = f'select {select_elm} from {tb_name} where c2 > 2 or c8 is not Null' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c2 > 2 and c8 is not Null' + query_sql = f'select {select_elm} from {tb_name} where c2 > 2 and c8 is not Null' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 3) + tdSql.checkEqual(self.queryLastC10(query_sql), 3) if select_elm == "*" else False ## > or < or >= or <= or != or <> or = Null - query_sql = f'select * from {tb_name} where c1 > 1 or c2 < 2 or c3 >= 4 or c4 <= 2 or c5 != 1.1 or c6 <> 1.1 or c7 is Null' + query_sql = f'select {select_elm} from {tb_name} where c1 > 1 or c2 < 2 or c3 >= 4 or c4 <= 2 or c5 != 1.1 or c6 <> 1.1 or c7 is Null' tdSql.query(query_sql) tdSql.checkRows(8) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 = 1 and c2 > 1 and c3 >= 1 and c4 <= 5 and c5 != 6.6 and c6 <> 7.7 and c7 is Null' + query_sql = f'select {select_elm} from {tb_name} where c1 = 1 and c2 > 1 and c3 >= 1 and c4 <= 5 and c5 != 6.6 and c6 <> 7.7 and c7 is Null' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False ## tiny small int big or - query_sql = f'select * from {tb_name} where c1 = 2 or c2 = 3 or c3 = 4 or c4 = 5' + query_sql = f'select {select_elm} from {tb_name} where c1 = 2 or c2 = 3 or c3 = 4 or c4 = 5' tdSql.query(query_sql) tdSql.checkRows(5) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1 = 1 and c2 = 2 and c3 = 1 and c4 = 3' + query_sql = f'select {select_elm} from {tb_name} where c1 = 1 and c2 = 2 and c3 = 1 and c4 = 3' tdSql.query(query_sql) tdSql.checkRows(5) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False ## float double binary nchar bool or - query_sql = f'select * from {tb_name} where c5=6.6 or c6=7.7 or c7="binary8" or c8="nchar9" or c9=false' + query_sql = f'select {select_elm} from {tb_name} where c5=6.6 or c6=7.7 or c7="binary8" or c8="nchar9" or c9=false' tdSql.query(query_sql) tdSql.checkRows(6) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c5=1.1 and c6=7.7 and c7="binary" and c8="nchar" and c9=true' + query_sql = f'select {select_elm} from {tb_name} where c5=1.1 and c6=7.7 and c7="binary" and c8="nchar" and c9=true' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 7) + tdSql.checkEqual(self.queryLastC10(query_sql), 7) if select_elm == "*" else False ## all types or - query_sql = f'select * from {tb_name} where c1=2 or c2=3 or c3=4 or c4=5 or c5=6.6 or c6=7.7 or c7 nmatch "binary[134]" or c8="nchar9" or c9=false' + query_sql = f'select {select_elm} from {tb_name} where c1=2 or c2=3 or c3=4 or c4=5 or c5=6.6 or c6=7.7 or c7 nmatch "binary[134]" or c8="nchar9" or c9=false' tdSql.query(query_sql) tdSql.checkRows(11) - tdSql.checkEqual(self.queryLastC10(query_sql), 11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1=1 and c2=2 and c3=1 and c4=3 and c5=1.1 and c6=1.1 and c7 match "binary[28]" and c8 in ("nchar") and c9=true' + query_sql = f'select {select_elm} from {tb_name} where c1=1 and c2=2 and c3=1 and c4=3 and c5=1.1 and c6=1.1 and c7 match "binary[28]" and c8 in ("nchar") and c9=true' tdSql.query(query_sql) tdSql.checkRows(1) - tdSql.checkEqual(self.queryLastC10(query_sql), 8) + tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False - query_sql = f'select * from {tb_name} where c1=1 and c2=2 or c3=1 and c4=3 and c5=1.1 and c6=1.1 and c7 match "binary[28]" and c8 in ("nchar") and c9=true' + query_sql = f'select {select_elm} from {tb_name} where c1=1 and c2=2 or c3=1 and c4=3 and c5=1.1 and c6=1.1 and c7 match "binary[28]" and c8 in ("nchar") and c9=true' tdSql.query(query_sql) tdSql.checkRows(7) - tdSql.checkEqual(self.queryLastC10(query_sql), 10) + tdSql.checkEqual(self.queryLastC10(query_sql), 10) if select_elm == "*" else False def queryFullTagType(self, tb_name): ## != or and @@ -1975,46 +1990,39 @@ class TDTestCase: res = tdSql.query(query_sql, True) tdSql.checkRows(2) - def checkTbColTypeOperator(self): + def checkColType(self, tb_name, check_elm): + self.queryTinyintCol(tb_name, check_elm) + self.queryUtinyintCol(tb_name, check_elm) + self.querySmallintCol(tb_name, check_elm) + self.queryUsmallintCol(tb_name, check_elm) + self.queryIntCol(tb_name, check_elm) + self.queryUintCol(tb_name, check_elm) + self.queryBigintCol(tb_name, check_elm) + self.queryUbigintCol(tb_name, check_elm) + self.queryFloatCol(tb_name, check_elm) + self.queryDoubleCol(tb_name, check_elm) + self.queryBinaryCol(tb_name, check_elm) + self.queryNcharCol(tb_name, check_elm) + self.queryBoolCol(tb_name, check_elm) + self.queryFullColType(tb_name, check_elm) + + def checkTbColTypeOperator(self, check_elm): ''' Ordinary table full column type and operator ''' tb_name = self.initTb() - self.queryTinyintCol(tb_name) - self.queryUtinyintCol(tb_name) - self.querySmallintCol(tb_name) - self.queryUsmallintCol(tb_name) - self.queryIntCol(tb_name) - self.queryUintCol(tb_name) - self.queryBigintCol(tb_name) - self.queryUbigintCol(tb_name) - self.queryFloatCol(tb_name) - self.queryDoubleCol(tb_name) - self.queryBinaryCol(tb_name) - self.queryNcharCol(tb_name) - self.queryBoolCol(tb_name) - self.queryFullColType(tb_name) + self.checkColType(tb_name, check_elm) - def checkStbColTypeOperator(self): + def checkStbColTypeOperator(self, check_elm): ''' Super table full column type and operator ''' stb_name = self.initStb() tb_name = stb_name + "_sub_1" - self.queryTinyintCol(tb_name) - self.queryUtinyintCol(tb_name) - self.querySmallintCol(tb_name) - self.queryUsmallintCol(tb_name) - self.queryIntCol(tb_name) - self.queryUintCol(tb_name) - self.queryBigintCol(tb_name) - self.queryUbigintCol(tb_name) - self.queryFloatCol(tb_name) - self.queryDoubleCol(tb_name) - self.queryBinaryCol(tb_name) - self.queryNcharCol(tb_name) - self.queryBoolCol(tb_name) - self.queryFullColType(tb_name) + if check_elm is None: + self.checkColType(tb_name, check_elm) + else: + self.checkColType(stb_name, check_elm) def checkStbTagTypeOperator(self): ''' @@ -2102,8 +2110,10 @@ class TDTestCase: def run(self): tdSql.prepare() - # self.checkTbColTypeOperator() - self.checkStbColTypeOperator() + column_name = random.choice(["c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13"]) + for check_elm in [None, column_name]: + # self.checkTbColTypeOperator(check_elm) + self.checkStbColTypeOperator(check_elm) # self.checkStbTagTypeOperator() # self.checkTbTsCol() # self.checkStbTsTol() From 3cad99a178df2aecaad1542416a7f09bfa1672be Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 7 May 2022 12:21:00 +0000 Subject: [PATCH 05/18] refact --- source/dnode/vnode/src/tsdb/tsdbMemTable2.c | 46 ++++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c index e401782747..dbea55f633 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c @@ -76,6 +76,8 @@ struct SMemSkipListCurosr { #define SL_HEAD_NODE_FORWARD(n, l) SL_NODE_FORWARD(n, l) #define SL_TAIL_NODE_BACKWARD(n, l) SL_NODE_FORWARD(n, l) +static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl); + // SMemTable int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) { SMemTable *pMemTb = NULL; @@ -176,20 +178,19 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p // do insert data to SMemData SMemSkipListCurosr slc = {0}; - const uint8_t *p = pSubmitBlk->pData; - const uint8_t *pt; const STSRow *pRow; - uint64_t szRow; + uint32_t szRow; SDecoder decoder = {0}; - // tCoderInit(&coder, TD_LITTLE_ENDIAN, pSubmitBlk->pData, pSubmitBlk->nData, TD_DECODER); + tDecoderInit(&decoder, pSubmitBlk->pData, pSubmitBlk->nData); for (;;) { - // if (tDecodeIsEnd(&coder)) break; + if (tDecodeIsEnd(&decoder)) break; + + if (tDecodeBinary(&decoder, (const uint8_t **)&pRow, &szRow) < 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } - // if (tDecodeBinary(&coder, (const uint8_t **)&pRow, &szRow) < 0) { - // terrno = TSDB_CODE_INVALID_MSG; - // return -1; - // } // check the row (todo) // // move the cursor to position to write (todo) @@ -197,7 +198,9 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p // tsdbMemSkipListCursorMoveTo(&slc, pTSRow, version, &c); // ASSERT(c); - // // encode row + // encode row + int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); + // int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); // int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (p - pt); // pSlNode = vnodeBufPoolMalloc(pPool, tsize); @@ -215,7 +218,7 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p if (pRow->ts < pMemData->minKey) pMemData->minKey = pRow->ts; if (pRow->ts > pMemData->maxKey) pMemData->maxKey = pRow->ts; } - // tCoderClear(&coder); + tDecoderClear(&decoder); // tsdbMemSkipListCursorClose(&slc); // update status @@ -228,4 +231,25 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p if (pMemTb->maxVer == -1 || pMemTb->maxVer < version) pMemTb->maxVer = version; return 0; +} + +static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) { + int8_t level = 1; + const uint32_t factor = 4; + + if (pSl->size) { + while ((taosRandR(&pSl->seed) % factor) == 0 && level < pSl->maxLevel) { + level++; + } + + if (level > pSl->level) { + if (pSl->level < pSl->maxLevel) { + level = pSl->level + 1; + } else { + level = pSl->level; + } + } + } + + return level; } \ No newline at end of file From 291d6d25eb81f0bf80fa0d9db8c0dd155525d43c Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Sat, 7 May 2022 20:56:43 +0800 Subject: [PATCH 06/18] fix(query): fix invalid write for concat/concat_ws function TD-15319 TD-15346 --- source/libs/scalar/src/sclfunc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 77caf67a2b..5127ae534a 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -432,7 +432,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu if (pInput[i].numOfRows == 1) { inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * factor * (numOfRows - numOfNulls); } else { - inputLen += pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE; + inputLen += (pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE) * factor; } } @@ -510,7 +510,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p } else if (pInput[i].numOfRows == 1) { inputLen += (pInputData[i]->varmeta.length - VARSTR_HEADER_SIZE) * (numOfRows - numOfNulls) * factor; } else { - inputLen += pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE; + inputLen += (pInputData[i]->varmeta.length - (numOfRows - numOfNulls) * VARSTR_HEADER_SIZE) * factor; } } From 16897f17dcbb0fe652f522e36ed237ae720db8dc Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 7 May 2022 13:16:07 +0000 Subject: [PATCH 07/18] more refact --- source/dnode/vnode/src/tsdb/tsdbMemTable2.c | 25 +++++++++------------ 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c index dbea55f633..952ccfda9c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable2.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable2.c @@ -199,12 +199,15 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p // ASSERT(c); // encode row - int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); + int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); + int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (0 /*todo*/); + SMemSkipListNode *pNode = vnodeBufPoolMalloc(pPool, tsize); + if (pNode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } - // int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl); - // int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (p - pt); - // pSlNode = vnodeBufPoolMalloc(pPool, tsize); - // pSlNode->level = level; + pNode->level = level; // uint8_t *pData = SL_NODE_DATA(pSlNode); // *(int64_t *)pData = version; @@ -235,20 +238,14 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) { int8_t level = 1; + int8_t tlevel; const uint32_t factor = 4; if (pSl->size) { - while ((taosRandR(&pSl->seed) % factor) == 0 && level < pSl->maxLevel) { + tlevel = TMIN(pSl->maxLevel, pSl->level + 1); + while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) { level++; } - - if (level > pSl->level) { - if (pSl->level < pSl->maxLevel) { - level = pSl->level + 1; - } else { - level = pSl->level; - } - } } return level; From fec25caad47a0aae2bc185354c5b3cc11cdba112 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Sat, 7 May 2022 22:12:44 +0800 Subject: [PATCH 08/18] test: finish stb select column --- tests/pytest/query/queryDiffColsTagsAndOr.py | 50 ++++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/tests/pytest/query/queryDiffColsTagsAndOr.py b/tests/pytest/query/queryDiffColsTagsAndOr.py index 0a74954f5a..55881db149 100644 --- a/tests/pytest/query/queryDiffColsTagsAndOr.py +++ b/tests/pytest/query/queryDiffColsTagsAndOr.py @@ -58,12 +58,12 @@ class TDTestCase: self.insertData(tb_name) return tb_name - def initStb(self): + def initStb(self, count=5): tdCom.cleanTb() tb_name = tdCom.getLongName(8, "letters") tdSql.execute( f"CREATE TABLE {tb_name} (ts timestamp, c1 tinyint, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 binary(100), c8 nchar(200), c9 bool, c10 tinyint unsigned, c11 smallint unsigned, c12 int unsigned, c13 bigint unsigned) tags (t1 tinyint, t2 smallint, t3 int, t4 bigint, t5 float, t6 double, t7 binary(100), t8 nchar(200), t9 bool, t10 tinyint unsigned, t11 smallint unsigned, t12 int unsigned, t13 bigint unsigned)") - for i in range(1, 6): + for i in range(1, count+1): tdSql.execute( f'CREATE TABLE {tb_name}_sub_{i} using {tb_name} tags ({i}, {i}, {i}, {i}, {i}.{i}, {i}.{i}, "binary{i}", "nchar{i}", true, {i}, {i}, {i}, {i})') self.insertData(f'{tb_name}_sub_{i}') @@ -1382,31 +1382,29 @@ class TDTestCase: tdSql.checkRows(2) tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # # not in - # # ! bug TD-15327 - # query_sql = f'select {select_elm} from {tb_name} where c9 not in ("true")' - # tdSql.query(query_sql) - # tdSql.checkRows(2) - # tdSql.checkEqual(self.queryLastC10(query_sql), 2) if select_elm == "*" else False + query_sql = f'select {select_elm} from {tb_name} where c9 not in (true)' + tdSql.query(query_sql) + tdSql.checkRows(2) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - # # ! bug TD-15327 # # and - # query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 = "true" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' - # tdSql.query(query_sql) - # tdSql.checkRows(1) - # tdSql.checkEqual(self.queryLastC10(query_sql), 8) if select_elm == "*" else False + query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" and c9 <> "binary" and c9 is not null and c9 in ("binary", true) and c9 not in ("binary")' + tdSql.query(query_sql) + tdSql.checkRows(9) + tdSql.checkEqual(self.queryLastC10(query_sql), 9) if select_elm == "*" else False # # or - # query_sql = f'select {select_elm} from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' - # tdSql.query(query_sql) - # tdSql.checkRows(2) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False + query_sql = f'select {select_elm} from {tb_name} where c9 = true or c9 != "false" or c9 <> "binary" or c9 = "true" or c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False # # and or - # query_sql = f'select {select_elm} from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' - # tdSql.query(query_sql) - # tdSql.checkRows(11) - # tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False - # query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' - # tdSql.query(query_sql) - # tdSql.checkRows(11) + query_sql = f'select {select_elm} from {tb_name} where c9 = true and c9 != "false" or c9 <> "binary" or c9 = "true" and c9 is not null or c9 in ("binary", true) or c9 not in ("binary")' + tdSql.query(query_sql) + tdSql.checkRows(11) + tdSql.checkEqual(self.queryLastC10(query_sql), 11) if select_elm == "*" else False + query_sql = f'select c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13 from {tb_name} where c9 > "binary" and c9 >= "binary8" or c9 < "binary9" and c9 <= "binary" and c9 != 2 and c9 <> 2 and c9 = 4 or c9 is not null and c9 between 2 and 4 and c9 not between 1 and 2 and c9 in (2,4) and c9 not in (1,2) or c9 match "binary[28]" or c9 nmatch "binary"' + tdSql.query(query_sql) + tdSql.checkRows(11) def queryFullColType(self, tb_name, check_elm=None): select_elm = "*" if check_elm is None else check_elm @@ -2017,7 +2015,7 @@ class TDTestCase: ''' Super table full column type and operator ''' - stb_name = self.initStb() + stb_name = self.initStb(count=1) tb_name = stb_name + "_sub_1" if check_elm is None: self.checkColType(tb_name, check_elm) @@ -2112,14 +2110,14 @@ class TDTestCase: tdSql.prepare() column_name = random.choice(["c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10", "c11", "c12", "c13"]) for check_elm in [None, column_name]: - # self.checkTbColTypeOperator(check_elm) + self.checkTbColTypeOperator(check_elm) self.checkStbColTypeOperator(check_elm) # self.checkStbTagTypeOperator() # self.checkTbTsCol() # self.checkStbTsTol() # self.checkStbTsTag() # self.checkStbTsColTag() - # self.checkTbMultiExpression() + self.checkTbMultiExpression() # self.checkStbMultiExpression() # self.checkTbPreCal() # self.checkStbPreCal() From a6b2181807592ca90e821278de1f83162e550293 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Sat, 7 May 2022 22:19:56 +0800 Subject: [PATCH 09/18] test: finish stb select column and tb select *|column --- .../2-query/query_cols_tags_and_or.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{pytest/query/queryDiffColsTagsAndOr.py => system-test/2-query/query_cols_tags_and_or.py} (100%) diff --git a/tests/pytest/query/queryDiffColsTagsAndOr.py b/tests/system-test/2-query/query_cols_tags_and_or.py similarity index 100% rename from tests/pytest/query/queryDiffColsTagsAndOr.py rename to tests/system-test/2-query/query_cols_tags_and_or.py From 712a1bfa71c14d4861847a77d6b87be27a45cbfd Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 7 May 2022 22:40:15 +0800 Subject: [PATCH 10/18] refactor: adjust trans logs --- source/dnode/mnode/impl/src/mndTrans.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index e57e9a0461..3d4254da03 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -967,7 +967,7 @@ static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) pAction->msgSent = 0; pAction->msgReceived = 0; pAction->errCode = 0; - mDebug("trans:%d, action:%d is reset and will be re-executed", pTrans->id, action); + mDebug("trans:%d, action:%d execute status is reset", pTrans->id, action); } } @@ -1043,7 +1043,7 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA return errCode; } } else { - mDebug("trans:%d, %d of %d actions executing", pTrans->id, numOfReceived, numOfActions); + mDebug("trans:%d, %d of %d actions executed", pTrans->id, numOfReceived, numOfActions); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } } From 48ca2e5f76888c12ad5c9a5ff1c154b34749a6db Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 7 May 2022 22:47:18 +0800 Subject: [PATCH 11/18] fix: datadir info is not recorded in monitor --- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 9329e7b15d..bafb9e7a5b 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -51,6 +51,7 @@ void vmGetMonitorInfo(SMgmtWrapper *pWrapper, SMonVmInfo *pInfo) { pInfo->vstat.numOfBatchInsertSuccessReqs = numOfBatchInsertSuccessReqs - pMgmt->state.numOfBatchInsertSuccessReqs; pMgmt->state = pInfo->vstat; + tfsGetMonitorInfo(pMgmt->pTfs, &pInfo->tfs); taosArrayDestroy(vloads.pVloads); } From 3ed1ab6acb1e339dcf995cb3d42b327bbc39b704 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sat, 7 May 2022 23:19:05 +0800 Subject: [PATCH 12/18] enh(stream): auto create ctb --- example/src/tmq.c | 4 +- include/common/tdatablock.h | 14 ++--- include/libs/stream/tstream.h | 10 ++- source/common/src/tdatablock.c | 71 +++++++++++++++++++--- source/common/src/tmsg.c | 3 +- source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/src/mndDef.c | 8 ++- source/dnode/mnode/impl/src/mndScheduler.c | 5 +- source/dnode/mnode/impl/src/mndStream.c | 3 + source/dnode/vnode/src/tq/tq.c | 46 +++++++++----- source/libs/stream/src/tstream.c | 10 +-- source/util/test/encodeTest.cpp | 2 +- 12 files changed, 129 insertions(+), 48 deletions(-) diff --git a/example/src/tmq.c b/example/src/tmq.c index 976d658fa6..2b73d8351f 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -101,8 +101,8 @@ int32_t create_topic() { } taos_free_result(pRes); - pRes = taos_query(pConn, "create topic topic_ctb_column as abc1"); - /*pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1");*/ + /*pRes = taos_query(pConn, "create topic topic_ctb_column as abc1");*/ + pRes = taos_query(pConn, "create topic topic_ctb_column as select ts, c1, c2, c3 from ct1"); if (taos_errno(pRes) != 0) { printf("failed to create topic topic_ctb_column, reason:%s\n", taos_errstr(pRes)); return -1; diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 19b108dcbf..1677ec0d4f 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -56,11 +56,11 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet); #define colDataSetNotNull_f(bm_, r_) \ do { \ - BMCharPos(bm_, r_) &= ~(1u << (7u - BitPos(r_))); \ + BMCharPos(bm_, r_) &= ~(1u << (7u - BitPos(r_))); \ } while (0) -#define colDataIsNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] == -1) -#define colDataSetNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] = -1) +#define colDataIsNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] == -1) +#define colDataSetNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] = -1) #define BitmapLen(_n) (((_n) + ((1 << NBIT) - 1)) >> NBIT) @@ -187,8 +187,8 @@ static FORCE_INLINE void colDataAppendDouble(SColumnInfoData* pColumnInfoData, u } int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); -int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, int32_t* capacity, const SColumnInfoData* pSource, - uint32_t numOfRow2); +int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, int32_t* capacity, + const SColumnInfoData* pSource, uint32_t numOfRow2); int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* pSource, int32_t numOfRows); int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock); @@ -230,9 +230,9 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock, bool copyData); void blockDebugShowData(const SArray* dataBlocks); int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId, - tb_uid_t uid, tb_uid_t suid); + tb_uid_t uid, tb_uid_t suid); -SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema); +SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid); static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) { return blockDataGetSerialMetaSize(pBlock) + blockDataGetSize(pBlock); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index d7df976e1a..71462a86d4 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -69,20 +69,24 @@ typedef struct { SUseDbRsp dbInfo; } STaskDispatcherShuffle; +typedef void FTbSink(void* vnode, int64_t ver, const SArray* data); + typedef struct { - int8_t reserved; + int64_t stbUid; SSchemaWrapper* pSchemaWrapper; // not applicable to encoder and decoder + void* vnode; + FTbSink* tbSinkFunc; STSchema* pTSchema; SHashObj* pHash; // groupId to tbuid } STaskSinkTb; -typedef void FSmaHandle(void* vnode, int64_t smaId, const SArray* data); +typedef void FSmaSink(void* vnode, int64_t smaId, const SArray* data); typedef struct { int64_t smaId; // following are not applicable to encoder and decoder - FSmaHandle* smaHandle; + FSmaSink* smaSink; } STaskSinkSma; typedef struct { diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 2c17f2c2fc..1c099afc93 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -363,9 +363,9 @@ int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pInd for (int32_t i = 0; i < pDest->info.numOfCols; ++i) { int32_t mapIndex = i; -// if (pIndexMap) { -// mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i); -// } + // if (pIndexMap) { + // mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i); + // } SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i); SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, mapIndex); @@ -1596,7 +1596,7 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks return TSDB_CODE_SUCCESS; } -SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema) { +SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid) { SSubmitReq* ret = NULL; // cal size @@ -1608,7 +1608,29 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema) { // TODO min int32_t rowSize = pDataBlock->info.rowSize; int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema); - cap += sizeof(SSubmitBlk) + rows * maxLen; + int32_t schemaLen = 0; + + if (createTb) { + SVCreateTbReq createTbReq = {0}; + createTbReq.name = "a"; + createTbReq.flags = 0; + createTbReq.type = TSDB_CHILD_TABLE; + createTbReq.ctb.suid = htobe64(suid); + + SKVRowBuilder kvRowBuilder = {0}; + if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { + ASSERT(0); + } + tdAddColToKVRow(&kvRowBuilder, 1, &pDataBlock->info.groupId, sizeof(uint64_t)); + createTbReq.ctb.pTag = tdGetKVRowFromBuilder(&kvRowBuilder); + tdDestroyKVRowBuilder(&kvRowBuilder); + + int32_t code; + tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code); + if (code < 0) return NULL; + } + + cap += sizeof(SSubmitBlk) + schemaLen + rows * maxLen; } // assign data @@ -1623,19 +1645,47 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema) { SSubmitBlk* blkHead = submitBlk; blkHead->numOfRows = htons(pDataBlock->info.rows); - blkHead->schemaLen = 0; blkHead->sversion = htonl(pTSchema->version); // TODO - blkHead->suid = 0; - blkHead->uid = htobe64(pDataBlock->info.uid); + blkHead->suid = htobe64(suid); + // uid is assigned by vnode + blkHead->uid = 0; int32_t rows = pDataBlock->info.rows; /*int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);*/ /*blkHead->dataLen = htonl(rows * maxLen);*/ blkHead->dataLen = 0; - void* blockData = POINTER_SHIFT(submitBlk, sizeof(SSubmitBlk)); - STSRow* rowData = blockData; + void* blockData = POINTER_SHIFT(submitBlk, sizeof(SSubmitBlk)); + + int32_t schemaLen = 0; + if (createTb) { + SVCreateTbReq createTbReq = {0}; + createTbReq.name = "a"; + createTbReq.flags = 0; + createTbReq.type = TSDB_CHILD_TABLE; + createTbReq.ctb.suid = suid; + + SKVRowBuilder kvRowBuilder = {0}; + if (tdInitKVRowBuilder(&kvRowBuilder) < 0) { + ASSERT(0); + } + tdAddColToKVRow(&kvRowBuilder, 1, &pDataBlock->info.groupId, sizeof(uint64_t)); + createTbReq.ctb.pTag = tdGetKVRowFromBuilder(&kvRowBuilder); + tdDestroyKVRowBuilder(&kvRowBuilder); + + int32_t code; + tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code); + if (code < 0) return NULL; + + SEncoder encoder = {0}; + tEncoderInit(&encoder, blockData, schemaLen); + if (tEncodeSVCreateTbReq(&encoder, &createTbReq) < 0) return NULL; + tEncoderClear(&encoder); + } + blkHead->schemaLen = htonl(schemaLen); + + STSRow* rowData = POINTER_SHIFT(blockData, schemaLen); for (int32_t j = 0; j < rows; j++) { SRowBuilder rb = {0}; @@ -1656,6 +1706,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema) { int32_t len = blkHead->dataLen; blkHead->dataLen = htonl(len); blkHead = POINTER_SHIFT(blkHead, len); + /*submitBlk = blkHead;*/ } return ret; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 129143593e..56bb93faa4 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -56,7 +56,6 @@ int32_t tGetSubmitMsgNext(SSubmitMsgIter *pIter, SSubmitBlk **pPBlock) { ASSERT(0); } - SSubmitBlk *pSubmitBlk = (SSubmitBlk *)POINTER_SHIFT(pIter->pMsg, pIter->len); pIter->len += (sizeof(SSubmitBlk) + pIter->dataLen + pIter->schemaLen); ASSERT(pIter->len > 0); } @@ -4013,4 +4012,4 @@ int32_t tDecodeSVSubmitReq(SDecoder *pCoder, SVSubmitReq *pReq) { tEndDecode(pCoder); return 0; -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 98d29a6ca5..2751e0752e 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -574,6 +574,7 @@ typedef struct { char sourceDb[TSDB_DB_FNAME_LEN]; char targetDb[TSDB_DB_FNAME_LEN]; char targetSTbName[TSDB_TABLE_FNAME_LEN]; + int64_t targetStbUid; int64_t createTime; int64_t updateTime; int64_t uid; diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index a143371089..a2c628b8a1 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -416,6 +416,9 @@ int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) { /*int32_t outputNameSz = 0;*/ if (tEncodeCStr(pEncoder, pObj->name) < 0) return -1; if (tEncodeCStr(pEncoder, pObj->sourceDb) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->targetDb) < 0) return -1; + if (tEncodeCStr(pEncoder, pObj->targetSTbName) < 0) return -1; + if (tEncodeI64(pEncoder, pObj->targetStbUid) < 0) return -1; if (tEncodeI64(pEncoder, pObj->createTime) < 0) return -1; if (tEncodeI64(pEncoder, pObj->updateTime) < 0) return -1; if (tEncodeI64(pEncoder, pObj->uid) < 0) return -1; @@ -465,6 +468,9 @@ int32_t tEncodeSStreamObj(SEncoder *pEncoder, const SStreamObj *pObj) { int32_t tDecodeSStreamObj(SDecoder *pDecoder, SStreamObj *pObj) { if (tDecodeCStrTo(pDecoder, pObj->name) < 0) return -1; if (tDecodeCStrTo(pDecoder, pObj->sourceDb) < 0) return -1; + if (tDecodeCStrTo(pDecoder, pObj->targetDb) < 0) return -1; + if (tDecodeCStrTo(pDecoder, pObj->targetSTbName) < 0) return -1; + if (tDecodeI64(pDecoder, &pObj->targetStbUid) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->createTime) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->updateTime) < 0) return -1; if (tDecodeI64(pDecoder, &pObj->uid) < 0) return -1; @@ -529,4 +535,4 @@ void *tDecodeSMqOffsetObj(void *buf, SMqOffsetObj *pOffset) { buf = taosDecodeStringTo(buf, pOffset->key); buf = taosDecodeFixedI64(buf, &pOffset->offset); return buf; -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 5bfa70e76d..824f031004 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -204,6 +204,7 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p pTask->smaSink.smaId = pStream->smaId; } else { pTask->sinkType = TASK_SINK__TABLE; + pTask->tbSink.stbUid = pStream->targetStbUid; pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema); ASSERT(pTask->tbSink.pSchemaWrapper); } @@ -244,9 +245,10 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr pTask->smaSink.smaId = pStream->smaId; } else { pTask->sinkType = TASK_SINK__TABLE; + pTask->tbSink.stbUid = pStream->targetStbUid; pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema); } - // + // dispatch pTask->dispatchType = TASK_DISPATCH__NONE; @@ -319,6 +321,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { pTask->smaSink.smaId = pStream->smaId; } else { pTask->sinkType = TASK_SINK__TABLE; + pTask->tbSink.stbUid = pStream->targetStbUid; pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema); } #endif diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 2541232a53..8c1557b73d 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -360,6 +360,8 @@ static int32_t mndCreateStbForStream(SMnode *pMnode, STrans *pTrans, const SStre goto _OVER; } + stbObj.uid = pStream->targetStbUid; + if (mndAddStbToTrans(pMnode, pTrans, pDb, &stbObj) < 0) goto _OVER; return 0; @@ -379,6 +381,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe streamObj.createTime = taosGetTimestampMs(); streamObj.updateTime = streamObj.createTime; streamObj.uid = mndGenerateUid(pCreate->name, strlen(pCreate->name)); + streamObj.targetStbUid = mndGenerateUid(pCreate->targetStbFullName, TSDB_TABLE_FNAME_LEN); streamObj.dbUid = pDb->uid; streamObj.version = 1; streamObj.sql = pCreate->sql; diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index f12c67bb9c..e769108d59 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -884,24 +884,38 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { } } -int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { - if (pTask->execType == TASK_EXEC__NONE) return 0; +void tqTableSink(void* vnode, int64_t ver, const SArray* data) { + // + SVnode* pVnode = (SVnode*)vnode; + // build write msg + // +} - pTask->exec.numOfRunners = parallel; - pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner)); - if (pTask->exec.runners == NULL) { - return -1; +int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { + if (pTask->execType != TASK_EXEC__NONE) { + // expand runners + pTask->exec.numOfRunners = parallel; + pTask->exec.runners = taosMemoryCalloc(parallel, sizeof(SStreamRunner)); + if (pTask->exec.runners == NULL) { + return -1; + } + for (int32_t i = 0; i < parallel; i++) { + STqReadHandle* pStreamReader = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); + SReadHandle handle = { + .reader = pStreamReader, + .meta = pTq->pVnode->pMeta, + }; + pTask->exec.runners[i].inputHandle = pStreamReader; + pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); + ASSERT(pTask->exec.runners[i].executor); + } } - for (int32_t i = 0; i < parallel; i++) { - STqReadHandle* pStreamReader = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); - SReadHandle handle = { - .reader = pStreamReader, - .meta = pTq->pVnode->pMeta, - }; - pTask->exec.runners[i].inputHandle = pStreamReader; - pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); - ASSERT(pTask->exec.runners[i].executor); + + if (pTask->sinkType == TASK_SINK__TABLE) { + pTask->tbSink.vnode = pTq->pVnode; + pTask->tbSink.tbSinkFunc = tqTableSink; } + return 0; } @@ -925,7 +939,7 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { // sink pTask->ahandle = pTq->pVnode; if (pTask->sinkType == TASK_SINK__SMA) { - pTask->smaSink.smaHandle = smaHandleRes; + pTask->smaSink.smaSink = smaHandleRes; } else if (pTask->sinkType == TASK_SINK__TABLE) { ASSERT(pTask->tbSink.pSchemaWrapper); ASSERT(pTask->tbSink.pSchemaWrapper->pSchema); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 707e153a0c..a78f818ded 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -152,12 +152,12 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in // sink if (pTask->sinkType == TASK_SINK__TABLE) { - /*blockDebugShowData(pRes);*/ + blockDebugShowData(pRes); ASSERT(pTask->tbSink.pTSchema); - SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema); + SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema, false, pTask->tbSink.stbUid); tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema); } else if (pTask->sinkType == TASK_SINK__SMA) { - pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes); + pTask->smaSink.smaSink(pTask->ahandle, pTask->smaSink.smaId, pRes); // } else if (pTask->sinkType == TASK_SINK__FETCH) { // @@ -276,7 +276,7 @@ int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) { } if (pTask->sinkType == TASK_SINK__TABLE) { - /*if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1;*/ + if (tEncodeI64(pEncoder, pTask->tbSink.stbUid) < 0) return -1; if (tEncodeSSchemaWrapper(pEncoder, pTask->tbSink.pSchemaWrapper) < 0) return -1; } else if (pTask->sinkType == TASK_SINK__SMA) { if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1; @@ -321,7 +321,7 @@ int32_t tDecodeSStreamTask(SDecoder* pDecoder, SStreamTask* pTask) { } if (pTask->sinkType == TASK_SINK__TABLE) { - /*if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1;*/ + if (tDecodeI64(pDecoder, &pTask->tbSink.stbUid) < 0) return -1; pTask->tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper)); if (pTask->tbSink.pSchemaWrapper == NULL) return -1; if (tDecodeSSchemaWrapper(pDecoder, pTask->tbSink.pSchemaWrapper) < 0) return -1; diff --git a/source/util/test/encodeTest.cpp b/source/util/test/encodeTest.cpp index 6715cb3db8..00e12a4fe8 100644 --- a/source/util/test/encodeTest.cpp +++ b/source/util/test/encodeTest.cpp @@ -442,4 +442,4 @@ TEST(td_encode_test, compound_struct_encode_test) { #endif #pragma GCC diagnostic pop -#endif \ No newline at end of file +#endif From db3cbbf22d6179a2cb9d148b0008e7cab848abbd Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sun, 8 May 2022 00:21:17 +0800 Subject: [PATCH 13/18] fix(query): column match --- source/libs/executor/src/scanoperator.c | 189 ++++++++++++------------ source/libs/stream/src/tstream.c | 2 +- 2 files changed, 99 insertions(+), 92 deletions(-) diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 72f285231b..0296a312d0 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -38,7 +38,8 @@ #define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) static int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity); -static int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName); +static int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, + const char* dbName); static void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { for (int32_t i = 0; i < numOfOutput; ++i) { @@ -159,7 +160,8 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn return false; } -static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { +static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, + uint32_t* status) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableScanInfo* pInfo = pOperator->info; @@ -189,7 +191,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca } else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) { pCost->loadBlockStatis += 1; - bool allColumnsHaveAgg = true; + bool allColumnsHaveAgg = true; SColumnDataAgg** pColAgg = NULL; tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg, &allColumnsHaveAgg); @@ -261,7 +263,7 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { STableScanInfo* pTableScanInfo = pOperator->info; - SSDataBlock* pBlock = pTableScanInfo->pResBlock; + SSDataBlock* pBlock = pTableScanInfo->pResBlock; while (tsdbNextDataBlock(pTableScanInfo->dataReader)) { if (isTaskKilled(pOperator->pTaskInfo)) { @@ -344,7 +346,8 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { pTableScanInfo->scanFlag = REPEAT_SCAN; qDebug("%s start to repeat descending order scan data blocks due to query func required, qrange:%" PRId64 - "-%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); + "-%" PRId64, + GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); // do prepare for the next round table scan operation tsdbResetReadHandle(pTableScanInfo->dataReader, &pTableScanInfo->cond); @@ -373,22 +376,22 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCon pInfo->cond = *pCond; pInfo->scanInfo = (SScanInfo){.numOfAsc = scanInfo[0], .numOfDesc = scanInfo[1]}; - pInfo->interval = *pInterval; - pInfo->sampleRatio = sampleRatio; + pInfo->interval = *pInterval; + pInfo->sampleRatio = sampleRatio; pInfo->dataBlockLoadFlag = dataLoadFlag; - pInfo->pResBlock = pResBlock; - pInfo->pFilterNode = pCondition; - pInfo->dataReader = pDataReader; - pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColMatchInfo; + pInfo->pResBlock = pResBlock; + pInfo->pFilterNode = pCondition; + pInfo->dataReader = pDataReader; + pInfo->scanFlag = MAIN_SCAN; + pInfo->pColMatchInfo = pColMatchInfo; - pOperator->name = "TableScanOperator"; // for dubug purpose - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = numOfOutput; - pOperator->pTaskInfo = pTaskInfo; + pOperator->name = "TableScanOperator"; // for dubug purpose + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = numOfOutput; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, NULL, NULL, NULL, NULL); @@ -404,17 +407,17 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCon SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pTaskInfo) { STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - pInfo->dataReader = pReadHandle; -// pInfo->prevGroupId = -1; + pInfo->dataReader = pReadHandle; + // pInfo->prevGroupId = -1; - pOperator->name = "TableSeqScanOperator"; + pOperator->name = "TableSeqScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL, NULL, NULL); return pOperator; @@ -514,18 +517,18 @@ static void doClearBufferedBlocks(SStreamBlockScanInfo* pInfo) { static SSDataBlock* getUpdateDataBlock(SStreamBlockScanInfo* pInfo) { SColumnInfoData* pColDataInfo = taosArrayGet(pInfo->pRes->pDataBlock, pInfo->primaryTsIndex); - TSKEY* ts = (TSKEY*)pColDataInfo->pData; + TSKEY* ts = (TSKEY*)pColDataInfo->pData; for (int32_t i = 0; i < pInfo->pRes->info.rows; i++) { if (updateInfoIsUpdated(pInfo->pUpdateInfo, pInfo->pRes->info.uid, ts[i])) { - taosArrayPush(pInfo->tsArray, ts+i); + taosArrayPush(pInfo->tsArray, ts + i); } } if (taosArrayGetSize(pInfo->tsArray) > 0) { - //TODO(liuyao) get from tsdb - // SSDataBlock* p = createOneDataBlock(pInfo->pRes, true); - // p->info.type = STREAM_INVERT; - // taosArrayClear(pInfo->tsArray); - // return p; + // TODO(liuyao) get from tsdb + // SSDataBlock* p = createOneDataBlock(pInfo->pRes, true); + // p->info.type = STREAM_INVERT; + // taosArrayClear(pInfo->tsArray); + // return p; return NULL; } return NULL; @@ -535,7 +538,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { // NOTE: this operator does never check if current status is done or not SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SStreamBlockScanInfo* pInfo = pOperator->info; - int32_t rows = 0; + int32_t rows = 0; pTaskInfo->code = pOperator->fpSet._openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS || pOperator->status == OP_EXEC_DONE) { @@ -571,7 +574,7 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator) { int32_t numOfRows = 0; int16_t outputCol = 0; - int32_t code = tqRetrieveDataBlock(&pCols, pInfo->readerHandle, &groupId, &uid, &numOfRows, &outputCol); + int32_t code = tqRetrieveDataBlock(&pCols, pInfo->readerHandle, &groupId, &uid, &numOfRows, &outputCol); if (code != TSDB_CODE_SUCCESS || numOfRows == 0) { pTaskInfo->code = code; @@ -652,8 +655,9 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* SArray* pColIds = taosArrayInit(4, sizeof(int16_t)); for (int32_t i = 0; i < numOfOutput; ++i) { - int16_t* id = taosArrayGet(pColList, i); - taosArrayPush(pColIds, id); + SColMatchInfo* id = taosArrayGet(pColList, i); + int16_t colId = id->colId; + taosArrayPush(pColIds, &colId); } pInfo->pColMatchInfo = pColList; @@ -678,8 +682,8 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* return NULL; } - pInfo->primaryTsIndex = 0; //TODO(liuyao) get it from physical plan - pInfo->pUpdateInfo = updateInfoInit(60000, 0, 100); //TODO(liuyao) get it from physical plan + pInfo->primaryTsIndex = 0; // TODO(liuyao) get it from physical plan + pInfo->pUpdateInfo = updateInfoInit(60000, 0, 100); // TODO(liuyao) get it from physical plan if (pInfo->pUpdateInfo == NULL) { taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -687,25 +691,26 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* } pInfo->readerHandle = streamReadHandle; - pInfo->pRes = pResBlock; - pInfo->pCondition = pCondition; + pInfo->pRes = pResBlock; + pInfo->pCondition = pCondition; - pOperator->name = "StreamBlockScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = pResBlock->info.numOfCols; - pOperator->fpSet._openFn = operatorDummyOpenFn; + pOperator->name = "StreamBlockScanOperator"; + pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = pResBlock->info.numOfCols; + pOperator->fpSet._openFn = operatorDummyOpenFn; pOperator->fpSet.getNextFn = doStreamBlockScan; - pOperator->fpSet.closeFn = operatorDummyCloseFn; + pOperator->fpSet.closeFn = operatorDummyCloseFn; pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamBlockScan, NULL, NULL, operatorDummyCloseFn, NULL, NULL, NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doStreamBlockScan, NULL, NULL, operatorDummyCloseFn, NULL, NULL, NULL); return pOperator; - _error: +_error: taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); return NULL; @@ -774,7 +779,7 @@ static void getDBNameFromCondition(SNode* pCondition, const char* dbName) { if (NULL == pCondition) { return; } - nodesWalkExpr(pCondition, getDBNameFromConditionWalker, (char*) dbName); + nodesWalkExpr(pCondition, getDBNameFromConditionWalker, (char*)dbName); } static int32_t loadSysTableCallback(void* param, const SDataBuf* pMsg, int32_t code) { @@ -809,7 +814,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { code = filterSetDataFromSlotId(filter, ¶m1); int8_t* rowRes = NULL; - bool keep = filterExecute(filter, pInfo->pRes, &rowRes, NULL, param1.numOfCols); + bool keep = filterExecute(filter, pInfo->pRes, &rowRes, NULL, param1.numOfCols); filterFreeInfo(filter); SSDataBlock* px = createOneDataBlock(pInfo->pRes, false); @@ -853,13 +858,13 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { static SSDataBlock* buildSysTableMetaBlock() { SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - size_t size = 0; - const SSysTableMeta *pMeta = NULL; + size_t size = 0; + const SSysTableMeta* pMeta = NULL; getInfosDbMeta(&pMeta, &size); int32_t index = 0; - for(int32_t i = 0; i < size; ++i) { - if(strcmp(pMeta[i].name, TSDB_INS_TABLE_USER_TABLES) == 0) { + for (int32_t i = 0; i < size; ++i) { + if (strcmp(pMeta[i].name, TSDB_INS_TABLE_USER_TABLES) == 0) { index = i; break; } @@ -867,7 +872,7 @@ static SSDataBlock* buildSysTableMetaBlock() { pBlock->pDataBlock = taosArrayInit(pBlock->info.numOfCols, sizeof(SColumnInfoData)); - for(int32_t i = 0; i < pMeta[index].colNum; ++i) { + for (int32_t i = 0; i < pMeta[index].colNum; ++i) { SColumnInfoData colInfoData = {0}; colInfoData.info.colId = i + 1; colInfoData.info.type = pMeta[index].schema[i].type; @@ -1091,7 +1096,7 @@ int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) { SSDataBlock* p = buildSysTableMetaBlock(); blockDataEnsureCapacity(p, capacity); - size_t size = 0; + size_t size = 0; const SSysTableMeta* pSysDbTableMeta = NULL; getInfosDbMeta(&pSysDbTableMeta, &size); @@ -1100,18 +1105,19 @@ int32_t buildSysDbTableInfo(const SSysTableScanInfo* pInfo, int32_t capacity) { getPerfDbMeta(&pSysDbTableMeta, &size); p->info.rows = buildDbTableInfoBlock(p, pSysDbTableMeta, size, TSDB_PERFORMANCE_SCHEMA_DB); - relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock); -// blockDataDestroy(p); todo handle memory leak + relocateColumnData(pInfo->pRes, pInfo->scanCols, p->pDataBlock); + // blockDataDestroy(p); todo handle memory leak pInfo->pRes->info.rows = p->info.rows; return p->info.rows; } -int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, const char* dbName) { - char n[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; +int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbTableMeta, size_t size, + const char* dbName) { + char n[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; int32_t numOfRows = p->info.rows; - for(int32_t i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { const SSysTableMeta* pm = &pSysDbTableMeta[i]; SColumnInfoData* pColInfoData = taosArrayGet(p->pDataBlock, 0); @@ -1132,7 +1138,7 @@ int32_t buildDbTableInfoBlock(const SSDataBlock* p, const SSysTableMeta* pSysDbT pColInfoData = taosArrayGet(p->pDataBlock, 3); colDataAppend(pColInfoData, numOfRows, (char*)&pm->colNum, false); - for(int32_t j = 4; j <= 8; ++j) { + for (int32_t j = 4; j <= 8; ++j) { pColInfoData = taosArrayGet(p->pDataBlock, j); colDataAppendNULL(pColInfoData, numOfRows); } @@ -1160,18 +1166,18 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe return NULL; } - pInfo->accountId = accountId; + pInfo->accountId = accountId; pInfo->showRewrite = showRewrite; - pInfo->pRes = pResBlock; - pInfo->pCondition = pCondition; - pInfo->scanCols = colList; + pInfo->pRes = pResBlock; + pInfo->pCondition = pCondition; + pInfo->scanCols = colList; initResultSizeInfo(pOperator, 4096); tNameAssign(&pInfo->name, pName); const char* name = tNameGetTableName(&pInfo->name); if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) { - pInfo->readHandle = *(SReadHandle*) readHandle; + pInfo->readHandle = *(SReadHandle*)readHandle; blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); } else { tsem_init(&pInfo->ready, 0, 0); @@ -1201,14 +1207,14 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe #endif } - pOperator->name = "SysTableScanOperator"; + pOperator->name = "SysTableScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfExprs = pResBlock->info.numOfCols; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, - NULL, NULL, NULL); + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfExprs = pResBlock->info.numOfCols; + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL, NULL, NULL); pOperator->pTaskInfo = pTaskInfo; return pOperator; @@ -1355,26 +1361,27 @@ static void destroyTagScanOperatorInfo(void* param, int32_t numOfOutput) { } SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, SExprInfo* pExpr, int32_t numOfOutput, - SSDataBlock* pResBlock, SArray* pColMatchInfo, STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { + SSDataBlock* pResBlock, SArray* pColMatchInfo, + STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { STagScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STagScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->pTableGroups = pTableGroupInfo; - pInfo->pColMatchInfo = pColMatchInfo; - pInfo->pRes = pResBlock; - pInfo->readHandle = *pReadHandle; - pInfo->curPos = 0; - pOperator->name = "TagScanOperator"; + pInfo->pTableGroups = pTableGroupInfo; + pInfo->pColMatchInfo = pColMatchInfo; + pInfo->pRes = pResBlock; + pInfo->readHandle = *pReadHandle; + pInfo->curPos = 0; + pOperator->name = "TagScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pExpr = pExpr; - pOperator->numOfExprs = numOfOutput; - pOperator->pTaskInfo = pTaskInfo; + pOperator->blocking = false; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->pExpr = pExpr; + pOperator->numOfExprs = numOfOutput; + pOperator->pTaskInfo = pTaskInfo; initResultSizeInfo(pOperator, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index a78f818ded..3b49dca800 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -152,7 +152,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in // sink if (pTask->sinkType == TASK_SINK__TABLE) { - blockDebugShowData(pRes); + /*blockDebugShowData(pRes);*/ ASSERT(pTask->tbSink.pTSchema); SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema, false, pTask->tbSink.stbUid); tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema); From d17b478e96afcf6838209b819215b2a1c0c77d22 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sun, 8 May 2022 02:37:23 +0800 Subject: [PATCH 14/18] feat(stream): auto create ctb --- include/common/tdatablock.h | 2 +- include/libs/stream/tstream.h | 9 +- source/common/src/tdatablock.c | 18 ++- source/dnode/mgmt/mgmt_vnode/inc/vmInt.h | 1 + source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 1 + source/dnode/mgmt/mgmt_vnode/src/vmInt.c | 3 +- source/dnode/mgmt/mgmt_vnode/src/vmWorker.c | 8 ++ source/dnode/vnode/src/tq/tq.c | 18 ++- source/libs/executor/src/timewindowoperator.c | 104 +++++++++--------- source/libs/stream/src/tstream.c | 6 +- 10 files changed, 99 insertions(+), 71 deletions(-) diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 1677ec0d4f..cea40f4785 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -232,7 +232,7 @@ void blockDebugShowData(const SArray* dataBlocks); int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId, tb_uid_t uid, tb_uid_t suid); -SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid); +SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema, bool createTb, int64_t suid, int32_t vgId); static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) { return blockDataGetSerialMetaSize(pBlock) + blockDataGetSize(pBlock); diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 71462a86d4..e277622c40 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -25,6 +25,8 @@ extern "C" { #ifndef _TSTREAM_H_ #define _TSTREAM_H_ +typedef struct SStreamTask SStreamTask; + enum { STREAM_TASK_STATUS__RUNNING = 1, STREAM_TASK_STATUS__STOP, @@ -69,7 +71,7 @@ typedef struct { SUseDbRsp dbInfo; } STaskDispatcherShuffle; -typedef void FTbSink(void* vnode, int64_t ver, const SArray* data); +typedef void FTbSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data); typedef struct { int64_t stbUid; @@ -119,7 +121,7 @@ enum { TASK_SINK__FETCH, }; -typedef struct { +struct SStreamTask { int64_t streamId; int32_t taskId; int8_t status; @@ -154,8 +156,7 @@ typedef struct { // application storage void* ahandle; - -} SStreamTask; +}; SStreamTask* tNewSStreamTask(int64_t streamId); int32_t tEncodeSStreamTask(SEncoder* pEncoder, const SStreamTask* pTask); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 1c099afc93..0d0bbb07be 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1596,7 +1596,8 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks return TSDB_CODE_SUCCESS; } -SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid) { +SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid, + int32_t vgId) { SSubmitReq* ret = NULL; // cal size @@ -1634,9 +1635,11 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo } // assign data - ret = taosMemoryCalloc(1, cap); + ret = taosMemoryCalloc(1, cap + 46); + ret = POINTER_SHIFT(ret, 46); + ret->header.vgId = vgId; ret->version = htonl(1); - ret->length = htonl(cap - sizeof(SSubmitReq)); + ret->length = sizeof(SSubmitReq); ret->numOfBlocks = htonl(sz); void* submitBlk = POINTER_SHIFT(ret, sizeof(SSubmitReq)); @@ -1703,11 +1706,14 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo rowData = POINTER_SHIFT(rowData, rowLen); blkHead->dataLen += rowLen; } - int32_t len = blkHead->dataLen; - blkHead->dataLen = htonl(len); - blkHead = POINTER_SHIFT(blkHead, len); + int32_t dataLen = blkHead->dataLen; + blkHead->dataLen = htonl(dataLen); + + ret->length += sizeof(SSubmitBlk) + schemaLen + dataLen; + blkHead = POINTER_SHIFT(blkHead, schemaLen + dataLen); /*submitBlk = blkHead;*/ } + ret->length = htonl(ret->length); return ret; } diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index 4b42f97f53..fa5e1d78a0 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -106,6 +106,7 @@ int32_t vmAllocQueue(SVnodesMgmt *pMgmt, SVnodeObj *pVnode); void vmFreeQueue(SVnodesMgmt *pMgmt, SVnodeObj *pVnode); int32_t vmPutMsgToSyncQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); // sync integration +int32_t vmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc); int32_t vmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t vmPutMsgToFetchQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); int32_t vmPutMsgToApplyQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 9329e7b15d..8939aa23e0 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -177,6 +177,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) { SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; + msgCb.queueFps[WRITE_QUEUE] = vmPutMsgToWriteQueue; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; msgCb.queueFps[APPLY_QUEUE] = vmPutMsgToApplyQueue; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 3088c5dea4..17c7563885 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -135,6 +135,7 @@ static void *vmOpenVnodeFunc(void *param) { SMsgCb msgCb = pMgmt->pDnode->data.msgCb; msgCb.pWrapper = pMgmt->pWrapper; + msgCb.queueFps[WRITE_QUEUE] = vmPutMsgToWriteQueue; msgCb.queueFps[QUERY_QUEUE] = vmPutMsgToQueryQueue; msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue; msgCb.queueFps[APPLY_QUEUE] = vmPutMsgToApplyQueue; @@ -147,7 +148,7 @@ static void *vmOpenVnodeFunc(void *param) { pThread->failed++; } else { vmOpenVnode(pMgmt, pCfg, pImpl); - //vnodeStart(pImpl); + // vnodeStart(pImpl); dDebug("vgId:%d, is opened by thread:%d", pCfg->vgId, pThread->threadIndex); pThread->opened++; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index f3d7253e71..06e24cb48a 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -357,6 +357,10 @@ static int32_t vmPutRpcMsgToQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, EQueueT pMsg->rpcMsg = *pRpc; // if (pMsg->rpcMsg.handle != NULL) assert(pMsg->rpcMsg.refId != 0); switch (qtype) { + case WRITE_QUEUE: + dTrace("msg:%p, will be put into vnode-write queue", pMsg); + taosWriteQitem(pVnode->pWriteQ, pMsg); + break; case QUERY_QUEUE: dTrace("msg:%p, will be put into vnode-query queue", pMsg); taosWriteQitem(pVnode->pQueryQ, pMsg); @@ -387,6 +391,10 @@ static int32_t vmPutRpcMsgToQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, EQueueT return code; } +int32_t vmPutMsgToWriteQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { + return vmPutRpcMsgToQueue(pWrapper, pRpc, WRITE_QUEUE); +} + int32_t vmPutMsgToQueryQueue(SMgmtWrapper *pWrapper, SRpcMsg *pRpc) { return vmPutRpcMsgToQueue(pWrapper, pRpc, QUERY_QUEUE); } diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index e769108d59..b7378e44f2 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -884,11 +884,21 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { } } -void tqTableSink(void* vnode, int64_t ver, const SArray* data) { - // - SVnode* pVnode = (SVnode*)vnode; +void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) { + const SArray* pRes = (const SArray*)data; + SVnode* pVnode = (SVnode*)vnode; + + ASSERT(pTask->tbSink.pTSchema); + SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema, true, pTask->tbSink.stbUid, pVnode->config.vgId); + tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema); // build write msg - // + SRpcMsg msg = { + .msgType = TDMT_VND_SUBMIT, + .pCont = pReq, + .contLen = ntohl(pReq->length), + }; + + ASSERT(tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &msg) == 0); } int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 5c609303ff..ebde1c7997 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -1,7 +1,7 @@ -#include "ttime.h" -#include "tdatablock.h" #include "executorimpl.h" #include "functionMgt.h" +#include "tdatablock.h" +#include "ttime.h" typedef enum SResultTsInterpType { RESULT_ROW_START_INTERP = 1, @@ -545,7 +545,6 @@ static void setResultRowInterpo(SResultRow* pResult, SResultTsInterpType type) { } } - static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBlock* pBlock, SqlFunctionCtx* pCtx, SResultRow* pResult, STimeWindow* win, int32_t startPos, int32_t forwardStep, int32_t order, bool timeWindowInterpo) { @@ -759,10 +758,10 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { return TSDB_CODE_SUCCESS; } - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SIntervalAggOperatorInfo* pInfo = pOperator->info; - int32_t order = TSDB_ORDER_ASC; + int32_t order = TSDB_ORDER_ASC; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { @@ -808,7 +807,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) { } static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo* pInfo, SSDataBlock* pBlock) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SColumnInfoData* pStateColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->colIndex); int64_t gid = pBlock->info.groupId; @@ -932,7 +931,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) { SIntervalAggOperatorInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_EXEC_DONE) { return NULL; @@ -981,10 +980,10 @@ static void finalizeUpdatedResult(int32_t numOfOutput, SDiskbasedBuf* pBuf, SArr } } static void setInverFunction(SqlFunctionCtx* pCtx, int32_t num, EStreamType type) { - for ( int i = 0; i < num; i++) { + for (int i = 0; i < num; i++) { if (type == STREAM_INVERT) { fmSetInvertFunc(pCtx[i].functionId, &(pCtx[i].fpSet)); - } else if (type == STREAM_NORMAL){ + } else if (type == STREAM_NORMAL) { fmSetNormalFunc(pCtx[i].functionId, &(pCtx[i].fpSet)); } } @@ -992,7 +991,7 @@ static void setInverFunction(SqlFunctionCtx* pCtx, int32_t num, EStreamType type static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { SIntervalAggOperatorInfo* pInfo = pOperator->info; - int32_t order = TSDB_ORDER_ASC; + int32_t order = TSDB_ORDER_ASC; if (pOperator->status == OP_EXEC_DONE) { return NULL; @@ -1038,7 +1037,8 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); doBuildResultDatablock(&pInfo->binfo, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf); - ASSERT(pInfo->binfo.pRes->info.rows > 0); + // TODO: remove for stream + /*ASSERT(pInfo->binfo.pRes->info.rows > 0);*/ pOperator->status = OP_RES_TO_RETURN; return pInfo->binfo.pRes->info.rows == 0 ? NULL : pInfo->binfo.pRes; @@ -1070,17 +1070,17 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* STimeWindowAggSupp* pTwAggSupp, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { SIntervalAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SIntervalAggOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } - pInfo->order = TSDB_ORDER_ASC; - pInfo->interval = *pInterval; + pInfo->order = TSDB_ORDER_ASC; + pInfo->interval = *pInterval; // pInfo->execModel = OPTR_EXEC_MODEL_STREAM; - pInfo->execModel = pTaskInfo->execModel; - pInfo->win = pTaskInfo->window; - pInfo->twAggSup = *pTwAggSupp; + pInfo->execModel = pTaskInfo->execModel; + pInfo->win = pTaskInfo->window; + pInfo->twAggSup = *pTwAggSupp; pInfo->primaryTsIndex = primaryTsSlotId; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; @@ -1099,14 +1099,14 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1); - pOperator->name = "TimeIntervalAggOperator"; + pOperator->name = "TimeIntervalAggOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INTERVAL; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->numOfExprs = numOfCols; - pOperator->info = pInfo; + pOperator->blocking = true; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->pTaskInfo = pTaskInfo; + pOperator->numOfExprs = numOfCols; + pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, doStreamIntervalAgg, NULL, destroyIntervalOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); @@ -1118,7 +1118,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* return pOperator; - _error: +_error: destroyIntervalOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -1131,7 +1131,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr STimeWindowAggSupp* pTwAggSupp, const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo) { SIntervalAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SIntervalAggOperatorInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { goto _error; } @@ -1177,7 +1177,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr return pOperator; - _error: +_error: destroyIntervalOperatorInfo(pInfo, numOfCols); taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); @@ -1321,7 +1321,7 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo* pOperator) { return pSliceInfo->binfo.pRes; } - int32_t order = TSDB_ORDER_ASC; + int32_t order = TSDB_ORDER_ASC; SOperatorInfo* downstream = pOperator->pDownstream[0]; while (1) { @@ -1379,7 +1379,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: taosMemoryFree(pInfo); taosMemoryFree(pOperator); pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; @@ -1402,18 +1402,18 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf initAggInfo(&pInfo->binfo, &pInfo->aggSup, pExpr, numOfCols, pResBlock, keyBufSize, pTaskInfo->id.str); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); - pInfo->twAggSup = *pTwAggSup; + pInfo->twAggSup = *pTwAggSup; initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); - pInfo->tsSlotId = tsSlotId; - pOperator->name = "StateWindowOperator"; + pInfo->tsSlotId = tsSlotId; + pOperator->name = "StateWindowOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW; pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExpr; - pOperator->numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; - pOperator->info = pInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExpr; + pOperator->numOfExprs = numOfCols; + pOperator->pTaskInfo = pTaskInfo; + pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStateWindowAgg, NULL, NULL, destroyStateWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); @@ -1421,7 +1421,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: pTaskInfo->code = TSDB_CODE_SUCCESS; return NULL; } @@ -1432,8 +1432,8 @@ void destroySWindowOperatorInfo(void* param, int32_t numOfOutput) { } SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, - SSDataBlock* pResBlock, int64_t gap, int32_t tsSlotId, STimeWindowAggSupp* pTwAggSupp, - SExecTaskInfo* pTaskInfo) { + SSDataBlock* pResBlock, int64_t gap, int32_t tsSlotId, + STimeWindowAggSupp* pTwAggSupp, SExecTaskInfo* pTaskInfo) { SSessionAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSessionAggOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -1453,18 +1453,18 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); - pInfo->tsSlotId = tsSlotId; - pInfo->gap = gap; - pInfo->binfo.pRes = pResBlock; - pInfo->winSup.prevTs = INT64_MIN; - pInfo->reptScan = false; - pOperator->name = "SessionWindowAggOperator"; + pInfo->tsSlotId = tsSlotId; + pInfo->gap = gap; + pInfo->binfo.pRes = pResBlock; + pInfo->winSup.prevTs = INT64_MIN; + pInfo->reptScan = false; + pOperator->name = "SessionWindowAggOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW; pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pExpr = pExprInfo; - pOperator->numOfExprs = numOfCols; - pOperator->info = pInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->pExpr = pExprInfo; + pOperator->numOfExprs = numOfCols; + pOperator->info = pInfo; pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL, destroySWindowOperatorInfo, aggEncodeResultRow, aggDecodeResultRow, NULL); @@ -1473,7 +1473,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo code = appendDownstream(pOperator, &downstream, 1); return pOperator; - _error: +_error: if (pInfo != NULL) { destroySWindowOperatorInfo(pInfo, numOfCols); } @@ -1482,4 +1482,4 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo taosMemoryFreeClear(pOperator); pTaskInfo->code = code; return NULL; -} \ No newline at end of file +} diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 3b49dca800..237f673a47 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -150,12 +150,12 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in pRes = (SArray*)input; } + if (pRes == NULL || taosArrayGetSize(pRes) == 0) return 0; + // sink if (pTask->sinkType == TASK_SINK__TABLE) { /*blockDebugShowData(pRes);*/ - ASSERT(pTask->tbSink.pTSchema); - SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema, false, pTask->tbSink.stbUid); - tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema); + pTask->tbSink.tbSinkFunc(pTask, pTask->tbSink.vnode, 0, pRes); } else if (pTask->sinkType == TASK_SINK__SMA) { pTask->smaSink.smaSink(pTask->ahandle, pTask->smaSink.smaId, pRes); // From b78918c72a5b98dbe87d95a85cb0723ad97a1db0 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sun, 8 May 2022 03:16:00 +0800 Subject: [PATCH 15/18] test(stream): add stream case --- tests/script/jenkins/basic.txt | 3 ++ tests/script/tsim/tstream/basic0.sim | 71 ++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 tests/script/tsim/tstream/basic0.sim diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index b95e822df3..f4a7a1d822 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -65,6 +65,9 @@ ./test.sh -f tsim/tmq/basic3.sim ./test.sh -f tsim/tmq/basic4.sim +# ---- tstream +./test.sh -f tstream/basic0.sim + # --- stable ./test.sh -f tsim/stable/disk.sim ./test.sh -f tsim/stable/dnode3.sim diff --git a/tests/script/tsim/tstream/basic0.sim b/tests/script/tsim/tstream/basic0.sim new file mode 100644 index 0000000000..b3d51cdcc8 --- /dev/null +++ b/tests/script/tsim/tstream/basic0.sim @@ -0,0 +1,71 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +print =============== create database +sql create database d0 vgroups 1 +sql show databases +if $rows != 3 then + return -1 +endi + +print $data00 $data01 $data02 + +sql use d0 + +print =============== create super table, include column type for count/sum/min/max/first +sql create table if not exists stb (ts timestamp, k int) tags (a int) + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +sql create table ct1 using stb tags(1000) +sql create table ct2 using stb tags(2000) +sql create table ct3 using stb tags(3000) + +sql show tables +if $rows != 3 then + return -1 +endi + +sql create stream s1 into outstb as select _wstartts, min(k), max(k), sum(k) from ct1 interval(10m) + +sql show stables +if $rows != 2 then + return -1 +endi + +print =============== insert data + +sql insert into ct1 values(now+0s, 234) + +sleep 100 + +#=================================================================== +#=================================================================== +print =============== query data from child table +sql select `_wstartts`,`min(k)`,`max(k)`,`sum(k)` from outstb +print rows: $rows +print $data00 $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi + +if $data01 != 234 then + return -1 +endi + +if $data02 != 234 then + return -1 +endi + +if $data03 != 234 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 72437147d9c01611cee7bef2be7d727f517b7bb3 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sun, 8 May 2022 03:40:52 +0800 Subject: [PATCH 16/18] test(stream): add stream case --- tests/script/jenkins/basic.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index f4a7a1d822..8cce169d99 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -59,15 +59,16 @@ # ---- table ./test.sh -f tsim/table/basic1.sim +# ---- tstream +./test.sh -f tsim/tstream/basic0.sim + + # ---- tmq ./test.sh -f tsim/tmq/basic1.sim ./test.sh -f tsim/tmq/basic2.sim ./test.sh -f tsim/tmq/basic3.sim ./test.sh -f tsim/tmq/basic4.sim -# ---- tstream -./test.sh -f tstream/basic0.sim - # --- stable ./test.sh -f tsim/stable/disk.sim ./test.sh -f tsim/stable/dnode3.sim From 597f42aa5e43f9259ebe75c1d24fed192718c435 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 8 May 2022 03:19:57 +0000 Subject: [PATCH 17/18] fix auto-create table req --- source/dnode/vnode/src/meta/metaTable.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 3c140cc668..7663047429 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -141,16 +141,19 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) { goto _err; } - // preprocess req - pReq->uid = tGenIdPI64(); - pReq->ctime = taosGetTimestampMs(); - // validate req metaReaderInit(&mr, pMeta, 0); if (metaGetTableEntryByName(&mr, pReq->name) == 0) { + pReq->uid = mr.me.uid; + if (pReq->type == TSDB_CHILD_TABLE) { + pReq->ctb.suid = mr.me.ctbEntry.suid; + } terrno = TSDB_CODE_TDB_TABLE_ALREADY_EXIST; metaReaderClear(&mr); return -1; + } else { + pReq->uid = tGenIdPI64(); + pReq->ctime = taosGetTimestampMs(); } metaReaderClear(&mr); From 68b9424f8a1e014965d64d4e7a7becd60eb0bb32 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Sun, 8 May 2022 11:58:19 +0800 Subject: [PATCH 18/18] test(stream): more stream case --- source/dnode/vnode/src/tq/tq.c | 2 +- tests/script/tsim/tstream/basic0.sim | 78 ++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index b7378e44f2..b8d6e84b1c 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -890,7 +890,7 @@ void tqTableSink(SStreamTask* pTask, void* vnode, int64_t ver, void* data) { ASSERT(pTask->tbSink.pTSchema); SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema, true, pTask->tbSink.stbUid, pVnode->config.vgId); - tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema); + /*tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema);*/ // build write msg SRpcMsg msg = { .msgType = TDMT_VND_SUBMIT, diff --git a/tests/script/tsim/tstream/basic0.sim b/tests/script/tsim/tstream/basic0.sim index b3d51cdcc8..2a1bd14531 100644 --- a/tests/script/tsim/tstream/basic0.sim +++ b/tests/script/tsim/tstream/basic0.sim @@ -33,7 +33,7 @@ if $rows != 3 then return -1 endi -sql create stream s1 into outstb as select _wstartts, min(k), max(k), sum(k) from ct1 interval(10m) +sql create stream s1 into outstb as select _wstartts, min(k), max(k), sum(k) as sum_alias from ct1 interval(10m) sql show stables if $rows != 2 then @@ -42,14 +42,13 @@ endi print =============== insert data -sql insert into ct1 values(now+0s, 234) - +sql insert into ct1 values('2022-05-08 03:42:00.000', 234) sleep 100 -#=================================================================== #=================================================================== print =============== query data from child table -sql select `_wstartts`,`min(k)`,`max(k)`,`sum(k)` from outstb + +sql select `_wstartts`,`min(k)`,`max(k)`,sum_alias from outstb print rows: $rows print $data00 $data01 $data02 $data03 if $rows != 1 then @@ -68,4 +67,73 @@ if $data03 != 234 then return -1 endi +#=================================================================== +print =============== insert data + +sql insert into ct1 values('2022-05-08 03:43:00.000', -111) +sleep 100 + +#=================================================================== +print =============== query data from child table + +sql select `_wstartts`,`min(k)`,`max(k)`,sum_alias from outstb +print rows: $rows +print $data00 $data01 $data02 $data03 +if $rows != 1 then + return -1 +endi + +if $data01 != -111 then + return -1 +endi + +if $data02 != 234 then + return -1 +endi + +if $data03 != 123 then + return -1 +endi + +#=================================================================== +print =============== insert data + +sql insert into ct1 values('2022-05-08 03:53:00.000', 789) +sleep 100 + +#=================================================================== +print =============== query data from child table + +sql select `_wstartts`,`min(k)`,`max(k)`,sum_alias from outstb +print rows: $rows +print $data00 $data01 $data02 $data03 +print $data10 $data11 $data12 $data13 +if $rows != 2 then + return -1 +endi + +if $data01 != -111 then + return -1 +endi + +if $data02 != 234 then + return -1 +endi + +if $data03 != 123 then + return -1 +endi + +if $data11 != 789 then + return -1 +endi + +if $data12 != 789 then + return -1 +endi + +if $data13 != 789 then + return -1 +endi + system sh/exec.sh -n dnode1 -s stop -x SIGINT