update
This commit is contained in:
parent
d8659d7a37
commit
ae100c06e3
|
@ -102,8 +102,8 @@ class TDCom:
|
||||||
self.smlChildTableName_value = None
|
self.smlChildTableName_value = None
|
||||||
self.defaultJSONStrType_value = None
|
self.defaultJSONStrType_value = None
|
||||||
self.smlTagNullName_value = None
|
self.smlTagNullName_value = None
|
||||||
self.default_varchar_length = 256
|
self.default_varchar_length = 6
|
||||||
self.default_nchar_length = 256
|
self.default_nchar_length = 6
|
||||||
self.default_varchar_datatype = "letters"
|
self.default_varchar_datatype = "letters"
|
||||||
self.default_nchar_datatype = "letters"
|
self.default_nchar_datatype = "letters"
|
||||||
self.default_tagname_prefix = "t"
|
self.default_tagname_prefix = "t"
|
||||||
|
@ -122,6 +122,7 @@ class TDCom:
|
||||||
self.stb_name = "stb"
|
self.stb_name = "stb"
|
||||||
self.ctb_name = "ctb"
|
self.ctb_name = "ctb"
|
||||||
self.tb_name = "tb"
|
self.tb_name = "tb"
|
||||||
|
self.tbname = str()
|
||||||
self.need_tagts = False
|
self.need_tagts = False
|
||||||
self.tag_type_str = ""
|
self.tag_type_str = ""
|
||||||
self.column_type_str = ""
|
self.column_type_str = ""
|
||||||
|
@ -139,6 +140,38 @@ class TDCom:
|
||||||
self.range_count = 5
|
self.range_count = 5
|
||||||
self.default_interval = 5
|
self.default_interval = 5
|
||||||
self.stream_timeout = 12
|
self.stream_timeout = 12
|
||||||
|
self.record_history_ts = str()
|
||||||
|
self.subtable = True
|
||||||
|
self.partition_tbname_alias = "ptn_alias" if self.subtable else ""
|
||||||
|
self.partition_col_alias = "pcol_alias" if self.subtable else ""
|
||||||
|
self.partition_tag_alias = "ptag_alias" if self.subtable else ""
|
||||||
|
self.partition_expression_alias = "pexp_alias" if self.subtable else ""
|
||||||
|
self.des_table_suffix = "_output"
|
||||||
|
self.stream_suffix = "_stream"
|
||||||
|
self.subtable_prefix = "prefix_" if self.subtable else ""
|
||||||
|
self.subtable_suffix = "_suffix" if self.subtable else ""
|
||||||
|
self.downsampling_function_list = ["min(c1)", "max(c2)", "sum(c3)", "first(c4)", "last(c5)", "apercentile(c6, 50)", "avg(c7)", "count(c8)", "spread(c1)",
|
||||||
|
"stddev(c2)", "hyperloglog(c11)", "timediff(1, 0, 1h)", "timezone()", "to_iso8601(1)", 'to_unixtimestamp("1970-01-01T08:00:00+08:00")', "min(t1)", "max(t2)", "sum(t3)",
|
||||||
|
"first(t4)", "last(t5)", "apercentile(t6, 50)", "avg(t7)", "count(t8)", "spread(t1)", "stddev(t2)", "hyperloglog(t11)"]
|
||||||
|
self.stb_output_select_str = ','.join(list(map(lambda x:f'`{x}`', self.downsampling_function_list)))
|
||||||
|
self.tb_output_select_str = ','.join(list(map(lambda x:f'`{x}`', self.downsampling_function_list[0:15])))
|
||||||
|
self.stb_source_select_str = ','.join(self.downsampling_function_list)
|
||||||
|
self.tb_source_select_str = ','.join(self.downsampling_function_list[0:15])
|
||||||
|
self.fill_function_list = ["min(c1)", "max(c2)", "sum(c3)", "apercentile(c6, 50)", "avg(c7)", "count(c8)", "spread(c1)",
|
||||||
|
"stddev(c2)", "hyperloglog(c11)", "timediff(1, 0, 1h)", "timezone()", "to_iso8601(1)", 'to_unixtimestamp("1970-01-01T08:00:00+08:00")', "min(t1)", "max(t2)", "sum(t3)",
|
||||||
|
"first(t4)", "last(t5)", "apercentile(t6, 50)", "avg(t7)", "count(t8)", "spread(t1)", "stddev(t2)", "hyperloglog(t11)"]
|
||||||
|
self.fill_stb_output_select_str = ','.join(list(map(lambda x:f'`{x}`', self.fill_function_list)))
|
||||||
|
self.fill_stb_source_select_str = ','.join(self.fill_function_list)
|
||||||
|
self.fill_tb_output_select_str = ','.join(list(map(lambda x:f'`{x}`', self.fill_function_list[0:13])))
|
||||||
|
self.fill_tb_source_select_str = ','.join(self.fill_function_list[0:13])
|
||||||
|
self.stream_case_when_tbname = "tbname"
|
||||||
|
|
||||||
|
self.update = True
|
||||||
|
self.disorder = True
|
||||||
|
if self.disorder:
|
||||||
|
self.update = False
|
||||||
|
self.partition_by_downsampling_function_list = ["min(c1)", "max(c2)", "sum(c3)", "first(c4)", "last(c5)", "count(c8)", "spread(c1)",
|
||||||
|
"stddev(c2)", "hyperloglog(c11)", "min(t1)", "max(t2)", "sum(t3)", "first(t4)", "last(t5)", "count(t8)", "spread(t1)", "stddev(t2)"]
|
||||||
# def init(self, conn, logSql):
|
# def init(self, conn, logSql):
|
||||||
# # tdSql.init(conn.cursor(), logSql)
|
# # tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
@ -1148,10 +1181,10 @@ class TDCom:
|
||||||
if dbname is not None:
|
if dbname is not None:
|
||||||
self.dbname = dbname
|
self.dbname = dbname
|
||||||
if tbname is not None:
|
if tbname is not None:
|
||||||
self.tb_name = f'{self.dbname}.{tbname}'
|
self.tbname = f'{self.dbname}.{tbname}'
|
||||||
else:
|
else:
|
||||||
if tbname is not None:
|
if tbname is not None:
|
||||||
self.tb_name = tbname
|
self.tbname = tbname
|
||||||
|
|
||||||
self.sgen_column_value_list(column_ele_list, need_null, ts_value)
|
self.sgen_column_value_list(column_ele_list, need_null, ts_value)
|
||||||
# column_value_str = ", ".join(str(v) for v in self.column_value_list)
|
# column_value_str = ", ".join(str(v) for v in self.column_value_list)
|
||||||
|
@ -1165,7 +1198,7 @@ class TDCom:
|
||||||
column_value_str += f'{column_value}, '
|
column_value_str += f'{column_value}, '
|
||||||
column_value_str = column_value_str.rstrip()[:-1]
|
column_value_str = column_value_str.rstrip()[:-1]
|
||||||
if int(count) <= 1:
|
if int(count) <= 1:
|
||||||
insert_sql = f'insert into {self.tb_name} values ({column_value_str});'
|
insert_sql = f'insert into {self.tbname} values ({column_value_str});'
|
||||||
tdSql.execute(insert_sql)
|
tdSql.execute(insert_sql)
|
||||||
else:
|
else:
|
||||||
for num in range(count):
|
for num in range(count):
|
||||||
|
@ -1180,24 +1213,23 @@ class TDCom:
|
||||||
else:
|
else:
|
||||||
column_value_str += f'{column_value}, '
|
column_value_str += f'{column_value}, '
|
||||||
column_value_str = column_value_str.rstrip()[:-1]
|
column_value_str = column_value_str.rstrip()[:-1]
|
||||||
insert_sql = f'insert into {self.tb_name} values ({column_value_str});'
|
insert_sql = f'insert into {self.tbname} values ({column_value_str});'
|
||||||
print(insert_sql)
|
|
||||||
tdSql.execute(insert_sql)
|
tdSql.execute(insert_sql)
|
||||||
|
|
||||||
def sdelete_rows(self, dbname=None, tbname=None, start_ts=None, end_ts=None, ts_key=None):
|
def sdelete_rows(self, dbname=None, tbname=None, start_ts=None, end_ts=None, ts_key=None):
|
||||||
if dbname is not None:
|
if dbname is not None:
|
||||||
self.dbname = dbname
|
self.dbname = dbname
|
||||||
if tbname is not None:
|
if tbname is not None:
|
||||||
self.tb_name = f'{self.dbname}.{tbname}'
|
self.tbname = f'{self.dbname}.{tbname}'
|
||||||
else:
|
else:
|
||||||
if tbname is not None:
|
if tbname is not None:
|
||||||
self.tb_name = tbname
|
self.tbname = tbname
|
||||||
if ts_key is None:
|
if ts_key is None:
|
||||||
ts_col_name = self.default_colts_name
|
ts_col_name = self.default_colts_name
|
||||||
else:
|
else:
|
||||||
ts_col_name = ts_key
|
ts_col_name = ts_key
|
||||||
|
|
||||||
base_del_sql = f'delete from {self.tb_name} '
|
base_del_sql = f'delete from {self.tbname} '
|
||||||
if end_ts is not None:
|
if end_ts is not None:
|
||||||
if ":" in start_ts and "-" in start_ts:
|
if ":" in start_ts and "-" in start_ts:
|
||||||
start_ts = f"{start_ts}"
|
start_ts = f"{start_ts}"
|
||||||
|
@ -1266,6 +1298,10 @@ class TDCom:
|
||||||
final_list.append(tuple(tmpl))
|
final_list.append(tuple(tmpl))
|
||||||
return final_list
|
return final_list
|
||||||
|
|
||||||
|
def str_ts_trans_bigint(self, str_ts):
|
||||||
|
tdSql.query(f'select cast({str_ts} as bigint)')
|
||||||
|
return tdSql.queryResult[0][0]
|
||||||
|
|
||||||
def cast_query_data(self, query_data):
|
def cast_query_data(self, query_data):
|
||||||
tdLog.info("cast query data ...")
|
tdLog.info("cast query data ...")
|
||||||
col_type_list = self.column_type_str.split(',')
|
col_type_list = self.column_type_str.split(',')
|
||||||
|
@ -1276,8 +1312,8 @@ class TDCom:
|
||||||
query_data_l = list(query_data_t)
|
query_data_l = list(query_data_t)
|
||||||
for i,v in enumerate(query_data_l):
|
for i,v in enumerate(query_data_l):
|
||||||
if v is not None:
|
if v is not None:
|
||||||
if " ".join(col_tag_type_list[i].strip().split(" ")[1:]) == "nchar(256)":
|
if " ".join(col_tag_type_list[i].strip().split(" ")[1:]) == "nchar(6)":
|
||||||
tdSql.query(f'select cast("{v}" as binary(256))')
|
tdSql.query(f'select cast("{v}" as binary(6))')
|
||||||
else:
|
else:
|
||||||
tdSql.query(f'select cast("{v}" as {" ".join(col_tag_type_list[i].strip().split(" ")[1:])})')
|
tdSql.query(f'select cast("{v}" as {" ".join(col_tag_type_list[i].strip().split(" ")[1:])})')
|
||||||
query_data_l[i] = tdSql.queryResult[0][0]
|
query_data_l[i] = tdSql.queryResult[0][0]
|
||||||
|
@ -1404,6 +1440,63 @@ class TDCom:
|
||||||
tdSql.checkNotEqual(res1, res2)
|
tdSql.checkNotEqual(res1, res2)
|
||||||
# tdSql.checkEqual(res1, res2) if not reverse_check else tdSql.checkNotEqual(res1, res2)
|
# tdSql.checkEqual(res1, res2) if not reverse_check else tdSql.checkNotEqual(res1, res2)
|
||||||
|
|
||||||
|
def check_stream_res(self, sql, expected_res, max_delay):
|
||||||
|
tdSql.query(sql)
|
||||||
|
latency = 0
|
||||||
|
|
||||||
|
while tdSql.queryRows != expected_res:
|
||||||
|
tdSql.query(sql)
|
||||||
|
if latency < self.stream_timeout:
|
||||||
|
latency += 0.2
|
||||||
|
time.sleep(0.2)
|
||||||
|
else:
|
||||||
|
if max_delay is not None:
|
||||||
|
if latency == 0:
|
||||||
|
return False
|
||||||
|
tdSql.checkEqual(tdSql.queryRows, expected_res)
|
||||||
|
|
||||||
|
def check_stream(self, sql1, sql2, expected_count, max_delay=None):
|
||||||
|
self.check_stream_res(sql1, expected_count, max_delay)
|
||||||
|
self.check_query_data(sql1, sql2)
|
||||||
|
|
||||||
|
def cal_watermark_window_close_session_endts(self, start_ts, watermark=None, session=None):
|
||||||
|
"""cal endts for close window
|
||||||
|
|
||||||
|
:param start_ts: [start timestamp: self.date_time]
|
||||||
|
:type start_ts: [epoch time]
|
||||||
|
:param watermark: [second level and > session]
|
||||||
|
:type watermark: [s]
|
||||||
|
:param precision: [default "ms" and only support "ms" now]
|
||||||
|
:type precision: str, optional
|
||||||
|
"""
|
||||||
|
if watermark is not None:
|
||||||
|
return start_ts + watermark*self.offset + 1
|
||||||
|
else:
|
||||||
|
return start_ts + session*self.offset + 1
|
||||||
|
|
||||||
|
def cal_watermark_window_close_interval_endts(self, start_ts, interval, watermark=None):
|
||||||
|
"""cal endts for close window
|
||||||
|
|
||||||
|
:param start_ts: [start timestamp: self.date_time]
|
||||||
|
:type start_ts: [epoch time]
|
||||||
|
:param interval: [second level]
|
||||||
|
:type interval: [s]
|
||||||
|
:param watermark: [second level and > interval]
|
||||||
|
:type watermark: [s]
|
||||||
|
:param precision: [default "ms" and only support "ms" now]
|
||||||
|
:type precision: str, optional
|
||||||
|
"""
|
||||||
|
if watermark is not None:
|
||||||
|
return int(start_ts/self.offset)*self.offset + (interval - (int(start_ts/self.offset))%interval)*self.offset + watermark*self.offset
|
||||||
|
else:
|
||||||
|
return int(start_ts/self.offset)*self.offset + (interval - (int(start_ts/self.offset))%interval)*self.offset
|
||||||
|
|
||||||
|
def update_delete_history_data(self, delete):
|
||||||
|
self.sinsert_rows(tbname=self.ctb_name, ts_value=self.record_history_ts)
|
||||||
|
self.sinsert_rows(tbname=self.tb_name, ts_value=self.record_history_ts)
|
||||||
|
if delete:
|
||||||
|
self.sdelete_rows(tbname=self.ctb_name, start_ts=self.time_cast(self.record_history_ts, "-"))
|
||||||
|
self.sdelete_rows(tbname=self.tb_name, start_ts=self.time_cast(self.record_history_ts, "-"))
|
||||||
|
|
||||||
def prepare_data(self, interval=None, watermark=None, session=None, state_window=None, state_window_max=127, interation=3, range_count=None, precision="ms", fill_history_value=0, ext_stb=None):
|
def prepare_data(self, interval=None, watermark=None, session=None, state_window=None, state_window_max=127, interation=3, range_count=None, precision="ms", fill_history_value=0, ext_stb=None):
|
||||||
self.clean_env()
|
self.clean_env()
|
||||||
|
|
|
@ -1,240 +0,0 @@
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
import threading
|
|
||||||
from taos.tmq import Consumer
|
|
||||||
from util.log import *
|
|
||||||
from util.sql import *
|
|
||||||
from util.cases import *
|
|
||||||
from util.dnodes import *
|
|
||||||
from util.common import *
|
|
||||||
|
|
||||||
class TDTestCase:
|
|
||||||
updatecfgDict = {'debugFlag': 135, 'asynclog': 0}
|
|
||||||
def init(self, conn, logSql, replicaVar=1):
|
|
||||||
self.replicaVar = int(replicaVar)
|
|
||||||
tdLog.debug("start to execute %s" % __file__)
|
|
||||||
tdSql.init(conn.cursor(), logSql)
|
|
||||||
self.tdCom = tdCom
|
|
||||||
self.subtable = True
|
|
||||||
self.partition_tbname_alias = "ptn_alias" if self.subtable else ""
|
|
||||||
self.partition_col_alias = "pcol_alias" if self.subtable else ""
|
|
||||||
self.partition_tag_alias = "ptag_alias" if self.subtable else ""
|
|
||||||
self.partition_expression_alias = "pexp_alias" if self.subtable else ""
|
|
||||||
self.stb_name = str()
|
|
||||||
self.ctb_name = str()
|
|
||||||
self.tb_name = str()
|
|
||||||
self.des_table_suffix = "_output"
|
|
||||||
self.stream_suffix = "_stream"
|
|
||||||
self.subtable_prefix = "prefix_" if self.subtable else ""
|
|
||||||
self.subtable_suffix = "_suffix" if self.subtable else ""
|
|
||||||
self.stb_stream_des_table = str()
|
|
||||||
self.ctb_stream_des_table = str()
|
|
||||||
self.tb_stream_des_table = str()
|
|
||||||
self.downsampling_function_list = ["min(c1)", "max(c2)", "sum(c3)", "first(c4)", "last(c5)", "apercentile(c6, 50)", "avg(c7)", "count(c8)", "spread(c1)",
|
|
||||||
"stddev(c2)", "hyperloglog(c11)", "timediff(1, 0, 1h)", "timezone()", "to_iso8601(1)", 'to_unixtimestamp("1970-01-01T08:00:00+08:00")', "min(t1)", "max(t2)", "sum(t3)",
|
|
||||||
"first(t4)", "last(t5)", "apercentile(t6, 50)", "avg(t7)", "count(t8)", "spread(t1)", "stddev(t2)", "hyperloglog(t11)"]
|
|
||||||
self.stb_output_select_str = ','.join(list(map(lambda x:f'`{x}`', self.downsampling_function_list)))
|
|
||||||
self.stb_source_select_str = ','.join(self.downsampling_function_list)
|
|
||||||
self.tb_source_select_str = ','.join(self.downsampling_function_list[0:15])
|
|
||||||
|
|
||||||
def at_once_interval(self, interval, partition="tbname", delete=False, fill_value=None, fill_history_value=None, case_when=None):
|
|
||||||
tdLog.info(f"testing stream at_once+interval: interval: {interval}, partition: {partition}, fill_history: {fill_history_value}")
|
|
||||||
self.delete = delete
|
|
||||||
self.tdCom.case_name = sys._getframe().f_code.co_name
|
|
||||||
self.tdCom.prepare_data(interval=interval, fill_history_value=fill_history_value)
|
|
||||||
self.stb_name = self.tdCom.stb_name.replace(f"{self.tdCom.dbname}.", "")
|
|
||||||
self.ctb_name = self.tdCom.ctb_name.replace(f"{self.tdCom.dbname}.", "")
|
|
||||||
self.tb_name = self.tdCom.tb_name.replace(f"{self.tdCom.dbname}.", "")
|
|
||||||
self.stb_stream_des_table = f'{self.stb_name}{self.des_table_suffix}'
|
|
||||||
self.ctb_stream_des_table = f'{self.ctb_name}{self.des_table_suffix}'
|
|
||||||
self.tb_stream_des_table = f'{self.tb_name}{self.des_table_suffix}'
|
|
||||||
self.tb_output_select_str = ','.join(list(map(lambda x:f'`{x}`', self.downsampling_function_list[0:15])))
|
|
||||||
|
|
||||||
if partition == "tbname":
|
|
||||||
if case_when:
|
|
||||||
stream_case_when_partition = case_when
|
|
||||||
else:
|
|
||||||
stream_case_when_partition = self.partition_tbname_alias
|
|
||||||
|
|
||||||
partition_elm_alias = self.partition_tbname_alias
|
|
||||||
elif partition == "c1":
|
|
||||||
if case_when:
|
|
||||||
stream_case_when_partition = case_when
|
|
||||||
else:
|
|
||||||
stream_case_when_partition = self.partition_col_alias
|
|
||||||
partition_elm_alias = self.partition_col_alias
|
|
||||||
elif partition == "abs(c1)":
|
|
||||||
partition_elm_alias = self.partition_expression_alias
|
|
||||||
elif partition is None:
|
|
||||||
partition_elm_alias = '"no_partition"'
|
|
||||||
else:
|
|
||||||
partition_elm_alias = self.partition_tag_alias
|
|
||||||
if partition == "tbname" or partition is None:
|
|
||||||
if case_when:
|
|
||||||
stb_subtable_value = f'concat(concat("{self.stb_name}_{self.subtable_prefix}", {stream_case_when_partition}), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
ctb_subtable_value = f'concat(concat("{self.ctb_name}_{self.subtable_prefix}", {stream_case_when_partition}), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
tb_subtable_value = f'concat(concat("{self.tb_name}_{self.subtable_prefix}", {stream_case_when_partition}), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
else:
|
|
||||||
stb_subtable_value = f'concat(concat("{self.stb_name}_{self.subtable_prefix}", {partition_elm_alias}), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
ctb_subtable_value = f'concat(concat("{self.ctb_name}_{self.subtable_prefix}", {partition_elm_alias}), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
tb_subtable_value = f'concat(concat("{self.tb_name}_{self.subtable_prefix}", {partition_elm_alias}), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
else:
|
|
||||||
stb_subtable_value = f'concat(concat("{self.stb_name}_{self.subtable_prefix}", cast(cast(abs(cast({partition_elm_alias} as int)) as bigint) as varchar(100))), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
ctb_subtable_value = f'concat(concat("{self.ctb_name}_{self.subtable_prefix}", cast(cast(abs(cast({partition_elm_alias} as int)) as bigint) as varchar(100))), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
tb_subtable_value = f'concat(concat("{self.tb_name}_{self.subtable_prefix}", cast(cast(abs(cast({partition_elm_alias} as int)) as bigint) as varchar(100))), "{self.subtable_suffix}")' if self.subtable else None
|
|
||||||
if partition:
|
|
||||||
partition_elm = f'partition by {partition} {partition_elm_alias}'
|
|
||||||
else:
|
|
||||||
partition_elm = ""
|
|
||||||
if fill_value:
|
|
||||||
if "value" in fill_value.lower():
|
|
||||||
fill_value='VALUE,1,2,3,4,5,6,7,8,9,10,11,1,2,3,4,5,6,7,8,9,10,11'
|
|
||||||
self.tdCom.create_stream(stream_name=f'{self.stb_name}{self.stream_suffix}', des_table=self.stb_stream_des_table, source_sql=f'select _wstart AS wstart, {self.stb_source_select_str} from {self.stb_name} {partition_elm} interval({self.tdCom.dataDict["interval"]}s)', trigger_mode="at_once", subtable_value=stb_subtable_value, fill_value=fill_value, fill_history_value=fill_history_value)
|
|
||||||
self.tdCom.create_stream(stream_name=f'{self.ctb_name}{self.stream_suffix}', des_table=self.ctb_stream_des_table, source_sql=f'select _wstart AS wstart, {self.stb_source_select_str} from {self.ctb_name} {partition_elm} interval({self.tdCom.dataDict["interval"]}s)', trigger_mode="at_once", subtable_value=ctb_subtable_value, fill_value=fill_value, fill_history_value=fill_history_value)
|
|
||||||
if fill_value:
|
|
||||||
if "value" in fill_value.lower():
|
|
||||||
fill_value='VALUE,1,2,3,4,5,6,7,8,9,10,11'
|
|
||||||
self.tdCom.create_stream(stream_name=f'{self.tb_name}{self.stream_suffix}', des_table=self.tb_stream_des_table, source_sql=f'select _wstart AS wstart, {self.tb_source_select_str} from {self.tb_name} {partition_elm} interval({self.tdCom.dataDict["interval"]}s)', trigger_mode="at_once", subtable_value=tb_subtable_value, fill_value=fill_value, fill_history_value=fill_history_value)
|
|
||||||
start_time = self.tdCom.date_time
|
|
||||||
for i in range(self.tdCom.range_count):
|
|
||||||
ts_value = str(self.tdCom.date_time+self.tdCom.dataDict["interval"])+f'+{i*10}s'
|
|
||||||
ts_cast_delete_value = self.tdCom.time_cast(ts_value)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tdCom.ctb_name, ts_value=ts_value)
|
|
||||||
if i%2 == 0:
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tdCom.ctb_name, ts_value=ts_value)
|
|
||||||
if self.delete and i%2 != 0:
|
|
||||||
self.tdCom.sdelete_rows(tbname=self.tdCom.ctb_name, start_ts=ts_cast_delete_value)
|
|
||||||
self.tdCom.date_time += 1
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tdCom.tb_name, ts_value=ts_value)
|
|
||||||
if i%2 == 0:
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tdCom.tb_name, ts_value=ts_value)
|
|
||||||
if self.delete and i%2 != 0:
|
|
||||||
self.tdCom.sdelete_rows(tbname=self.tdCom.tb_name, start_ts=ts_cast_delete_value)
|
|
||||||
self.tdCom.date_time += 1
|
|
||||||
if partition:
|
|
||||||
partition_elm = f'partition by {partition}'
|
|
||||||
else:
|
|
||||||
partition_elm = ""
|
|
||||||
|
|
||||||
if not fill_value:
|
|
||||||
for tbname in [self.stb_name, self.ctb_name, self.tb_name]:
|
|
||||||
if tbname != self.tb_name:
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.stb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart', f'select _wstart AS wstart, {self.stb_source_select_str} from {tbname} {partition_elm} interval({self.tdCom.dataDict["interval"]}s) order by wstart', sorted=True)
|
|
||||||
else:
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.tb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart', f'select _wstart AS wstart, {self.tb_source_select_str} from {tbname} {partition_elm} interval({self.tdCom.dataDict["interval"]}s) order by wstart', sorted=True)
|
|
||||||
|
|
||||||
if self.subtable:
|
|
||||||
for tname in [self.stb_name, self.ctb_name]:
|
|
||||||
tdSql.query(f'select * from {self.ctb_name}')
|
|
||||||
ptn_counter = 0
|
|
||||||
for c1_value in tdSql.queryResult:
|
|
||||||
if partition == "c1":
|
|
||||||
tdSql.query(f'select count(*) from `{tname}_{self.subtable_prefix}{abs(c1_value[1])}{self.subtable_suffix}`;')
|
|
||||||
elif partition is None:
|
|
||||||
tdSql.query(f'select count(*) from `{tname}_{self.subtable_prefix}no_partition{self.subtable_suffix}`;')
|
|
||||||
elif partition == "abs(c1)":
|
|
||||||
abs_c1_value = abs(c1_value[1])
|
|
||||||
tdSql.query(f'select count(*) from `{tname}_{self.subtable_prefix}{abs_c1_value}{self.subtable_suffix}`;')
|
|
||||||
elif partition == "tbname" and ptn_counter == 0:
|
|
||||||
tdSql.query(f'select count(*) from `{tname}_{self.subtable_prefix}{self.ctb_name}{self.subtable_suffix}`;')
|
|
||||||
ptn_counter += 1
|
|
||||||
tdSql.checkEqual(tdSql.queryResult[0][0] > 0, True)
|
|
||||||
|
|
||||||
tdSql.query(f'select * from {self.tb_name}')
|
|
||||||
ptn_counter = 0
|
|
||||||
for c1_value in tdSql.queryResult:
|
|
||||||
if partition == "c1":
|
|
||||||
tdSql.query(f'select count(*) from `{self.tb_name}_{self.subtable_prefix}{abs(c1_value[1])}{self.subtable_suffix}`;')
|
|
||||||
elif partition is None:
|
|
||||||
tdSql.query(f'select count(*) from `{self.tb_name}_{self.subtable_prefix}no_partition{self.subtable_suffix}`;')
|
|
||||||
elif partition == "abs(c1)":
|
|
||||||
abs_c1_value = abs(c1_value[1])
|
|
||||||
tdSql.query(f'select count(*) from `{self.tb_name}_{self.subtable_prefix}{abs_c1_value}{self.subtable_suffix}`;')
|
|
||||||
elif partition == "tbname" and ptn_counter == 0:
|
|
||||||
tdSql.query(f'select count(*) from `{self.tb_name}_{self.subtable_prefix}{self.tb_name}{self.subtable_suffix}`;')
|
|
||||||
ptn_counter += 1
|
|
||||||
|
|
||||||
tdSql.checkEqual(tdSql.queryResult[0][0] > 0, True)
|
|
||||||
if fill_value:
|
|
||||||
end_date_time = self.tdCom.date_time
|
|
||||||
final_range_count = self.tdCom.range_count
|
|
||||||
history_ts = str(start_time)+f'-{self.tdCom.dataDict["interval"]*(final_range_count+2)}s'
|
|
||||||
start_ts = self.tdCom.time_cast(history_ts, "-")
|
|
||||||
future_ts = str(end_date_time)+f'+{self.tdCom.dataDict["interval"]*(final_range_count+2)}s'
|
|
||||||
end_ts = self.tdCom.time_cast(future_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.ctb_name, ts_value=history_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tb_name, ts_value=history_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.ctb_name, ts_value=future_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tb_name, ts_value=future_ts)
|
|
||||||
self.tdCom.date_time = start_time
|
|
||||||
# update
|
|
||||||
history_ts = str(start_time)+f'-{self.tdCom.dataDict["interval"]*(final_range_count+2)}s'
|
|
||||||
start_ts = self.tdCom.time_cast(history_ts, "-")
|
|
||||||
future_ts = str(end_date_time)+f'+{self.tdCom.dataDict["interval"]*(final_range_count+2)}s'
|
|
||||||
end_ts = self.tdCom.time_cast(future_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.ctb_name, ts_value=history_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tb_name, ts_value=history_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.ctb_name, ts_value=future_ts)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tb_name, ts_value=future_ts)
|
|
||||||
self.tdCom.date_time = start_time
|
|
||||||
for i in range(self.tdCom.range_count):
|
|
||||||
ts_value = str(self.tdCom.date_time+self.tdCom.dataDict["interval"])+f'+{i*10}s'
|
|
||||||
ts_cast_delete_value = self.tdCom.time_cast(ts_value)
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.ctb_name, ts_value=ts_value)
|
|
||||||
self.tdCom.date_time += 1
|
|
||||||
self.tdCom.sinsert_rows(tbname=self.tb_name, ts_value=ts_value)
|
|
||||||
self.tdCom.date_time += 1
|
|
||||||
if self.delete:
|
|
||||||
self.tdCom.sdelete_rows(tbname=self.ctb_name, start_ts=self.tdCom.time_cast(start_time), end_ts=ts_cast_delete_value)
|
|
||||||
self.tdCom.sdelete_rows(tbname=self.tb_name, start_ts=self.tdCom.time_cast(start_time), end_ts=ts_cast_delete_value)
|
|
||||||
for tbname in [self.stb_name, self.ctb_name, self.tb_name]:
|
|
||||||
if tbname != self.tb_name:
|
|
||||||
if "value" in fill_value.lower():
|
|
||||||
fill_value='VALUE,1,2,3,6,7,8,9,10,11,1,2,3,4,5,6,7,8,9,10,11'
|
|
||||||
if partition == "tbname":
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_stb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart', f'select _wstart AS wstart, {self.fill_stb_source_select_str} from {tbname} where ts >= {start_ts} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart', fill_value=fill_value)
|
|
||||||
else:
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_stb_output_select_str} from {tbname}{self.des_table_suffix} where `min(c1)` is not Null order by wstart,`min(c1)`', f'select * from (select _wstart AS wstart, {self.fill_stb_source_select_str} from {tbname} where ts >= {start_ts} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart) where `min(c1)` is not Null order by wstart,`min(c1)`', fill_value=fill_value)
|
|
||||||
else:
|
|
||||||
if "value" in fill_value.lower():
|
|
||||||
fill_value='VALUE,1,2,3,6,7,8,9,10,11'
|
|
||||||
if partition == "tbname":
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_tb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart', f'select _wstart AS wstart, {self.fill_tb_source_select_str} from {tbname} where ts >= {start_ts} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart', fill_value=fill_value)
|
|
||||||
else:
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_tb_output_select_str} from {tbname}{self.des_table_suffix} where `min(c1)` is not Null order by wstart,`min(c1)`', f'select * from (select _wstart AS wstart, {self.fill_tb_source_select_str} from {tbname} where ts >= {start_ts} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart) where `min(c1)` is not Null order by wstart,`min(c1)`', fill_value=fill_value)
|
|
||||||
|
|
||||||
if self.delete:
|
|
||||||
self.tdCom.sdelete_rows(tbname=self.ctb_name, start_ts=start_ts, end_ts=ts_cast_delete_value)
|
|
||||||
self.tdCom.sdelete_rows(tbname=self.tb_name, start_ts=start_ts, end_ts=ts_cast_delete_value)
|
|
||||||
for tbname in [self.stb_name, self.ctb_name, self.tb_name]:
|
|
||||||
if tbname != self.tb_name:
|
|
||||||
if "value" in fill_value.lower():
|
|
||||||
fill_value='VALUE,1,2,3,6,7,8,9,10,11,1,2,3,4,5,6,7,8,9,10,11'
|
|
||||||
if partition == "tbname":
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_stb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart', f'select _wstart AS wstart, {self.fill_stb_source_select_str} from {tbname} where ts >= {start_ts.replace("-", "+")} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart', fill_value=fill_value)
|
|
||||||
else:
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_stb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart,`min(c1)`', f'select * from (select _wstart AS wstart, {self.fill_stb_source_select_str} from {tbname} where ts >= {start_ts} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart) where `min(c1)` is not Null order by wstart,`min(c1)`', fill_value=fill_value)
|
|
||||||
|
|
||||||
else:
|
|
||||||
if "value" in fill_value.lower():
|
|
||||||
fill_value='VALUE,1,2,3,6,7,8,9,10,11'
|
|
||||||
if partition == "tbname":
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_tb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart', f'select _wstart AS wstart, {self.fill_tb_source_select_str} from {tbname} where ts >= {start_ts.replace("-", "+")} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart', fill_value=fill_value)
|
|
||||||
else:
|
|
||||||
self.tdCom.check_query_data(f'select wstart, {self.fill_tb_output_select_str} from {tbname}{self.des_table_suffix} order by wstart,`min(c1)`', f'select * from (select _wstart AS wstart, {self.fill_tb_source_select_str} from {tbname} where ts >= {start_ts} and ts <= {end_ts} partition by {partition} interval({self.tdCom.dataDict["interval"]}s) fill ({fill_value}) order by wstart) where `min(c1)` is not Null order by wstart,`min(c1)`', fill_value=fill_value)
|
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
self.at_once_interval(interval=random.randint(10, 15), partition="tbname", delete=True)
|
|
||||||
self.at_once_interval(interval=random.randint(10, 15), partition="c1", delete=True)
|
|
||||||
self.at_once_interval(interval=random.randint(10, 15), partition="abs(c1)", delete=True)
|
|
||||||
self.at_once_interval(interval=random.randint(10, 15), partition=None, delete=True)
|
|
||||||
|
|
||||||
def stop(self):
|
|
||||||
tdSql.close()
|
|
||||||
tdLog.success(f"{__file__} successfully executed")
|
|
||||||
|
|
||||||
event = threading.Event()
|
|
||||||
|
|
||||||
tdCases.addLinux(__file__, TDTestCase())
|
|
||||||
tdCases.addWindows(__file__, TDTestCase())
|
|
Loading…
Reference in New Issue