diff --git a/tests/pytest/util/common.py b/tests/pytest/util/common.py index 94043ed01a..7133e8365d 100644 --- a/tests/pytest/util/common.py +++ b/tests/pytest/util/common.py @@ -11,13 +11,13 @@ # -*- coding: utf-8 -*- -from collections import defaultdict import random import string import requests import time import socket import json +import toml from .boundary import DataBoundary import taos from util.log import * @@ -25,6 +25,79 @@ from util.sql import * from util.cases import * from util.dnodes import * from util.common import * +from util.constant import * +from dataclasses import dataclass,field +from typing import List + +@dataclass +class DataSet: + ts_data : List[int] = field(default_factory=list) + int_data : List[int] = field(default_factory=list) + bint_data : List[int] = field(default_factory=list) + sint_data : List[int] = field(default_factory=list) + tint_data : List[int] = field(default_factory=list) + uint_data : List[int] = field(default_factory=list) + ubint_data : List[int] = field(default_factory=list) + usint_data : List[int] = field(default_factory=list) + utint_data : List[int] = field(default_factory=list) + float_data : List[float] = field(default_factory=list) + double_data : List[float] = field(default_factory=list) + bool_data : List[int] = field(default_factory=list) + vchar_data : List[str] = field(default_factory=list) + nchar_data : List[str] = field(default_factory=list) + + def get_order_set(self, + rows, + int_step :int = 1, + bint_step :int = 1, + sint_step :int = 1, + tint_step :int = 1, + uint_step :int = 1, + ubint_step :int = 1, + usint_step :int = 1, + utint_step :int = 1, + float_step :float = 1, + double_step :float = 1, + bool_start :int = 1, + vchar_prefix:str = "vachar_", + vchar_step :int = 1, + nchar_prefix:str = "nchar_测试_", + nchar_step :int = 1, + ts_step :int = 1 + ): + for i in range(rows): + self.int_data.append( int(i * int_step % INT_MAX )) + self.bint_data.append( int(i * bint_step % BIGINT_MAX )) + self.sint_data.append( int(i * sint_step % SMALLINT_MAX )) + self.tint_data.append( int(i * tint_step % TINYINT_MAX )) + self.uint_data.append( int(i * uint_step % INT_UN_MAX )) + self.ubint_data.append( int(i * ubint_step % BIGINT_UN_MAX )) + self.usint_data.append( int(i * usint_step % SMALLINT_UN_MAX )) + self.utint_data.append( int(i * utint_step % TINYINT_UN_MAX )) + self.float_data.append( float(i * float_step % FLOAT_MAX )) + self.double_data.append( float(i * double_step % DOUBLE_MAX )) + self.bool_data.append( bool((i + bool_start) % 2 )) + self.vchar_data.append( f"{vchar_prefix}_{i * vchar_step}" ) + self.nchar_data.append( f"{nchar_prefix}_{i * nchar_step}") + self.ts_data.append( int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000 - i * ts_step)) + + def get_disorder_set(self, + rows, + int_low :int = INT_MIN, + int_up :int = INT_MAX, + bint_low :int = BIGINT_MIN, + bint_up :int = BIGINT_MAX, + sint_low :int = SMALLINT_MIN, + sint_up :int = SMALLINT_MAX, + tint_low :int = TINYINT_MIN, + tint_up :int = TINYINT_MAX, + ubint_low :int = BIGINT_UN_MIN, + ubint_up :int = BIGINT_UN_MAX, + + + ): + pass + class TDCom: def __init__(self): @@ -372,6 +445,7 @@ class TDCom: def getClientCfgPath(self): buildPath = self.getBuildPath() + if (buildPath == ""): tdLog.exit("taosd not found!") else: @@ -650,7 +724,7 @@ class TDCom: else: column_value_str += f'{column_value}, ' idx += 1 - column_value_str = column_value_str.rstrip()[:-1] + column_value_str = column_value_str.rstrip()[:-1] insert_sql = f'insert into {dbname}.{tbname} values ({column_value_str});' tsql.execute(insert_sql) def getOneRow(self, location, containElm): @@ -662,12 +736,12 @@ class TDCom: return res_list else: tdLog.exit(f"getOneRow out of range: row_index={location} row_count={self.query_row}") - - def killProcessor(self, processorName): + + def killProcessor(self, processorName): if (platform.system().lower() == 'windows'): os.system("TASKKILL /F /IM %s.exe"%processorName) else: - os.system('pkill %s'%processorName) + os.system('pkill %s'%processorName) def is_json(msg): @@ -680,4 +754,29 @@ def is_json(msg): else: return False +def get_path(tool="taosd"): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + paths = [] + for root, dirs, files in os.walk(projPath): + if ((tool) in files or ("%s.exe"%tool) in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + paths.append(os.path.join(root, tool)) + break + if (len(paths) == 0): + return "" + return paths[0] + +def dict2toml(in_dict: dict, file:str): + if not isinstance(in_dict, dict): + return "" + with open(file, 'w') as f: + toml.dump(in_dict, f) + tdCom = TDCom() diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 656687255e..59e247105c 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -96,9 +96,9 @@ class TDSimClient: for key, value in self.cfgDict.items(): self.cfg(key, value) - + try: - if bool(updatecfgDict) and updatecfgDict[0] and updatecfgDict[0][0]: + if bool(updatecfgDict) and updatecfgDict[0] and updatecfgDict[0][0]: clientCfg = dict (updatecfgDict[0][0].get('clientCfg')) for key, value in clientCfg.items(): self.cfg(key, value) @@ -244,7 +244,6 @@ class TDDnode: # print(updatecfgDict) isFirstDir = 1 if bool(updatecfgDict) and updatecfgDict[0] and updatecfgDict[0][0]: - print(updatecfgDict[0][0]) for key, value in updatecfgDict[0][0].items(): if key == "clientCfg" and self.remoteIP == "" and not platform.system().lower() == 'windows': continue @@ -324,7 +323,6 @@ class TDDnode: if os.system(cmd) != 0: tdLog.exit(cmd) self.running = 1 - print("dnode:%d is running with %s " % (self.index, cmd)) tdLog.debug("dnode:%d is running with %s " % (self.index, cmd)) if self.valgrind == 0: time.sleep(0.1) @@ -358,7 +356,7 @@ class TDDnode: # break # elif bkey2 in line: # popen.kill() - # break + # break # if time.time() > timeout: # print(time.time(),timeout) # tdLog.exit('wait too long for taosd start') @@ -407,7 +405,6 @@ class TDDnode: if os.system(cmd) != 0: tdLog.exit(cmd) self.running = 1 - print("dnode:%d is running with %s " % (self.index, cmd)) tdLog.debug("dnode:%d is running with %s " % (self.index, cmd)) if self.valgrind == 0: time.sleep(0.1) @@ -664,7 +661,6 @@ class TDDnodes: def stoptaosd(self, index): self.check(index) self.dnodes[index - 1].stoptaosd() - def start(self, index): self.check(index) diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 85a782ecb1..01955ec93a 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -235,9 +235,17 @@ class TDSql: tdLog.info("sql:%s, row:%d col:%d data:%s == expect:%s" % (self.sql, row, col, self.queryResult[row][col], data)) return - elif isinstance(data, float) and abs(self.queryResult[row][col] - data) <= 0.000001: - tdLog.info("sql:%s, row:%d col:%d data:%f == expect:%f" % - (self.sql, row, col, self.queryResult[row][col], data)) + elif isinstance(data, float): + if abs(data) >= 1 and abs((self.queryResult[row][col] - data) / data) <= 0.000001: + tdLog.info("sql:%s, row:%d col:%d data:%f == expect:%f" % + (self.sql, row, col, self.queryResult[row][col], data)) + elif abs(data) < 1 and abs(self.queryResult[row][col] - data) <= 0.000001: + tdLog.info("sql:%s, row:%d col:%d data:%f == expect:%f" % + (self.sql, row, col, self.queryResult[row][col], data)) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) + tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) return else: caller = inspect.getframeinfo(inspect.stack()[1][0]) @@ -323,13 +331,32 @@ class TDSql: args = (caller.filename, caller.lineno, self.sql, col_name_list, expect_col_name_list) tdLog.exit("%s(%d) failed: sql:%s, col_name_list:%s != expect_col_name_list:%s" % args) + def __check_equal(self, elm, expect_elm): + if not type(elm) in(list, tuple) and elm == expect_elm: + return True + if type(elm) in(list, tuple) and type(expect_elm) in(list, tuple): + if len(elm) != len(expect_elm): + return False + if len(elm) == 0: + return True + for i in range(len(elm)): + flag = self.__check_equal(elm[i], expect_elm[i]) + if not flag: + return False + return True + return False + def checkEqual(self, elm, expect_elm): if elm == expect_elm: tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (self.sql, elm, expect_elm)) - else: - caller = inspect.getframeinfo(inspect.stack()[1][0]) - args = (caller.filename, caller.lineno, self.sql, elm, expect_elm) - tdLog.exit("%s(%d) failed: sql:%s, elm:%s != expect_elm:%s" % args) + return + if self.__check_equal(elm, expect_elm): + tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (self.sql, elm, expect_elm)) + return + + caller = inspect.getframeinfo(inspect.stack()[1][0]) + args = (caller.filename, caller.lineno, self.sql, elm, expect_elm) + tdLog.exit("%s(%d) failed: sql:%s, elm:%s != expect_elm:%s" % args) def checkNotEqual(self, elm, expect_elm): if elm != expect_elm: diff --git a/tests/pytest/util/taosadapter.py b/tests/pytest/util/taosadapter.py new file mode 100644 index 0000000000..1a198240d7 --- /dev/null +++ b/tests/pytest/util/taosadapter.py @@ -0,0 +1,260 @@ +import socket +from fabric2 import Connection +from util.log import * +from util.common import * + + +class TAdapter: + def __init__(self): + self.running = 0 + self.deployed = 0 + self.remoteIP = "" + self.taosadapter_cfg_dict = { + "debug" : True, + "taosConfigDir" : "", + "port" : 6041, + "logLevel" : "debug", + "cors" : { + "allowAllOrigins" : True, + }, + "pool" : { + "maxConnect" : 4000, + "maxIdle" : 4000, + "idleTimeout" : "1h" + }, + "ssl" : { + "enable" : False, + "certFile" : "", + "keyFile" : "", + }, + "log" : { + "path" : "", + "rotationCount" : 30, + "rotationTime" : "24h", + "rotationSize" : "1GB", + "enableRecordHttpSql" : True, + "sqlRotationCount" : 2, + "sqlRotationTime" : "24h", + "sqlRotationSize" : "1GB", + }, + "monitor" : { + "collectDuration" : "3s", + "incgroup" : False, + "pauseQueryMemoryThreshold" : 70, + "pauseAllMemoryThreshold" : 80, + "identity" : "", + "writeToTD" : True, + "user" : "root", + "password" : "taosdata", + "writeInterval" : "30s" + }, + "opentsdb" : { + "enable" : False + }, + "influxdb" : { + "enable" : False + }, + "statsd" : { + "enable" : False + }, + "collectd" : { + "enable" : False + }, + "opentsdb_telnet" : { + "enable" : False + }, + "node_exporter" : { + "enable" : False + }, + "prometheus" : { + "enable" : False + }, + } + # TODO: add taosadapter env: + # 1. init cfg.toml.dict :OK + # 2. dump dict to toml : OK + # 3. update cfg.toml.dict :OK + # 4. check adapter exists : OK + # 5. deploy adapter cfg : OK + # 6. adapter start : OK + # 7. adapter stop + + def init(self, path, remoteIP=""): + self.path = path + self.remoteIP = remoteIP + binPath = get_path() + "/../../../" + binPath = os.path.realpath(binPath) + + if path == "": + self.path = os.path.abspath(binPath + "../../") + else: + self.path = os.path.realpath(path) + + if self.remoteIP: + try: + self.config = eval(remoteIP) + self.remote_conn = Connection(host=self.config["host"], port=self.config["port"], user=self.config["user"], connect_kwargs={'password':self.config["password"]}) + except Exception as e: + tdLog.notice(e) + + def update_cfg(self, update_dict :dict): + if not isinstance(update_dict, dict): + return + if "log" in update_dict and "path" in update_dict["log"]: + del update_dict["log"]["path"] + for key, value in update_dict.items(): + if key in ["cors", "pool", "ssl", "log", "monitor", "opentsdb", "influxdb", "statsd", "collectd", "opentsdb_telnet", "node_exporter", "prometheus"]: + if isinstance(value, dict): + for k, v in value.items(): + self.taosadapter_cfg_dict[key][k] = v + else: + self.taosadapter_cfg_dict[key] = value + + def check_adapter(self): + if getPath(tool="taosadapter"): + return False + else: + return True + + def remote_exec(self, updateCfgDict, execCmd): + remoteCfgDict = copy.deepcopy(updateCfgDict) + if "log" in remoteCfgDict and "path" in remoteCfgDict["log"]: + del remoteCfgDict["log"]["path"] + + remoteCfgDictStr = base64.b64encode(toml.dumps(remoteCfgDict).encode()).decode() + execCmdStr = base64.b64encode(execCmd.encode()).decode() + with self.remote_conn.cd((self.config["path"]+sys.path[0].replace(self.path, '')).replace('\\','/')): + self.remote_conn.run(f"python3 ./test.py -D {remoteCfgDictStr} -e {execCmdStr}" ) + + def cfg(self, option, value): + cmd = f"echo {option} = {value} >> {self.cfg_path}" + if os.system(cmd) != 0: + tdLog.exit(cmd) + + def deploy(self, *update_cfg_dict): + self.log_dir = f"{self.path}/sim/dnode1/log" + self.cfg_dir = f"{self.path}/sim/dnode1/cfg" + self.cfg_path = f"{self.cfg_dir}/taosadapter.toml" + + cmd = f"touch {self.cfg_path}" + if os.system(cmd) != 0: + tdLog.exit(cmd) + + self.taosadapter_cfg_dict["log"]["path"] = self.log_dir + if bool(update_cfg_dict): + self.update_cfg(update_dict=update_cfg_dict) + + if (self.remoteIP == ""): + dict2toml(self.taosadapter_cfg_dict, self.cfg_path) + else: + self.remote_exec(self.taosadapter_cfg_dict, "tAdapter.deploy(update_cfg_dict)") + + self.deployed = 1 + + tdLog.debug(f"taosadapter is deployed and configured by {self.cfg_path}") + + def start(self): + bin_path = get_path(tool="taosadapter") + + if (bin_path == ""): + tdLog.exit("taosadapter not found!") + else: + tdLog.info(f"taosadapter found: {bin_path}") + + if platform.system().lower() == 'windows': + cmd = f"mintty -h never {bin_path} -c {self.cfg_dir}" + else: + cmd = f"nohup {bin_path} -c {self.cfg_path} > /dev/null 2>&1 & " + + if self.remoteIP: + self.remote_exec(self.taosadapter_cfg_dict, f"tAdapter.deployed=1\ntAdapter.log_dir={self.log_dir}\ntAdapter.cfg_dir={self.cfg_dir}\ntAdapter.start()") + self.running = 1 + else: + os.system(f"rm -rf {self.log_dir}/taosadapter*") + if os.system(cmd) != 0: + tdLog.exit(cmd) + self.running = 1 + tdLog.debug(f"taosadapter is running with {cmd} " ) + + time.sleep(0.1) + + taosadapter_port = self.taosadapter_cfg_dict["port"] + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(3) + try: + res = s.connect_ex((self.remoteIP, taosadapter_port)) + s.shutdown(2) + if res == 0: + tdLog.info(f"the taosadapter has been started, using port:{taosadapter_port}") + else: + tdLog.info(f"the taosadapter do not started!!!") + except socket.error as e: + tdLog.notice("socket connect error!") + finally: + if s: + s.close() + # tdLog.debug("the taosadapter has been started.") + time.sleep(1) + + def start_taosadapter(self): + """ + use this method, must deploy taosadapter + """ + bin_path = get_path(tool="taosadapter") + + if (bin_path == ""): + tdLog.exit("taosadapter not found!") + else: + tdLog.info(f"taosadapter found: {bin_path}") + + if self.deployed == 0: + tdLog.exit("taosadapter is not deployed") + + if platform.system().lower() == 'windows': + cmd = f"mintty -h never {bin_path} -c {self.cfg_dir}" + else: + cmd = f"nohup {bin_path} -c {self.cfg_path} > /dev/null 2>&1 & " + + if self.remoteIP: + self.remote_exec(self.taosadapter_cfg_dict, f"tAdapter.deployed=1\ntAdapter.log_dir={self.log_dir}\ntAdapter.cfg_dir={self.cfg_dir}\ntAdapter.start()") + self.running = 1 + else: + if os.system(cmd) != 0: + tdLog.exit(cmd) + self.running = 1 + tdLog.debug(f"taosadapter is running with {cmd} " ) + + time.sleep(0.1) + + def stop(self, force_kill=False): + signal = "-SIGKILL" if force_kill else "-SIGTERM" + + if self.remoteIP: + self.remote_exec(self.taosadapter_cfg_dict, "tAdapter.running=1\ntAdapter.stop()") + tdLog.info("stop taosadapter") + return + + toBeKilled = "taosadapter" + + if self.running != 0: + psCmd = f"ps -ef|grep -w {toBeKilled}| grep -v grep | awk '{{print $2}}'" + processID = subprocess.check_output( + psCmd, shell=True).decode("utf-8") + + while(processID): + killCmd = f"kill {signal} {processID} > /dev/null 2>&1" + os.system(killCmd) + time.sleep(1) + processID = subprocess.check_output( + psCmd, shell=True).decode("utf-8") + if not platform.system().lower() == 'windows': + for port in range(6030, 6041): + fuserCmd = f"fuser -k -n tcp {port} > /dev/null" + os.system(fuserCmd) + + self.running = 0 + tdLog.debug(f"taosadapter is stopped by kill {signal}") + + + +tAdapter = TAdapter() \ No newline at end of file diff --git a/tests/system-test/1-insert/create_retentions.py b/tests/system-test/1-insert/create_retentions.py index e333dafa28..2b611420c6 100644 --- a/tests/system-test/1-insert/create_retentions.py +++ b/tests/system-test/1-insert/create_retentions.py @@ -9,31 +9,41 @@ from util.dnodes import * PRIMARY_COL = "ts" -INT_COL = "c_int" -BINT_COL = "c_bint" -SINT_COL = "c_sint" -TINT_COL = "c_tint" -FLOAT_COL = "c_float" -DOUBLE_COL = "c_double" -BOOL_COL = "c_bool" -TINT_UN_COL = "c_tint_un" -SINT_UN_COL = "c_sint_un" -BINT_UN_COL = "c_bint_un" -INT_UN_COL = "c_int_un" +INT_COL = "c_int" +BINT_COL = "c_bint" +SINT_COL = "c_sint" +TINT_COL = "c_tint" +FLOAT_COL = "c_float" +DOUBLE_COL = "c_double" +BOOL_COL = "c_bool" +TINT_UN_COL = "c_utint" +SINT_UN_COL = "c_usint" +BINT_UN_COL = "c_ubint" +INT_UN_COL = "c_uint" +BINARY_COL = "c_binary" +NCHAR_COL = "c_nchar" +TS_COL = "c_ts" -BINARY_COL = "c_binary" -NCHAR_COL = "c_nchar" -TS_COL = "c_ts" +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, TINT_UN_COL, SINT_UN_COL, BINT_UN_COL, INT_UN_COL] +CHAR_COL = [BINARY_COL, NCHAR_COL, ] +BOOLEAN_COL = [BOOL_COL, ] +TS_TYPE_COL = [TS_COL, ] -NUM_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] -CHAR_COL = [ BINARY_COL, NCHAR_COL, ] -BOOLEAN_COL = [ BOOL_COL, ] -TS_TYPE_COL = [ TS_COL, ] +INT_TAG = "t_int" + +ALL_COL = [PRIMARY_COL, INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BINARY_COL, NCHAR_COL, BOOL_COL, TS_COL] +TAG_COL = [INT_TAG] ## insert data args: TIME_STEP = 10000 NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) +# init db/table +DBNAME = "db" +STBNAME = "stb1" +CTBNAME = "ct1" +NTBNAME = "nt1" + @dataclass class DataSet: ts_data : List[int] = field(default_factory=list) @@ -152,29 +162,31 @@ class TDTestCase: self.test_create_databases() self.test_create_stb() - def __create_tb(self): + def __create_tb(self, stb=STBNAME, ctb_num=20, ntbnum=1, rsma=False): tdLog.printNoPrefix("==========step: create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {stb}( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned - ) tags (t1 int) - ''' - create_ntb_sql = f'''create table t1( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, - {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, - {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned - ) + ) tags ({INT_TAG} int) ''' + for i in range(ntbnum): + + create_ntb_sql = f'''create table nt{i+1}( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) + ''' tdSql.execute(create_stb_sql) tdSql.execute(create_ntb_sql) - for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + for i in range(ctb_num): + tdSql.execute(f'create table ct{i+1} using {stb} tags ( {i+1} )') def __data_set(self, rows): data_set = DataSet() @@ -220,7 +232,7 @@ class TDTestCase: tdSql.execute( f"insert into ct1 values ( {NOW - i * TIME_STEP}, {row_data} )" ) tdSql.execute( f"insert into ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )" ) tdSql.execute( f"insert into ct4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )" ) - tdSql.execute( f"insert into t1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )" ) + tdSql.execute( f"insert into {NTBNAME} values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )" ) tdSql.execute( f"insert into ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )" ) tdSql.execute( f"insert into ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )" ) @@ -230,9 +242,9 @@ class TDTestCase: tdSql.execute( f"insert into ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )" ) tdSql.execute( f"insert into ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )" ) - tdSql.execute( f"insert into t1 values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )" ) - tdSql.execute( f"insert into t1 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )" ) - tdSql.execute( f"insert into t1 values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )" ) + tdSql.execute( f"insert into {NTBNAME} values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )" ) + tdSql.execute( f"insert into {NTBNAME} values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )" ) + tdSql.execute( f"insert into {NTBNAME} values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )" ) def run(self): diff --git a/tests/system-test/1-insert/time_range_wise.py b/tests/system-test/1-insert/time_range_wise.py index 2596f82476..f945bafe3b 100644 --- a/tests/system-test/1-insert/time_range_wise.py +++ b/tests/system-test/1-insert/time_range_wise.py @@ -325,10 +325,17 @@ class TDTestCase: def __sma_create_check(self, sma:SMAschema): if self.updatecfgDict["querySmaOptimize"] == 0: return False - # TODO: if database is a rollup-db, can not create sma index - # tdSql.query("select database()") - # if sma.rollup_db : - # return False + tdSql.query("select database()") + dbname = tdSql.getData(0,0) + tdSql.query("show databases") + for row in tdSql.queryResult: + if row[0] == dbname: + if row[-1] is None: + continue + if ":" in row[-1]: + sma.rollup_db = True + if sma.rollup_db : + return False tdSql.query("show stables") if not sma.tbname: return False @@ -379,12 +386,15 @@ class TDTestCase: tdSql.query(self.__create_sma_index(sma)) self.sma_count += 1 self.sma_created_index.append(sma.index_name) - tdSql.query("show streams") + tdSql.query(self.__show_sma_index(sma)) tdSql.checkRows(self.sma_count) + tdSql.checkData(0, 2, sma.tbname) else: tdSql.error(self.__create_sma_index(sma)) + + def __drop_sma_index(self, sma:SMAschema): sql = f"{sma.drop} {sma.drop_flag} {sma.index_name}" return sql @@ -402,12 +412,12 @@ class TDTestCase: def sma_drop_check(self, sma:SMAschema): if self.__sma_drop_check(sma): tdSql.query(self.__drop_sma_index(sma)) - print(self.__drop_sma_index(sma)) self.sma_count -= 1 self.sma_created_index = list(filter(lambda x: x != sma.index_name, self.sma_created_index)) tdSql.query("show streams") tdSql.checkRows(self.sma_count) + else: tdSql.error(self.__drop_sma_index(sma)) @@ -614,20 +624,20 @@ class TDTestCase: self.__insert_data() self.all_test() - #tdLog.printNoPrefix("==========step2:create table in rollup database") - #tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m") - #tdSql.execute("use db3") - # self.__create_tb() - #tdSql.execute(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL}) ") - #self.all_test() - - # self.__insert_data() + tdLog.printNoPrefix("==========step2:create table in rollup database") + tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m") + tdSql.execute("use db3") + tdSql.execute(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL}) ") + self.all_test() tdSql.execute("drop database if exists db1 ") tdSql.execute("drop database if exists db2 ") - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + + tdSql.execute("flush database db ") + tdLog.printNoPrefix("==========step4:after wal, all check again ") self.all_test() diff --git a/tests/system-test/2-query/abs.py b/tests/system-test/2-query/abs.py index f924cb7c3d..c9fc025b97 100644 --- a/tests/system-test/2-query/abs.py +++ b/tests/system-test/2-query/abs.py @@ -10,13 +10,13 @@ import random class TDTestCase: - updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, - "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, - "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} + # updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, + # "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, + # "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(), True) + tdSql.init(conn.cursor(), False) self.tb_nums = 10 self.row_nums = 20 self.ts = 1434938400000 @@ -24,14 +24,17 @@ class TDTestCase: def insert_datas_and_check_abs(self ,tbnums , rownums , time_step ): tdLog.info(" prepare datas for auto check abs function ") + dbname = "test" + stbname = f"{dbname}.stb" + ctbname_pre = f"{dbname}.sub_tb_" - tdSql.execute(" create database test ") - tdSql.execute(" use test ") - tdSql.execute(" create stable stb (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ + tdSql.execute(f" create database {dbname} ") + tdSql.execute(f" use {dbname} ") + tdSql.execute(f" create stable {stbname} (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int)") for tbnum in range(tbnums): - tbname = "sub_tb_%d"%tbnum - tdSql.execute(" create table %s using stb tags(%d) "%(tbname , tbnum)) + tbname = f"{ctbname_pre}{tbnum}" + tdSql.execute(f" create table {tbname} using {stbname} tags({tbnum}) ") ts = self.ts for row in range(rownums): @@ -48,8 +51,8 @@ class TDTestCase: c10 = ts tdSql.execute(f" insert into {tbname} values ({ts},{c1},{c2},{c3},{c4},{c5},{c6},{c7},{c8},{c9},{c10})") - tdSql.execute("use test") - tbnames = ["stb", "sub_tb_1"] + tdSql.execute(f"use {dbname}") + tbnames = [f"{stbname}", f"{ctbname_pre}1"] support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] for tbname in tbnames: tdSql.query("desc {}".format(tbname)) @@ -62,48 +65,48 @@ class TDTestCase: self.check_result_auto(origin_sql , abs_sql) - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") tdSql.execute( - "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -119,53 +122,53 @@ class TDTestCase: ''' ) - def prepare_tag_datas(self): + def prepare_tag_datas(self, dbname="testdb"): # prepare datas tdSql.execute( - "create database if not exists testdb keep 3650 duration 1000") + f"create database if not exists {dbname} keep 3650 duration 1000") tdSql.execute(" use testdb ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): tdSql.execute( - f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") tdSql.execute( - "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -213,43 +216,45 @@ class TDTestCase: "abs value check pass , it work as expected ,sql is \"%s\" " % abs_query) def test_errors(self): - tdSql.execute("use testdb") + dbname = "testdb" + tdSql.execute(f"use {dbname}") error_sql_lists = [ - "select abs from t1", - "select abs(-+--+c1) from t1", - # "select +-abs(c1) from t1", - # "select ++-abs(c1) from t1", - # "select ++--abs(c1) from t1", - # "select - -abs(c1)*0 from t1", - # "select abs(tbname+1) from t1 ", - "select abs(123--123)==1 from t1", - "select abs(c1) as 'd1' from t1", - "select abs(c1 ,c2 ) from t1", - "select abs(c1 ,NULL) from t1", - "select abs(,) from t1;", - "select abs(abs(c1) ab from t1)", - "select abs(c1) as int from t1", - "select abs from stb1", - # "select abs(-+--+c1) from stb1", - # "select +-abs(c1) from stb1", - # "select ++-abs(c1) from stb1", - # "select ++--abs(c1) from stb1", - # "select - -abs(c1)*0 from stb1", - # "select abs(tbname+1) from stb1 ", - "select abs(123--123)==1 from stb1", - "select abs(c1) as 'd1' from stb1", - "select abs(c1 ,c2 ) from stb1", - "select abs(c1 ,NULL) from stb1", - "select abs(,) from stb1;", - "select abs(abs(c1) ab from stb1)", - "select abs(c1) as int from stb1" + f"select abs from {dbname}.t1", + f"select abs(-+--+c1) from {dbname}.t1", + # f"select +-abs(c1) from {dbname}.t1", + # f"select ++-abs(c1) from {dbname}.t1", + # f"select ++--abs(c1) from {dbname}.t1", + # f"select - -abs(c1)*0 from {dbname}.t1", + # f"select abs(tbname+1) from {dbname}.t1 ", + f"select abs(123--123)==1 from {dbname}.t1", + f"select abs(c1) as 'd1' from {dbname}.t1", + f"select abs(c1 ,c2 ) from {dbname}.t1", + f"select abs(c1 ,NULL) from {dbname}.t1", + f"select abs(,) from {dbname}.t1;", + f"select abs(abs(c1) ab from {dbname}.t1)", + f"select abs(c1) as int from {dbname}.t1", + f"select abs from {dbname}.stb1", + # f"select abs(-+--+c1) from {dbname}.stb1", + # f"select +-abs(c1) from {dbname}.stb1", + # f"select ++-abs(c1) from {dbname}.stb1", + # f"select ++--abs(c1) from {dbname}.stb1", + # f"select - -abs(c1)*0 from {dbname}.stb1", + # f"select abs(tbname+1) from {dbname}.stb1 ", + f"select abs(123--123)==1 from {dbname}.stb1", + f"select abs(c1) as 'd1' from {dbname}.stb1", + f"select abs(c1 ,c2 ) from {dbname}.stb1", + f"select abs(c1 ,NULL) from {dbname}.stb1", + f"select abs(,) from {dbname}.stb1;", + f"select abs(abs(c1) ab from {dbname}.stb1)", + f"select abs(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) def support_types(self): - tdSql.execute("use testdb") - tbnames = ["stb1", "t1", "ct1", "ct2"] + dbname = "testdb" + tdSql.execute(f"use {dbname}") + tbnames = [f"{dbname}.stb1", f"{dbname}.t1", f"{dbname}.ct1", f"{dbname}.ct2"] support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] for tbname in tbnames: tdSql.query("desc {}".format(tbname)) @@ -262,96 +267,96 @@ class TDTestCase: else: tdSql.error(abs_sql) - def basic_abs_function(self): + def basic_abs_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select abs(c1) from ct3") + tdSql.query(f"select abs(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c2) from ct3") + tdSql.query(f"select abs(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c3) from ct3") + tdSql.query(f"select abs(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c4) from ct3") + tdSql.query(f"select abs(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c5) from ct3") + tdSql.query(f"select abs(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c6) from ct3") + tdSql.query(f"select abs(c6) from {dbname}.ct3") # used for regular table - tdSql.query("select abs(c1) from t1") + tdSql.query(f"select abs(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, 1) tdSql.checkData(3, 0, 3) tdSql.checkData(5, 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto("select c1, c2, c3 , c4, c5 from t1", - "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from t1") + self.check_result_auto(f"select c1, c2, c3 , c4, c5 from {dbname}.t1", + f"select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from {dbname}.t1") # used for sub table - tdSql.query("select abs(c1) from ct1") + tdSql.query(f"select abs(c1) from {dbname}.ct1") tdSql.checkData(0, 0, 8) tdSql.checkData(1, 0, 7) tdSql.checkData(3, 0, 5) tdSql.checkData(5, 0, 4) - tdSql.query("select abs(c1) from ct1") - self.check_result_auto("select c1, c2, c3 , c4, c5 from ct1", - "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct1") + tdSql.query(f"select abs(c1) from {dbname}.ct1") + self.check_result_auto(f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", + f"select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from {dbname}.ct1") self.check_result_auto( - "select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct1;", "select c1 from ct1") + f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from {dbname}.ct1;", f"select c1 from {dbname}.ct1") # used for stable table - tdSql.query("select abs(c1) from stb1") + tdSql.query(f"select abs(c1) from {dbname}.stb1") tdSql.checkRows(25) - self.check_result_auto("select c1, c2, c3 , c4, c5 from ct4 ", - "select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from ct4") + self.check_result_auto(f"select c1, c2, c3 , c4, c5 from {dbname}.ct4 ", + f"select (c1), abs(c2) ,abs(c3), abs(c4), abs(c5) from {dbname}.ct4") self.check_result_auto( - "select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from ct4;", "select c1 from ct4") + f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from {dbname}.ct4;", f"select c1 from {dbname}.ct4") # used for not exists table - tdSql.error("select abs(c1) from stbbb1") - tdSql.error("select abs(c1) from tbname") - tdSql.error("select abs(c1) from ct5") + tdSql.error(f"select abs(c1) from {dbname}.stbbb1") + tdSql.error(f"select abs(c1) from {dbname}.tbname") + tdSql.error(f"select abs(c1) from {dbname}.ct5") # mix with common col - tdSql.query("select c1, abs(c1) from ct1") + tdSql.query(f"select c1, abs(c1) from {dbname}.ct1") tdSql.checkData(0, 0, 8) tdSql.checkData(0, 1, 8) tdSql.checkData(4, 0, 0) tdSql.checkData(4, 1, 0) - tdSql.query("select c1, abs(c1) from ct4") + tdSql.query(f"select c1, abs(c1) from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(4, 0, 5) tdSql.checkData(4, 1, 5) tdSql.checkData(5, 0, None) tdSql.checkData(5, 1, None) - tdSql.query("select c1, abs(c1) from ct4 ") + tdSql.query(f"select c1, abs(c1) from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(4, 0, 5) tdSql.checkData(4, 1, 5) # mix with common functions - tdSql.query("select c1, abs(c1),c5, floor(c5) from ct4 ") + tdSql.query(f"select c1, abs(c1),c5, floor(c5) from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -362,33 +367,33 @@ class TDTestCase: tdSql.checkData(3, 2, 6.66000) tdSql.checkData(3, 3, 6.00000) - tdSql.query("select c1, abs(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, abs(c1),c5, floor(c5) from {dbname}.stb1 ") # mix with agg functions , not support - tdSql.error("select c1, abs(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, abs(c1),c5, count(c5) from ct1 ") - tdSql.error("select abs(c1), count(c5) from stb1 ") - tdSql.error("select abs(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, abs(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, abs(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select abs(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select abs(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") # bug fix for count - tdSql.query("select count(c1) from ct4 ") + tdSql.query(f"select count(c1) from {dbname}.ct4 ") tdSql.checkData(0, 0, 9) - tdSql.query("select count(*) from ct4 ") + tdSql.query(f"select count(*) from {dbname}.ct4 ") tdSql.checkData(0, 0, 12) - tdSql.query("select count(c1) from stb1 ") + tdSql.query(f"select count(c1) from {dbname}.stb1 ") tdSql.checkData(0, 0, 22) - tdSql.query("select count(*) from stb1 ") + tdSql.query(f"select count(*) from {dbname}.stb1 ") tdSql.checkData(0, 0, 25) # bug fix for compute - tdSql.query("select c1, abs(c1) -0 ,ceil(c1)-0 from ct4 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -396,7 +401,7 @@ class TDTestCase: tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 2, 8.000000000) - tdSql.query(" select c1, abs(c1) -0 ,ceil(c1-0.1)-0.1 from ct4") + tdSql.query(f" select c1, abs(c1) -0 ,ceil(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -404,10 +409,10 @@ class TDTestCase: tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 2, 7.900000000) - def abs_func_filter(self): - tdSql.execute("use db") + def abs_func_filter(self, dbname="db"): + tdSql.execute(f"use {dbname}") tdSql.query( - "select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0, 0, 8) tdSql.checkData(0, 1, 8.000000000) @@ -416,7 +421,7 @@ class TDTestCase: tdSql.checkData(0, 4, 3.000000000) tdSql.query( - "select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0, 0, 5) tdSql.checkData(0, 1, 5.000000000) @@ -425,7 +430,7 @@ class TDTestCase: tdSql.checkData(0, 4, 2.000000000) tdSql.query( - "select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0, 0, 5) tdSql.checkData(0, 1, 5.000000000) @@ -434,7 +439,7 @@ class TDTestCase: tdSql.checkData(0, 4, 2.000000000) tdSql.query( - "select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1>log(c1,2) limit 1 ") tdSql.checkRows(1) tdSql.checkData(0, 0, 8) tdSql.checkData(0, 1, 88888) @@ -448,130 +453,138 @@ class TDTestCase: def check_boundary_values(self): - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") + dbname = "bound_test" + + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"use {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - self.check_result_auto("select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", - "select abs(c1), abs(c2) ,abs(c3), abs(c4), abs(c5) ,abs(c6) from sub1_bound") - self.check_result_auto("select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", - "select abs(c1), abs(c2) ,abs(c3), abs(c3), abs(c2) ,abs(c1) from sub1_bound") + self.check_result_auto(f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", + f"select abs(c1), abs(c2) ,abs(c3), abs(c4), abs(c5) ,abs(c6) from {dbname}.sub1_bound") + self.check_result_auto(f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", + f"select abs(c1), abs(c2) ,abs(c3), abs(c3), abs(c2) ,abs(c1) from {dbname}.sub1_bound") self.check_result_auto( - "select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from sub1_bound;", "select abs(c1) from sub1_bound") + f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1)))))))))) nest_col_func from {dbname}.sub1_bound;", f"select abs(c1) from {dbname}.sub1_bound") # check basic elem for table per row tdSql.query( - "select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from sub1_bound ") + f"select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from {dbname}.sub1_bound ") tdSql.checkData(0, 0, 2147483647) tdSql.checkData(0, 1, 9223372036854775807) tdSql.checkData(0, 2, 32767) tdSql.checkData(0, 3, 127) - tdSql.checkData(0, 4, 339999995214436424907732413799364296704.00000) - tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + # tdSql.checkData(0, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(0, 4, 3.4E+38) + # tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(0, 5, 1.7E+308) tdSql.checkData(1, 0, 2147483647) tdSql.checkData(1, 1, 9223372036854775807) tdSql.checkData(1, 2, 32767) tdSql.checkData(1, 3, 127) - tdSql.checkData(1, 4, 339999995214436424907732413799364296704.00000) - tdSql.checkData(1, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + # tdSql.checkData(1, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(1, 4, 3.4E+38) + # tdSql.checkData(1, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(1, 5, 1.7E+308) tdSql.checkData(3, 0, 2147483646) tdSql.checkData(3, 1, 9223372036854775806) tdSql.checkData(3, 2, 32766) tdSql.checkData(3, 3, 126) - tdSql.checkData(3, 4, 339999995214436424907732413799364296704.00000) - tdSql.checkData(3, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + # tdSql.checkData(3, 4, 339999995214436424907732413799364296704.00000) + tdSql.checkData(3, 4, 3.4E+38) + # tdSql.checkData(3, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) + tdSql.checkData(3, 5, 1.7E+308) # check + - * / in functions tdSql.query( - "select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + f"select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from {dbname}.sub1_bound ") tdSql.checkData(0, 0, 2147483648.000000000) tdSql.checkData(0, 1, 9223372036854775807) tdSql.checkData(0, 2, 32767.000000000) tdSql.checkData(0, 3, 63.500000000) - tdSql.checkData( - 0, 4, 169999997607218212453866206899682148352.000000000) + tdSql.checkData(0, 4, 169999997607218212453866206899682148352.000000000) tdSql.checkData(0, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) tdSql.checkData(1, 0, 2147483646.000000000) tdSql.checkData(1, 1, 9223372036854775808.000000000) tdSql.checkData(1, 2, 32767.000000000) tdSql.checkData(1, 3, 63.500000000) - tdSql.checkData( - 1, 4, 169999997607218212453866206899682148352.000000000) + tdSql.checkData(1, 4, 169999997607218212453866206899682148352.000000000) - self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound", - "select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + self.check_result_auto(f"select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from {dbname}.sub1_bound", + f"select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from {dbname}.sub1_bound ") def test_tag_compute_for_scalar_function(self): + dbname = "testdb" - tdSql.execute("use testdb") + tdSql.execute(f"use {dbname}") - self.check_result_auto("select c1, t2, t3 , t4, t5 from ct4 ", - "select (c1), abs(t2) ,abs(t3), abs(t4), abs(t5) from ct4") - self.check_result_auto("select c1+2, t2+2, t3 , t4, t5 from ct4 ", - "select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from ct4") - self.check_result_auto("select c1+2, t2+2, t3 , t4, t5 from stb1 order by t1 ", - "select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from stb1 order by t1") + self.check_result_auto(f"select c1, t2, t3 , t4, t5 from {dbname}.ct4 ", + f"select (c1), abs(t2) ,abs(t3), abs(t4), abs(t5) from {dbname}.ct4") + self.check_result_auto(f"select c1+2, t2+2, t3 , t4, t5 from {dbname}.ct4 ", + f"select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from {dbname}.ct4") + self.check_result_auto(f"select c1+2, t2+2, t3 , t4, t5 from {dbname}.stb1 order by t1 ", + f"select (c1)+2, abs(t2)+2 ,abs(t3), abs(t4), abs(t5) from {dbname}.stb1 order by t1") # bug need fix # tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") # taosd crash - tdSql.query("select c1 ,t1 from stb1 where t1 =0 ") + tdSql.query(f"select c1 ,t1 from {dbname}.stb1 where t1 =0 ") tdSql.checkRows(13) - tdSql.query("select t1 from stb1 where t1 >0 ") + tdSql.query(f"select t1 from {dbname}.stb1 where t1 >0 ") tdSql.checkRows(12) - tdSql.query("select t1 from stb1 where t1 =3 ") + tdSql.query(f"select t1 from {dbname}.stb1 where t1 =3 ") tdSql.checkRows(12) - # tdSql.query("select sum(t1) from (select c1 ,t1 from stb1)") + # tdSql.query(f"select sum(t1) from (select c1 ,t1 from {dbname}.stb1)") # tdSql.checkData(0,0,61) - # tdSql.query("select distinct(c1) ,t1 from stb1") + # tdSql.query(f"select distinct(c1) ,t1 from {dbname}.stb1") # tdSql.checkRows(20) - tdSql.query("select max(t2) , t1 ,c1, t2 from stb1") + tdSql.query(f"select max(t2) , t1 ,c1, t2 from {dbname}.stb1") tdSql.checkData(0,3,33333) # tag filter with abs function - tdSql.query("select t1 from stb1 where abs(t1)=1") + tdSql.query(f"select t1 from {dbname}.stb1 where abs(t1)=1") tdSql.checkRows(0) - tdSql.query("select t1 from stb1 where abs(c1+t1)=1") + tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1") tdSql.checkRows(1) tdSql.checkData(0,0,0) - - tdSql.query("select abs(c1) from (select ts , c1 ,t1 from stb1)") + + tdSql.query(f"select abs(c1) from (select ts , c1 ,t1 from {dbname}.stb1)") tdSql.checkRows(25) tdSql.query( - "select abs(c1+t1)*t1 from stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") + f"select abs(c1+t1)*t1 from {dbname}.stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") def support_super_table_test(self): - tdSql.execute(" use testdb ") - self.check_result_auto( " select c1 from stb1 order by ts " , "select abs(c1) from stb1 order by ts" ) - self.check_result_auto( " select c1 from stb1 order by tbname " , "select abs(c1) from stb1 order by tbname" ) - self.check_result_auto( " select c1 from stb1 where c1 > 0 order by tbname " , "select abs(c1) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto( " select c1 from stb1 where c1 > 0 order by tbname " , "select abs(c1) from stb1 where c1 > 0 order by tbname" ) + dbname = "testdb" + tdSql.execute(f" use {dbname} ") + self.check_result_auto( f" select c1 from {dbname}.stb1 order by ts " , f"select abs(c1) from {dbname}.stb1 order by ts" ) + self.check_result_auto( f" select c1 from {dbname}.stb1 order by tbname " , f"select abs(c1) from {dbname}.stb1 order by tbname" ) + self.check_result_auto( f" select c1 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select abs(c1) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto( f" select c1 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select abs(c1) from {dbname}.stb1 where c1 > 0 order by tbname" ) - self.check_result_auto( " select t1,c1 from stb1 order by ts " , "select t1, abs(c1) from stb1 order by ts" ) - self.check_result_auto( " select t2,c1 from stb1 order by tbname " , "select t2 ,abs(c1) from stb1 order by tbname" ) - self.check_result_auto( " select t3,c1 from stb1 where c1 > 0 order by tbname " , "select t3 ,abs(c1) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto( " select t4,c1 from stb1 where c1 > 0 order by tbname " , "select t4 , abs(c1) from stb1 where c1 > 0 order by tbname" ) + self.check_result_auto( f" select t1,c1 from {dbname}.stb1 order by ts " , f"select t1, abs(c1) from {dbname}.stb1 order by ts" ) + self.check_result_auto( f" select t2,c1 from {dbname}.stb1 order by tbname " , f"select t2 ,abs(c1) from {dbname}.stb1 order by tbname" ) + self.check_result_auto( f" select t3,c1 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select t3 ,abs(c1) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto( f" select t4,c1 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select t4 , abs(c1) from {dbname}.stb1 where c1 > 0 order by tbname" ) pass diff --git a/tests/system-test/2-query/and_or_for_byte.py b/tests/system-test/2-query/and_or_for_byte.py index 62951e571f..7d156da379 100644 --- a/tests/system-test/2-query/and_or_for_byte.py +++ b/tests/system-test/2-query/and_or_for_byte.py @@ -10,28 +10,31 @@ import random class TDTestCase: - updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, - "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, - "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} + # updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, + # "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, + # "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(), True) + tdSql.init(conn.cursor(), False) self.tb_nums = 10 self.row_nums = 20 self.ts = 1434938400000 self.time_step = 1000 def insert_datas_and_check_abs(self ,tbnums , rownums , time_step ): + dbname = "test" + stb = f"{dbname}.stb" + ctb_pre = f"{dbname}.sub_tb_" tdLog.info(" prepare datas for auto check abs function ") - tdSql.execute(" create database test ") - tdSql.execute(" use test ") - tdSql.execute(" create stable stb (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ + tdSql.execute(f" create database {dbname} ") + tdSql.execute(f" use {dbname} ") + tdSql.execute(f" create stable {stb} (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int)") for tbnum in range(tbnums): - tbname = "sub_tb_%d"%tbnum - tdSql.execute(" create table %s using stb tags(%d) "%(tbname , tbnum)) + tbname = f"{ctb_pre}{tbnum}" + tdSql.execute(f" create table {tbname} using {stb} tags({tbnum}) ") ts = self.ts for row in range(rownums): @@ -49,7 +52,7 @@ class TDTestCase: tdSql.execute(f" insert into {tbname} values ({ts},{c1},{c2},{c3},{c4},{c5},{c6},{c7},{c8},{c9},{c10})") tdSql.execute("use test") - tbnames = ["stb", "sub_tb_1"] + tbnames = [stb, f"{ctb_pre}1"] support_types = ["BIGINT", "SMALLINT", "TINYINT", "FLOAT", "DOUBLE", "INT"] for tbname in tbnames: tdSql.query("desc {}".format(tbname)) @@ -64,48 +67,48 @@ class TDTestCase: self.check_function("|",False,tbname,cols[0],cols[1],cols[2]) - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") tdSql.execute( - "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -121,53 +124,53 @@ class TDTestCase: ''' ) - def prepare_tag_datas(self): + def prepare_tag_datas(self, dbname="testdb"): # prepare datas tdSql.execute( - "create database if not exists testdb keep 3650 duration 1000") - tdSql.execute(" use testdb ") + f"create database if not exists {dbname} keep 3650 duration 1000") + tdSql.execute(f" use {dbname} ") tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t0 timestamp, t1 int, t2 bigint, t3 smallint, t4 tinyint, t5 float, t6 double, t7 bool, t8 binary(16),t9 nchar(32)) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): tdSql.execute( - f'create table ct{i+1} using stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') + f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( now(), {1*i}, {11111*i}, {111*i}, {1*i}, {1.11*i}, {11.11*i}, {i%2}, "binary{i}", "nchar{i}" )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - "insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") tdSql.execute( - "insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") tdSql.execute( - "insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - "insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -270,88 +273,88 @@ class TDTestCase: for ind , result in enumerate(compute_result): tdSql.checkData(ind,0,result) - def test_errors(self): - tdSql.execute("use testdb") + def test_errors(self, dbname="testdb"): + tdSql.execute(f"use {dbname}") error_sql_lists = [ - "select c1&&c2 from t1", - "select c1&|c2 from t1", - "select c1&(c1=c2) from t1", - "select c1&* from t1", - "select 123&, from t1", - "select 123&\" from t1", - "select c1&- from t1;", - "select c1&&= from t1)", - "select c1&! from t1", - "select c1&@ from stb1", - "select c1&# from stb1", - "select c1&$ from stb1", - "select c1&% from stb1", - "select c1&() from stb1", + f"select c1&&c2 from {dbname}.t1", + f"select c1&|c2 from {dbname}.t1", + f"select c1&(c1=c2) from {dbname}.t1", + f"select c1&* from {dbname}.t1", + f"select 123&, from {dbname}.t1", + f"select 123&\" from {dbname}.t1", + f"select c1&- from {dbname}.t1;", + f"select c1&&= from {dbname}.t1)", + f"select c1&! from {dbname}.t1", + f"select c1&@ from {dbname}.stb1", + f"select c1&# from {dbname}.stb1", + f"select c1&$ from {dbname}.stb1", + f"select c1&% from {dbname}.stb1", + f"select c1&() from {dbname}.stb1", ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def basic_query(self): + def basic_query(self, dbname="testdb"): # basic query - tdSql.query("select c1&c2|c3 from ct1") + tdSql.query(f"select c1&c2|c3 from {dbname}.ct1") tdSql.checkRows(13) - tdSql.query("select c1 ,c2&c3, c1&c2&c3 from t1") + tdSql.query(f"select c1 ,c2&c3, c1&c2&c3 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 ,c1&c1&c1|c1 from stb1") + tdSql.query(f"select c1 ,c1&c1&c1|c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select abs(c1)&c2&c3 from ct3") + tdSql.query(f"select abs(c1)&c2&c3 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c2&c1&c3) from ct3") + tdSql.query(f"select abs(c2&c1&c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c3)+c1&c3+c2 from ct3") + tdSql.query(f"select abs(c3)+c1&c3+c2 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select abs(c1)&c2&c3 from ct4") + tdSql.query(f"select abs(c1)&c2&c3 from {dbname}.ct4") tdSql.checkRows(12) tdSql.checkData(0,0,None) tdSql.checkData(1,0,8) tdSql.checkData(10,0,0) - tdSql.query("select abs(c2&c1&c3) from ct4") + tdSql.query(f"select abs(c2&c1&c3) from {dbname}.ct4") tdSql.checkRows(12) tdSql.checkData(0,0,None) tdSql.checkData(1,0,8) tdSql.checkData(10,0,0) - tdSql.query("select (abs(c3)+c1)&(c3+c2) from ct4") + tdSql.query(f"select (abs(c3)+c1)&(c3+c2) from {dbname}.ct4") tdSql.checkRows(12) tdSql.checkData(0,0,None) tdSql.checkData(1,0,640) tdSql.checkData(10,0,0) # used for regular table - tdSql.query("select abs(c1)&c3&c3 from t1") + tdSql.query(f"select abs(c1)&c3&c3 from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1, 0, 1) tdSql.checkData(3, 0, 1) tdSql.checkData(5, 0, None) - tdSql.query("select abs(c1)&c2|ceil(c3)&c4|floor(c5) from t1") + tdSql.query(f"select abs(c1)&c2|ceil(c3)&c4|floor(c5) from {dbname}.t1") tdSql.checkData(1, 0, 11) tdSql.checkData(3, 0, 3) tdSql.checkData(5, 0, None) - tdSql.query("select ts,c1, c2, c3&c4|c5 from t1") + tdSql.query(f"select ts,c1, c2, c3&c4|c5 from {dbname}.t1") tdSql.checkData(1, 3, 11) tdSql.checkData(3, 3, 3) tdSql.checkData(5, 3, None) - self.check_function("&",False,"stb1","c1","ceil(c2)","abs(c3)","c4+1") - self.check_function("|",False,"stb1","c1","ceil(c2)","abs(c3)","c4+1") - self.check_function("&",False,"stb1","c1+c2","ceil(c2)","abs(c3+c2)","c4+1") - self.check_function("&",False,"ct4","123","ceil(c2)","abs(c3+c2)","c4+1") - self.check_function("&",False,"ct4","123","ceil(t1)","abs(c3+c2)","c4+1") - self.check_function("&",False,"ct4","t1+c1","-ceil(t1)","abs(c3+c2)","c4+1") - self.check_function("&",False,"stb1","c1","floor(t1)","abs(c1+c2)","t1+1") - self.check_function("&",True,"stb1","max(c1)","min(floor(t1))","sum(abs(c1+c2))","last(t1)+1") - self.check_function("&",False,"stb1","abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))))","floor(t1)","abs(c1+c2)","t1+1") + self.check_function("&",False,f"{dbname}.stb1","c1","ceil(c2)","abs(c3)","c4+1") + self.check_function("|",False,f"{dbname}.stb1","c1","ceil(c2)","abs(c3)","c4+1") + self.check_function("&",False,f"{dbname}.stb1","c1+c2","ceil(c2)","abs(c3+c2)","c4+1") + self.check_function("&",False,f"{dbname}.ct4","123","ceil(c2)","abs(c3+c2)","c4+1") + self.check_function("&",False,f"{dbname}.ct4","123","ceil(t1)","abs(c3+c2)","c4+1") + self.check_function("&",False,f"{dbname}.ct4","t1+c1","-ceil(t1)","abs(c3+c2)","c4+1") + self.check_function("&",False,f"{dbname}.stb1","c1","floor(t1)","abs(c1+c2)","t1+1") + self.check_function("&",True,f"{dbname}.stb1","max(c1)","min(floor(t1))","sum(abs(c1+c2))","last(t1)+1") + self.check_function("&",False,f"{dbname}.stb1","abs(abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))))","floor(t1)","abs(c1+c2)","t1+1") # mix with common col - tdSql.query("select c1&abs(c1)&c2&c3 ,c1,c2, t1 from ct1") + tdSql.query(f"select c1&abs(c1)&c2&c3 ,c1,c2, t1 from {dbname}.ct1") tdSql.checkData(0, 0, 8) tdSql.checkData(1, 0, 1) tdSql.checkData(4, 0, 0) @@ -360,7 +363,7 @@ class TDTestCase: # mix with common functions - tdSql.query(" select c1&abs(c1)&c2&c3, abs(c1), c5, floor(c5) from ct4 ") + tdSql.query(f" select c1&abs(c1)&c2&c3, abs(c1), c5, floor(c5) from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -371,28 +374,28 @@ class TDTestCase: tdSql.checkData(3, 2, 6.66000) tdSql.checkData(3, 3, 6.00000) - tdSql.query("select c1&abs(c1)&c2&c3, abs(c1),c5, floor(c5) from stb1 order by ts ") + tdSql.query(f"select c1&abs(c1)&c2&c3, abs(c1),c5, floor(c5) from {dbname}.stb1 order by ts ") tdSql.checkData(3, 0, 2) tdSql.checkData(3, 1, 6) tdSql.checkData(3, 2, 6.66000) tdSql.checkData(3, 3, 6.00000) # mix with agg functions , not support - tdSql.error("select c1&abs(c1)&c2&c3, abs(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1&abs(c1)&c2&c3, abs(c1),c5, count(c5) from ct1 ") - tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from stb1 ") - tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from ct1 ") - tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from ct1 ") - tdSql.error("select c1&abs(c1)&c2&c3, count(c5) from stb1 ") + tdSql.error(f"select c1&abs(c1)&c2&c3, abs(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1&abs(c1)&c2&c3, abs(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1&abs(c1)&c2&c3, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1&abs(c1)&c2&c3, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1&abs(c1)&c2&c3, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1&abs(c1)&c2&c3, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select sum(c1&abs(c1)&c2&c3) ,max(c5), count(c5) from stb1") + tdSql.query(f"select sum(c1&abs(c1)&c2&c3) ,max(c5), count(c5) from {dbname}.stb1") - tdSql.query("select max(c1)&max(c2)|first(ts), count(c5) from ct1") + tdSql.query(f"select max(c1)&max(c2)|first(ts), count(c5) from {dbname}.ct1") # bug fix for compute - tdSql.query("select c1&abs(c1)&c2&c3, abs(c1&abs(c1)&c2&c3) -0 ,ceil(c1&abs(c1)&c2&c3)-0 from ct4 ") + tdSql.query(f"select c1&abs(c1)&c2&c3, abs(c1&abs(c1)&c2&c3) -0 ,ceil(c1&abs(c1)&c2&c3)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -400,7 +403,7 @@ class TDTestCase: tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 2, 8.000000000) - tdSql.query(" select c1&c2|c3, abs(c1&c2|c3) -0 ,ceil(c1&c2|c3-0.1)-0.1 from ct4") + tdSql.query(f" select c1&c2|c3, abs(c1&c2|c3) -0 ,ceil(c1&c2|c3-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -411,38 +414,38 @@ class TDTestCase: - def check_boundary_values(self): + def check_boundary_values(self, dbname="bound_test"): - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"use {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - self.check_function("&", False , "sub1_bound" ,"c1","c2","c3","c4","c5","c6" ) - self.check_function("&", False ,"sub1_bound","abs(c1)","abs(c2)","abs(c3)","abs(c4)","abs(c5)","abs(c6)" ) - self.check_function("&", False ,"stb_bound","123","abs(c2)","t1","abs(c4)","abs(c5)","abs(c6)" ) + self.check_function("&", False , f"{dbname}.sub1_bound" ,"c1","c2","c3","c4","c5","c6" ) + self.check_function("&", False , f"{dbname}.sub1_bound","abs(c1)","abs(c2)","abs(c3)","abs(c4)","abs(c5)","abs(c6)" ) + self.check_function("&", False , f"{dbname}.stb_bound","123","abs(c2)","t1","abs(c4)","abs(c5)","abs(c6)" ) # check basic elem for table per row tdSql.query( - "select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from sub1_bound ") + f"select abs(c1) ,abs(c2) , abs(c3) , abs(c4), abs(c5), abs(c6) from {dbname}.sub1_bound ") tdSql.checkData(0, 0, 2147483647) tdSql.checkData(0, 1, 9223372036854775807) tdSql.checkData(0, 2, 32767) @@ -463,10 +466,10 @@ class TDTestCase: tdSql.checkData(3, 5, 169999999999999993883079578865998174333346074304075874502773119193537729178160565864330091787584707988572262467983188919169916105593357174268369962062473635296474636515660464935663040684957844303524367815028553272712298986386310828644513212353921123253311675499856875650512437415429217994623324794855339589632.000000000) # check + - * / in functions - self.check_function("&", False ,"stb_bound","abs(c1+1)","abs(c2)","t1","abs(c3*1)","abs(c5)/2","abs(c6)" ) + self.check_function("&", False , f"{dbname}.stb_bound","abs(c1+1)","abs(c2)","t1","abs(c3*1)","abs(c5)/2","abs(c6)" ) tdSql.query( - "select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from sub1_bound ") + f"select abs(c1+1) ,abs(c2) , abs(c3*1) , abs(c4/2), abs(c5)/2, abs(c6) from {dbname}.sub1_bound ") tdSql.checkData(0, 0, 2147483648.000000000) tdSql.checkData(0, 1, 9223372036854775807) tdSql.checkData(0, 2, 32767.000000000) @@ -483,44 +486,44 @@ class TDTestCase: 1, 4, 169999997607218212453866206899682148352.000000000) - def test_tag_compute_for_scalar_function(self): + def test_tag_compute_for_scalar_function(self, dbname="testdb"): - tdSql.execute("use testdb") + tdSql.execute(f"use {dbname}") - self.check_function("&", False ,"ct4","123","abs(c1)","t1","abs(t2)","abs(t3)","abs(t4)","t5") - self.check_function("&", False ,"ct4","c1+2","abs(t2+2)","t3","abs(t4)","abs(t5)","abs(c1)","t5") + self.check_function("&", False , f"{dbname}.ct4","123","abs(c1)","t1","abs(t2)","abs(t3)","abs(t4)","t5") + self.check_function("&", False , f"{dbname}.ct4","c1+2","abs(t2+2)","t3","abs(t4)","abs(t5)","abs(c1)","t5") - tdSql.query(" select sum(c1) from stb1 where t1+10 >1; ") - tdSql.query("select c1 ,t1 from stb1 where t1 =0 ") + tdSql.query(f" select sum(c1) from {dbname}.stb1 where t1+10 >1; ") + tdSql.query(f"select c1 ,t1 from {dbname}.stb1 where t1 =0 ") tdSql.checkRows(13) - self.check_function("&", False ,"t1","c1+2","abs(c2)") - tdSql.query("select t1 from stb1 where t1 >0 ") + self.check_function("&", False , f"{dbname}.t1","c1+2","abs(c2)") + tdSql.query(f"select t1 from {dbname}.stb1 where t1 >0 ") tdSql.checkRows(12) - tdSql.query("select t1 from stb1 where t1 =3 ") + tdSql.query(f"select t1 from {dbname}.stb1 where t1 =3 ") tdSql.checkRows(12) # tdSql.query("select sum(t1) from (select c1 ,t1 from stb1)") # tdSql.checkData(0,0,61) # tdSql.query("select distinct(c1) ,t1 from stb1") # tdSql.checkRows(20) - tdSql.query("select max(c1) , t1&c2&t2 from stb1;") + tdSql.query(f"select max(c1) , t1&c2&t2 from {dbname}.stb1;") tdSql.checkData(0,1,0) # tag filter with abs function - tdSql.query("select t1 from stb1 where abs(t1)=1") + tdSql.query(f"select t1 from {dbname}.stb1 where abs(t1)=1") tdSql.checkRows(0) - tdSql.query("select t1 from stb1 where abs(c1+t1)=1") + tdSql.query(f"select t1 from {dbname}.stb1 where abs(c1+t1)=1") tdSql.checkRows(1) tdSql.checkData(0,0,0) tdSql.query( - "select abs(c1+t1)*t1 from stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") + f"select abs(c1+t1)*t1 from {dbname}.stb1 where abs(c1)/floor(abs(ceil(t1))) ==1") - def support_super_table_test(self): - tdSql.execute(" use testdb ") - self.check_function("|", False , "stb1" , "c1","c2","c3","c4" ) - self.check_function("|", False , "stb1" , "c1","c2","abs(c3)","c4","ceil(t1)" ) - self.check_function("&", False , "stb1" , "c1","c2","abs(c3)","floor(c4)","ceil(t1)" ) - self.check_function("&", True , "stb1" , "max(c1)","max(c2)","sum(abs(c3))","max(floor(c4))","min(ceil(t1))" ) + def support_super_table_test(self, dbname="testdb"): + tdSql.execute(f" use {dbname} ") + self.check_function("|", False , f"{dbname}.stb1" , "c1","c2","c3","c4" ) + self.check_function("|", False , f"{dbname}.stb1" , "c1","c2","abs(c3)","c4","ceil(t1)" ) + self.check_function("&", False , f"{dbname}.stb1" , "c1","c2","abs(c3)","floor(c4)","ceil(t1)" ) + self.check_function("&", True , f"{dbname}.stb1" , "max(c1)","max(c2)","sum(abs(c3))","max(floor(c4))","min(ceil(t1))" ) def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring diff --git a/tests/system-test/2-query/apercentile.py b/tests/system-test/2-query/apercentile.py index 6e4b4eeb8a..128a03937a 100644 --- a/tests/system-test/2-query/apercentile.py +++ b/tests/system-test/2-query/apercentile.py @@ -20,12 +20,13 @@ from util.sqlset import TDSetSql class TDTestCase: def init(self, conn, logSql): tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(),logSql) + tdSql.init(conn.cursor(),False) self.rowNum = 10 self.ts = 1537146000000 self.setsql = TDSetSql() - self.ntbname = 'ntb' - self.stbname = 'stb' + self.dbname = "db" + self.ntbname = f"{self.dbname}.ntb" + self.stbname = f'{self.dbname}.stb' self.binary_length = 20 # the length of binary for column_dict self.nchar_length = 20 # the length of nchar for column_dict self.column_dict = { diff --git a/tests/system-test/2-query/arccos.py b/tests/system-test/2-query/arccos.py index d5656d9104..1787521517 100644 --- a/tests/system-test/2-query/arccos.py +++ b/tests/system-test/2-query/arccos.py @@ -9,49 +9,48 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - self.PI =3.1415926 - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -102,68 +101,68 @@ class TDTestCase: else: tdLog.info("acos value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - "select acos from t1", - # "select acos(-+--+c1 ) from t1", - # "select +-acos(c1) from t1", - # "select ++-acos(c1) from t1", - # "select ++--acos(c1) from t1", - # "select - -acos(c1)*0 from t1", - # "select acos(tbname+1) from t1 ", - "select acos(123--123)==1 from t1", - "select acos(c1) as 'd1' from t1", - "select acos(c1 ,c2) from t1", - "select acos(c1 ,NULL ) from t1", - "select acos(,) from t1;", - "select acos(acos(c1) ab from t1)", - "select acos(c1 ) as int from t1", - "select acos from stb1", - # "select acos(-+--+c1) from stb1", - # "select +-acos(c1) from stb1", - # "select ++-acos(c1) from stb1", - # "select ++--acos(c1) from stb1", - # "select - -acos(c1)*0 from stb1", - # "select acos(tbname+1) from stb1 ", - "select acos(123--123)==1 from stb1", - "select acos(c1) as 'd1' from stb1", - "select acos(c1 ,c2 ) from stb1", - "select acos(c1 ,NULL) from stb1", - "select acos(,) from stb1;", - "select acos(acos(c1) ab from stb1)", - "select acos(c1) as int from stb1" + f"select acos from {dbname}.t1", + # f"select acos(-+--+c1 ) from {dbname}.t1", + # f"select +-acos(c1) from {dbname}.t1", + # f"select ++-acos(c1) from {dbname}.t1", + # f"select ++--acos(c1) from {dbname}.t1", + # f"select - -acos(c1)*0 from {dbname}.t1", + # f"select acos(tbname+1) from {dbname}.t1 ", + f"select acos(123--123)==1 from {dbname}.t1", + f"select acos(c1) as 'd1' from {dbname}.t1", + f"select acos(c1 ,c2) from {dbname}.t1", + f"select acos(c1 ,NULL ) from {dbname}.t1", + f"select acos(,) from {dbname}.t1;", + f"select acos(acos(c1) ab from {dbname}.t1)", + f"select acos(c1 ) as int from {dbname}.t1", + f"select acos from {dbname}.stb1", + # f"select acos(-+--+c1) from {dbname}.stb1", + # f"select +-acos(c1) from {dbname}.stb1", + # f"select ++-acos(c1) from {dbname}.stb1", + # f"select ++--acos(c1) from {dbname}.stb1", + # f"select - -acos(c1)*0 from {dbname}.stb1", + # f"select acos(tbname+1) from {dbname}.stb1 ", + f"select acos(123--123)==1 from {dbname}.stb1", + f"select acos(c1) as 'd1' from {dbname}.stb1", + f"select acos(c1 ,c2 ) from {dbname}.stb1", + f"select acos(c1 ,NULL) from {dbname}.stb1", + f"select acos(,) from {dbname}.stb1;", + f"select acos(acos(c1) ab from {dbname}.stb1)", + f"select acos(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def support_types(self): + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select acos(ts) from t1" , - "select acos(c7) from t1", - "select acos(c8) from t1", - "select acos(c9) from t1", - "select acos(ts) from ct1" , - "select acos(c7) from ct1", - "select acos(c8) from ct1", - "select acos(c9) from ct1", - "select acos(ts) from ct3" , - "select acos(c7) from ct3", - "select acos(c8) from ct3", - "select acos(c9) from ct3", - "select acos(ts) from ct4" , - "select acos(c7) from ct4", - "select acos(c8) from ct4", - "select acos(c9) from ct4", - "select acos(ts) from stb1" , - "select acos(c7) from stb1", - "select acos(c8) from stb1", - "select acos(c9) from stb1" , + f"select acos(ts) from {dbname}.t1" , + f"select acos(c7) from {dbname}.t1", + f"select acos(c8) from {dbname}.t1", + f"select acos(c9) from {dbname}.t1", + f"select acos(ts) from {dbname}.ct1" , + f"select acos(c7) from {dbname}.ct1", + f"select acos(c8) from {dbname}.ct1", + f"select acos(c9) from {dbname}.ct1", + f"select acos(ts) from {dbname}.ct3" , + f"select acos(c7) from {dbname}.ct3", + f"select acos(c8) from {dbname}.ct3", + f"select acos(c9) from {dbname}.ct3", + f"select acos(ts) from {dbname}.ct4" , + f"select acos(c7) from {dbname}.ct4", + f"select acos(c8) from {dbname}.ct4", + f"select acos(c9) from {dbname}.ct4", + f"select acos(ts) from {dbname}.stb1" , + f"select acos(c7) from {dbname}.stb1", + f"select acos(c8) from {dbname}.stb1", + f"select acos(c9) from {dbname}.stb1" , - "select acos(ts) from stbbb1" , - "select acos(c7) from stbbb1", + f"select acos(ts) from {dbname}.stbbb1" , + f"select acos(c7) from {dbname}.stbbb1", - "select acos(ts) from tbname", - "select acos(c9) from tbname" + f"select acos(ts) from {dbname}.tbname", + f"select acos(c9) from {dbname}.tbname" ] @@ -172,103 +171,103 @@ class TDTestCase: type_sql_lists = [ - "select acos(c1) from t1", - "select acos(c2) from t1", - "select acos(c3) from t1", - "select acos(c4) from t1", - "select acos(c5) from t1", - "select acos(c6) from t1", + f"select acos(c1) from {dbname}.t1", + f"select acos(c2) from {dbname}.t1", + f"select acos(c3) from {dbname}.t1", + f"select acos(c4) from {dbname}.t1", + f"select acos(c5) from {dbname}.t1", + f"select acos(c6) from {dbname}.t1", - "select acos(c1) from ct1", - "select acos(c2) from ct1", - "select acos(c3) from ct1", - "select acos(c4) from ct1", - "select acos(c5) from ct1", - "select acos(c6) from ct1", + f"select acos(c1) from {dbname}.ct1", + f"select acos(c2) from {dbname}.ct1", + f"select acos(c3) from {dbname}.ct1", + f"select acos(c4) from {dbname}.ct1", + f"select acos(c5) from {dbname}.ct1", + f"select acos(c6) from {dbname}.ct1", - "select acos(c1) from ct3", - "select acos(c2) from ct3", - "select acos(c3) from ct3", - "select acos(c4) from ct3", - "select acos(c5) from ct3", - "select acos(c6) from ct3", + f"select acos(c1) from {dbname}.ct3", + f"select acos(c2) from {dbname}.ct3", + f"select acos(c3) from {dbname}.ct3", + f"select acos(c4) from {dbname}.ct3", + f"select acos(c5) from {dbname}.ct3", + f"select acos(c6) from {dbname}.ct3", - "select acos(c1) from stb1", - "select acos(c2) from stb1", - "select acos(c3) from stb1", - "select acos(c4) from stb1", - "select acos(c5) from stb1", - "select acos(c6) from stb1", + f"select acos(c1) from {dbname}.stb1", + f"select acos(c2) from {dbname}.stb1", + f"select acos(c3) from {dbname}.stb1", + f"select acos(c4) from {dbname}.stb1", + f"select acos(c5) from {dbname}.stb1", + f"select acos(c6) from {dbname}.stb1", - "select acos(c6) as alisb from stb1", - "select acos(c6) alisb from stb1", + f"select acos(c6) as alisb from {dbname}.stb1", + f"select acos(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def basic_acos_function(self): + def basic_acos_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select acos(c1) from ct3") + tdSql.query(f"select acos(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select acos(c2) from ct3") + tdSql.query(f"select acos(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select acos(c3) from ct3") + tdSql.query(f"select acos(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select acos(c4) from ct3") + tdSql.query(f"select acos(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select acos(c5) from ct3") + tdSql.query(f"select acos(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select acos(c6) from ct3") + tdSql.query(f"select acos(c6) from {dbname}.ct3") tdSql.checkRows(0) # # used for regular table - tdSql.query("select acos(c1) from t1") + tdSql.query(f"select acos(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1 , 0, 0.000000000) tdSql.checkData(3 , 0, None) tdSql.checkData(5 , 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto_acos( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select acos(abs(c1)), acos(abs(c2)) ,acos(abs(c3)), acos(abs(c4)), acos(abs(c5)) from t1") + self.check_result_auto_acos( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.t1", f"select acos(abs(c1)), acos(abs(c2)) ,acos(abs(c3)), acos(abs(c4)), acos(abs(c5)) from {dbname}.t1") # used for sub table - tdSql.query("select c2 ,acos(c2) from ct1") + tdSql.query(f"select c2 ,acos(c2) from {dbname}.ct1") tdSql.checkData(0, 1, None) tdSql.checkData(1 , 1, None) tdSql.checkData(3 , 1, None) tdSql.checkData(4 , 1, 1.570796327) - tdSql.query("select c1, c5 ,acos(c5) from ct4") + tdSql.query(f"select c1, c5 ,acos(c5) from {dbname}.ct4") tdSql.checkData(0 , 2, None) tdSql.checkData(1 , 2, None) tdSql.checkData(2 , 2, None) tdSql.checkData(3 , 2, None) tdSql.checkData(5 , 2, None) - self.check_result_auto_acos( "select c1, c2, c3 , c4, c5 from ct1", "select acos(c1), acos(c2) ,acos(c3), acos(c4), acos(c5) from ct1") + self.check_result_auto_acos( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select acos(c1), acos(c2) ,acos(c3), acos(c4), acos(c5) from {dbname}.ct1") # nest query for acos functions - tdSql.query("select c4 , acos(c4) ,acos(acos(c4)) , acos(acos(acos(c4))) from ct1;") + tdSql.query(f"select c4 , acos(c4) ,acos(acos(c4)) , acos(acos(acos(c4))) from {dbname}.ct1;") tdSql.checkData(0 , 0 , 88) tdSql.checkData(0 , 1 , None) tdSql.checkData(0 , 2 , None) @@ -286,22 +285,22 @@ class TDTestCase: # used for stable table - tdSql.query("select acos(c1) from stb1") + tdSql.query(f"select acos(c1) from {dbname}.stb1") tdSql.checkRows(25) # used for not exists table - tdSql.error("select acos(c1) from stbbb1") - tdSql.error("select acos(c1) from tbname") - tdSql.error("select acos(c1) from ct5") + tdSql.error(f"select acos(c1) from {dbname}.stbbb1") + tdSql.error(f"select acos(c1) from {dbname}.tbname") + tdSql.error(f"select acos(c1) from {dbname}.ct5") # mix with common col - tdSql.query("select c1, acos(c1) from ct1") - tdSql.query("select c2, acos(c2) from ct4") + tdSql.query(f"select c1, acos(c1) from {dbname}.ct1") + tdSql.query(f"select c2, acos(c2) from {dbname}.ct4") # mix with common functions - tdSql.query("select c1, acos(c1),acos(c1), acos(acos(c1)) from ct4 ") + tdSql.query(f"select c1, acos(c1),acos(c1), acos(acos(c1)) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) @@ -312,24 +311,24 @@ class TDTestCase: tdSql.checkData(3 , 2 ,None) tdSql.checkData(3 , 3 ,None) - tdSql.query("select c1, acos(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, acos(c1),c5, floor(c5) from {dbname}.stb1 ") # # mix with agg functions , not support - tdSql.error("select c1, acos(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, acos(c1),c5, count(c5) from ct1 ") - tdSql.error("select acos(c1), count(c5) from stb1 ") - tdSql.error("select acos(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, acos(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, acos(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select acos(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select acos(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") # # bug fix for compute - tdSql.query("select c1, acos(c1) -0 ,acos(c1-4)-0 from ct4 ") + tdSql.query(f"select c1, acos(c1) -0 ,acos(c1-4)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -337,7 +336,7 @@ class TDTestCase: tdSql.checkData(1, 1, None) tdSql.checkData(1, 2, None) - tdSql.query(" select c1, acos(c1) -0 ,acos(c1-0.1)-0.1 from ct4") + tdSql.query(f" select c1, acos(c1) -0 ,acos(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -345,35 +344,35 @@ class TDTestCase: tdSql.checkData(1, 1, None) tdSql.checkData(1, 2, None) - tdSql.query("select c1, acos(c1), c2, acos(c2), c3, acos(c3) from ct1") + tdSql.query(f"select c1, acos(c1), c2, acos(c2), c3, acos(c3) from {dbname}.ct1") - def test_big_number(self): + def test_big_number(self, dbname="db"): - tdSql.query("select c1, acos(100000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, acos(100000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, None) - tdSql.query("select c1, acos(10000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, acos(10000000000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, None) - tdSql.query("select c1, acos(10000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, acos(10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, acos(10000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, acos(10000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(1, 1, None) - tdSql.query("select c1, acos(10000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, acos(10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, acos(10000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, acos(10000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, None) - tdSql.query("select c1, acos(10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, acos(10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, acos(10000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, acos(10000000000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, None) - tdSql.query("select c1, acos(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, acos(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow - def abs_func_filter(self): - tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(acos(c1)-0.5) from ct4 where c1>5 ") + def abs_func_filter(self, dbname="db"): + tdSql.execute(f"use {dbname}") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(acos(c1)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0,0,8) tdSql.checkData(0,1,8.000000000) @@ -381,7 +380,7 @@ class TDTestCase: tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,4,None) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(acos(c1)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(acos(c1)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -389,7 +388,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,None) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(acos(c1)-0.5) from ct4 where c1 0 order by tbname " , "select acos(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_acos( " select c5 from stb1 where c1 > 0 order by tbname " , "select acos(c5) from stb1 where c1 > 0 order by tbname" ) + def support_super_table_test(self, dbname="db"): + tdSql.execute(f" use {dbname} ") + self.check_result_auto_acos( f" select c5 from {dbname}.stb1 order by ts " , f"select acos(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_acos( f" select c5 from {dbname}.stb1 order by tbname " , f"select acos(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_acos( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select acos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_acos( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select acos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_acos( " select t1,c5 from stb1 order by ts " , "select acos(t1), acos(c5) from stb1 order by ts" ) - self.check_result_auto_acos( " select t1,c5 from stb1 order by tbname " , "select acos(t1) ,acos(c5) from stb1 order by tbname" ) - self.check_result_auto_acos( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select acos(t1) ,acos(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_acos( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select acos(t1) , acos(c5) from stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_acos( f" select t1,c5 from {dbname}.stb1 order by ts " , f"select acos(t1), acos(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_acos( f" select t1,c5 from {dbname}.stb1 order by tbname " , f"select acos(t1) ,acos(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_acos( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select acos(t1) ,acos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_acos( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select acos(t1) , acos(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) pass @@ -526,9 +525,9 @@ class TDTestCase: self.abs_func_filter() - tdLog.printNoPrefix("==========step7: acos filter query ============") + # tdLog.printNoPrefix("==========step7: acos filter query ============") - self.abs_func_filter() + # self.abs_func_filter() tdLog.printNoPrefix("==========step8: check acos result of stable query ============") diff --git a/tests/system-test/2-query/arcsin.py b/tests/system-test/2-query/arcsin.py index 31185ffcaa..127419029b 100644 --- a/tests/system-test/2-query/arcsin.py +++ b/tests/system-test/2-query/arcsin.py @@ -9,49 +9,48 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - self.PI =3.1415926 - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -102,68 +101,68 @@ class TDTestCase: else: tdLog.info("asin value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - "select asin from t1", - # "select asin(-+--+c1 ) from t1", - # "select +-asin(c1) from t1", - # "select ++-asin(c1) from t1", - # "select ++--asin(c1) from t1", - # "select - -asin(c1)*0 from t1", - # "select asin(tbname+1) from t1 ", - "select asin(123--123)==1 from t1", - "select asin(c1) as 'd1' from t1", - "select asin(c1 ,c2) from t1", - "select asin(c1 ,NULL ) from t1", - "select asin(,) from t1;", - "select asin(asin(c1) ab from t1)", - "select asin(c1 ) as int from t1", - "select asin from stb1", - # "select asin(-+--+c1) from stb1", - # "select +-asin(c1) from stb1", - # "select ++-asin(c1) from stb1", - # "select ++--asin(c1) from stb1", - # "select - -asin(c1)*0 from stb1", - # "select asin(tbname+1) from stb1 ", - "select asin(123--123)==1 from stb1", - "select asin(c1) as 'd1' from stb1", - "select asin(c1 ,c2 ) from stb1", - "select asin(c1 ,NULL) from stb1", - "select asin(,) from stb1;", - "select asin(asin(c1) ab from stb1)", - "select asin(c1) as int from stb1" + f"select asin from {dbname}.t1", + # f"select asin(-+--+c1 ) from {dbname}.t1", + # f"select +-asin(c1) from {dbname}.t1", + # f"select ++-asin(c1) from {dbname}.t1", + # f"select ++--asin(c1) from {dbname}.t1", + # f"select - -asin(c1)*0 from {dbname}.t1", + # f"select asin(tbname+1) from {dbname}.t1 ", + f"select asin(123--123)==1 from {dbname}.t1", + f"select asin(c1) as 'd1' from {dbname}.t1", + f"select asin(c1 ,c2) from {dbname}.t1", + f"select asin(c1 ,NULL ) from {dbname}.t1", + f"select asin(,) from {dbname}.t1;", + f"select asin(asin(c1) ab from {dbname}.t1)", + f"select asin(c1 ) as int from {dbname}.t1", + f"select asin from {dbname}.stb1", + # f"select asin(-+--+c1) from {dbname}.stb1", + # f"select +-asin(c1) from {dbname}.stb1", + # f"select ++-asin(c1) from {dbname}.stb1", + # f"select ++--asin(c1) from {dbname}.stb1", + # f"select - -asin(c1)*0 from {dbname}.stb1", + # f"select asin(tbname+1) from {dbname}.stb1 ", + f"select asin(123--123)==1 from {dbname}.stb1", + f"select asin(c1) as 'd1' from {dbname}.stb1", + f"select asin(c1 ,c2 ) from {dbname}.stb1", + f"select asin(c1 ,NULL) from {dbname}.stb1", + f"select asin(,) from {dbname}.stb1;", + f"select asin(asin(c1) ab from {dbname}.stb1)", + f"select asin(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def support_types(self): + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select asin(ts) from t1" , - "select asin(c7) from t1", - "select asin(c8) from t1", - "select asin(c9) from t1", - "select asin(ts) from ct1" , - "select asin(c7) from ct1", - "select asin(c8) from ct1", - "select asin(c9) from ct1", - "select asin(ts) from ct3" , - "select asin(c7) from ct3", - "select asin(c8) from ct3", - "select asin(c9) from ct3", - "select asin(ts) from ct4" , - "select asin(c7) from ct4", - "select asin(c8) from ct4", - "select asin(c9) from ct4", - "select asin(ts) from stb1" , - "select asin(c7) from stb1", - "select asin(c8) from stb1", - "select asin(c9) from stb1" , + f"select asin(ts) from {dbname}.t1" , + f"select asin(c7) from {dbname}.t1", + f"select asin(c8) from {dbname}.t1", + f"select asin(c9) from {dbname}.t1", + f"select asin(ts) from {dbname}.ct1" , + f"select asin(c7) from {dbname}.ct1", + f"select asin(c8) from {dbname}.ct1", + f"select asin(c9) from {dbname}.ct1", + f"select asin(ts) from {dbname}.ct3" , + f"select asin(c7) from {dbname}.ct3", + f"select asin(c8) from {dbname}.ct3", + f"select asin(c9) from {dbname}.ct3", + f"select asin(ts) from {dbname}.ct4" , + f"select asin(c7) from {dbname}.ct4", + f"select asin(c8) from {dbname}.ct4", + f"select asin(c9) from {dbname}.ct4", + f"select asin(ts) from {dbname}.stb1" , + f"select asin(c7) from {dbname}.stb1", + f"select asin(c8) from {dbname}.stb1", + f"select asin(c9) from {dbname}.stb1" , - "select asin(ts) from stbbb1" , - "select asin(c7) from stbbb1", + f"select asin(ts) from {dbname}.stbbb1" , + f"select asin(c7) from {dbname}.stbbb1", - "select asin(ts) from tbname", - "select asin(c9) from tbname" + f"select asin(ts) from {dbname}.tbname", + f"select asin(c9) from {dbname}.tbname" ] @@ -172,103 +171,103 @@ class TDTestCase: type_sql_lists = [ - "select asin(c1) from t1", - "select asin(c2) from t1", - "select asin(c3) from t1", - "select asin(c4) from t1", - "select asin(c5) from t1", - "select asin(c6) from t1", + f"select asin(c1) from {dbname}.t1", + f"select asin(c2) from {dbname}.t1", + f"select asin(c3) from {dbname}.t1", + f"select asin(c4) from {dbname}.t1", + f"select asin(c5) from {dbname}.t1", + f"select asin(c6) from {dbname}.t1", - "select asin(c1) from ct1", - "select asin(c2) from ct1", - "select asin(c3) from ct1", - "select asin(c4) from ct1", - "select asin(c5) from ct1", - "select asin(c6) from ct1", + f"select asin(c1) from {dbname}.ct1", + f"select asin(c2) from {dbname}.ct1", + f"select asin(c3) from {dbname}.ct1", + f"select asin(c4) from {dbname}.ct1", + f"select asin(c5) from {dbname}.ct1", + f"select asin(c6) from {dbname}.ct1", - "select asin(c1) from ct3", - "select asin(c2) from ct3", - "select asin(c3) from ct3", - "select asin(c4) from ct3", - "select asin(c5) from ct3", - "select asin(c6) from ct3", + f"select asin(c1) from {dbname}.ct3", + f"select asin(c2) from {dbname}.ct3", + f"select asin(c3) from {dbname}.ct3", + f"select asin(c4) from {dbname}.ct3", + f"select asin(c5) from {dbname}.ct3", + f"select asin(c6) from {dbname}.ct3", - "select asin(c1) from stb1", - "select asin(c2) from stb1", - "select asin(c3) from stb1", - "select asin(c4) from stb1", - "select asin(c5) from stb1", - "select asin(c6) from stb1", + f"select asin(c1) from {dbname}.stb1", + f"select asin(c2) from {dbname}.stb1", + f"select asin(c3) from {dbname}.stb1", + f"select asin(c4) from {dbname}.stb1", + f"select asin(c5) from {dbname}.stb1", + f"select asin(c6) from {dbname}.stb1", - "select asin(c6) as alisb from stb1", - "select asin(c6) alisb from stb1", + f"select asin(c6) as alisb from {dbname}.stb1", + f"select asin(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def basic_asin_function(self): + def basic_asin_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select asin(c1) from ct3") + tdSql.query(f"select asin(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select asin(c2) from ct3") + tdSql.query(f"select asin(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select asin(c3) from ct3") + tdSql.query(f"select asin(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select asin(c4) from ct3") + tdSql.query(f"select asin(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select asin(c5) from ct3") + tdSql.query(f"select asin(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select asin(c6) from ct3") + tdSql.query(f"select asin(c6) from {dbname}.ct3") tdSql.checkRows(0) # # used for regular table - tdSql.query("select asin(c1) from t1") + tdSql.query(f"select asin(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1 , 0, 1.570796327) tdSql.checkData(3 , 0, None) tdSql.checkData(5 , 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto_asin( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select asin(abs(c1)), asin(abs(c2)) ,asin(abs(c3)), asin(abs(c4)), asin(abs(c5)) from t1") + self.check_result_auto_asin( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.t1", f"select asin(abs(c1)), asin(abs(c2)) ,asin(abs(c3)), asin(abs(c4)), asin(abs(c5)) from {dbname}.t1") # used for sub table - tdSql.query("select c2 ,asin(c2) from ct1") + tdSql.query(f"select c2 ,asin(c2) from {dbname}.ct1") tdSql.checkData(0, 1, None) tdSql.checkData(1 , 1, None) tdSql.checkData(3 , 1, None) - tdSql.checkData(4 , 1, 0.000000000) + tdSql.checkData(4 , 1, 0) - tdSql.query("select c1, c5 ,asin(c5) from ct4") + tdSql.query(f"select c1, c5 ,asin(c5) from {dbname}.ct4") tdSql.checkData(0 , 2, None) tdSql.checkData(1 , 2, None) tdSql.checkData(2 , 2, None) tdSql.checkData(3 , 2, None) tdSql.checkData(5 , 2, None) - self.check_result_auto_asin( "select c1, c2, c3 , c4, c5 from ct1", "select asin(c1), asin(c2) ,asin(c3), asin(c4), asin(c5) from ct1") + self.check_result_auto_asin( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select asin(c1), asin(c2) ,asin(c3), asin(c4), asin(c5) from {dbname}.ct1") # nest query for asin functions - tdSql.query("select c4 , asin(c4) ,asin(asin(c4)) , asin(asin(asin(c4))) from ct1;") + tdSql.query(f"select c4 , asin(c4) ,asin(asin(c4)) , asin(asin(asin(c4))) from {dbname}.ct1;") tdSql.checkData(0 , 0 , 88) tdSql.checkData(0 , 1 , None) tdSql.checkData(0 , 2 , None) @@ -286,22 +285,22 @@ class TDTestCase: # used for stable table - tdSql.query("select asin(c1) from stb1") + tdSql.query(f"select asin(c1) from {dbname}.stb1") tdSql.checkRows(25) # used for not exists table - tdSql.error("select asin(c1) from stbbb1") - tdSql.error("select asin(c1) from tbname") - tdSql.error("select asin(c1) from ct5") + tdSql.error(f"select asin(c1) from {dbname}.stbbb1") + tdSql.error(f"select asin(c1) from {dbname}.tbname") + tdSql.error(f"select asin(c1) from {dbname}.ct5") # mix with common col - tdSql.query("select c1, asin(c1) from ct1") - tdSql.query("select c2, asin(c2) from ct4") + tdSql.query(f"select c1, asin(c1) from {dbname}.ct1") + tdSql.query(f"select c2, asin(c2) from {dbname}.ct4") # mix with common functions - tdSql.query("select c1, asin(c1),asin(c1), asin(asin(c1)) from ct4 ") + tdSql.query(f"select c1, asin(c1),asin(c1), asin(asin(c1)) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) @@ -312,24 +311,24 @@ class TDTestCase: tdSql.checkData(3 , 2 ,None) tdSql.checkData(3 , 3 ,None) - tdSql.query("select c1, asin(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, asin(c1),c5, floor(c5) from {dbname}.stb1 ") # # mix with agg functions , not support - tdSql.error("select c1, asin(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, asin(c1),c5, count(c5) from ct1 ") - tdSql.error("select asin(c1), count(c5) from stb1 ") - tdSql.error("select asin(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, asin(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, asin(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select asin(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select asin(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") # # bug fix for compute - tdSql.query("select c1, asin(c1) -0 ,asin(c1-4)-0 from ct4 ") + tdSql.query(f"select c1, asin(c1) -0 ,asin(c1-4)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -337,7 +336,7 @@ class TDTestCase: tdSql.checkData(1, 1, None) tdSql.checkData(1, 2, None) - tdSql.query(" select c1, asin(c1) -0 ,asin(c1-0.1)-0.1 from ct4") + tdSql.query(f" select c1, asin(c1) -0 ,asin(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -345,35 +344,35 @@ class TDTestCase: tdSql.checkData(1, 1, None) tdSql.checkData(1, 2, None) - tdSql.query("select c1, asin(c1), c2, asin(c2), c3, asin(c3) from ct1") + tdSql.query(f"select c1, asin(c1), c2, asin(c2), c3, asin(c3) from {dbname}.ct1") - def test_big_number(self): + def test_big_number(self, dbname="db"): - tdSql.query("select c1, asin(100000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, asin(100000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, None) - tdSql.query("select c1, asin(10000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, asin(10000000000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, None) - tdSql.query("select c1, asin(10000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, asin(10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, asin(10000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, asin(10000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(1, 1, None) - tdSql.query("select c1, asin(10000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, asin(10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, asin(10000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, asin(10000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, None) - tdSql.query("select c1, asin(10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, asin(10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, asin(10000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, asin(10000000000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, None) - tdSql.query("select c1, asin(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, asin(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow - def abs_func_filter(self): - tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(asin(c1)-0.5) from ct4 where c1>5 ") + def abs_func_filter(self, dbname="db"): + tdSql.execute(f"use {dbname}") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(asin(c1)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0,0,8) tdSql.checkData(0,1,8.000000000) @@ -381,7 +380,7 @@ class TDTestCase: tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,4,None) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(asin(c1)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(asin(c1)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -389,7 +388,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,None) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(asin(c1)-0.5) from ct4 where c1 0 order by tbname " , "select asin(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_asin( " select c5 from stb1 where c1 > 0 order by tbname " , "select asin(c5) from stb1 where c1 > 0 order by tbname" ) + def support_super_table_test(self, dbname="db"): + tdSql.execute(f" use {dbname} ") + self.check_result_auto_asin( f" select c5 from {dbname}.stb1 order by ts " , f"select asin(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_asin( f" select c5 from {dbname}.stb1 order by tbname " , f"select asin(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_asin( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select asin(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_asin( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select asin(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_asin( " select t1,c5 from stb1 order by ts " , "select asin(t1), asin(c5) from stb1 order by ts" ) - self.check_result_auto_asin( " select t1,c5 from stb1 order by tbname " , "select asin(t1) ,asin(c5) from stb1 order by tbname" ) - self.check_result_auto_asin( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select asin(t1) ,asin(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_asin( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select asin(t1) , asin(c5) from stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_asin( f" select t1,c5 from {dbname}.stb1 order by ts " , f"select asin(t1), asin(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_asin( f" select t1,c5 from {dbname}.stb1 order by tbname " , f"select asin(t1) ,asin(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_asin( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select asin(t1) ,asin(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_asin( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select asin(t1) , asin(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) pass diff --git a/tests/system-test/2-query/arctan.py b/tests/system-test/2-query/arctan.py index 4c729bd521..e6ae16b8d9 100644 --- a/tests/system-test/2-query/arctan.py +++ b/tests/system-test/2-query/arctan.py @@ -9,48 +9,48 @@ from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, powSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -87,7 +87,7 @@ class TDTestCase: for row_index , row in enumerate(pow_result): for col_index , elem in enumerate(row): - if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None): + if auto_result[row_index][col_index] == None and elem: check_status = False elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001): check_status = False @@ -99,68 +99,68 @@ class TDTestCase: else: tdLog.info("atan value check pass , it work as expected ,sql is \"%s\" "%pow_query ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - "select atan from t1", - # "select atan(-+--+c1 ) from t1", - # "select +-atan(c1) from t1", - # "select ++-atan(c1) from t1", - # "select ++--atan(c1) from t1", - # "select - -atan(c1)*0 from t1", - # "select atan(tbname+1) from t1 ", - "select atan(123--123)==1 from t1", - "select atan(c1) as 'd1' from t1", - "select atan(c1 ,c2) from t1", - "select atan(c1 ,NULL ) from t1", - "select atan(,) from t1;", - "select atan(atan(c1) ab from t1)", - "select atan(c1 ) as int from t1", - "select atan from stb1", - # "select atan(-+--+c1) from stb1", - # "select +-atan(c1) from stb1", - # "select ++-atan(c1) from stb1", - # "select ++--atan(c1) from stb1", - # "select - -atan(c1)*0 from stb1", - # "select atan(tbname+1) from stb1 ", - "select atan(123--123)==1 from stb1", - "select atan(c1) as 'd1' from stb1", - "select atan(c1 ,c2 ) from stb1", - "select atan(c1 ,NULL) from stb1", - "select atan(,) from stb1;", - "select atan(atan(c1) ab from stb1)", - "select atan(c1) as int from stb1" + f"select atan from {dbname}.t1", + # f"select atan(-+--+c1 ) from {dbname}.t1", + # f"select +-atan(c1) from {dbname}.t1", + # f"select ++-atan(c1) from {dbname}.t1", + # f"select ++--atan(c1) from {dbname}.t1", + # f"select - -atan(c1)*0 from {dbname}.t1", + # f"select atan(tbname+1) from {dbname}.t1 ", + f"select atan(123--123)==1 from {dbname}.t1", + f"select atan(c1) as 'd1' from {dbname}.t1", + f"select atan(c1 ,c2) from {dbname}.t1", + f"select atan(c1 ,NULL ) from {dbname}.t1", + f"select atan(,) from {dbname}.t1;", + f"select atan(atan(c1) ab from {dbname}.t1)", + f"select atan(c1 ) as int from {dbname}.t1", + f"select atan from {dbname}.stb1", + # f"select atan(-+--+c1) from {dbname}.stb1", + # f"select +-atan(c1) from {dbname}.stb1", + # f"select ++-atan(c1) from {dbname}.stb1", + # f"select ++--atan(c1) from {dbname}.stb1", + # f"select - -atan(c1)*0 from {dbname}.stb1", + # f"select atan(tbname+1) from {dbname}.stb1 ", + f"select atan(123--123)==1 from {dbname}.stb1", + f"select atan(c1) as 'd1' from {dbname}.stb1", + f"select atan(c1 ,c2 ) from {dbname}.stb1", + f"select atan(c1 ,NULL) from {dbname}.stb1", + f"select atan(,) from {dbname}.stb1;", + f"select atan(atan(c1) ab from {dbname}.stb1)", + f"select atan(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def support_types(self): + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select atan(ts) from t1" , - "select atan(c7) from t1", - "select atan(c8) from t1", - "select atan(c9) from t1", - "select atan(ts) from ct1" , - "select atan(c7) from ct1", - "select atan(c8) from ct1", - "select atan(c9) from ct1", - "select atan(ts) from ct3" , - "select atan(c7) from ct3", - "select atan(c8) from ct3", - "select atan(c9) from ct3", - "select atan(ts) from ct4" , - "select atan(c7) from ct4", - "select atan(c8) from ct4", - "select atan(c9) from ct4", - "select atan(ts) from stb1" , - "select atan(c7) from stb1", - "select atan(c8) from stb1", - "select atan(c9) from stb1" , + f"select atan(ts) from {dbname}.t1" , + f"select atan(c7) from {dbname}.t1", + f"select atan(c8) from {dbname}.t1", + f"select atan(c9) from {dbname}.t1", + f"select atan(ts) from {dbname}.ct1" , + f"select atan(c7) from {dbname}.ct1", + f"select atan(c8) from {dbname}.ct1", + f"select atan(c9) from {dbname}.ct1", + f"select atan(ts) from {dbname}.ct3" , + f"select atan(c7) from {dbname}.ct3", + f"select atan(c8) from {dbname}.ct3", + f"select atan(c9) from {dbname}.ct3", + f"select atan(ts) from {dbname}.ct4" , + f"select atan(c7) from {dbname}.ct4", + f"select atan(c8) from {dbname}.ct4", + f"select atan(c9) from {dbname}.ct4", + f"select atan(ts) from {dbname}.stb1" , + f"select atan(c7) from {dbname}.stb1", + f"select atan(c8) from {dbname}.stb1", + f"select atan(c9) from {dbname}.stb1" , - "select atan(ts) from stbbb1" , - "select atan(c7) from stbbb1", + f"select atan(ts) from {dbname}.stbbb1" , + f"select atan(c7) from {dbname}.stbbb1", - "select atan(ts) from tbname", - "select atan(c9) from tbname" + f"select atan(ts) from {dbname}.tbname", + f"select atan(c9) from {dbname}.tbname" ] @@ -169,103 +169,103 @@ class TDTestCase: type_sql_lists = [ - "select atan(c1) from t1", - "select atan(c2) from t1", - "select atan(c3) from t1", - "select atan(c4) from t1", - "select atan(c5) from t1", - "select atan(c6) from t1", + f"select atan(c1) from {dbname}.t1", + f"select atan(c2) from {dbname}.t1", + f"select atan(c3) from {dbname}.t1", + f"select atan(c4) from {dbname}.t1", + f"select atan(c5) from {dbname}.t1", + f"select atan(c6) from {dbname}.t1", - "select atan(c1) from ct1", - "select atan(c2) from ct1", - "select atan(c3) from ct1", - "select atan(c4) from ct1", - "select atan(c5) from ct1", - "select atan(c6) from ct1", + f"select atan(c1) from {dbname}.ct1", + f"select atan(c2) from {dbname}.ct1", + f"select atan(c3) from {dbname}.ct1", + f"select atan(c4) from {dbname}.ct1", + f"select atan(c5) from {dbname}.ct1", + f"select atan(c6) from {dbname}.ct1", - "select atan(c1) from ct3", - "select atan(c2) from ct3", - "select atan(c3) from ct3", - "select atan(c4) from ct3", - "select atan(c5) from ct3", - "select atan(c6) from ct3", + f"select atan(c1) from {dbname}.ct3", + f"select atan(c2) from {dbname}.ct3", + f"select atan(c3) from {dbname}.ct3", + f"select atan(c4) from {dbname}.ct3", + f"select atan(c5) from {dbname}.ct3", + f"select atan(c6) from {dbname}.ct3", - "select atan(c1) from stb1", - "select atan(c2) from stb1", - "select atan(c3) from stb1", - "select atan(c4) from stb1", - "select atan(c5) from stb1", - "select atan(c6) from stb1", + f"select atan(c1) from {dbname}.stb1", + f"select atan(c2) from {dbname}.stb1", + f"select atan(c3) from {dbname}.stb1", + f"select atan(c4) from {dbname}.stb1", + f"select atan(c5) from {dbname}.stb1", + f"select atan(c6) from {dbname}.stb1", - "select atan(c6) as alisb from stb1", - "select atan(c6) alisb from stb1", + f"select atan(c6) as alisb from {dbname}.stb1", + f"select atan(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def basic_atan_function(self): + def basic_atan_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select atan(c1) from ct3") + tdSql.query(f"select atan(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select atan(c2) from ct3") + tdSql.query(f"select atan(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select atan(c3) from ct3") + tdSql.query(f"select atan(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select atan(c4) from ct3") + tdSql.query(f"select atan(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select atan(c5) from ct3") + tdSql.query(f"select atan(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select atan(c6) from ct3") + tdSql.query(f"select atan(c6) from {dbname}.ct3") tdSql.checkRows(0) # # used for regular table - tdSql.query("select atan(c1) from t1") + tdSql.query(f"select atan(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1 , 0, 0.785398163) tdSql.checkData(3 , 0, 1.249045772) tdSql.checkData(5 , 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto_atan( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from t1", "select atan(abs(c1)), atan(abs(c2)) ,atan(abs(c3)), atan(abs(c4)), atan(abs(c5)) from t1") + self.check_result_auto_atan( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.t1", f"select atan(abs(c1)), atan(abs(c2)) ,atan(abs(c3)), atan(abs(c4)), atan(abs(c5)) from {dbname}.t1") # used for sub table - tdSql.query("select c2 ,atan(c2) from ct1") + tdSql.query(f"select c2 ,atan(c2) from {dbname}.ct1") tdSql.checkData(0, 1, 1.570785077) tdSql.checkData(1 , 1, 1.570783470) tdSql.checkData(3 , 1, 1.570778327) - tdSql.checkData(4 , 1, 0.000000000) + tdSql.checkData(4 , 1, 0) - tdSql.query("select c1, c5 ,atan(c5) from ct4") + tdSql.query(f"select c1, c5 ,atan(c5) from {dbname}.ct4") tdSql.checkData(0 , 2, None) tdSql.checkData(1 , 2, 1.458656162) tdSql.checkData(2 , 2, 1.442799803) tdSql.checkData(3 , 2, 1.421759533) tdSql.checkData(5 , 2, None) - self.check_result_auto_atan( "select c1, c2, c3 , c4, c5 from ct1", "select atan(c1), atan(c2) ,atan(c3), atan(c4), atan(c5) from ct1") + self.check_result_auto_atan( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select atan(c1), atan(c2) ,atan(c3), atan(c4), atan(c5) from {dbname}.ct1") # nest query for atan functions - tdSql.query("select c4 , atan(c4) ,atan(atan(c4)) , atan(atan(atan(c4))) from ct1;") + tdSql.query(f"select c4 , atan(c4) ,atan(atan(c4)) , atan(atan(atan(c4))) from {dbname}.ct1;") tdSql.checkData(0 , 0 , 88) tdSql.checkData(0 , 1 , 1.559433180) tdSql.checkData(0 , 2 , 1.000590740) @@ -283,22 +283,22 @@ class TDTestCase: # used for stable table - tdSql.query("select atan(c1) from stb1") + tdSql.query(f"select atan(c1) from {dbname}.stb1") tdSql.checkRows(25) # used for not exists table - tdSql.error("select atan(c1) from stbbb1") - tdSql.error("select atan(c1) from tbname") - tdSql.error("select atan(c1) from ct5") + tdSql.error(f"select atan(c1) from {dbname}.stbbb1") + tdSql.error(f"select atan(c1) from {dbname}.tbname") + tdSql.error(f"select atan(c1) from {dbname}.ct5") # mix with common col - tdSql.query("select c1, atan(c1) from ct1") - tdSql.query("select c2, atan(c2) from ct4") + tdSql.query(f"select c1, atan(c1) from {dbname}.ct1") + tdSql.query(f"select c2, atan(c2) from {dbname}.ct4") # mix with common functions - tdSql.query("select c1, atan(c1),atan(c1), atan(atan(c1)) from ct4 ") + tdSql.query(f"select c1, atan(c1),atan(c1), atan(atan(c1)) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) @@ -309,24 +309,24 @@ class TDTestCase: tdSql.checkData(3 , 2 ,1.405647649) tdSql.checkData(3 , 3 ,0.952449745) - tdSql.query("select c1, atan(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, atan(c1),c5, floor(c5) from {dbname}.stb1 ") # # mix with agg functions , not support - tdSql.error("select c1, atan(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, atan(c1),c5, count(c5) from ct1 ") - tdSql.error("select atan(c1), count(c5) from stb1 ") - tdSql.error("select atan(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, atan(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, atan(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select atan(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select atan(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") # # bug fix for compute - tdSql.query("select c1, atan(c1) -0 ,atan(c1-4)-0 from ct4 ") + tdSql.query(f"select c1, atan(c1) -0 ,atan(c1-4)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -334,7 +334,7 @@ class TDTestCase: tdSql.checkData(1, 1, 1.446441332) tdSql.checkData(1, 2, 1.325817664) - tdSql.query(" select c1, atan(c1) -0 ,atan(c1-0.1)-0.1 from ct4") + tdSql.query(f" select c1, atan(c1) -0 ,atan(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -342,35 +342,35 @@ class TDTestCase: tdSql.checkData(1, 1, 1.446441332) tdSql.checkData(1, 2, 1.344883701) - tdSql.query("select c1, atan(c1), c2, atan(c2), c3, atan(c3) from ct1") + tdSql.query(f"select c1, atan(c1), c2, atan(c2), c3, atan(c3) from {dbname}.ct1") - def test_big_number(self): + def test_big_number(self, dbname="db"): - tdSql.query("select c1, atan(100000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, atan(100000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, math.atan(100000000)) - tdSql.query("select c1, atan(10000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, atan(10000000000000) from {dbname}.ct1") # bigint to double data overflow tdSql.checkData(4, 1, math.atan(10000000000000)) - tdSql.query("select c1, atan(10000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, atan(10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, atan(10000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, atan(10000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(1, 1, math.atan(10000000000000000000000000.0)) - tdSql.query("select c1, atan(10000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, atan(10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, atan(10000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, atan(10000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, math.atan(10000000000000000000000000000000000.0)) - tdSql.query("select c1, atan(10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow - tdSql.query("select c1, atan(10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value + tdSql.query(f"select c1, atan(10000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow + tdSql.query(f"select c1, atan(10000000000000000000000000000000000000000.0) from {dbname}.ct1") # 10000000000000000000000000.0 is a double value tdSql.checkData(4, 1, math.atan(10000000000000000000000000000000000000000.0)) - tdSql.query("select c1, atan(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow + tdSql.query(f"select c1, atan(10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from {dbname}.ct1") # bigint to double data overflow - def abs_func_filter(self): - tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(atan(c1)-0.5) from ct4 where c1>5 ") + def abs_func_filter(self, dbname="db"): + tdSql.execute(f"use {dbname}") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(atan(c1)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0,0,8) tdSql.checkData(0,1,8.000000000) @@ -378,7 +378,7 @@ class TDTestCase: tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,4,1.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(atan(c1)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(atan(c1)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -386,7 +386,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,1.000000000) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(atan(c1)-0.5) from ct4 where c1=atan(c1) limit 1 ") + tdSql.query(f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(atan(c1)-0.5) from {dbname}.ct4 where c1=atan(c1) limit 1 ") tdSql.checkRows(1) tdSql.checkData(0,0,0) tdSql.checkData(0,1,0) @@ -398,41 +398,41 @@ class TDTestCase: def pow_Arithmetic(self): pass - def check_boundary_values(self): + def check_boundary_values(self, dbname="bound_test"): PI=3.1415926 - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"use {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - self.check_result_auto_atan( "select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from sub1_bound ", "select atan(abs(c1)), atan(abs(c2)) ,atan(abs(c3)), atan(abs(c4)), atan(abs(c5)) from sub1_bound") + self.check_result_auto_atan( f"select abs(c1), abs(c2), abs(c3) , abs(c4), abs(c5) from {dbname}.sub1_bound ", f"select atan(abs(c1)), atan(abs(c2)) ,atan(abs(c3)), atan(abs(c4)), atan(abs(c5)) from {dbname}.sub1_bound") - self.check_result_auto_atan( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select atan(c1), atan(c2) ,atan(c3), atan(c3), atan(c2) ,atan(c1) from sub1_bound") + self.check_result_auto_atan( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select atan(c1), atan(c2) ,atan(c3), atan(c3), atan(c2) ,atan(c1) from {dbname}.sub1_bound") - self.check_result_auto_atan("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select atan(abs(c1)) from sub1_bound" ) + self.check_result_auto_atan(f"select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from {dbname}.sub1_bound" , f"select atan(abs(c1)) from {dbname}.sub1_bound" ) # check basic elem for table per row - tdSql.query("select atan(abs(c1)) ,atan(abs(c2)) , atan(abs(c3)) , atan(abs(c4)), atan(abs(c5)), atan(abs(c6)) from sub1_bound ") + tdSql.query(f"select atan(abs(c1)) ,atan(abs(c2)) , atan(abs(c3)) , atan(abs(c4)), atan(abs(c5)), atan(abs(c6)) from {dbname}.sub1_bound ") tdSql.checkData(0,0,math.atan(2147483647)) tdSql.checkData(0,1,math.atan(9223372036854775807)) tdSql.checkData(0,2,math.atan(32767)) @@ -450,47 +450,47 @@ class TDTestCase: tdSql.checkData(3,4,math.atan(339999995214436424907732413799364296704.00000)) # check + - * / in functions - tdSql.query("select atan(abs(c1+1)) ,atan(abs(c2)) , atan(abs(c3*1)) , atan(abs(c4/2)), atan(abs(c5))/2, atan(abs(c6)) from sub1_bound ") + tdSql.query(f"select atan(abs(c1+1)) ,atan(abs(c2)) , atan(abs(c3*1)) , atan(abs(c4/2)), atan(abs(c5))/2, atan(abs(c6)) from {dbname}.sub1_bound ") tdSql.checkData(0,0,math.atan(2147483648.000000000)) tdSql.checkData(0,1,math.atan(9223372036854775807)) tdSql.checkData(0,2,math.atan(32767.000000000)) tdSql.checkData(0,3,math.atan(63.500000000)) - tdSql.execute("create stable st (ts timestamp, num1 float, num2 double) tags (t1 int);") - tdSql.execute(f'create table tb1 using st tags (1)') - tdSql.execute(f'create table tb2 using st tags (2)') - tdSql.execute(f'create table tb3 using st tags (3)') - tdSql.execute('insert into tb1 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) - tdSql.execute('insert into tb1 values (now()-30s, {}, {})'.format(PI ,PI )) - tdSql.execute('insert into tb1 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) - tdSql.execute('insert into tb1 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) - tdSql.execute('insert into tb1 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) + tdSql.execute(f"create stable {dbname}.st (ts timestamp, num1 float, num2 double) tags (t1 int);") + tdSql.execute(f'create table {dbname}.tb1 using {dbname}.st tags (1)') + tdSql.execute(f'create table {dbname}.tb2 using {dbname}.st tags (2)') + tdSql.execute(f'create table {dbname}.tb3 using {dbname}.st tags (3)') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-40s, {PI/2}, {PI/2})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-30s, {PI}, {PI})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-20s, {PI*1.5}, {PI*1.5})') + tdSql.execute(f'insert into {dbname}.tb1 values (now()-10s, {PI*2}, {PI*2})') + tdSql.execute(f'insert into {dbname}.tb1 values (now(), {PI*2.5}, {PI*2.5})') - tdSql.execute('insert into tb2 values (now()-40s, {}, {})'.format(PI/2 ,PI/2 )) - tdSql.execute('insert into tb2 values (now()-30s, {}, {})'.format(PI ,PI )) - tdSql.execute('insert into tb2 values (now()-20s, {}, {})'.format(PI*1.5 ,PI*1.5)) - tdSql.execute('insert into tb2 values (now()-10s, {}, {})'.format(PI*2 ,PI*2)) - tdSql.execute('insert into tb2 values (now(), {}, {})'.format(PI*2.5 ,PI*2.5)) + tdSql.execute(f'insert into {dbname}.tb2 values (now()-40s, {PI/2}, {PI/2})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-30s, {PI}, {PI})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-20s, {PI*1.5}, {PI*1.5})') + tdSql.execute(f'insert into {dbname}.tb2 values (now()-10s, {PI*2}, {PI*2})') + tdSql.execute(f'insert into {dbname}.tb2 values (now(), {PI*2.5}, {PI*2.5})') for i in range(100): - tdSql.execute('insert into tb3 values (now()+{}s, {}, {})'.format(i,PI*(5+i)/2 ,PI*(5+i)/2)) + tdSql.execute(f'insert into {dbname}.tb3 values (now()+{i}s, {PI*(5+i)/2}, {PI*(5+i)/2})') - self.check_result_auto_atan("select num1,num2 from tb3;" , "select atan(num1),atan(num2) from tb3") + self.check_result_auto_atan(f"select num1,num2 from {dbname}.tb3;" , f"select atan(num1),atan(num2) from {dbname}.tb3") + def support_super_table_test(self, dbname="db"): + tdSql.execute(f" use {dbname} ") + self.check_result_auto_atan( f" select c5 from {dbname}.stb1 order by ts " , f"select atan(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_atan( f" select c5 from {dbname}.stb1 order by tbname " , f"select atan(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_atan( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select atan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_atan( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select atan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) - def support_super_table_test(self): - tdSql.execute(" use db ") - self.check_result_auto_atan( " select c5 from stb1 order by ts " , "select atan(c5) from stb1 order by ts" ) - self.check_result_auto_atan( " select c5 from stb1 order by tbname " , "select atan(c5) from stb1 order by tbname" ) - self.check_result_auto_atan( " select c5 from stb1 where c1 > 0 order by tbname " , "select atan(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_atan( " select c5 from stb1 where c1 > 0 order by tbname " , "select atan(c5) from stb1 where c1 > 0 order by tbname" ) - - self.check_result_auto_atan( " select t1,c5 from stb1 order by ts " , "select atan(t1), atan(c5) from stb1 order by ts" ) - self.check_result_auto_atan( " select t1,c5 from stb1 order by tbname " , "select atan(t1) ,atan(c5) from stb1 order by tbname" ) - self.check_result_auto_atan( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select atan(t1) ,atan(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto_atan( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select atan(t1) , atan(c5) from stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_atan( f" select t1,c5 from {dbname}.stb1 order by ts " , f"select atan(t1), atan(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto_atan( f" select t1,c5 from {dbname}.stb1 order by tbname " , f"select atan(t1) ,atan(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto_atan( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select atan(t1) ,atan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto_atan( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select atan(t1) , atan(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) pass + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() @@ -523,12 +523,11 @@ class TDTestCase: self.abs_func_filter() - tdLog.printNoPrefix("==========step8: check arctan result of stable query ============") + tdLog.printNoPrefix("==========step8: check atan result of stable query ============") self.support_super_table_test() - def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/system-test/2-query/avg.py b/tests/system-test/2-query/avg.py index 607968936d..ea7c3329ea 100644 --- a/tests/system-test/2-query/avg.py +++ b/tests/system-test/2-query/avg.py @@ -8,48 +8,48 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(), True) + tdSql.init(conn.cursor(), False) - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -80,68 +80,68 @@ class TDTestCase: else: tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - "select avg from t1", - # "select avg(-+--+c1) from t1", - # "select +-avg(c1) from t1", - # "select ++-avg(c1) from t1", - # "select ++--avg(c1) from t1", - # "select - -avg(c1)*0 from t1", - # "select avg(tbname+1) from t1 ", - "select avg(123--123)==1 from t1", - "select avg(c1) as 'd1' from t1", - "select avg(c1 ,c2 ) from t1", - "select avg(c1 ,NULL) from t1", - "select avg(,) from t1;", - "select avg(avg(c1) ab from t1)", - "select avg(c1) as int from t1", - "select avg from stb1", - # "select avg(-+--+c1) from stb1", - # "select +-avg(c1) from stb1", - # "select ++-avg(c1) from stb1", - # "select ++--avg(c1) from stb1", - # "select - -avg(c1)*0 from stb1", - # "select avg(tbname+1) from stb1 ", - "select avg(123--123)==1 from stb1", - "select avg(c1) as 'd1' from stb1", - "select avg(c1 ,c2 ) from stb1", - "select avg(c1 ,NULL) from stb1", - "select avg(,) from stb1;", - "select avg(avg(c1) ab from stb1)", - "select avg(c1) as int from stb1" + f"select avg from {dbname}.t1", + # f"select avg(-+--+c1) from {dbname}.t1", + # f"select +-avg(c1) from {dbname}.t1", + # f"select ++-avg(c1) from {dbname}.t1", + # f"select ++--avg(c1) from {dbname}.t1", + # f"select - -avg(c1)*0 from {dbname}.t1", + # f"select avg(tbname+1) from {dbname}.t1 ", + f"select avg(123--123)==1 from {dbname}.t1", + f"select avg(c1) as 'd1' from {dbname}.t1", + f"select avg(c1 ,c2 ) from {dbname}.t1", + f"select avg(c1 ,NULL) from {dbname}.t1", + f"select avg(,) from {dbname}.t1;", + f"select avg(avg(c1) ab from {dbname}.t1)", + f"select avg(c1) as int from {dbname}.t1", + f"select avg from {dbname}.stb1", + # f"select avg(-+--+c1) from {dbname}.stb1", + # f"select +-avg(c1) from {dbname}.stb1", + # f"select ++-avg(c1) from {dbname}.stb1", + # f"select ++--avg(c1) from {dbname}.stb1", + # f"select - -avg(c1)*0 from {dbname}.stb1", + # f"select avg(tbname+1) from {dbname}.stb1 ", + f"select avg(123--123)==1 from {dbname}.stb1", + f"select avg(c1) as 'd1' from {dbname}.stb1", + f"select avg(c1 ,c2 ) from {dbname}.stb1", + f"select avg(c1 ,NULL) from {dbname}.stb1", + f"select avg(,) from {dbname}.stb1;", + f"select avg(avg(c1) ab from {dbname}.stb1)", + f"select avg(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def support_types(self): + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select avg(ts) from t1" , - "select avg(c7) from t1", - "select avg(c8) from t1", - "select avg(c9) from t1", - "select avg(ts) from ct1" , - "select avg(c7) from ct1", - "select avg(c8) from ct1", - "select avg(c9) from ct1", - "select avg(ts) from ct3" , - "select avg(c7) from ct3", - "select avg(c8) from ct3", - "select avg(c9) from ct3", - "select avg(ts) from ct4" , - "select avg(c7) from ct4", - "select avg(c8) from ct4", - "select avg(c9) from ct4", - "select avg(ts) from stb1" , - "select avg(c7) from stb1", - "select avg(c8) from stb1", - "select avg(c9) from stb1" , + f"select avg(ts) from {dbname}.t1" , + f"select avg(c7) from {dbname}.t1", + f"select avg(c8) from {dbname}.t1", + f"select avg(c9) from {dbname}.t1", + f"select avg(ts) from {dbname}.ct1" , + f"select avg(c7) from {dbname}.ct1", + f"select avg(c8) from {dbname}.ct1", + f"select avg(c9) from {dbname}.ct1", + f"select avg(ts) from {dbname}.ct3" , + f"select avg(c7) from {dbname}.ct3", + f"select avg(c8) from {dbname}.ct3", + f"select avg(c9) from {dbname}.ct3", + f"select avg(ts) from {dbname}.ct4" , + f"select avg(c7) from {dbname}.ct4", + f"select avg(c8) from {dbname}.ct4", + f"select avg(c9) from {dbname}.ct4", + f"select avg(ts) from {dbname}.stb1" , + f"select avg(c7) from {dbname}.stb1", + f"select avg(c8) from {dbname}.stb1", + f"select avg(c9) from {dbname}.stb1" , - "select avg(ts) from stbbb1" , - "select avg(c7) from stbbb1", + f"select avg(ts) from {dbname}.stbbb1" , + f"select avg(c7) from {dbname}.stbbb1", - "select avg(ts) from tbname", - "select avg(c9) from tbname" + f"select avg(ts) from {dbname}.tbname", + f"select avg(c9) from {dbname}.tbname" ] @@ -150,157 +150,157 @@ class TDTestCase: type_sql_lists = [ - "select avg(c1) from t1", - "select avg(c2) from t1", - "select avg(c3) from t1", - "select avg(c4) from t1", - "select avg(c5) from t1", - "select avg(c6) from t1", + f"select avg(c1) from {dbname}.t1", + f"select avg(c2) from {dbname}.t1", + f"select avg(c3) from {dbname}.t1", + f"select avg(c4) from {dbname}.t1", + f"select avg(c5) from {dbname}.t1", + f"select avg(c6) from {dbname}.t1", - "select avg(c1) from ct1", - "select avg(c2) from ct1", - "select avg(c3) from ct1", - "select avg(c4) from ct1", - "select avg(c5) from ct1", - "select avg(c6) from ct1", + f"select avg(c1) from {dbname}.ct1", + f"select avg(c2) from {dbname}.ct1", + f"select avg(c3) from {dbname}.ct1", + f"select avg(c4) from {dbname}.ct1", + f"select avg(c5) from {dbname}.ct1", + f"select avg(c6) from {dbname}.ct1", - "select avg(c1) from ct3", - "select avg(c2) from ct3", - "select avg(c3) from ct3", - "select avg(c4) from ct3", - "select avg(c5) from ct3", - "select avg(c6) from ct3", + f"select avg(c1) from {dbname}.ct3", + f"select avg(c2) from {dbname}.ct3", + f"select avg(c3) from {dbname}.ct3", + f"select avg(c4) from {dbname}.ct3", + f"select avg(c5) from {dbname}.ct3", + f"select avg(c6) from {dbname}.ct3", - "select avg(c1) from stb1", - "select avg(c2) from stb1", - "select avg(c3) from stb1", - "select avg(c4) from stb1", - "select avg(c5) from stb1", - "select avg(c6) from stb1", + f"select avg(c1) from {dbname}.stb1", + f"select avg(c2) from {dbname}.stb1", + f"select avg(c3) from {dbname}.stb1", + f"select avg(c4) from {dbname}.stb1", + f"select avg(c5) from {dbname}.stb1", + f"select avg(c6) from {dbname}.stb1", - "select avg(c6) as alisb from stb1", - "select avg(c6) alisb from stb1", + f"select avg(c6) as alisb from {dbname}.stb1", + f"select avg(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def basic_avg_function(self): + def basic_avg_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) # used for empty table , ct3 is empty - tdSql.query("select avg(c1) from ct3") + tdSql.query(f"select avg(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select avg(c2) from ct3") + tdSql.query(f"select avg(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select avg(c3) from ct3") + tdSql.query(f"select avg(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select avg(c4) from ct3") + tdSql.query(f"select avg(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select avg(c5) from ct3") + tdSql.query(f"select avg(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select avg(c6) from ct3") + tdSql.query(f"select avg(c6) from {dbname}.ct3") # used for regular table - tdSql.query("select avg(c1) from t1") + tdSql.query(f"select avg(c1) from {dbname}.t1") tdSql.checkData(0, 0, 5.000000000) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_avg(" select avg(c1) , avg(c2) , avg(c3) from t1 " , " select sum(c1)/count(c1) , sum(c2)/count(c2) , sum(c3)/count(c3) from t1 ") + self.check_avg(f" select avg(c1) , avg(c2) , avg(c3) from {dbname}.t1 " , f" select sum(c1)/count(c1) , sum(c2)/count(c2) , sum(c3)/count(c3) from {dbname}.t1 ") # used for sub table - tdSql.query("select avg(c1) from ct1") + tdSql.query(f"select avg(c1) from {dbname}.ct1") tdSql.checkData(0, 0, 4.846153846) - tdSql.query("select avg(c1) from ct3") + tdSql.query(f"select avg(c1) from {dbname}.ct3") tdSql.checkRows(0) - self.check_avg(" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from t1 " , " select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from t1 ") - self.check_avg(" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from stb1 " , " select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from stb1 ") + self.check_avg(f" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from {dbname}.t1 " , f" select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from {dbname}.t1 ") + self.check_avg(f" select avg(abs(c1)) , avg(abs(c2)) , avg(abs(c3)) from {dbname}.stb1 " , f" select sum(abs(c1))/count(c1) , sum(abs(c2))/count(c2) , sum(abs(c3))/count(c3) from {dbname}.stb1 ") # used for stable table - tdSql.query("select avg(c1) from stb1") + tdSql.query(f"select avg(c1) from {dbname}.stb1") tdSql.checkRows(1) - self.check_avg(" select avg(abs(ceil(c1))) , avg(abs(ceil(c2))) , avg(abs(ceil(c3))) from stb1 " , " select sum(abs(ceil(c1)))/count(c1) , sum(abs(ceil(c2)))/count(c2) , sum(abs(ceil(c3)))/count(c3) from stb1 ") + self.check_avg(f" select avg(abs(ceil(c1))) , avg(abs(ceil(c2))) , avg(abs(ceil(c3))) from {dbname}.stb1 " , f" select sum(abs(ceil(c1)))/count(c1) , sum(abs(ceil(c2)))/count(c2) , sum(abs(ceil(c3)))/count(c3) from {dbname}.stb1 ") # used for not exists table - tdSql.error("select avg(c1) from stbbb1") - tdSql.error("select avg(c1) from tbname") - tdSql.error("select avg(c1) from ct5") + tdSql.error(f"select avg(c1) from {dbname}.stbbb1") + tdSql.error(f"select avg(c1) from {dbname}.tbname") + tdSql.error(f"select avg(c1) from {dbname}.ct5") # mix with common col - tdSql.error("select c1, avg(c1) from ct1") - tdSql.error("select c1, avg(c1) from ct4") + tdSql.error(f"select c1, avg(c1) from {dbname}.ct1") + tdSql.error(f"select c1, avg(c1) from {dbname}.ct4") # mix with common functions - tdSql.error("select c1, avg(c1),c5, floor(c5) from ct4 ") - tdSql.error("select c1, avg(c1),c5, floor(c5) from stb1 ") + tdSql.error(f"select c1, avg(c1),c5, floor(c5) from {dbname}.ct4 ") + tdSql.error(f"select c1, avg(c1),c5, floor(c5) from {dbname}.stb1 ") # mix with agg functions , not support - tdSql.error("select c1, avg(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, avg(c1),c5, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, avg(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, avg(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query(" select max(c5), count(c5) , avg(c5) from stb1 ") + tdSql.query(f" select max(c5), count(c5) , avg(c5) from {dbname}.stb1 ") tdSql.checkData(0, 0, 8.88000 ) tdSql.checkData(0, 1, 22 ) tdSql.checkData(0, 2, 2.270454591 ) - tdSql.query(" select max(c5), count(c5) , avg(c5) ,elapsed(ts) , spread(c1) from ct1; ") + tdSql.query(f" select max(c5), count(c5) , avg(c5) ,elapsed(ts) , spread(c1) from {dbname}.ct1; ") tdSql.checkData(0, 0, 8.88000 ) tdSql.checkData(0, 1, 13 ) tdSql.checkData(0, 2, 0.768461603 ) # bug fix for count - tdSql.query("select count(c1) from ct4 ") + tdSql.query(f"select count(c1) from {dbname}.ct4 ") tdSql.checkData(0,0,9) - tdSql.query("select count(*) from ct4 ") + tdSql.query(f"select count(*) from {dbname}.ct4 ") tdSql.checkData(0,0,12) - tdSql.query("select count(c1) from stb1 ") + tdSql.query(f"select count(c1) from {dbname}.stb1 ") tdSql.checkData(0,0,22) - tdSql.query("select count(*) from stb1 ") + tdSql.query(f"select count(*) from {dbname}.stb1 ") tdSql.checkData(0,0,25) # bug fix for compute - tdSql.error("select c1, avg(c1) -0 ,ceil(c1)-0 from ct4 ") - tdSql.error(" select c1, avg(c1) -0 ,avg(ceil(c1-0.1))-0.1 from ct4") + tdSql.error(f"select c1, avg(c1) -0 ,ceil(c1)-0 from {dbname}.ct4 ") + tdSql.error(f" select c1, avg(c1) -0 ,avg(ceil(c1-0.1))-0.1 from {dbname}.ct4") # mix with nest query - self.check_avg("select avg(col) from (select abs(c1) col from stb1)" , "select avg(abs(c1)) from stb1") - self.check_avg("select avg(col) from (select ceil(abs(c1)) col from stb1)" , "select avg(abs(c1)) from stb1") + self.check_avg(f"select avg(col) from (select abs(c1) col from {dbname}.stb1)" , f"select avg(abs(c1)) from {dbname}.stb1") + self.check_avg(f"select avg(col) from (select ceil(abs(c1)) col from {dbname}.stb1)" , f"select avg(abs(c1)) from {dbname}.stb1") - tdSql.query(" select abs(avg(abs(abs(c1)))) from stb1 ") + tdSql.query(f" select abs(avg(abs(abs(c1)))) from {dbname}.stb1 ") tdSql.checkData(0, 0, 4.500000000) - tdSql.query(" select abs(avg(abs(abs(c1)))) from t1 ") + tdSql.query(f" select abs(avg(abs(abs(c1)))) from {dbname}.t1 ") tdSql.checkData(0, 0, 5.000000000) - tdSql.query(" select abs(avg(abs(abs(c1)))) from stb1 ") + tdSql.query(f" select abs(avg(abs(abs(c1)))) from {dbname}.stb1 ") tdSql.checkData(0, 0, 4.500000000) - tdSql.query(" select avg(c1) from stb1 where c1 is null ") + tdSql.query(f" select avg(c1) from {dbname}.stb1 where c1 is null ") tdSql.checkRows(0) - def avg_func_filter(self): - tdSql.execute("use db") - tdSql.query(" select avg(c1), avg(c1) -0 ,avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2)-0.5)) from ct4 where c1>5 ") + def avg_func_filter(self, dbname="db"): + tdSql.execute(f"use {dbname}") + tdSql.query(f" select avg(c1), avg(c1) -0 ,avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2)-0.5)) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(1) tdSql.checkData(0,0,7.000000000) tdSql.checkData(0,1,7.000000000) @@ -308,7 +308,7 @@ class TDTestCase: tdSql.checkData(0,3,6.900000000) tdSql.checkData(0,4,3.000000000) - tdSql.query("select avg(c1), avg(c1) -0 ,avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2)-0.5)) from ct4 where c1=5 ") + tdSql.query(f"select avg(c1), avg(c1) -0 ,avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2)-0.5)) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5.000000000) tdSql.checkData(0,1,5.000000000) @@ -316,59 +316,56 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,2.000000000) - tdSql.query("select avg(c1) ,avg(c2) , avg(c1) -0 , avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2))-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.query(f"select avg(c1) ,avg(c2) , avg(c1) -0 , avg(ceil(c1-0.1))-0 ,avg(floor(c1+0.1))-0.1 ,avg(ceil(log(c1,2))-0.5) from {dbname}.ct4 where c1>log(c1,2) limit 1 ") tdSql.checkRows(1) tdSql.checkData(0, 0, 4.500000000) tdSql.checkData(0, 1, 49999.500000000) tdSql.checkData(0, 5, 1.625000000) - def avg_Arithmetic(self): - pass + def check_boundary_values(self, dbname="bound_test"): - def check_boundary_values(self): - - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"use {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483645, 9223372036854775805, 32765, 125, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483645, 9223372036854775805, 32765, 125, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483644, 9223372036854775804, 32764, 124, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483644, 9223372036854775804, 32764, 124, 3.40E+37, 1.7e+307, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - self.check_avg("select avg(c1), avg(c2), avg(c3) , avg(c4), avg(c5) ,avg(c6) from sub1_bound " , " select sum(c1)/count(c1), sum(c2)/count(c2) ,sum(c3)/count(c3), sum(c4)/count(c4), sum(c5)/count(c5) ,sum(c6)/count(c6) from sub1_bound ") + self.check_avg(f"select avg(c1), avg(c2), avg(c3) , avg(c4), avg(c5) ,avg(c6) from {dbname}.sub1_bound " , f" select sum(c1)/count(c1), sum(c2)/count(c2) ,sum(c3)/count(c3), sum(c4)/count(c4), sum(c5)/count(c5) ,sum(c6)/count(c6) from {dbname}.sub1_bound ") # check basic elem for table per row - tdSql.query("select avg(c1) ,avg(c2) , avg(c3) , avg(c4), avg(c5), avg(c6) from sub1_bound ") + tdSql.query(f"select avg(c1) ,avg(c2) , avg(c3) , avg(c4), avg(c5), avg(c6) from {dbname}.sub1_bound ") tdSql.checkRows(1) tdSql.checkData(0,0,920350133.571428537) tdSql.checkData(0,1,1.3176245766935393e+18) @@ -379,7 +376,7 @@ class TDTestCase: # check + - * / in functions - tdSql.query(" select avg(c1+1) ,avg(c2) , avg(c3*1) , avg(c4/2), avg(c5)/2, avg(c6) from sub1_bound ") + tdSql.query(f" select avg(c1+1) ,avg(c2) , avg(c3*1) , avg(c4/2), avg(c5)/2, avg(c6) from {dbname}.sub1_bound ") tdSql.checkData(0,0,920350134.5714285) tdSql.checkData(0,1,1.3176245766935393e+18) tdSql.checkData(0,2,14042.142857143) diff --git a/tests/system-test/2-query/between.py b/tests/system-test/2-query/between.py index 7e2ac1c8b9..a9dde5617d 100644 --- a/tests/system-test/2-query/between.py +++ b/tests/system-test/2-query/between.py @@ -13,190 +13,195 @@ class TDTestCase: tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def run(self): # sourcery skip: extract-duplicate-method + def run(self): + dbname = "db" + stb = f"{dbname}.stb1" + rows = 10 + tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") tdSql.execute( - '''create table if not exists supt + f'''create table if not exists {stb} (ts timestamp, c1 int, c2 float, c3 bigint, c4 double, c5 smallint, c6 tinyint) tags(location binary(64), type int, isused bool , family nchar(64))''' ) - tdSql.execute("create table t1 using supt tags('beijing', 1, 1, 'nchar1')") - tdSql.execute("create table t2 using supt tags('shanghai', 2, 0, 'nchar2')") + tdSql.execute(f"create table {dbname}.t1 using {stb} tags('beijing', 1, 1, 'nchar1')") + tdSql.execute(f"create table {dbname}.t2 using {stb} tags('shanghai', 2, 0, 'nchar2')") tdLog.printNoPrefix("==========step2:insert data") - for i in range(10): + for i in range(rows): tdSql.execute( - f"insert into t1 values (now()+{i}m, {32767+i}, {20.0+i/10}, {2**31+i}, {3.4*10**38+i/10}, {127+i}, {i})" + f"insert into {dbname}.t1 values (now()+{i}m, {32767+i}, {20.0+i/10}, {2**31+i}, {3.4*10**38+i/10}, {127+i}, {i})" ) tdSql.execute( - f"insert into t2 values (now()-{i}m, {-32767-i}, {20.0-i/10}, {-i-2**31}, {-i/10-3.4*10**38}, {-127-i}, {-i})" + f"insert into {dbname}.t2 values (now()-{i}m, {-32767-i}, {20.0-i/10}, {-i-2**31}, {-i/10-3.4*10**38}, {-127-i}, {-i})" ) tdSql.execute( - f"insert into t1 values (now()+11m, {2**31-1}, {pow(10,37)*34}, {pow(2,63)-1}, {1.7*10**308}, 32767, 127)" + f"insert into {dbname}.t1 values (now()+11m, {2**31-1}, {pow(10,37)*34}, {pow(2,63)-1}, {1.7*10**308}, 32767, 127)" ) tdSql.execute( - f"insert into t2 values (now()-11m, {1-2**31}, {-3.4*10**38}, {1-2**63}, {-1.7*10**308}, -32767, -127)" + f"insert into {dbname}.t2 values (now()-11m, {1-2**31}, {-3.4*10**38}, {1-2**63}, {-1.7*10**308}, -32767, -127)" ) tdSql.execute( - f"insert into t2 values (now()-12m, null , {-3.4*10**38}, null , {-1.7*10**308}, null , null)" + f"insert into {dbname}.t2 values (now()-12m, null , {-3.4*10**38}, null , {-1.7*10**308}, null , null)" ) tdLog.printNoPrefix("==========step3:query timestamp type") - tdSql.query("select * from t1 where ts between now()-1m and now()+10m") - tdSql.checkRows(10) - tdSql.query("select * from t1 where ts between '2021-01-01 00:00:00.000' and '2121-01-01 00:00:00.000'") + tdSql.query(f"select * from {dbname}.t1 where ts between now()-1m and now()+10m") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where ts between '2021-01-01 00:00:00.000' and '2121-01-01 00:00:00.000'") # tdSql.checkRows(11) - tdSql.query("select * from t1 where ts between '1969-01-01 00:00:00.000' and '1969-12-31 23:59:59.999'") + tdSql.query(f"select * from {dbname}.t1 where ts between '1969-01-01 00:00:00.000' and '1969-12-31 23:59:59.999'") # tdSql.checkRows(0) - tdSql.query("select * from t1 where ts between -2793600 and 31507199") + tdSql.query(f"select * from {dbname}.t1 where ts between -2793600 and 31507199") tdSql.checkRows(0) - tdSql.query("select * from t1 where ts between 1609430400000 and 4765104000000") - tdSql.checkRows(11) + tdSql.query(f"select * from {dbname}.t1 where ts between 1609430400000 and 4765104000000") + tdSql.checkRows(rows+1) tdLog.printNoPrefix("==========step4:query int type") - tdSql.query("select * from t1 where c1 between 32767 and 32776") - tdSql.checkRows(10) - tdSql.query("select * from t1 where c1 between 32766.9 and 32776.1") - tdSql.checkRows(10) - tdSql.query("select * from t1 where c1 between 32776 and 32767") + tdSql.query(f"select * from {dbname}.t1 where c1 between 32767 and 32776") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where c1 between 32766.9 and 32776.1") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where c1 between 32776 and 32767") tdSql.checkRows(0) - tdSql.query("select * from t1 where c1 between 'a' and 'e'") + tdSql.query(f"select * from {dbname}.t1 where c1 between 'a' and 'e'") tdSql.checkRows(0) - # tdSql.query("select * from t1 where c1 between 0x64 and 0x69") + # tdSql.query("select * from {dbname}.t1 where c1 between 0x64 and 0x69") # tdSql.checkRows(6) - tdSql.query("select * from t1 where c1 not between 100 and 106") - tdSql.checkRows(11) - tdSql.query(f"select * from t1 where c1 between {2**31-2} and {2**31+1}") + tdSql.query(f"select * from {dbname}.t1 where c1 not between 100 and 106") + tdSql.checkRows(rows+1) + tdSql.query(f"select * from {dbname}.t1 where c1 between {2**31-2} and {2**31+1}") tdSql.checkRows(1) - tdSql.query(f"select * from t2 where c1 between null and {1-2**31}") + tdSql.query(f"select * from {dbname}.t2 where c1 between null and {1-2**31}") # tdSql.checkRows(3) - tdSql.query(f"select * from t2 where c1 between {-2**31} and {1-2**31}") + tdSql.query(f"select * from {dbname}.t2 where c1 between {-2**31} and {1-2**31}") tdSql.checkRows(1) tdLog.printNoPrefix("==========step5:query float type") - tdSql.query("select * from t1 where c2 between 20.0 and 21.0") + tdSql.query(f"select * from {dbname}.t1 where c2 between 20.0 and 21.0") tdSql.checkRows(10) - tdSql.query(f"select * from t1 where c2 between {-3.4*10**38-1} and {3.4*10**38+1}") - tdSql.checkRows(11) - tdSql.query("select * from t1 where c2 between 21.0 and 20.0") + tdSql.query(f"select * from {dbname}.t1 where c2 between {-3.4*10**38-1} and {3.4*10**38+1}") + tdSql.checkRows(rows+1) + tdSql.query(f"select * from {dbname}.t1 where c2 between 21.0 and 20.0") tdSql.checkRows(0) - tdSql.query("select * from t1 where c2 between 'DC3' and 'SYN'") + tdSql.query(f"select * from {dbname}.t1 where c2 between 'DC3' and 'SYN'") tdSql.checkRows(0) - tdSql.query("select * from t1 where c2 not between 0.1 and 0.2") - tdSql.checkRows(11) - tdSql.query(f"select * from t1 where c2 between {pow(10,38)*3.4} and {pow(10,38)*3.4+1}") + tdSql.query(f"select * from {dbname}.t1 where c2 not between 0.1 and 0.2") + tdSql.checkRows(rows+1) + tdSql.query(f"select * from {dbname}.t1 where c2 between {pow(10,38)*3.4} and {pow(10,38)*3.4+1}") # tdSql.checkRows(1) - tdSql.query(f"select * from t2 where c2 between {-3.4*10**38-1} and {-3.4*10**38}") + tdSql.query(f"select * from {dbname}.t2 where c2 between {-3.4*10**38-1} and {-3.4*10**38}") # tdSql.checkRows(2) - tdSql.query(f"select * from t2 where c2 between null and {-3.4*10**38}") + tdSql.query(f"select * from {dbname}.t2 where c2 between null and {-3.4*10**38}") # tdSql.checkRows(3) tdLog.printNoPrefix("==========step6:query bigint type") - tdSql.query(f"select * from t1 where c3 between {2**31} and {2**31+10}") - tdSql.checkRows(10) - tdSql.query(f"select * from t1 where c3 between {-2**63} and {2**63}") - tdSql.checkRows(11) - tdSql.query(f"select * from t1 where c3 between {2**31+10} and {2**31}") + tdSql.query(f"select * from {dbname}.t1 where c3 between {2**31} and {2**31+10}") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where c3 between {-2**63} and {2**63}") + tdSql.checkRows(rows+1) + tdSql.query(f"select * from {dbname}.t1 where c3 between {2**31+10} and {2**31}") tdSql.checkRows(0) - tdSql.query("select * from t1 where c3 between 'a' and 'z'") + tdSql.query(f"select * from {dbname}.t1 where c3 between 'a' and 'z'") tdSql.checkRows(0) - tdSql.query("select * from t1 where c3 not between 1 and 2") + tdSql.query(f"select * from {dbname}.t1 where c3 not between 1 and 2") # tdSql.checkRows(0) - tdSql.query(f"select * from t1 where c3 between {2**63-2} and {2**63-1}") + tdSql.query(f"select * from {dbname}.t1 where c3 between {2**63-2} and {2**63-1}") tdSql.checkRows(1) - tdSql.query(f"select * from t2 where c3 between {-2**63} and {1-2**63}") + tdSql.query(f"select * from {dbname}.t2 where c3 between {-2**63} and {1-2**63}") # tdSql.checkRows(3) - tdSql.query(f"select * from t2 where c3 between null and {1-2**63}") + tdSql.query(f"select * from {dbname}.t2 where c3 between null and {1-2**63}") # tdSql.checkRows(2) tdLog.printNoPrefix("==========step7:query double type") - tdSql.query(f"select * from t1 where c4 between {3.4*10**38} and {3.4*10**38+10}") - tdSql.checkRows(10) - tdSql.query(f"select * from t1 where c4 between {1.7*10**308+1} and {1.7*10**308+2}") + tdSql.query(f"select * from {dbname}.t1 where c4 between {3.4*10**38} and {3.4*10**38+10}") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where c4 between {1.7*10**308+1} and {1.7*10**308+2}") # 因为精度原因,在超出bigint边界后,数值不能进行准确的判断 # tdSql.checkRows(0) - tdSql.query(f"select * from t1 where c4 between {3.4*10**38+10} and {3.4*10**38}") + tdSql.query(f"select * from {dbname}.t1 where c4 between {3.4*10**38+10} and {3.4*10**38}") # tdSql.checkRows(0) - tdSql.query("select * from t1 where c4 between 'a' and 'z'") + tdSql.query(f"select * from {dbname}.t1 where c4 between 'a' and 'z'") tdSql.checkRows(0) - tdSql.query("select * from t1 where c4 not between 1 and 2") + tdSql.query(f"select * from {dbname}.t1 where c4 not between 1 and 2") # tdSql.checkRows(0) - tdSql.query(f"select * from t1 where c4 between {1.7*10**308} and {1.7*10**308+1}") + tdSql.query(f"select * from {dbname}.t1 where c4 between {1.7*10**308} and {1.7*10**308+1}") tdSql.checkRows(1) - tdSql.query(f"select * from t2 where c4 between {-1.7*10**308-1} and {-1.7*10**308}") + tdSql.query(f"select * from {dbname}.t2 where c4 between {-1.7*10**308-1} and {-1.7*10**308}") # tdSql.checkRows(3) - tdSql.query(f"select * from t2 where c4 between null and {-1.7*10**308}") + tdSql.query(f"select * from {dbname}.t2 where c4 between null and {-1.7*10**308}") # tdSql.checkRows(3) tdLog.printNoPrefix("==========step8:query smallint type") - tdSql.query("select * from t1 where c5 between 127 and 136") - tdSql.checkRows(10) - tdSql.query("select * from t1 where c5 between 126.9 and 135.9") - tdSql.checkRows(9) - tdSql.query("select * from t1 where c5 between 136 and 127") + tdSql.query(f"select * from {dbname}.t1 where c5 between 127 and 136") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where c5 between 126.9 and 135.9") + tdSql.checkRows(rows-1) + tdSql.query(f"select * from {dbname}.t1 where c5 between 136 and 127") tdSql.checkRows(0) - tdSql.query("select * from t1 where c5 between '~' and '^'") + tdSql.query(f"select * from {dbname}.t1 where c5 between '~' and '^'") tdSql.checkRows(0) - tdSql.query("select * from t1 where c5 not between 1 and 2") + tdSql.query(f"select * from {dbname}.t1 where c5 not between 1 and 2") # tdSql.checkRows(0) - tdSql.query("select * from t1 where c5 between 32767 and 32768") + tdSql.query(f"select * from {dbname}.t1 where c5 between 32767 and 32768") tdSql.checkRows(1) - tdSql.query("select * from t2 where c5 between -32768 and -32767") + tdSql.query(f"select * from {dbname}.t2 where c5 between -32768 and -32767") tdSql.checkRows(1) - tdSql.query("select * from t2 where c5 between null and -32767") + tdSql.query(f"select * from {dbname}.t2 where c5 between null and -32767") # tdSql.checkRows(1) tdLog.printNoPrefix("==========step9:query tinyint type") - tdSql.query("select * from t1 where c6 between 0 and 9") - tdSql.checkRows(10) - tdSql.query("select * from t1 where c6 between -1.1 and 8.9") - tdSql.checkRows(9) - tdSql.query("select * from t1 where c6 between 9 and 0") + tdSql.query(f"select * from {dbname}.t1 where c6 between 0 and 9") + tdSql.checkRows(rows) + tdSql.query(f"select * from {dbname}.t1 where c6 between -1.1 and 8.9") + tdSql.checkRows(rows-1) + tdSql.query(f"select * from {dbname}.t1 where c6 between 9 and 0") tdSql.checkRows(0) - tdSql.query("select * from t1 where c6 between 'NUL' and 'HT'") + tdSql.query(f"select * from {dbname}.t1 where c6 between 'NUL' and 'HT'") tdSql.checkRows(1) - tdSql.query("select * from t1 where c6 not between 1 and 2") + tdSql.query(f"select * from {dbname}.t1 where c6 not between 1 and 2") # tdSql.checkRows(1) - tdSql.query("select * from t1 where c6 between 127 and 128") + tdSql.query(f"select * from {dbname}.t1 where c6 between 127 and 128") tdSql.checkRows(1) - tdSql.query("select * from t2 where c6 between -128 and -127") + tdSql.query(f"select * from {dbname}.t2 where c6 between -128 and -127") tdSql.checkRows(1) - tdSql.query("select * from t2 where c6 between null and -127") + tdSql.query(f"select * from {dbname}.t2 where c6 between null and -127") # tdSql.checkRows(3) tdLog.printNoPrefix("==========step10:invalid query type") # TODO tag is not finished - # tdSql.query("select * from supt where location between 'beijing' and 'shanghai'") - # tdSql.checkRows(23) - # # 非0值均解析为1,因此"between 负值 and o"解析为"between 1 and 0" - # tdSql.query("select * from supt where isused between 0 and 1") - # tdSql.checkRows(23) - # tdSql.query("select * from supt where isused between -1 and 0") - # tdSql.checkRows(0) - # tdSql.error("select * from supt where isused between false and true") - # tdSql.query("select * from supt where family between '拖拉机' and '自行车'") - # tdSql.checkRows(23) + tdSql.query(f"select * from {stb} where location between 'beijing' and 'shanghai'") + tdSql.checkRows(rows * 2 + 3) + # 非0值均解析为1,因此"between 负值 and o"解析为"between 1 and 0" + tdSql.query(f"select * from {stb} where isused between 0 and 1") + tdSql.checkRows(rows * 2 + 3) + tdSql.query(f"select * from {stb} where isused between -1 and 0") + tdSql.checkRows(rows + 2) + tdSql.query(f"select * from {stb} where isused between false and true") + tdSql.checkRows(rows * 2 + 3) + tdSql.query(f"select * from {stb} where family between '拖拉机' and '自行车'") + tdSql.checkRows(0) tdLog.printNoPrefix("==========step11:query HEX/OCT/BIN type") - tdSql.error("select * from t1 where c6 between 0x7f and 0x80") # check filter HEX - tdSql.error("select * from t1 where c6 between 0b1 and 0b11111") # check filter BIN - tdSql.error("select * from t1 where c6 between 0b1 and 0x80") - tdSql.error("select * from t1 where c6=0b1") - tdSql.error("select * from t1 where c6=0x1") + tdSql.error(f"select * from {dbname}.t1 where c6 between 0x7f and 0x80") # check filter HEX + tdSql.error(f"select * from {dbname}.t1 where c6 between 0b1 and 0b11111") # check filter BIN + tdSql.error(f"select * from {dbname}.t1 where c6 between 0b1 and 0x80") + tdSql.error(f"select * from {dbname}.t1 where c6=0b1") + tdSql.error(f"select * from {dbname}.t1 where c6=0x1") # 八进制数据会按照十进制数据进行判定 - tdSql.query("select * from t1 where c6 between 01 and 0200") # check filter OCT - tdSql.checkRows(10) + tdSql.query(f"select * from {dbname}.t1 where c6 between 01 and 0200") # check filter OCT + tdSql.checkRows(rows) def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/bottom.py b/tests/system-test/2-query/bottom.py index 1b7c967348..923575695f 100644 --- a/tests/system-test/2-query/bottom.py +++ b/tests/system-test/2-query/bottom.py @@ -26,7 +26,7 @@ class TDTestCase: tdSql.init(conn.cursor()) self.dbname = 'db_test' self.setsql = TDSetSql() - self.ntbname = 'ntb' + self.ntbname = f'{self.dbname}.ntb' self.rowNum = 10 self.tbnum = 20 self.ts = 1537146000000 @@ -96,7 +96,7 @@ class TDTestCase: self.bottom_check_data(self.ntbname,'normal_table') tdSql.execute(f'drop database {self.dbname}') def bottom_check_stb(self): - stbname = tdCom.getLongName(5, "letters") + stbname = f'{self.dbname}.{tdCom.getLongName(5, "letters")}' tag_dict = { 't0':'int' } @@ -109,7 +109,7 @@ class TDTestCase: for i in range(self.tbnum): tdSql.execute(f"create table {stbname}_{i} using {stbname} tags({tag_values[0]})") self.insert_data(self.column_dict,f'{stbname}_{i}',self.rowNum) - tdSql.query('show tables') + tdSql.query(f'show {self.dbname}.tables') vgroup_list = [] for i in range(len(tdSql.queryResult)): vgroup_list.append(tdSql.queryResult[i][6]) diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index 934bbbd7b4..bdac2b6175 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -15,6 +15,7 @@ class TDTestCase: def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) + self.dbname = "db" def __cast_to_bigint(self, col_name, tbname): __sql = f"select cast({col_name} as bigint), {col_name} from {tbname}" @@ -35,7 +36,7 @@ class TDTestCase: for i in range(tdSql.queryRows): if data_tb_col[i] is None: tdSql.checkData( i, 0 , None ) - if col_name not in ["c2", "double"] or tbname != "t1" or i != 10: + if col_name not in ["c2", "double"] or tbname != f"{self.dbname}.t1" or i != 10: utc_zone = datetime.timezone.utc utc_8 = datetime.timezone(datetime.timedelta(hours=8)) date_init_stamp = datetime.datetime.utcfromtimestamp(data_tb_col[i]/1000) @@ -48,52 +49,52 @@ class TDTestCase: self.__cast_to_timestamp(col_name=col, tbname=table) def __test_bigint(self): - __table_list = ["ct1", "ct4", "t1"] + __table_list = [f"{self.dbname}.ct1", f"{self.dbname}.ct4", f"{self.dbname}.t1"] __col_list = ["c1","c2","c3","c4","c5","c6","c7","c10","c1+c2"] self.__range_to_bigint(cols=__col_list, tables=__table_list) def __test_timestamp(self): - __table_list = ["ct1", "ct4", "t1"] + __table_list = [f"{self.dbname}.ct1", f"{self.dbname}.ct4", f"{self.dbname}.t1"] __col_list = ["c1","c2","c3","c4","c5","c6","c7","c1+c2"] self.__range_to_timestamp(cols=__col_list, tables=__table_list) def all_test(self): - tdSql.query("select c1 from ct4") + tdSql.query(f"select c1 from {self.dbname}.ct4") data_ct4_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {self.dbname}.t1") data_t1_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] tdLog.printNoPrefix("==========step2: cast int to bigint, expect no changes") - tdSql.query("select cast(c1 as bigint) as b from ct4") + tdSql.query(f"select cast(c1 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c1)): tdSql.checkData( i, 0, data_ct4_c1[i]) - tdSql.query("select cast(c1 as bigint) as b from t1") + tdSql.query(f"select cast(c1 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c1)): tdSql.checkData( i, 0, data_t1_c1[i]) tdLog.printNoPrefix("==========step5: cast int to binary, expect changes to str(int) ") - #tdSql.query("select cast(c1 as binary(32)) as b from ct4") + #tdSql.query(f"select cast(c1 as binary(32)) as b from {self.dbname}.ct4") #for i in range(len(data_ct4_c1)): # tdSql.checkData( i, 0, str(data_ct4_c1[i]) ) - tdSql.query("select cast(c1 as binary(32)) as b from t1") + tdSql.query(f"select cast(c1 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c1)): tdSql.checkData( i, 0, str(data_t1_c1[i]) ) tdLog.printNoPrefix("==========step6: cast int to nchar, expect changes to str(int) ") - tdSql.query("select cast(c1 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c1 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c1)): tdSql.checkData( i, 0, str(data_ct4_c1[i]) ) - tdSql.query("select cast(c1 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c1 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c1)): tdSql.checkData( i, 0, str(data_t1_c1[i]) ) tdLog.printNoPrefix("==========step7: cast int to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c1 as timestamp) as b from ct4") + tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c1)): if data_ct4_c1[i] is None: tdSql.checkData( i, 0 , None ) @@ -104,7 +105,7 @@ class TDTestCase: date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c1 as timestamp) as b from t1") + tdSql.query(f"select cast(c1 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c1)): if data_ct4_c1[i] is None: tdSql.checkData( i, 0 , None ) @@ -117,40 +118,40 @@ class TDTestCase: tdLog.printNoPrefix("==========step8: cast bigint to bigint, expect no changes") - tdSql.query("select c2 from ct4") + tdSql.query(f"select c2 from {self.dbname}.ct4") data_ct4_c2 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c2 from t1") + tdSql.query(f"select c2 from {self.dbname}.t1") data_t1_c2 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select cast(c2 as bigint) as b from ct4") + tdSql.query(f"select cast(c2 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c2)): tdSql.checkData( i, 0, data_ct4_c2[i]) - tdSql.query("select cast(c2 as bigint) as b from t1") + tdSql.query(f"select cast(c2 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c2)): tdSql.checkData( i, 0, data_t1_c2[i]) tdLog.printNoPrefix("==========step9: cast bigint to binary, expect changes to str(int) ") - tdSql.query("select cast(c2 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c2 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c2)): tdSql.checkData( i, 0, str(data_ct4_c2[i]) ) - tdSql.query("select cast(c2 as binary(32)) as b from t1") + tdSql.query(f"select cast(c2 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c2)): tdSql.checkData( i, 0, str(data_t1_c2[i]) ) tdLog.printNoPrefix("==========step10: cast bigint to nchar, expect changes to str(int) ") - tdSql.query("select cast(c2 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c2 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c2)): tdSql.checkData( i, 0, str(data_ct4_c2[i]) ) - tdSql.query("select cast(c2 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c2 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c2)): tdSql.checkData( i, 0, str(data_t1_c2[i]) ) tdLog.printNoPrefix("==========step11: cast bigint to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c2 as timestamp) as b from ct4") + tdSql.query(f"select cast(c2 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c2)): if data_ct4_c2[i] is None: tdSql.checkData( i, 0 , None ) @@ -162,7 +163,7 @@ class TDTestCase: tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c2 as timestamp) as b from t1") + tdSql.query(f"select cast(c2 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c2)): if data_t1_c2[i] is None: tdSql.checkData( i, 0 , None ) @@ -177,40 +178,40 @@ class TDTestCase: tdLog.printNoPrefix("==========step12: cast smallint to bigint, expect no changes") - tdSql.query("select c3 from ct4") + tdSql.query(f"select c3 from {self.dbname}.ct4") data_ct4_c3 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c3 from t1") + tdSql.query(f"select c3 from {self.dbname}.t1") data_t1_c3 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select cast(c3 as bigint) as b from ct4") + tdSql.query(f"select cast(c3 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c3)): tdSql.checkData( i, 0, data_ct4_c3[i]) - tdSql.query("select cast(c3 as bigint) as b from t1") + tdSql.query(f"select cast(c3 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c3)): tdSql.checkData( i, 0, data_t1_c3[i]) tdLog.printNoPrefix("==========step13: cast smallint to binary, expect changes to str(int) ") - tdSql.query("select cast(c3 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c3 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c3)): tdSql.checkData( i, 0, str(data_ct4_c3[i]) ) - tdSql.query("select cast(c3 as binary(32)) as b from t1") + tdSql.query(f"select cast(c3 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c3)): tdSql.checkData( i, 0, str(data_t1_c3[i]) ) tdLog.printNoPrefix("==========step14: cast smallint to nchar, expect changes to str(int) ") - tdSql.query("select cast(c3 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c3 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c3)): tdSql.checkData( i, 0, str(data_ct4_c3[i]) ) - tdSql.query("select cast(c3 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c3 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c3)): tdSql.checkData( i, 0, str(data_t1_c3[i]) ) tdLog.printNoPrefix("==========step15: cast smallint to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c3 as timestamp) as b from ct4") + tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c3)): if data_ct4_c3[i] is None: tdSql.checkData( i, 0 , None ) @@ -221,7 +222,7 @@ class TDTestCase: date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c3 as timestamp) as b from t1") + tdSql.query(f"select cast(c3 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c3)): if data_ct4_c3[i] is None: tdSql.checkData( i, 0 , None ) @@ -234,40 +235,40 @@ class TDTestCase: tdLog.printNoPrefix("==========step16: cast tinyint to bigint, expect no changes") - tdSql.query("select c4 from ct4") + tdSql.query(f"select c4 from {self.dbname}.ct4") data_ct4_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c4 from t1") + tdSql.query(f"select c4 from {self.dbname}.t1") data_t1_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select cast(c4 as bigint) as b from ct4") + tdSql.query(f"select cast(c4 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c4)): tdSql.checkData( i, 0, data_ct4_c4[i]) - tdSql.query("select cast(c4 as bigint) as b from t1") + tdSql.query(f"select cast(c4 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c4)): tdSql.checkData( i, 0, data_t1_c4[i]) tdLog.printNoPrefix("==========step17: cast tinyint to binary, expect changes to str(int) ") - tdSql.query("select cast(c4 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c4 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c4)): tdSql.checkData( i, 0, str(data_ct4_c4[i]) ) - tdSql.query("select cast(c4 as binary(32)) as b from t1") + tdSql.query(f"select cast(c4 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c4)): tdSql.checkData( i, 0, str(data_t1_c4[i]) ) tdLog.printNoPrefix("==========step18: cast tinyint to nchar, expect changes to str(int) ") - tdSql.query("select cast(c4 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c4 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c4)): tdSql.checkData( i, 0, str(data_ct4_c4[i]) ) - tdSql.query("select cast(c4 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c4 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c4)): tdSql.checkData( i, 0, str(data_t1_c4[i]) ) tdLog.printNoPrefix("==========step19: cast tinyint to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c4 as timestamp) as b from ct4") + tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c4)): if data_ct4_c4[i] is None: tdSql.checkData( i, 0 , None ) @@ -278,7 +279,7 @@ class TDTestCase: date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c4 as timestamp) as b from t1") + tdSql.query(f"select cast(c4 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c4)): if data_ct4_c4[i] is None: tdSql.checkData( i, 0 , None ) @@ -291,36 +292,36 @@ class TDTestCase: tdLog.printNoPrefix("==========step20: cast float to bigint, expect no changes") - tdSql.query("select c5 from ct4") + tdSql.query(f"select c5 from {self.dbname}.ct4") data_ct4_c5 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c5 from t1") + tdSql.query(f"select c5 from {self.dbname}.t1") data_t1_c5 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select cast(c5 as bigint) as b from ct4") + tdSql.query(f"select cast(c5 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c5)): tdSql.checkData( i, 0, None ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, int(data_ct4_c5[i]) ) - tdSql.query("select cast(c5 as bigint) as b from t1") + tdSql.query(f"select cast(c5 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c5)): tdSql.checkData( i, 0, None ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, int(data_t1_c5[i]) ) tdLog.printNoPrefix("==========step21: cast float to binary, expect changes to str(int) ") - tdSql.query("select cast(c5 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c5 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c5)): tdSql.checkData( i, 0, str(data_ct4_c5[i]) ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c5[i]:.6f}' ) - tdSql.query("select cast(c5 as binary(32)) as b from t1") + tdSql.query(f"select cast(c5 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c5)): tdSql.checkData( i, 0, str(data_t1_c5[i]) ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, f'{data_t1_c5[i]:.6f}' ) tdLog.printNoPrefix("==========step22: cast float to nchar, expect changes to str(int) ") - tdSql.query("select cast(c5 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c5 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c5)): tdSql.checkData( i, 0, None ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c5[i]:.6f}' ) - tdSql.query("select cast(c5 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c5 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c5)): tdSql.checkData( i, 0, None ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, f'{data_t1_c5[i]:.6f}' ) tdLog.printNoPrefix("==========step23: cast float to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c5 as timestamp) as b from ct4") + tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c5)): if data_ct4_c5[i] is None: tdSql.checkData( i, 0 , None ) @@ -330,7 +331,7 @@ class TDTestCase: date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c5[i]/1000)) date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c5 as timestamp) as b from t1") + tdSql.query(f"select cast(c5 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c5)): if data_t1_c5[i] is None: tdSql.checkData( i, 0 , None ) @@ -342,15 +343,15 @@ class TDTestCase: tdSql.checkData( i, 0, date_data) tdLog.printNoPrefix("==========step24: cast double to bigint, expect no changes") - tdSql.query("select c6 from ct4") + tdSql.query(f"select c6 from {self.dbname}.ct4") data_ct4_c6 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c6 from t1") + tdSql.query(f"select c6 from {self.dbname}.t1") data_t1_c6 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select cast(c6 as bigint) as b from ct4") + tdSql.query(f"select cast(c6 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c6)): tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, int(data_ct4_c6[i]) ) - tdSql.query("select cast(c6 as bigint) as b from t1") + tdSql.query(f"select cast(c6 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c6)): if data_t1_c6[i] is None: tdSql.checkData( i, 0, None ) @@ -360,23 +361,23 @@ class TDTestCase: tdSql.checkData( i, 0, int(data_t1_c6[i]) ) tdLog.printNoPrefix("==========step25: cast double to binary, expect changes to str(int) ") - tdSql.query("select cast(c6 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c6 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c6)): tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c6[i]:.6f}' ) - tdSql.query("select cast(c6 as binary(32)) as b from t1") + tdSql.query(f"select cast(c6 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c6)): tdSql.checkData( i, 0, None ) if data_t1_c6[i] is None else tdSql.checkData( i, 0, f'{data_t1_c6[i]:.6f}' ) tdLog.printNoPrefix("==========step26: cast double to nchar, expect changes to str(int) ") - tdSql.query("select cast(c6 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c6 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c6)): tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c6[i]:.6f}' ) - tdSql.query("select cast(c6 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c6 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c6)): tdSql.checkData( i, 0, None ) if data_t1_c6[i] is None else tdSql.checkData( i, 0, f'{data_t1_c6[i]:.6f}' ) tdLog.printNoPrefix("==========step27: cast double to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c6 as timestamp) as b from ct4") + tdSql.query(f"select cast(c6 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c6)): if data_ct4_c6[i] is None: tdSql.checkData( i, 0 , None ) @@ -387,7 +388,7 @@ class TDTestCase: date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c6 as timestamp) as b from t1") + tdSql.query(f"select cast(c6 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c6)): if data_t1_c6[i] is None: tdSql.checkData( i, 0 , None ) @@ -401,36 +402,36 @@ class TDTestCase: tdSql.checkData( i, 0, date_data) tdLog.printNoPrefix("==========step28: cast bool to bigint, expect no changes") - tdSql.query("select c7 from ct4") + tdSql.query(f"select c7 from {self.dbname}.ct4") data_ct4_c7 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c7 from t1") + tdSql.query(f"select c7 from {self.dbname}.t1") data_t1_c7 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select cast(c7 as bigint) as b from ct4") + tdSql.query(f"select cast(c7 as bigint) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c7)): tdSql.checkData( i, 0, data_ct4_c7[i]) - tdSql.query("select cast(c7 as bigint) as b from t1") + tdSql.query(f"select cast(c7 as bigint) as b from {self.dbname}.t1") for i in range(len(data_t1_c7)): tdSql.checkData( i, 0, data_t1_c7[i]) tdLog.printNoPrefix("==========step29: cast bool to binary, expect changes to str(int) ") - tdSql.query("select cast(c7 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c7 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c7)): tdSql.checkData( i, 0, None ) if data_ct4_c7[i] is None else tdSql.checkData( i, 0, str(data_ct4_c7[i]).lower() ) - tdSql.query("select cast(c7 as binary(32)) as b from t1") + tdSql.query(f"select cast(c7 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c7)): tdSql.checkData( i, 0, None ) if data_t1_c7[i] is None else tdSql.checkData( i, 0, str(data_t1_c7[i]).lower() ) tdLog.printNoPrefix("==========step30: cast bool to nchar, expect changes to str(int) ") - tdSql.query("select cast(c7 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c7 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c7)): tdSql.checkData( i, 0, None ) if data_ct4_c7[i] is None else tdSql.checkData( i, 0, str(data_ct4_c7[i]).lower() ) - tdSql.query("select cast(c7 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c7 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c7)): tdSql.checkData( i, 0, None ) if data_t1_c7[i] is None else tdSql.checkData( i, 0, str(data_t1_c7[i]).lower() ) tdLog.printNoPrefix("==========step31: cast bool to timestamp, expect changes to timestamp ") - tdSql.query("select cast(c7 as timestamp) as b from ct4") + tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c7)): if data_ct4_c7[i] is None: tdSql.checkData( i, 0 , None ) @@ -440,7 +441,7 @@ class TDTestCase: date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c7[i]/1000)) date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") tdSql.checkData( i, 0, date_data) - tdSql.query("select cast(c7 as timestamp) as b from t1") + tdSql.query(f"select cast(c7 as timestamp) as b from {self.dbname}.t1") for i in range(len(data_t1_c7)): if data_t1_c7[i] is None: tdSql.checkData( i, 0 , None ) @@ -452,22 +453,22 @@ class TDTestCase: tdSql.checkData( i, 0, date_data) - tdSql.query("select c8 from ct4") + tdSql.query(f"select c8 from {self.dbname}.ct4") data_ct4_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c8 from t1") + tdSql.query(f"select c8 from {self.dbname}.t1") data_t1_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] tdLog.printNoPrefix("==========step32: cast binary to binary, expect no changes ") - tdSql.query("select cast(c8 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c8 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c8)): tdSql.checkData( i, 0, None ) if data_ct4_c8[i] is None else tdSql.checkData(i,0,data_ct4_c8[i]) - tdSql.query("select cast(c8 as binary(32)) as b from t1") + tdSql.query(f"select cast(c8 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c8)): tdSql.checkData( i, 0, None ) if data_t1_c8[i] is None else tdSql.checkData(i,0,data_t1_c8[i]) tdLog.printNoPrefix("==========step33: cast binary to binary, expect truncate ") - tdSql.query("select cast(c8 as binary(2)) as b from ct4") + tdSql.query(f"select cast(c8 as binary(2)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c8)): if data_ct4_c8[i] is None: tdSql.checkData( i, 0, None) @@ -476,7 +477,7 @@ class TDTestCase: else: caller = inspect.getframeinfo(inspect.stack()[1][0]) tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c8[i][:2]}") - tdSql.query("select cast(c8 as binary(2)) as b from t1") + tdSql.query(f"select cast(c8 as binary(2)) as b from {self.dbname}.t1") for i in range(len(data_t1_c8)): if data_t1_c8[i] is None: tdSql.checkData( i, 0, None) @@ -487,7 +488,7 @@ class TDTestCase: tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c8[i][:2]}") tdLog.printNoPrefix("==========step34: cast binary to nchar, expect changes to str(int) ") - tdSql.query("select cast(c8 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c8 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c8)): if data_ct4_c8[i] is None: tdSql.checkData( i, 0, None) @@ -496,7 +497,7 @@ class TDTestCase: else: caller = inspect.getframeinfo(inspect.stack()[1][0]) tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c8[i]}") - tdSql.query("select cast(c8 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c8 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c8)): if data_t1_c8[i] is None: tdSql.checkData( i, 0, None) @@ -507,14 +508,14 @@ class TDTestCase: tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c8[i]}") - tdSql.query("select c9 from ct4") + tdSql.query(f"select c9 from {self.dbname}.ct4") data_ct4_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c9 from t1") + tdSql.query(f"select c9 from {self.dbname}.t1") data_t1_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] "c10 timestamp" tdLog.printNoPrefix("==========step35: cast nchar to nchar, expect no changes ") - tdSql.query("select cast(c9 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c9 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c9)): if data_ct4_c9[i] is None: tdSql.checkData( i, 0, None) @@ -523,7 +524,7 @@ class TDTestCase: else: caller = inspect.getframeinfo(inspect.stack()[1][0]) tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c9[i]}") - tdSql.query("select cast(c9 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c9 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c9)): tdSql.checkData( i, 0, data_t1_c9[i] ) if data_t1_c9[i] is None: @@ -535,7 +536,7 @@ class TDTestCase: tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c9[i]}") tdLog.printNoPrefix("==========step36: cast nchar to nchar, expect truncate ") - tdSql.query("select cast(c9 as nchar(2)) as b from ct4") + tdSql.query(f"select cast(c9 as nchar(2)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c9)): if data_ct4_c9[i] is None: tdSql.checkData( i, 0, None) @@ -544,7 +545,7 @@ class TDTestCase: else: caller = inspect.getframeinfo(inspect.stack()[1][0]) tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c9[i][:2]}") - tdSql.query("select cast(c9 as nchar(2)) as b from t1") + tdSql.query(f"select cast(c9 as nchar(2)) as b from {self.dbname}.t1") for i in range(len(data_t1_c9)): if data_t1_c9[i] is None: tdSql.checkData( i, 0, None) @@ -554,141 +555,144 @@ class TDTestCase: caller = inspect.getframeinfo(inspect.stack()[1][0]) tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c9[i][:2]}") - tdSql.query("select c10 from ct4") + tdSql.query(f"select c10 from {self.dbname}.ct4") data_ct4_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - tdSql.query("select c10 from t1") + tdSql.query(f"select c10 from {self.dbname}.t1") data_t1_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] tdLog.printNoPrefix("==========step37: cast timestamp to nchar, expect no changes ") - tdSql.query("select cast(c10 as nchar(32)) as b from ct4") + tdSql.query(f"select cast(c10 as nchar(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c10)): if data_ct4_c10[i] is None: tdSql.checkData( i, 0, None ) else: - time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + # time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + time2str = str(int((datetime.datetime.timestamp(data_ct4_c10[i])-datetime.datetime.timestamp(datetime.datetime.fromtimestamp(0)))*1000)) tdSql.checkData( i, 0, time2str ) - tdSql.query("select cast(c10 as nchar(32)) as b from t1") + tdSql.query(f"select cast(c10 as nchar(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c10)): if data_t1_c10[i] is None: tdSql.checkData( i, 0, None ) elif i == 10: continue else: - time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + # time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + time2str = str(int((datetime.datetime.timestamp(data_t1_c10[i])-datetime.datetime.timestamp(datetime.datetime.fromtimestamp(0)))*1000)) tdSql.checkData( i, 0, time2str ) tdLog.printNoPrefix("==========step38: cast timestamp to binary, expect no changes ") - tdSql.query("select cast(c10 as binary(32)) as b from ct4") + tdSql.query(f"select cast(c10 as binary(32)) as b from {self.dbname}.ct4") for i in range(len(data_ct4_c10)): if data_ct4_c10[i] is None: tdSql.checkData( i, 0, None ) else: - time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + # time2str = str(int((data_ct4_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + time2str = str(int((datetime.datetime.timestamp(data_ct4_c10[i])-datetime.datetime.timestamp(datetime.datetime.fromtimestamp(0)))*1000)) tdSql.checkData( i, 0, time2str ) - tdSql.query("select cast(c10 as binary(32)) as b from t1") + tdSql.query(f"select cast(c10 as binary(32)) as b from {self.dbname}.t1") for i in range(len(data_t1_c10)): if data_t1_c10[i] is None: tdSql.checkData( i, 0, None ) elif i == 10: continue else: - time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + # time2str = str(int((data_t1_c10[i]-datetime.datetime.fromtimestamp(0)).total_seconds()*1000)) + time2str = str(int((datetime.datetime.timestamp(data_t1_c10[i])-datetime.datetime.timestamp(datetime.datetime.fromtimestamp(0)))*1000)) tdSql.checkData( i, 0, time2str ) tdLog.printNoPrefix("==========step39: cast constant operation to bigint, expect change to int ") - tdSql.query("select cast(12121.23323131 as bigint) as b from ct4") + tdSql.query(f"select cast(12121.23323131 as bigint) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, 12121) for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 as binary(16)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 as binary(16)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 as binary(2)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 as binary(2)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 as nchar(16)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 as nchar(16)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 as nchar(2)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 as nchar(2)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 321.876897998 as bigint) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 321.876897998 as bigint) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, 12443) for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 321.876897998 as binary(16)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 321.876897998 as binary(16)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12443.110129') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 321.876897998 as binary(3)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 321.876897998 as binary(3)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '124') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 321.876897998 as nchar(16)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 321.876897998 as nchar(16)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12443.110129') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 321.876897998 as nchar(3)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 321.876897998 as nchar(3)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '124') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as bigint) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as bigint) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, 12121) for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as binary(16)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as binary(16)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as binary(2)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as binary(2)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as nchar(16)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as nchar(16)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12121.233231') for i in range(tdSql.queryRows) ) - tdSql.query("select cast(12121.23323131 + 'test~!@`#$%^&*()}{][;><.,' as nchar(2)) as b from ct4") + tdSql.query(f"select cast(12121.23323131 + 'test~!@`#$%^&*(){'}'}{'{'}][;><.,' as nchar(2)) as b from {self.dbname}.ct4") ( tdSql.checkData(i, 0, '12') for i in range(tdSql.queryRows) ) - tdLog.printNoPrefix("==========step40: error cast condition, should return error ") - #tdSql.error("select cast(c1 as int) as b from ct4") - #tdSql.error("select cast(c1 as bool) as b from ct4") - #tdSql.error("select cast(c1 as tinyint) as b from ct4") - #tdSql.error("select cast(c1 as smallint) as b from ct4") - #tdSql.error("select cast(c1 as float) as b from ct4") - #tdSql.error("select cast(c1 as double) as b from ct4") - #tdSql.error("select cast(c1 as tinyint unsigned) as b from ct4") - #tdSql.error("select cast(c1 as smallint unsigned) as b from ct4") - #tdSql.error("select cast(c1 as int unsigned) as b from ct4") + tdLog.printNoPrefix("==========step40: current cast condition, should return ok ") + tdSql.query(f"select cast(c1 as int) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as bool) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as tinyint) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as smallint) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as float) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as double) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as tinyint unsigned) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as smallint unsigned) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c1 as int unsigned) as b from {self.dbname}.ct4") - #tdSql.error("select cast(c2 as int) as b from ct4") - #tdSql.error("select cast(c3 as bool) as b from ct4") - #tdSql.error("select cast(c4 as tinyint) as b from ct4") - #tdSql.error("select cast(c5 as smallint) as b from ct4") - #tdSql.error("select cast(c6 as float) as b from ct4") - #tdSql.error("select cast(c7 as double) as b from ct4") - #tdSql.error("select cast(c8 as tinyint unsigned) as b from ct4") + tdSql.query(f"select cast(c2 as int) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c4 as tinyint) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c5 as smallint) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c6 as float) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c8 as tinyint unsigned) as b from {self.dbname}.ct4") - #tdSql.error("select cast(c8 as timestamp ) as b from ct4") - #tdSql.error("select cast(c9 as timestamp ) as b from ct4") - #tdSql.error("select cast(c9 as binary(64) ) as b from ct4") - pass + tdSql.query(f"select cast(c8 as timestamp ) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c9 as timestamp ) as b from {self.dbname}.ct4") + tdSql.query(f"select cast(c9 as binary(64) ) as b from {self.dbname}.ct4") def run(self): tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") tdSql.execute( - '''create table stb1 + f'''create table {self.dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {self.dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {self.dbname}.ct{i+1} using {self.dbname}.stb1 tags ( {i+1} )') tdLog.printNoPrefix("==========step2:insert data") for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {self.dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {self.dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {self.dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {self.dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {self.dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {self.dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {self.dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {self.dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -706,10 +710,10 @@ class TDTestCase: self.all_test() - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) - tdSql.execute("use db") + tdSql.execute(f"flush database {self.dbname}") self.all_test() diff --git a/tests/system-test/2-query/ceil.py b/tests/system-test/2-query/ceil.py index f1379e6661..6777b449f9 100644 --- a/tests/system-test/2-query/ceil.py +++ b/tests/system-test/2-query/ceil.py @@ -9,49 +9,49 @@ from util.sql import * from util.cases import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) - def prepare_datas(self): + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) tdSql.execute( - ''' - create table t1 + f''' + create table {dbname}.t1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) ''' ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) @@ -95,68 +95,56 @@ class TDTestCase: else: tdLog.info("ceil value check pass , it work as expected ,sql is \"%s\" "%ceil_query ) - def test_errors(self): + def test_errors(self, dbname="db"): error_sql_lists = [ - "select ceil from t1", - # "select ceil(-+--+c1) from t1", - # "select +-ceil(c1) from t1", - # "select ++-ceil(c1) from t1", - # "select ++--ceil(c1) from t1", - # "select - -ceil(c1)*0 from t1", - # "select ceil(tbname+1) from t1 ", - "select ceil(123--123)==1 from t1", - "select ceil(c1) as 'd1' from t1", - "select ceil(c1 ,c2 ) from t1", - "select ceil(c1 ,NULL) from t1", - "select ceil(,) from t1;", - "select ceil(ceil(c1) ab from t1)", - "select ceil(c1) as int from t1", - "select ceil from stb1", - # "select ceil(-+--+c1) from stb1", - # "select +-ceil(c1) from stb1", - # "select ++-ceil(c1) from stb1", - # "select ++--ceil(c1) from stb1", - # "select - -ceil(c1)*0 from stb1", - # "select ceil(tbname+1) from stb1 ", - "select ceil(123--123)==1 from stb1", - "select ceil(c1) as 'd1' from stb1", - "select ceil(c1 ,c2 ) from stb1", - "select ceil(c1 ,NULL) from stb1", - "select ceil(,) from stb1;", - "select ceil(ceil(c1) ab from stb1)", - "select ceil(c1) as int from stb1" + f"select ceil from {dbname}.t1", + f"select ceil(123--123)==1 from {dbname}.t1", + f"select ceil(c1) as 'd1' from {dbname}.t1", + f"select ceil(c1 ,c2 ) from {dbname}.t1", + f"select ceil(c1 ,NULL) from {dbname}.t1", + f"select ceil(,) from {dbname}.t1;", + f"select ceil(ceil(c1) ab from {dbname}.t1)", + f"select ceil(c1) as int from {dbname}.t1", + f"select ceil from {dbname}.stb1", + f"select ceil(123--123)==1 from {dbname}.stb1", + f"select ceil(c1) as 'd1' from {dbname}.stb1", + f"select ceil(c1 ,c2 ) from {dbname}.stb1", + f"select ceil(c1 ,NULL) from {dbname}.stb1", + f"select ceil(,) from {dbname}.stb1;", + f"select ceil(ceil(c1) ab from {dbname}.stb1)", + f"select ceil(c1) as int from {dbname}.stb1" ] for error_sql in error_sql_lists: tdSql.error(error_sql) - def support_types(self): + def support_types(self, dbname="db"): type_error_sql_lists = [ - "select ceil(ts) from t1" , - "select ceil(c7) from t1", - "select ceil(c8) from t1", - "select ceil(c9) from t1", - "select ceil(ts) from ct1" , - "select ceil(c7) from ct1", - "select ceil(c8) from ct1", - "select ceil(c9) from ct1", - "select ceil(ts) from ct3" , - "select ceil(c7) from ct3", - "select ceil(c8) from ct3", - "select ceil(c9) from ct3", - "select ceil(ts) from ct4" , - "select ceil(c7) from ct4", - "select ceil(c8) from ct4", - "select ceil(c9) from ct4", - "select ceil(ts) from stb1" , - "select ceil(c7) from stb1", - "select ceil(c8) from stb1", - "select ceil(c9) from stb1" , + f"select ceil(ts) from {dbname}.t1" , + f"select ceil(c7) from {dbname}.t1", + f"select ceil(c8) from {dbname}.t1", + f"select ceil(c9) from {dbname}.t1", + f"select ceil(ts) from {dbname}.ct1" , + f"select ceil(c7) from {dbname}.ct1", + f"select ceil(c8) from {dbname}.ct1", + f"select ceil(c9) from {dbname}.ct1", + f"select ceil(ts) from {dbname}.ct3" , + f"select ceil(c7) from {dbname}.ct3", + f"select ceil(c8) from {dbname}.ct3", + f"select ceil(c9) from {dbname}.ct3", + f"select ceil(ts) from {dbname}.ct4" , + f"select ceil(c7) from {dbname}.ct4", + f"select ceil(c8) from {dbname}.ct4", + f"select ceil(c9) from {dbname}.ct4", + f"select ceil(ts) from {dbname}.stb1" , + f"select ceil(c7) from {dbname}.stb1", + f"select ceil(c8) from {dbname}.stb1", + f"select ceil(c9) from {dbname}.stb1" , - "select ceil(ts) from stbbb1" , - "select ceil(c7) from stbbb1", + f"select ceil(ts) from {dbname}.stbbb1" , + f"select ceil(c7) from {dbname}.stbbb1", - "select ceil(ts) from tbname", - "select ceil(c9) from tbname" + f"select ceil(ts) from {dbname}.tbname", + f"select ceil(c9) from {dbname}.tbname" ] @@ -165,127 +153,127 @@ class TDTestCase: type_sql_lists = [ - "select ceil(c1) from t1", - "select ceil(c2) from t1", - "select ceil(c3) from t1", - "select ceil(c4) from t1", - "select ceil(c5) from t1", - "select ceil(c6) from t1", + f"select ceil(c1) from {dbname}.t1", + f"select ceil(c2) from {dbname}.t1", + f"select ceil(c3) from {dbname}.t1", + f"select ceil(c4) from {dbname}.t1", + f"select ceil(c5) from {dbname}.t1", + f"select ceil(c6) from {dbname}.t1", - "select ceil(c1) from ct1", - "select ceil(c2) from ct1", - "select ceil(c3) from ct1", - "select ceil(c4) from ct1", - "select ceil(c5) from ct1", - "select ceil(c6) from ct1", + f"select ceil(c1) from {dbname}.ct1", + f"select ceil(c2) from {dbname}.ct1", + f"select ceil(c3) from {dbname}.ct1", + f"select ceil(c4) from {dbname}.ct1", + f"select ceil(c5) from {dbname}.ct1", + f"select ceil(c6) from {dbname}.ct1", - "select ceil(c1) from ct3", - "select ceil(c2) from ct3", - "select ceil(c3) from ct3", - "select ceil(c4) from ct3", - "select ceil(c5) from ct3", - "select ceil(c6) from ct3", + f"select ceil(c1) from {dbname}.ct3", + f"select ceil(c2) from {dbname}.ct3", + f"select ceil(c3) from {dbname}.ct3", + f"select ceil(c4) from {dbname}.ct3", + f"select ceil(c5) from {dbname}.ct3", + f"select ceil(c6) from {dbname}.ct3", - "select ceil(c1) from stb1", - "select ceil(c2) from stb1", - "select ceil(c3) from stb1", - "select ceil(c4) from stb1", - "select ceil(c5) from stb1", - "select ceil(c6) from stb1", + f"select ceil(c1) from {dbname}.stb1", + f"select ceil(c2) from {dbname}.stb1", + f"select ceil(c3) from {dbname}.stb1", + f"select ceil(c4) from {dbname}.stb1", + f"select ceil(c5) from {dbname}.stb1", + f"select ceil(c6) from {dbname}.stb1", - "select ceil(c6) as alisb from stb1", - "select ceil(c6) alisb from stb1", + f"select ceil(c6) as alisb from {dbname}.stb1", + f"select ceil(c6) alisb from {dbname}.stb1", ] for type_sql in type_sql_lists: tdSql.query(type_sql) - def basic_ceil_function(self): + def basic_ceil_function(self, dbname="db"): # basic query - tdSql.query("select c1 from ct3") + tdSql.query(f"select c1 from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select c1 from t1") + tdSql.query(f"select c1 from {dbname}.t1") tdSql.checkRows(12) - tdSql.query("select c1 from stb1") + tdSql.query(f"select c1 from {dbname}.stb1") tdSql.checkRows(25) - # used for empty table , ct3 is empty - tdSql.query("select ceil(c1) from ct3") + # used for empty table , {dbname}.ct3 is empty + tdSql.query(f"select ceil(c1) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select ceil(c2) from ct3") + tdSql.query(f"select ceil(c2) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select ceil(c3) from ct3") + tdSql.query(f"select ceil(c3) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select ceil(c4) from ct3") + tdSql.query(f"select ceil(c4) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select ceil(c5) from ct3") + tdSql.query(f"select ceil(c5) from {dbname}.ct3") tdSql.checkRows(0) - tdSql.query("select ceil(c6) from ct3") + tdSql.query(f"select ceil(c6) from {dbname}.ct3") # used for regular table - tdSql.query("select ceil(c1) from t1") + tdSql.query(f"select ceil(c1) from {dbname}.t1") tdSql.checkData(0, 0, None) tdSql.checkData(1 , 0, 1) tdSql.checkData(3 , 0, 3) tdSql.checkData(5 , 0, None) - tdSql.query("select c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 4, 1.11000) tdSql.checkData(3, 3, 33) tdSql.checkData(5, 4, None) - tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1") + tdSql.query(f"select ts,c1, c2, c3 , c4, c5 from {dbname}.t1") tdSql.checkData(1, 5, 1.11000) tdSql.checkData(3, 4, 33) tdSql.checkData(5, 5, None) - self.check_result_auto( "select c1, c2, c3 , c4, c5 from t1", "select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from t1") + self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.t1", f"select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from {dbname}.t1") # used for sub table - tdSql.query("select ceil(c1) from ct1") + tdSql.query(f"select ceil(c1) from {dbname}.ct1") tdSql.checkData(0, 0, 8) tdSql.checkData(1 , 0, 7) tdSql.checkData(3 , 0, 5) tdSql.checkData(5 , 0, 4) - tdSql.query("select ceil(c1) from ct1") - self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct1", "select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from ct1") - self.check_result_auto("select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from ct1;","select c1 from ct1" ) + tdSql.query(f"select ceil(c1) from {dbname}.ct1") + self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.ct1", f"select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from {dbname}.ct1") + self.check_result_auto(f"select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from {dbname}.ct1;", f"select c1 from {dbname}.ct1" ) # used for stable table - tdSql.query("select ceil(c1) from stb1") + tdSql.query(f"select ceil(c1) from {dbname}.stb1") tdSql.checkRows(25) - self.check_result_auto( "select c1, c2, c3 , c4, c5 from ct4 ", "select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from ct4") - self.check_result_auto("select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from ct4;" , "select c1 from ct4" ) + self.check_result_auto( f"select c1, c2, c3 , c4, c5 from {dbname}.ct4 ", f"select (c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) from {dbname}.ct4") + self.check_result_auto(f"select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from {dbname}.ct4;" , f"select c1 from {dbname}.ct4" ) # used for not exists table - tdSql.error("select ceil(c1) from stbbb1") - tdSql.error("select ceil(c1) from tbname") - tdSql.error("select ceil(c1) from ct5") + tdSql.error(f"select ceil(c1) from {dbname}.stbbb1") + tdSql.error(f"select ceil(c1) from {dbname}.tbname") + tdSql.error(f"select ceil(c1) from {dbname}.ct5") # mix with common col - tdSql.query("select c1, ceil(c1) from ct1") + tdSql.query(f"select c1, ceil(c1) from {dbname}.ct1") tdSql.checkData(0 , 0 ,8) tdSql.checkData(0 , 1 ,8) tdSql.checkData(4 , 0 ,0) tdSql.checkData(4 , 1 ,0) - tdSql.query("select c1, ceil(c1) from ct4") + tdSql.query(f"select c1, ceil(c1) from {dbname}.ct4") tdSql.checkData(0 , 0 , None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(4 , 0 ,5) tdSql.checkData(4 , 1 ,5) tdSql.checkData(5 , 0 ,None) tdSql.checkData(5 , 1 ,None) - tdSql.query("select c1, ceil(c1) from ct4 ") + tdSql.query(f"select c1, ceil(c1) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(4 , 0 ,5) tdSql.checkData(4 , 1 ,5) # mix with common functions - tdSql.query("select c1, ceil(c1),c5, ceil(c5) from ct4 ") + tdSql.query(f"select c1, ceil(c1),c5, ceil(c5) from {dbname}.ct4 ") tdSql.checkData(0 , 0 ,None) tdSql.checkData(0 , 1 ,None) tdSql.checkData(0 , 2 ,None) @@ -296,34 +284,34 @@ class TDTestCase: tdSql.checkData(3 , 2 ,6.66000) tdSql.checkData(3 , 3 ,7.00000) - tdSql.query("select c1, ceil(c1),c5, floor(c5) from stb1 ") + tdSql.query(f"select c1, ceil(c1),c5, floor(c5) from {dbname}.stb1 ") # mix with agg functions , not support - tdSql.error("select c1, ceil(c1),c5, count(c5) from stb1 ") - tdSql.error("select c1, ceil(c1),c5, count(c5) from ct1 ") - tdSql.error("select ceil(c1), count(c5) from stb1 ") - tdSql.error("select ceil(c1), count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from ct1 ") - tdSql.error("select c1, count(c5) from stb1 ") + tdSql.error(f"select c1, ceil(c1),c5, count(c5) from {dbname}.stb1 ") + tdSql.error(f"select c1, ceil(c1),c5, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select ceil(c1), count(c5) from {dbname}.stb1 ") + tdSql.error(f"select ceil(c1), count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.ct1 ") + tdSql.error(f"select c1, count(c5) from {dbname}.stb1 ") # agg functions mix with agg functions - tdSql.query("select max(c5), count(c5) from stb1") - tdSql.query("select max(c5), count(c5) from ct1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.stb1") + tdSql.query(f"select max(c5), count(c5) from {dbname}.ct1") # bug fix for count - tdSql.query("select count(c1) from ct4 ") + tdSql.query(f"select count(c1) from {dbname}.ct4 ") tdSql.checkData(0,0,9) - tdSql.query("select count(*) from ct4 ") + tdSql.query(f"select count(*) from {dbname}.ct4 ") tdSql.checkData(0,0,12) - tdSql.query("select count(c1) from stb1 ") + tdSql.query(f"select count(c1) from {dbname}.stb1 ") tdSql.checkData(0,0,22) - tdSql.query("select count(*) from stb1 ") + tdSql.query(f"select count(*) from {dbname}.stb1 ") tdSql.checkData(0,0,25) # bug fix for compute - tdSql.query("select c1, abs(c1) -0 ,ceil(c1)-0 from ct4 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1)-0 from {dbname}.ct4 ") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -331,7 +319,7 @@ class TDTestCase: tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 2, 8.000000000) - tdSql.query(" select c1, abs(c1) -0 ,ceil(c1-0.1)-0.1 from ct4") + tdSql.query(f" select c1, abs(c1) -0 ,ceil(c1-0.1)-0.1 from {dbname}.ct4") tdSql.checkData(0, 0, None) tdSql.checkData(0, 1, None) tdSql.checkData(0, 2, None) @@ -339,9 +327,9 @@ class TDTestCase: tdSql.checkData(1, 1, 8.000000000) tdSql.checkData(1, 2, 7.900000000) - def abs_func_filter(self): - tdSql.execute("use db") - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>5 ") + def abs_func_filter(self,dbname="db"): + tdSql.execute(f"use {dbname}") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1>5 ") tdSql.checkRows(3) tdSql.checkData(0,0,8) tdSql.checkData(0,1,8.000000000) @@ -349,7 +337,7 @@ class TDTestCase: tdSql.checkData(0,3,7.900000000) tdSql.checkData(0,4,3.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -357,7 +345,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,2.000000000) - tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1=5 ") + tdSql.query(f"select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1=5 ") tdSql.checkRows(1) tdSql.checkData(0,0,5) tdSql.checkData(0,1,5.000000000) @@ -365,7 +353,7 @@ class TDTestCase: tdSql.checkData(0,3,4.900000000) tdSql.checkData(0,4,2.000000000) - tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from ct4 where c1>log(c1,2) limit 1 ") + tdSql.query(f"select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(log(c1,2)-0.5) from {dbname}.ct4 where c1>log(c1,2) limit 1 ") tdSql.checkRows(1) tdSql.checkData(0,0,8) tdSql.checkData(0,1,88888) @@ -377,44 +365,44 @@ class TDTestCase: def ceil_Arithmetic(self): pass - def check_boundary_values(self): + def check_boundary_values(self, dbname="bound_test"): - tdSql.execute("drop database if exists bound_test") - tdSql.execute("create database if not exists bound_test") + tdSql.execute(f"drop database if exists {dbname}") + tdSql.execute(f"create database if not exists {dbname}") time.sleep(3) - tdSql.execute("use bound_test") + tdSql.execute(f"use {dbname}") tdSql.execute( - "create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" + f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" ) - tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )') + tdSql.execute(f'create table {dbname}.sub1_bound using {dbname}.stb_bound tags ( 1 )') tdSql.execute( - f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), 2147483643, 9223372036854775803, 32763, 123, 3.39E+38, 1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.execute( - f"insert into sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now(), -2147483643, -9223372036854775803, -32763, -123, -3.39E+38, -1.69e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) tdSql.error( - f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" + f"insert into {dbname}.sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )" ) - self.check_result_auto( "select c1, c2, c3 , c4, c5 ,c6 from sub1_bound ", "select ceil(c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) ,ceil(c6) from sub1_bound") - self.check_result_auto( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select ceil(c1), ceil(c2) ,ceil(c3), ceil(c3), ceil(c2) ,ceil(c1) from sub1_bound") - self.check_result_auto("select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from sub1_bound;" , "select ceil(c1) from sub1_bound" ) + self.check_result_auto( f"select c1, c2, c3 , c4, c5 ,c6 from {dbname}.sub1_bound ", f"select ceil(c1), ceil(c2) ,ceil(c3), ceil(c4), ceil(c5) ,ceil(c6) from {dbname}.sub1_bound") + self.check_result_auto( f"select c1, c2, c3 , c3, c2 ,c1 from {dbname}.sub1_bound ", f"select ceil(c1), ceil(c2) ,ceil(c3), ceil(c3), ceil(c2) ,ceil(c1) from {dbname}.sub1_bound") + self.check_result_auto(f"select ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(ceil(c1)))))))))) nest_col_func from {dbname}.sub1_bound;" , f"select ceil(c1) from {dbname}.sub1_bound" ) # check basic elem for table per row - tdSql.query("select ceil(c1+0.2) ,ceil(c2) , ceil(c3+0.3) , ceil(c4-0.3), ceil(c5/2), ceil(c6/2) from sub1_bound ") + tdSql.query(f"select ceil(c1+0.2) ,ceil(c2) , ceil(c3+0.3) , ceil(c4-0.3), ceil(c5/2), ceil(c6/2) from {dbname}.sub1_bound ") tdSql.checkData(0, 0, 2147483648.000000000) tdSql.checkData(0, 2, 32768.000000000) tdSql.checkData(0, 3, 127.000000000) @@ -425,19 +413,19 @@ class TDTestCase: tdSql.checkData(4, 3, -123.000000000) tdSql.checkData(4, 4, -169499995645668991474575059260979281920.000000000) - self.check_result_auto("select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from sub1_bound" ,"select ceil(c1+1) ,ceil(c2) , ceil(c3*1) , ceil(c4/2), ceil(c5)/2, ceil(c6) from sub1_bound ") + self.check_result_auto(f"select c1+1 ,c2 , c3*1 , c4/2, c5/2, c6 from {dbname}.sub1_bound" , f"select ceil(c1+1) ,ceil(c2) , ceil(c3*1) , ceil(c4/2), ceil(c5)/2, ceil(c6) from {dbname}.sub1_bound ") - def support_super_table_test(self): - tdSql.execute(" use db ") - self.check_result_auto( " select c5 from stb1 order by ts " , "select ceil(c5) from stb1 order by ts" ) - self.check_result_auto( " select c5 from stb1 order by tbname " , "select ceil(c5) from stb1 order by tbname" ) - self.check_result_auto( " select c5 from stb1 where c1 > 0 order by tbname " , "select ceil(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto( " select c5 from stb1 where c1 > 0 order by tbname " , "select ceil(c5) from stb1 where c1 > 0 order by tbname" ) + def support_super_table_test(self, dbname="db"): + tdSql.execute(f" use {dbname} ") + self.check_result_auto( f" select c5 from {dbname}.stb1 order by ts " , f"select ceil(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto( f" select c5 from {dbname}.stb1 order by tbname " , f"select ceil(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select ceil(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto( f" select c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select ceil(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) - self.check_result_auto( " select t1,c5 from stb1 order by ts " , "select ceil(t1), ceil(c5) from stb1 order by ts" ) - self.check_result_auto( " select t1,c5 from stb1 order by tbname " , "select ceil(t1) ,ceil(c5) from stb1 order by tbname" ) - self.check_result_auto( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select ceil(t1) ,ceil(c5) from stb1 where c1 > 0 order by tbname" ) - self.check_result_auto( " select t1,c5 from stb1 where c1 > 0 order by tbname " , "select ceil(t1) , ceil(c5) from stb1 where c1 > 0 order by tbname" ) + self.check_result_auto( f" select t1,c5 from {dbname}.stb1 order by ts " , f"select ceil(t1), ceil(c5) from {dbname}.stb1 order by ts" ) + self.check_result_auto( f" select t1,c5 from {dbname}.stb1 order by tbname " , f"select ceil(t1) ,ceil(c5) from {dbname}.stb1 order by tbname" ) + self.check_result_auto( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select ceil(t1) ,ceil(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) + self.check_result_auto( f" select t1,c5 from {dbname}.stb1 where c1 > 0 order by tbname " , f"select ceil(t1) , ceil(c5) from {dbname}.stb1 where c1 > 0 order by tbname" ) pass def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring diff --git a/tests/system-test/2-query/char_length.py b/tests/system-test/2-query/char_length.py index 97d5a5f59a..c0883e665e 100644 --- a/tests/system-test/2-query/char_length.py +++ b/tests/system-test/2-query/char_length.py @@ -1,3 +1,7 @@ +import imp + + +import datetime from util.log import * from util.sql import * from util.cases import * @@ -101,16 +105,16 @@ class TDTestCase: return sqls - def __test_current(self): + def __test_current(self, dbname="db"): tdLog.printNoPrefix("==========current sql condition check , must return query ok==========") - tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"] for tb in tbname: self.__char_length_current_check(tb) tdLog.printNoPrefix(f"==========current sql condition check in {tb} over==========") - def __test_error(self): + def __test_error(self, dbname="db"): tdLog.printNoPrefix("==========err sql condition check , must return error==========") - tbname = ["ct1", "ct2", "ct4", "t1", "stb1"] + tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.t1", f"{dbname}.stb1"] for tb in tbname: for errsql in self.__char_length_err_check(tb): @@ -123,17 +127,16 @@ class TDTestCase: self.__test_error() - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, dbname="db"): tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {dbname}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) tags (t1 int) + ) tags (t_int int) ''' - create_ntb_sql = f'''create table t1( + create_ntb_sql = f'''create table {dbname}.t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp @@ -143,29 +146,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') - def __insert_data(self, rows): + def __insert_data(self, rows, dbname="db"): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) for i in range(rows): tdSql.execute( - f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {dbname}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {dbname}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {dbname}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -181,7 +184,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {dbname}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -197,13 +200,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {dbname}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {dbname}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -232,8 +235,10 @@ class TDTestCase: tdLog.printNoPrefix("==========step3:all check") self.all_test() - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + + tdSql.execute("flush database db") tdSql.execute("use db") diff --git a/tests/system-test/2-query/check_tsdb.py b/tests/system-test/2-query/check_tsdb.py index 0ae1648d99..746906776d 100644 --- a/tests/system-test/2-query/check_tsdb.py +++ b/tests/system-test/2-query/check_tsdb.py @@ -9,73 +9,73 @@ from util.cases import * from util.dnodes import * class TDTestCase: - updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , - "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, - "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} + # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , + # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, + # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} def init(self, conn, logSql): tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(), True) - - def prepare_datas(self): + tdSql.init(conn.cursor(), False) + + def prepare_datas(self, dbname="db"): tdSql.execute( - '''create table stb1 + f'''create table {dbname}.stb1 (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int) ''' ) - - tdSql.execute( - ''' - create table t1 - (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) - ''' - ) + + # tdSql.execute( + # f''' + # create table t1 + # (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + # ''' + # ) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.stb1 tags ( {i+1} )') for i in range(9): tdSql.execute( - f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) tdSql.execute( - f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" + f"insert into {dbname}.ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )" ) - tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") - tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") - tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") - tdSql.execute( - f'''insert into t1 values - ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) - ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) - ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) - ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) - ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) - ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) - ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) - ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) - ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) - ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ''' - ) - + # tdSql.execute( + # f'''insert into t1 values + # ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + # ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + # ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + # ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + # ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + # ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + # ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + # ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + # ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + # ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + # ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + # ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + # ''' + # ) - def restart_taosd_query_sum(self): + + def restart_taosd_query_sum(self, dbname="db"): for i in range(5): tdLog.info(" this is %d_th restart taosd " %i) - os.system("taos -s ' use db ;select c6 from stb1 ; '") - tdSql.execute("use db ") - tdSql.query("select count(*) from stb1") + os.system(f"taos -s ' use db ;select c6 from {dbname}.stb1 ; '") + tdSql.execute(f"use {dbname} ") + tdSql.query(f"select count(*) from {dbname}.stb1") tdSql.checkRows(1) - tdSql.query("select sum(c1),sum(c2),sum(c3),sum(c4),sum(c5),sum(c6) from stb1;") + tdSql.query(f"select sum(c1),sum(c2),sum(c3),sum(c4),sum(c5),sum(c6) from {dbname}.stb1;") tdSql.checkData(0,0,99) tdSql.checkData(0,1,499995) tdSql.checkData(0,2,4995) @@ -85,17 +85,18 @@ class TDTestCase: tdDnodes.stop(1) tdDnodes.start(1) time.sleep(2) - + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring tdSql.prepare() + dbname = "db" tdLog.printNoPrefix("==========step1:create table ==============") - + self.prepare_datas() - os.system("taos -s ' select c6 from stb1 ; '") + os.system(f"taos -s ' select c6 from {dbname}.stb1 ; '") self.restart_taosd_query_sum() def stop(self): diff --git a/tests/system-test/2-query/histogram.py b/tests/system-test/2-query/histogram.py index 4b322c61cf..dc6e39ece9 100644 --- a/tests/system-test/2-query/histogram.py +++ b/tests/system-test/2-query/histogram.py @@ -5,7 +5,6 @@ import json from dataclasses import dataclass, field from typing import List, Any, Tuple -from certifi import where from util.log import tdLog from util.sql import tdSql from util.cases import tdCases diff --git a/tests/system-test/2-query/join.py b/tests/system-test/2-query/join.py index df6390f59c..2348873a34 100644 --- a/tests/system-test/2-query/join.py +++ b/tests/system-test/2-query/join.py @@ -1,5 +1,7 @@ import datetime +from dataclasses import dataclass, field +from typing import List, Any, Tuple from util.log import * from util.sql import * from util.cases import * @@ -7,22 +9,57 @@ from util.dnodes import * PRIMARY_COL = "ts" -INT_COL = "c1" -BINT_COL = "c2" -SINT_COL = "c3" -TINT_COL = "c4" -FLOAT_COL = "c5" -DOUBLE_COL = "c6" -BOOL_COL = "c7" +INT_COL = "c_int" +BINT_COL = "c_bint" +SINT_COL = "c_sint" +TINT_COL = "c_tint" +FLOAT_COL = "c_float" +DOUBLE_COL = "c_double" +BOOL_COL = "c_bool" +TINT_UN_COL = "c_utint" +SINT_UN_COL = "c_usint" +BINT_UN_COL = "c_ubint" +INT_UN_COL = "c_uint" +BINARY_COL = "c_binary" +NCHAR_COL = "c_nchar" +TS_COL = "c_ts" -BINARY_COL = "c8" -NCHAR_COL = "c9" -TS_COL = "c10" +NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] +CHAR_COL = [BINARY_COL, NCHAR_COL, ] +BOOLEAN_COL = [BOOL_COL, ] +TS_TYPE_COL = [TS_COL, ] + +INT_TAG = "t_int" + +ALL_COL = [PRIMARY_COL, INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BINARY_COL, NCHAR_COL, BOOL_COL, TS_COL] +TAG_COL = [INT_TAG] +# insert data args: +TIME_STEP = 10000 +NOW = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + +# init db/table +DBNAME = "db" +STBNAME = f"{DBNAME}.stb1" +CTBNAME = f"{DBNAME}.ct1" +NTBNAME = f"{DBNAME}.nt1" + +@dataclass +class DataSet: + ts_data : List[int] = field(default_factory=list) + int_data : List[int] = field(default_factory=list) + bint_data : List[int] = field(default_factory=list) + sint_data : List[int] = field(default_factory=list) + tint_data : List[int] = field(default_factory=list) + int_un_data : List[int] = field(default_factory=list) + bint_un_data: List[int] = field(default_factory=list) + sint_un_data: List[int] = field(default_factory=list) + tint_un_data: List[int] = field(default_factory=list) + float_data : List[float] = field(default_factory=list) + double_data : List[float] = field(default_factory=list) + bool_data : List[int] = field(default_factory=list) + binary_data : List[str] = field(default_factory=list) + nchar_data : List[str] = field(default_factory=list) -NUM_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] -CHAR_COL = [ BINARY_COL, NCHAR_COL, ] -BOOLEAN_COL = [ BOOL_COL, ] -TS_TYPE_COL = [ TS_COL, ] class TDTestCase: @@ -52,12 +89,12 @@ class TDTestCase: return query_condition - def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False): + def __join_condition(self, tb_list, filter=PRIMARY_COL, INNER=False, alias_tb1="tb1", alias_tb2="tb2"): table_reference = tb_list[0] join_condition = table_reference join = "inner join" if INNER else "join" for i in range(len(tb_list[1:])): - join_condition += f" {join} {tb_list[i+1]} on {table_reference}.{filter}={tb_list[i+1]}.{filter}" + join_condition += f" as {alias_tb1} {join} {tb_list[i+1]} as {alias_tb2} on {alias_tb1}.{filter}={alias_tb2}.{filter}" return join_condition @@ -103,19 +140,19 @@ class TDTestCase: return f"select {select_clause} from {from_clause} {where_condition} {group_condition}" @property - def __join_tblist(self): + def __join_tblist(self, dbname=DBNAME): return [ # ["ct1", "ct2"], - ["ct1", "ct4"], - ["ct1", "t1"], + [f"{dbname}.ct1", f"{dbname}.ct4"], + [f"{dbname}.ct1", f"{dbname}.nt1"], # ["ct2", "ct4"], - # ["ct2", "t1"], - # ["ct4", "t1"], + # ["ct2", "nt1"], + # ["ct4", "nt1"], # ["ct1", "ct2", "ct4"], - # ["ct1", "ct2", "t1"], - # ["ct1", "ct4", "t1"], - # ["ct2", "ct4", "t1"], - # ["ct1", "ct2", "ct4", "t1"], + # ["ct1", "ct2", "nt1"], + # ["ct1", "ct4", "nt1"], + # ["ct2", "ct4", "nt1"], + # ["ct1", "ct2", "ct4", "nt1"], ] @property @@ -123,28 +160,29 @@ class TDTestCase: sqls = [] __join_tblist = self.__join_tblist for join_tblist in __join_tblist: - for join_tb in join_tblist: - select_claus_list = self.__query_condition(join_tb) - for select_claus in select_claus_list: - group_claus = self.__group_condition( col=select_claus) - where_claus = self.__where_condition( query_conditon=select_claus ) - having_claus = self.__group_condition( col=select_claus, having=f"{select_claus} is not null" ) - sqls.extend( - ( - # self.__gen_sql(select_claus, self.__join_condition(join_tblist), where_claus, group_claus), - self.__gen_sql(select_claus, self.__join_condition(join_tblist), where_claus, having_claus), - self.__gen_sql(select_claus, self.__join_condition(join_tblist), where_claus), - # self.__gen_sql(select_claus, self.__join_condition(join_tblist), group_claus), - self.__gen_sql(select_claus, self.__join_condition(join_tblist), having_claus), - self.__gen_sql(select_claus, self.__join_condition(join_tblist)), - # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, group_claus), - self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, having_claus), - self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), where_claus, ), - self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), having_claus ), - # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True), group_claus ), - self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True) ), - ) + alias_tb = "tb1" + # for join_tb in join_tblist: + select_claus_list = self.__query_condition(alias_tb) + for select_claus in select_claus_list: + group_claus = self.__group_condition( col=select_claus) + where_claus = self.__where_condition( query_conditon=select_claus ) + having_claus = self.__group_condition( col=select_claus, having=f"{select_claus} is not null" ) + sqls.extend( + ( + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, alias_tb1=alias_tb), where_claus, group_claus), + self.__gen_sql(select_claus, self.__join_condition(join_tblist, alias_tb1=alias_tb), where_claus, having_claus), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, alias_tb1=alias_tb), where_claus), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, alias_tb1=alias_tb), group_claus), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, alias_tb1=alias_tb), having_claus), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, alias_tb1=alias_tb)), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True, alias_tb1=alias_tb), where_claus, group_claus), + self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True, alias_tb1=alias_tb), where_claus, having_claus), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True, alias_tb1=alias_tb), where_claus, ), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True, alias_tb1=alias_tb), having_claus ), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True, alias_tb1=alias_tb), group_claus ), + # self.__gen_sql(select_claus, self.__join_condition(join_tblist, INNER=True, alias_tb1=alias_tb) ), ) + ) return list(filter(None, sqls)) def __join_check(self,): @@ -172,7 +210,7 @@ class TDTestCase: tdSql.error(sql=sql) break if len(tblist) == 2: - if "ct1" in tblist or "t1" in tblist: + if "ct1" in tblist or "nt1" in tblist: self.__join_current(sql, checkrows) elif where_condition or "not null" in group_condition: self.__join_current(sql, checkrows + 2 ) @@ -187,14 +225,14 @@ class TDTestCase: tdSql.query(sql=sql) # tdSql.checkRows(checkrows) - def __test_error(self): + def __test_error(self, dbname=DBNAME): # sourcery skip: extract-duplicate-method, move-assign-in-block tdLog.printNoPrefix("==========err sql condition check , must return error==========") - err_list_1 = ["ct1","ct2", "ct4"] - err_list_2 = ["ct1","ct2", "t1"] - err_list_3 = ["ct1","ct4", "t1"] - err_list_4 = ["ct2","ct4", "t1"] - err_list_5 = ["ct1", "ct2","ct4", "t1"] + err_list_1 = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4"] + err_list_2 = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.nt1"] + err_list_3 = [f"{dbname}.ct1", f"{dbname}.ct4", f"{dbname}.nt1"] + err_list_4 = [f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.nt1"] + err_list_5 = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.nt1"] self.__join_check_old(err_list_1, -1) tdLog.printNoPrefix(f"==========err sql condition check in {err_list_1} over==========") self.__join_check_old(err_list_2, -1) @@ -208,16 +246,16 @@ class TDTestCase: self.__join_check_old(["ct2", "ct4"], -1, join_flag=False) tdLog.printNoPrefix("==========err sql condition check in has no join condition over==========") - tdSql.error( f"select c1, c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) - tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{INT_COL}=ct4.{INT_COL}" ) - tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{TS_COL}=ct4.{TS_COL}" ) - tdSql.error( f"select ct2.c1, ct2.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{TS_COL}" ) - tdSql.error( f"select ct2.c1, ct1.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) - tdSql.error( f"select ct2.c1, ct4.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL} and c1 is not null " ) - tdSql.error( f"select ct2.c1, ct4.c2 from ct2, ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL} and ct1.c1 is not null " ) + tdSql.error( f"select c1, c2 from {dbname}.ct2, {dbname}.ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) + tdSql.error( f"select ct2.c1, ct2.c2 from {dbname}.ct2 as ct2, {dbname}.ct4 as ct4 where ct2.{INT_COL}=ct4.{INT_COL}" ) + tdSql.error( f"select ct2.c1, ct2.c2 from {dbname}.ct2 as ct2, {dbname}.ct4 as ct4 where ct2.{TS_COL}=ct4.{TS_COL}" ) + tdSql.error( f"select ct2.c1, ct2.c2 from {dbname}.ct2 as ct2, {dbname}.ct4 as ct4 where ct2.{PRIMARY_COL}=ct4.{TS_COL}" ) + tdSql.error( f"select ct2.c1, ct1.c2 from {dbname}.ct2 as ct2, {dbname}.ct4 as ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL}" ) + tdSql.error( f"select ct2.c1, ct4.c2 from {dbname}.ct2 as ct2, {dbname}.ct4 as ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL} and c1 is not null " ) + tdSql.error( f"select ct2.c1, ct4.c2 from {dbname}.ct2 as ct2, {dbname}.ct4 as ct4 where ct2.{PRIMARY_COL}=ct4.{PRIMARY_COL} and ct1.c1 is not null " ) - tbname = ["ct1", "ct2", "ct4", "t1"] + tbname = [f"{dbname}.ct1", f"{dbname}.ct2", f"{dbname}.ct4", f"{dbname}.nt1"] # for tb in tbname: # for errsql in self.__join_err_check(tb): @@ -230,124 +268,147 @@ class TDTestCase: self.__test_error() - def __create_tb(self): - tdSql.prepare() + def __create_tb(self, stb="stb1", ctb_num=20, ntbnum=1, dbname=DBNAME): + create_stb_sql = f'''create table {dbname}.{stb}( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) tags ({INT_TAG} int) + ''' + for i in range(ntbnum): - tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) tags (tag1 int) - ''' - create_ntb_sql = f'''create table t1( - ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, - {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, - {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp - ) - ''' + create_ntb_sql = f'''create table {dbname}.nt{i+1}( + ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, + {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, + {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp, + {TINT_UN_COL} tinyint unsigned, {SINT_UN_COL} smallint unsigned, + {INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned + ) + ''' tdSql.execute(create_stb_sql) tdSql.execute(create_ntb_sql) - for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') - { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2} + for i in range(ctb_num): + tdSql.execute(f'create table {dbname}.ct{i+1} using {dbname}.{stb} tags ( {i+1} )') - def __insert_data(self, rows): - now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) - for i in range(rows): - tdSql.execute( - f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" - ) - tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" - ) - tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar_测试_{i}', { now_time + 1 * i } )" - ) - tdSql.execute( - f'''insert into ct1 values - ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar_测试_0', { now_time + 8 } ) - ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar_测试_9', { now_time + 9 } ) - ''' - ) - - tdSql.execute( - f'''insert into ct4 values - ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 5184000000}, {pow(2,31)-pow(2,15)}, {pow(2,63)-pow(2,30)}, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000} - ) - ( - { now_time + 2592000000 }, {pow(2,31)-pow(2,16)}, {pow(2,63)-pow(2,31)}, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000} - ) - ''' - ) - - tdSql.execute( - f'''insert into ct2 values - ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3888000000 + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( - { now_time + 5184000000 }, { -1 * pow(2,31) + pow(2,15) }, { -1 * pow(2,63) + pow(2,30) }, -32766, -126, - { -1 * 3.2 * pow(10,38) }, { -1.2 * pow(10,308) }, { rows % 2 }, "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } - ) - ( - { now_time + 2592000000 }, { -1 * pow(2,31) + pow(2,16) }, { -1 * pow(2,63) + pow(2,31) }, -32767, -127, - { - 3.3 * pow(10,38) }, { -1.3 * pow(10,308) }, { (rows-1) % 2 }, "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } - ) - ''' - ) + def __data_set(self, rows): + data_set = DataSet() for i in range(rows): - insert_data = f'''insert into t1 values - ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, - "binary_{i}", "nchar_测试_{i}", { now_time - 1000 * i } ) - ''' - tdSql.execute(insert_data) - tdSql.execute( - f'''insert into t1 values - ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) - ( { now_time + 7200000 }, { pow(2,31) - pow(2,15) }, { pow(2,63) - pow(2,30) }, 32767, 127, - { 3.3 * pow(10,38) }, { 1.3 * pow(10,308) }, { rows % 2 }, - "binary_limit-1", "nchar_测试_limit-1", { now_time - 86400000 } - ) - ( - { now_time + 3600000 } , { pow(2,31) - pow(2,16) }, { pow(2,63) - pow(2,31) }, 32766, 126, - { 3.2 * pow(10,38) }, { 1.2 * pow(10,308) }, { (rows-1) % 2 }, - "binary_limit-2", "nchar_测试_limit-2", { now_time - 172800000 } - ) + data_set.ts_data.append(NOW + 1 * (rows - i)) + data_set.int_data.append(rows - i) + data_set.bint_data.append(11111 * (rows - i)) + data_set.sint_data.append(111 * (rows - i) % 32767) + data_set.tint_data.append(11 * (rows - i) % 127) + data_set.int_un_data.append(rows - i) + data_set.bint_un_data.append(11111 * (rows - i)) + data_set.sint_un_data.append(111 * (rows - i) % 32767) + data_set.tint_un_data.append(11 * (rows - i) % 127) + data_set.float_data.append(1.11 * (rows - i)) + data_set.double_data.append(1100.0011 * (rows - i)) + data_set.bool_data.append((rows - i) % 2) + data_set.binary_data.append(f'binary{(rows - i)}') + data_set.nchar_data.append(f'nchar_测试_{(rows - i)}') + + return data_set + + def __insert_data(self, dbname=DBNAME): + tdLog.printNoPrefix("==========step: start inser data into tables now.....") + data = self.__data_set(rows=self.rows) + + # now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) + null_data = '''null, null, null, null, null, null, null, null, null, null, null, null, null, null''' + zero_data = "0, 0, 0, 0, 0, 0, 0, 'binary_0', 'nchar_0', 0, 0, 0, 0, 0" + + for i in range(self.rows): + row_data = f''' + {data.int_data[i]}, {data.bint_data[i]}, {data.sint_data[i]}, {data.tint_data[i]}, {data.float_data[i]}, {data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {data.tint_un_data[i]}, + {data.sint_un_data[i]}, {data.int_un_data[i]}, {data.bint_un_data[i]} ''' - ) + neg_row_data = f''' + {-1 * data.int_data[i]}, {-1 * data.bint_data[i]}, {-1 * data.sint_data[i]}, {-1 * data.tint_data[i]}, {-1 * data.float_data[i]}, {-1 * data.double_data[i]}, + {data.bool_data[i]}, '{data.binary_data[i]}', '{data.nchar_data[i]}', {data.ts_data[i]}, {1 * data.tint_un_data[i]}, + {1 * data.sint_un_data[i]}, {1 * data.int_un_data[i]}, {1 * data.bint_un_data[i]} + ''' + + tdSql.execute( f"insert into {dbname}.ct1 values ( {NOW - i * TIME_STEP}, {row_data} )" ) + tdSql.execute( f"insert into {dbname}.ct2 values ( {NOW - i * int(TIME_STEP * 0.6)}, {neg_row_data} )" ) + tdSql.execute( f"insert into {dbname}.ct4 values ( {NOW - i * int(TIME_STEP * 0.8) }, {row_data} )" ) + tdSql.execute( f"insert into {dbname}.nt1 values ( {NOW - i * int(TIME_STEP * 1.2)}, {row_data} )" ) + + tdSql.execute( f"insert into {dbname}.ct2 values ( {NOW + int(TIME_STEP * 0.6)}, {null_data} )" ) + tdSql.execute( f"insert into {dbname}.ct2 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.6)}, {null_data} )" ) + tdSql.execute( f"insert into {dbname}.ct2 values ( {NOW - self.rows * int(TIME_STEP * 0.29) }, {null_data} )" ) + + tdSql.execute( f"insert into {dbname}.ct4 values ( {NOW + int(TIME_STEP * 0.8)}, {null_data} )" ) + tdSql.execute( f"insert into {dbname}.ct4 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 0.8)}, {null_data} )" ) + tdSql.execute( f"insert into {dbname}.ct4 values ( {NOW - self.rows * int(TIME_STEP * 0.39)}, {null_data} )" ) + + tdSql.execute( f"insert into {dbname}.nt1 values ( {NOW + int(TIME_STEP * 1.2)}, {null_data} )" ) + tdSql.execute( f"insert into {dbname}.nt1 values ( {NOW - (self.rows + 1) * int(TIME_STEP * 1.2)}, {null_data} )" ) + tdSql.execute( f"insert into {dbname}.nt1 values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )" ) def run(self): tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - self.__create_tb() + self.__create_tb(dbname=DBNAME) tdLog.printNoPrefix("==========step2:insert data") self.rows = 10 - self.__insert_data(self.rows) + self.__insert_data(dbname=DBNAME) tdLog.printNoPrefix("==========step3:all check") + tdSql.query(f"select count(*) from {DBNAME}.ct1") + tdSql.checkData(0, 0, self.rows) self.all_test() - tdDnodes.stop(1) - tdDnodes.start(1) + tdLog.printNoPrefix("==========step4:cross db check") + dbname1 = "db1" + tdSql.execute(f"create database {dbname1} duration 432000m") + tdSql.execute(f"use {dbname1}") + self.__create_tb(dbname=dbname1) + self.__insert_data(dbname=dbname1) + + tdSql.query("select ct1.c_int from db.ct1 as ct1 join db1.ct1 as cy1 on ct1.ts=cy1.ts") + tdSql.checkRows(self.rows) + tdSql.query("select ct1.c_int from db.stb1 as ct1 join db1.ct1 as cy1 on ct1.ts=cy1.ts") + tdSql.checkRows(self.rows) + tdSql.query("select ct1.c_int from db.nt1 as ct1 join db1.nt1 as cy1 on ct1.ts=cy1.ts") + tdSql.checkRows(self.rows + 3) + tdSql.query("select ct1.c_int from db.stb1 as ct1 join db1.stb1 as cy1 on ct1.ts=cy1.ts") + tdSql.checkRows(self.rows * 3 + 6) + + tdSql.query("select count(*) from db.ct1") + tdSql.checkData(0, 0, self.rows) + tdSql.query("select count(*) from db1.ct1") + tdSql.checkData(0, 0, self.rows) + + self.all_test() + tdSql.query("select count(*) from db.ct1") + tdSql.checkData(0, 0, self.rows) + tdSql.query("select count(*) from db1.ct1") + tdSql.checkData(0, 0, self.rows) + + tdSql.execute(f"flush database {DBNAME}") + tdSql.execute(f"flush database {dbname1}") + # tdDnodes.stop(1) + # tdDnodes.start(1) tdSql.execute("use db") + tdSql.query("select count(*) from db.ct1") + tdSql.checkData(0, 0, self.rows) + tdSql.query("select count(*) from db1.ct1") + tdSql.checkData(0, 0, self.rows) tdLog.printNoPrefix("==========step4:after wal, all check again ") self.all_test() + tdSql.query("select count(*) from db.ct1") + tdSql.checkData(0, 0, self.rows) def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index f6ff4989e7..4f5ed34419 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -20,6 +20,8 @@ NUM_COL = [INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, ] UN_NUM_COL = [BOOL_COL, BINARY_COL, NCHAR_COL, ] TS_TYPE_COL = [TS_COL] +DBNAME = "db" + class TDTestCase: def init(self, conn, logSql): @@ -54,14 +56,14 @@ class TDTestCase: where_condition = self.__where_condition(condition) group_condition = self.__group_condition(condition, having=f"{condition} is not null " ) - tdSql.query(f"select {condition} from {tbname} {where_condition} ") + tdSql.query(f"select {condition} from {DBNAME}.{tbname} {where_condition} ") datas = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] sum_data = sum(filter(None, datas)) - tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} ") + tdSql.query(f"select sum( {condition} ) from {DBNAME}.{tbname} {where_condition} ") tdSql.checkData(0, 0, sum_data) - tdSql.query(f"select {condition} from {tbname} {where_condition} {group_condition} ") - tdSql.query(f"select sum( {condition} ) from {tbname} {where_condition} {group_condition} ") + tdSql.query(f"select {condition} from {DBNAME}.{tbname} {where_condition} {group_condition} ") + tdSql.query(f"select sum( {condition} ) from {DBNAME}.{tbname} {where_condition} {group_condition} ") def __sum_err_check(self,tbanme): sqls = [] @@ -69,19 +71,19 @@ class TDTestCase: for un_num_col in UN_NUM_COL: sqls.extend( ( - f"select sum( {un_num_col} ) from {tbanme} ", - f"select sum(ceil( {un_num_col} )) from {tbanme} ", + f"select sum( {un_num_col} ) from {DBNAME}.{tbanme} ", + f"select sum(ceil( {un_num_col} )) {DBNAME}.from {tbanme} ", ) ) # sqls.extend( f"select sum( {un_num_col} + {un_num_col_2} ) from {tbanme} " for un_num_col_2 in UN_NUM_COL ) - sqls.extend( f"select sum( {num_col} + {ts_col} ) from {tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) + sqls.extend( f"select sum( {num_col} + {ts_col} ) from {DBNAME}.{tbanme} " for num_col in NUM_COL for ts_col in TS_TYPE_COL) sqls.extend( ( - f"select sum() from {tbanme} ", - f"select sum(*) from {tbanme} ", - f"select sum(ccccccc) from {tbanme} ", - f"select sum('test') from {tbanme} ", + f"select sum() from {DBNAME}.{tbanme} ", + f"select sum(*) from {DBNAME}.{tbanme} ", + f"select sum(ccccccc) {DBNAME}.from {tbanme} ", + f"select sum('test') from {DBNAME}.{tbanme} ", ) ) @@ -110,16 +112,15 @@ class TDTestCase: def __create_tb(self): - tdSql.prepare() tdLog.printNoPrefix("==========step1:create table") - create_stb_sql = f'''create table stb1( + create_stb_sql = f'''create table {DBNAME}.stb1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp ) tags (t1 int) ''' - create_ntb_sql = f'''create table t1( + create_ntb_sql = f'''create table {DBNAME}.t1( ts timestamp, {INT_COL} int, {BINT_COL} bigint, {SINT_COL} smallint, {TINT_COL} tinyint, {FLOAT_COL} float, {DOUBLE_COL} double, {BOOL_COL} bool, {BINARY_COL} binary(16), {NCHAR_COL} nchar(32), {TS_COL} timestamp @@ -129,29 +130,29 @@ class TDTestCase: tdSql.execute(create_ntb_sql) for i in range(4): - tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )') + tdSql.execute(f'create table {DBNAME}.ct{i+1} using {DBNAME}.stb1 tags ( {i+1} )') def __insert_data(self, rows): now_time = int(datetime.datetime.timestamp(datetime.datetime.now()) * 1000) for i in range(rows): tdSql.execute( - f"insert into ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {DBNAME}.ct1 values ( { now_time - i * 1000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {DBNAME}.ct4 values ( { now_time - i * 7776000000 }, {i}, {11111 * i}, {111 * i % 32767 }, {11 * i % 127}, {1.11*i}, {1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f"insert into ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" + f"insert into {DBNAME}.ct2 values ( { now_time - i * 7776000000 }, {-i}, {-11111 * i}, {-111 * i % 32767 }, {-11 * i % 127}, {-1.11*i}, {-1100.0011*i}, {i%2}, 'binary{i}', 'nchar{i}', { now_time + 1 * i } )" ) tdSql.execute( - f'''insert into ct1 values + f'''insert into {DBNAME}.ct1 values ( { now_time - rows * 5 }, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', { now_time + 8 } ) ( { now_time + 10000 }, { rows }, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', { now_time + 9 } ) ''' ) tdSql.execute( - f'''insert into ct4 values + f'''insert into {DBNAME}.ct4 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -167,7 +168,7 @@ class TDTestCase: ) tdSql.execute( - f'''insert into ct2 values + f'''insert into {DBNAME}.ct2 values ( { now_time - rows * 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3888000000+ 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time + 7776000000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -183,13 +184,13 @@ class TDTestCase: ) for i in range(rows): - insert_data = f'''insert into t1 values + insert_data = f'''insert into {DBNAME}.t1 values ( { now_time - i * 3600000 }, {i}, {i * 11111}, { i % 32767 }, { i % 127}, { i * 1.11111 }, { i * 1000.1111 }, { i % 2}, "binary_{i}", "nchar_{i}", { now_time - 1000 * i } ) ''' tdSql.execute(insert_data) tdSql.execute( - f'''insert into t1 values + f'''insert into {DBNAME}.t1 values ( { now_time + 10800000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - (( rows // 2 ) * 60 + 30) * 60000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ( { now_time - rows * 3600000 }, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) @@ -218,8 +219,11 @@ class TDTestCase: tdLog.printNoPrefix("==========step3:all check") self.all_test() - tdDnodes.stop(1) - tdDnodes.start(1) + # tdDnodes.stop(1) + # tdDnodes.start(1) + + tdSql.execute("flush database db") + tdSql.execute("use db") diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index dbf85a28da..4588474753 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -32,22 +32,48 @@ python3 ./test.py -f 1-insert/block_wise.py python3 ./test.py -f 1-insert/create_retentions.py python3 ./test.py -f 1-insert/table_param_ttl.py +python3 ./test.py -f 2-query/abs.py +python3 ./test.py -f 2-query/abs.py -R +python3 ./test.py -f 2-query/and_or_for_byte.py +python3 ./test.py -f 2-query/and_or_for_byte.py -R +python3 ./test.py -f 2-query/apercentile.py +python3 ./test.py -f 2-query/apercentile.py -R +python3 ./test.py -f 2-query/arccos.py +python3 ./test.py -f 2-query/arccos.py -R +python3 ./test.py -f 2-query/arcsin.py +python3 ./test.py -f 2-query/arcsin.py -R +python3 ./test.py -f 2-query/arctan.py +python3 ./test.py -f 2-query/arctan.py -R +python3 ./test.py -f 2-query/avg.py +python3 ./test.py -f 2-query/avg.py -R +python3 ./test.py -f 2-query/between.py +python3 ./test.py -f 2-query/between.py -R +python3 ./test.py -f 2-query/bottom.py +python3 ./test.py -f 2-query/bottom.py -R +python3 ./test.py -f 2-query/cast.py +python3 ./test.py -f 2-query/cast.py -R +python3 ./test.py -f 2-query/ceil.py +python3 ./test.py -f 2-query/ceil.py -R +python3 ./test.py -f 2-query/char_length.py +python3 ./test.py -f 2-query/char_length.py -R +python3 ./test.py -f 2-query/check_tsdb.py +python3 ./test.py -f 2-query/check_tsdb.py -R + python3 ./test.py -f 1-insert/update_data.py python3 ./test.py -f 1-insert/delete_data.py python3 ./test.py -f 2-query/db.py -python3 ./test.py -f 2-query/between.py + +python3 ./test.py -f 2-query/db.py python3 ./test.py -f 2-query/distinct.py python3 ./test.py -f 2-query/varchar.py python3 ./test.py -f 2-query/ltrim.py python3 ./test.py -f 2-query/rtrim.py python3 ./test.py -f 2-query/length.py -python3 ./test.py -f 2-query/char_length.py python3 ./test.py -f 2-query/upper.py python3 ./test.py -f 2-query/lower.py python3 ./test.py -f 2-query/join.py python3 ./test.py -f 2-query/join2.py -python3 ./test.py -f 2-query/cast.py python3 ./test.py -f 2-query/substr.py python3 ./test.py -f 2-query/union.py python3 ./test.py -f 2-query/union1.py @@ -55,7 +81,6 @@ python3 ./test.py -f 2-query/concat.py python3 ./test.py -f 2-query/concat2.py python3 ./test.py -f 2-query/concat_ws.py python3 ./test.py -f 2-query/concat_ws2.py -python3 ./test.py -f 2-query/check_tsdb.py python3 ./test.py -f 2-query/spread.py python3 ./test.py -f 2-query/hyperloglog.py python3 ./test.py -f 2-query/explain.py @@ -79,11 +104,7 @@ python3 ./test.py -f 2-query/Timediff.py python3 ./test.py -f 2-query/json_tag.py python3 ./test.py -f 2-query/top.py -python3 ./test.py -f 2-query/bottom.py python3 ./test.py -f 2-query/percentile.py -python3 ./test.py -f 2-query/apercentile.py -python3 ./test.py -f 2-query/abs.py -python3 ./test.py -f 2-query/ceil.py python3 ./test.py -f 2-query/floor.py python3 ./test.py -f 2-query/round.py python3 ./test.py -f 2-query/log.py @@ -92,16 +113,12 @@ python3 ./test.py -f 2-query/sqrt.py python3 ./test.py -f 2-query/sin.py python3 ./test.py -f 2-query/cos.py python3 ./test.py -f 2-query/tan.py -python3 ./test.py -f 2-query/arcsin.py -python3 ./test.py -f 2-query/arccos.py -python3 ./test.py -f 2-query/arctan.py python3 ./test.py -f 2-query/query_cols_tags_and_or.py # python3 ./test.py -f 2-query/nestedQuery.py # TD-15983 subquery output duplicate name column. # Please Xiangyang Guo modify the following script # python3 ./test.py -f 2-query/nestedQuery_str.py -python3 ./test.py -f 2-query/avg.py python3 ./test.py -f 2-query/elapsed.py python3 ./test.py -f 2-query/csum.py python3 ./test.py -f 2-query/mavg.py @@ -124,7 +141,6 @@ python3 ./test.py -f 2-query/distribute_agg_avg.py python3 ./test.py -f 2-query/distribute_agg_stddev.py python3 ./test.py -f 2-query/twa.py python3 ./test.py -f 2-query/irate.py -python3 ./test.py -f 2-query/and_or_for_byte.py python3 ./test.py -f 2-query/count_partition.py python3 ./test.py -f 2-query/function_null.py python3 ./test.py -f 2-query/queryQnode.py @@ -144,7 +160,7 @@ python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py -N 5 # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py # python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 # python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 -# BUG Redict python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 +# BUG Redict python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 # python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertData.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 @@ -201,7 +217,7 @@ python3 ./test.py -f 7-tmq/stbTagFilter-multiCtb.py #------------querPolicy 2----------- -python3 ./test.py -f 2-query/between.py -Q 2 +python3 ./test.py -f 2-query/between.py -Q 2 python3 ./test.py -f 2-query/distinct.py -Q 2 python3 ./test.py -f 2-query/varchar.py -Q 2 python3 ./test.py -f 2-query/ltrim.py -Q 2 @@ -258,7 +274,7 @@ python3 ./test.py -f 2-query/arccos.py -Q 2 python3 ./test.py -f 2-query/arctan.py -Q 2 python3 ./test.py -f 2-query/query_cols_tags_and_or.py -Q 2 -# python3 ./test.py -f 2-query/nestedQuery.py -Q 2 +# python3 ./test.py -f 2-query/nestedQuery.py -Q 2 # python3 ./test.py -f 2-query/nestedQuery_str.py -Q 2 python3 ./test.py -f 2-query/avg.py -Q 2 diff --git a/tests/system-test/test.py b/tests/system-test/test.py index b893f7af64..eccd12aca6 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -22,13 +22,17 @@ import json import platform import socket import threading + +import toml sys.path.append("../pytest") from util.log import * from util.dnodes import * from util.cases import * from util.cluster import * +from util.taosadapter import * import taos +import taosrest def checkRunTimeError(): import win32gui @@ -50,7 +54,7 @@ def checkRunTimeError(): os.system("TASKKILL /F /IM taosd.exe") if __name__ == "__main__": - + fileName = "all" deployPath = "" masterIp = "" @@ -63,11 +67,13 @@ if __name__ == "__main__": dnodeNums = 1 mnodeNums = 0 updateCfgDict = {} + adapter_cfg_dict = {} execCmd = "" queryPolicy = 1 createDnodeNums = 1 - opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:', [ - 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums']) + restful = False + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:RD:', [ + 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums','restful','adaptercfgupdate']) for key, value in opts: if key in ['-h', '--help']: tdLog.printNoPrefix( @@ -87,11 +93,13 @@ if __name__ == "__main__": tdLog.printNoPrefix('-M create mnode numbers in clusters') tdLog.printNoPrefix('-Q set queryPolicy in one dnode') tdLog.printNoPrefix('-C create Dnode Numbers in one cluster') - + tdLog.printNoPrefix('-R restful realization form') + tdLog.printNoPrefix('-D taosadapter update cfg dict ') + sys.exit(0) - if key in ['-r', '--restart']: + if key in ['-r', '--restart']: restart = True if key in ['-f', '--file']: @@ -135,7 +143,7 @@ if __name__ == "__main__": try: execCmd = base64.b64decode(value.encode()).decode() except: - print('updateCfgDict convert fail.') + print('execCmd run fail.') sys.exit(0) if key in ['-N', '--dnodeNums']: @@ -150,8 +158,21 @@ if __name__ == "__main__": if key in ['-C', '--createDnodeNums']: createDnodeNums = value + if key in ['-R', '--restful']: + restful = True + + if key in ['-D', '--adaptercfgupdate']: + try: + adaptercfgupdate = eval(base64.b64decode(value.encode()).decode()) + except: + print('adapter cfg update convert fail.') + sys.exit(0) + if not execCmd == "": - tdDnodes.init(deployPath) + if restful: + tAdapter.init(deployPath) + else: + tdDnodes.init(deployPath) print(execCmd) exec(execCmd) quit() @@ -184,8 +205,33 @@ if __name__ == "__main__": if valgrind: time.sleep(2) + if restful: + toBeKilled = "taosadapter" + + killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + + psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled + processID = subprocess.check_output(psCmd, shell=True) + + while(processID): + os.system(killCmd) + time.sleep(1) + processID = subprocess.check_output(psCmd, shell=True) + + for port in range(6030, 6041): + usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port + processID = subprocess.check_output(usePortPID, shell=True) + + if processID: + killCmd = "kill -TERM %s" % processID + os.system(killCmd) + fuserCmd = "fuser -k -n tcp %d" % port + os.system(fuserCmd) + + tdLog.info('stop taosadapter') + tdLog.info('stop All dnodes') - + if masterIp == "": host = socket.gethostname() else: @@ -213,6 +259,7 @@ if __name__ == "__main__": except Exception as r: print(r) updateCfgDictStr = '' + # adapter_cfg_dict_str = '' if is_test_framework: moduleName = fileName.replace(".py", "").replace(os.sep, ".") uModule = importlib.import_module(moduleName) @@ -221,30 +268,44 @@ if __name__ == "__main__": if ((json.dumps(updateCfgDict) == '{}') and hasattr(ucase, 'updatecfgDict')): updateCfgDict = ucase.updatecfgDict updateCfgDictStr = "-d %s"%base64.b64encode(json.dumps(updateCfgDict).encode()).decode() + if ((json.dumps(adapter_cfg_dict) == '{}') and hasattr(ucase, 'taosadapter_cfg_dict')): + adapter_cfg_dict = ucase.taosadapter_cfg_dict + # adapter_cfg_dict_str = f"-D {base64.b64encode(toml.dumps(adapter_cfg_dict).encode()).decode()}" except Exception as r: print(r) else: pass + if restful: + tAdapter.init(deployPath, masterIp) + tAdapter.stop(force_kill=True) + if dnodeNums == 1 : tdDnodes.deploy(1,updateCfgDict) tdDnodes.start(1) tdCases.logSql(logSql) + if restful: + tAdapter.deploy(adapter_cfg_dict) + tAdapter.start() + if queryPolicy != 1: queryPolicy=int(queryPolicy) - conn = taos.connect( - host, - config=tdDnodes.getSimCfgPath()) - tdSql.init(conn.cursor()) - tdSql.execute("create qnode on dnode 1") - tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy) - tdSql.query("show local variables;") - for i in range(tdSql.queryRows): - if tdSql.queryResult[i][0] == "queryPolicy" : - if int(tdSql.queryResult[i][1]) == int(queryPolicy): - tdLog.success('alter queryPolicy to %d successfully'%queryPolicy) - else : - tdLog.debug(tdSql.queryResult) - tdLog.exit("alter queryPolicy to %d failed"%queryPolicy) + if restful: + conn = taosrest.connect(url=f"http://{host}:6041") + else: + conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + + cursor = conn.cursor() + cursor.execute("create qnode on dnode 1") + cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"') + cursor.execute("show local variables") + res = cursor.fetchall() + for i in range(cursor.rowcount): + if res[i][0] == "queryPolicy" : + if int(res[i][1]) == int(queryPolicy): + tdLog.success(f'alter queryPolicy to {queryPolicy} successfully') + else: + tdLog.debug(res) + tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") else : tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) @@ -258,10 +319,16 @@ if __name__ == "__main__": for dnode in tdDnodes.dnodes: tdDnodes.starttaosd(dnode.index) tdCases.logSql(logSql) - conn = taos.connect( - host, - config=tdDnodes.getSimCfgPath()) - print(tdDnodes.getSimCfgPath(),host) + + if restful: + tAdapter.deploy(adapter_cfg_dict) + tAdapter.start() + + if not restful: + conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + else: + conn = taosrest.connect(url=f"http://{host}:6041") + tdLog.info(tdDnodes.getSimCfgPath(),host) if createDnodeNums == 1: createDnodeNums=dnodeNums else: @@ -275,9 +342,10 @@ if __name__ == "__main__": if ucase is not None and hasattr(ucase, 'noConn') and ucase.noConn == True: conn = None else: - conn = taos.connect( - host="%s"%(host), - config=tdDnodes.sim.getCfgDir()) + if not restful: + conn = taos.connect(host="%s"%(host), config=tdDnodes.sim.getCfgDir()) + else: + conn = taosrest.connect(url=f"http://{host}:6041") if is_test_framework: tdCases.runOneWindows(conn, fileName) else: @@ -302,28 +370,55 @@ if __name__ == "__main__": ucase = uModule.TDTestCase() if (json.dumps(updateCfgDict) == '{}'): updateCfgDict = ucase.updatecfgDict + if (json.dumps(adapter_cfg_dict) == '{}'): + adapter_cfg_dict = ucase.taosadapter_cfg_dict except: pass + + if restful: + tAdapter.init(deployPath, masterIp) + tAdapter.stop(force_kill=True) + if dnodeNums == 1 : tdDnodes.deploy(1,updateCfgDict) tdDnodes.start(1) tdCases.logSql(logSql) + + if restful: + tAdapter.deploy(adapter_cfg_dict) + tAdapter.start() + if queryPolicy != 1: queryPolicy=int(queryPolicy) - conn = taos.connect( - host, - config=tdDnodes.getSimCfgPath()) - tdSql.init(conn.cursor()) - tdSql.execute("create qnode on dnode 1") - tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy) - tdSql.query("show local variables;") - for i in range(tdSql.queryRows): - if tdSql.queryResult[i][0] == "queryPolicy" : - if int(tdSql.queryResult[i][1]) == int(queryPolicy): - tdLog.success('alter queryPolicy to %d successfully'%queryPolicy) - else : - tdLog.debug(tdSql.queryResult) - tdLog.exit("alter queryPolicy to %d failed"%queryPolicy) + if not restful: + conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + else: + conn = taosrest.connect(url=f"http://{host}:6041") + # tdSql.init(conn.cursor()) + # tdSql.execute("create qnode on dnode 1") + # tdSql.execute('alter local "queryPolicy" "%d"'%queryPolicy) + # tdSql.query("show local variables;") + # for i in range(tdSql.queryRows): + # if tdSql.queryResult[i][0] == "queryPolicy" : + # if int(tdSql.queryResult[i][1]) == int(queryPolicy): + # tdLog.success('alter queryPolicy to %d successfully'%queryPolicy) + # else : + # tdLog.debug(tdSql.queryResult) + # tdLog.exit("alter queryPolicy to %d failed"%queryPolicy) + + cursor = conn.cursor() + cursor.execute("create qnode on dnode 1") + cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"') + cursor.execute("show local variables") + res = cursor.fetchall() + for i in range(cursor.rowcount): + if res[i][0] == "queryPolicy" : + if int(res[i][1]) == int(queryPolicy): + tdLog.success(f'alter queryPolicy to {queryPolicy} successfully') + else: + tdLog.debug(res) + tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") + else : tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) @@ -337,9 +432,15 @@ if __name__ == "__main__": for dnode in tdDnodes.dnodes: tdDnodes.starttaosd(dnode.index) tdCases.logSql(logSql) - conn = taos.connect( - host, - config=tdDnodes.getSimCfgPath()) + + if restful: + tAdapter.deploy(adapter_cfg_dict) + tAdapter.start() + + if not restful: + conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + else: + conn = taosrest.connect(url=f"http://{host}:6041") print(tdDnodes.getSimCfgPath(),host) if createDnodeNums == 1: createDnodeNums=dnodeNums @@ -351,8 +452,8 @@ if __name__ == "__main__": print("check dnode ready") except Exception as r: print(r) - - + + if testCluster: tdLog.info("Procedures for testing cluster") if fileName == "all": @@ -361,30 +462,35 @@ if __name__ == "__main__": tdCases.runOneCluster(fileName) else: tdLog.info("Procedures for testing self-deployment") - conn = taos.connect( - host, - config=tdDnodes.getSimCfgPath()) - + if not restful: + conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + else: + conn = taosrest.connect(url=f"http://{host}:6041") + if fileName == "all": tdCases.runAllLinux(conn) else: tdCases.runOneLinux(conn, fileName) - + if restart: if fileName == "all": tdLog.info("not need to query ") - else: + else: sp = fileName.rsplit(".", 1) if len(sp) == 2 and sp[1] == "py": tdDnodes.stopAll() tdDnodes.start(1) - time.sleep(1) - conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) + time.sleep(1) + if not restful: + conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) + else: + conn = taosrest.connect(url=f"http://{host}:6041") tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info("query test after taosd restart") tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py") else: tdLog.info("not need to query") + if conn is not None: conn.close() sys.exit(0)