fix case
This commit is contained in:
parent
57de6806ce
commit
50b612082f
|
@ -51,12 +51,28 @@ class DataSet:
|
|||
binary_data : List[str] = None
|
||||
nchar_data : List[str] = None
|
||||
|
||||
def __post_init__(self):
|
||||
self.ts_data = []
|
||||
self.int_data = []
|
||||
self.bint_data = []
|
||||
self.sint_data = []
|
||||
self.tint_data = []
|
||||
self.int_un_data = []
|
||||
self.bint_un_data = []
|
||||
self.sint_un_data = []
|
||||
self.tint_un_data = []
|
||||
self.float_data = []
|
||||
self.double_data = []
|
||||
self.bool_data = []
|
||||
self.binary_data = []
|
||||
self.nchar_data = []
|
||||
|
||||
|
||||
class TDTestCase:
|
||||
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
tdSql.init(conn.cursor(), False)
|
||||
|
||||
@property
|
||||
def create_databases_sql_err(self):
|
||||
|
@ -87,28 +103,28 @@ class TDTestCase:
|
|||
@property
|
||||
def create_stable_sql_err(self):
|
||||
return [
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(ceil) watermark 1s maxdelay 1m",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(ceil) watermark 1s max_delay 1m",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(count) watermark 1min",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay -1s",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay -1s",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark -1m",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) maxdelay 1m ",
|
||||
# f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 1m ",
|
||||
# f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) max_delay 1m ",
|
||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} binary(16)) tags (tag1 int) rollup(avg) watermark 1s",
|
||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) rollup(avg) maxdelay 1m",
|
||||
# f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) rollup(avg) watermark 1s maxdelay 1s",
|
||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) rollup(avg) max_delay 1m",
|
||||
# f"create table ntb_1 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) rollup(avg) watermark 1s max_delay 1s",
|
||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) tags (tag1 int) " ,
|
||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) " ,
|
||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) " ,
|
||||
# f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int, {BINARY_COL} nchar(16)) " ,
|
||||
|
||||
# watermark, maxdelay: [0, 900000], [ms, s, m, ?]
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 1u",
|
||||
# watermark, max_delay: [0, 900000], [ms, s, m, ?]
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1u",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 1b",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 900001ms",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 16m",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 901s",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 1h",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) maxdelay 0.2h",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 16m",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 901s",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 1h",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) max_delay 0.2h",
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 0.002d",
|
||||
|
||||
]
|
||||
|
@ -117,11 +133,11 @@ class TDTestCase:
|
|||
def create_stable_sql_current(self):
|
||||
return [
|
||||
f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(avg)",
|
||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 5s maxdelay 1m",
|
||||
f"create stable stb3 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(max) watermark 5s maxdelay 1m",
|
||||
f"create stable stb4 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(sum) watermark 5s maxdelay 1m",
|
||||
# f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s maxdelay 1m",
|
||||
# f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s maxdelay 1m",
|
||||
f"create stable stb2 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(min) watermark 5s max_delay 1m",
|
||||
f"create stable stb3 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(max) watermark 5s max_delay 1m",
|
||||
f"create stable stb4 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(sum) watermark 5s max_delay 1m",
|
||||
# f"create stable stb5 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(last) watermark 5s max_delay 1m",
|
||||
# f"create stable stb6 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m",
|
||||
]
|
||||
|
||||
def test_create_stb(self):
|
||||
|
@ -135,7 +151,7 @@ class TDTestCase:
|
|||
tdSql.checkRows(len(self.create_stable_sql_current))
|
||||
|
||||
# tdSql.execute("use db") # because db is a noraml database, not a rollup database, should not be able to create a rollup database
|
||||
# tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) file_factor 5.0")
|
||||
# tdSql.error(f"create stable nor_db_rollup_stb ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) watermark 5s max_delay 1m")
|
||||
|
||||
|
||||
def test_create_databases(self):
|
||||
|
@ -177,21 +193,6 @@ class TDTestCase:
|
|||
|
||||
def __data_set(self, rows):
|
||||
data_set = DataSet()
|
||||
# neg_data_set = DataSet()
|
||||
data_set.ts_data = []
|
||||
data_set.int_data = []
|
||||
data_set.bint_data = []
|
||||
data_set.sint_data = []
|
||||
data_set.tint_data = []
|
||||
data_set.int_un_data = []
|
||||
data_set.bint_un_data = []
|
||||
data_set.sint_un_data = []
|
||||
data_set.tint_un_data = []
|
||||
data_set.float_data = []
|
||||
data_set.double_data = []
|
||||
data_set.bool_data = []
|
||||
data_set.binary_data = []
|
||||
data_set.nchar_data = []
|
||||
|
||||
for i in range(rows):
|
||||
data_set.ts_data.append(NOW + 1 * (rows - i))
|
||||
|
@ -226,6 +227,7 @@ class TDTestCase:
|
|||
return data_set
|
||||
|
||||
def __insert_data(self):
|
||||
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)
|
||||
|
@ -264,10 +266,10 @@ class TDTestCase:
|
|||
|
||||
def run(self):
|
||||
self.rows = 10
|
||||
|
||||
tdSql.prepare()
|
||||
|
||||
tdLog.printNoPrefix("==========step0:all check")
|
||||
# self.all_test()
|
||||
self.all_test()
|
||||
|
||||
tdLog.printNoPrefix("==========step1:create table in normal database")
|
||||
tdSql.prepare()
|
||||
|
|
|
@ -7,6 +7,7 @@ from util.sql import *
|
|||
from util.cases import *
|
||||
from util.dnodes import *
|
||||
from util.constant import *
|
||||
from ...pytest.util.sql import *
|
||||
|
||||
PRIMARY_COL = "ts"
|
||||
|
||||
|
@ -25,8 +26,6 @@ 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, ]
|
||||
CHAR_COL = [BINARY_COL, NCHAR_COL, ]
|
||||
BOOLEAN_COL = [BOOL_COL, ]
|
||||
|
@ -36,6 +35,12 @@ TS_TYPE_COL = [TS_COL, ]
|
|||
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:
|
||||
|
@ -78,14 +83,15 @@ class SMAschema:
|
|||
index_flag : str = "SMA INDEX"
|
||||
operator : str = "ON"
|
||||
tbname : str = None
|
||||
watermark : str = None
|
||||
maxdelay : str = None
|
||||
watermark : str = "5s"
|
||||
max_delay : str = "6m"
|
||||
func : Tuple[str] = None
|
||||
interval : Tuple[str] = None
|
||||
sliding : str = None
|
||||
interval : Tuple[str] = ("6m", "10s")
|
||||
sliding : str = "6m"
|
||||
other : Any = None
|
||||
drop : str = "DROP"
|
||||
drop_flag : str = "INDEX"
|
||||
querySmaOptimize : int = 1
|
||||
|
||||
def __post_init__(self):
|
||||
if isinstance(self.other, dict):
|
||||
|
@ -111,8 +117,8 @@ class SMAschema:
|
|||
self.watermark = v
|
||||
del self.other[k]
|
||||
|
||||
if k.lower() == "maxdelay" and isinstance(v, str) and not self.maxdelay:
|
||||
self.maxdelay = v
|
||||
if k.lower() == "max_delay" and isinstance(v, str) and not self.max_delay:
|
||||
self.max_delay = v
|
||||
del self.other[k]
|
||||
|
||||
if k.lower() == "functions" and isinstance(v, tuple) and not self.func:
|
||||
|
@ -133,6 +139,7 @@ class SMAschema:
|
|||
|
||||
|
||||
class TDTestCase:
|
||||
updatecfgDict = {"querySmaOptimize": 1}
|
||||
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
|
@ -160,8 +167,8 @@ class TDTestCase:
|
|||
sql += f" sliding({sma.sliding})"
|
||||
if sma.watermark:
|
||||
sql += f" watermark {sma.watermark}"
|
||||
if sma.maxdelay:
|
||||
sql += f" maxdelay {sma.maxdelay}"
|
||||
if sma.max_delay:
|
||||
sql += f" max_delay {sma.max_delay}"
|
||||
if isinstance(sma.other, dict):
|
||||
for k,v in sma.other.items():
|
||||
if isinstance(v,tuple) or isinstance(v, list):
|
||||
|
@ -171,26 +178,36 @@ class TDTestCase:
|
|||
if isinstance(sma.other, tuple) or isinstance(sma.other, list):
|
||||
sql += " ".join(sma.other)
|
||||
if isinstance(sma.other, int) or isinstance(sma.other, float) or isinstance(sma.other, str):
|
||||
sql += sma.other
|
||||
sql += f" {sma.other}"
|
||||
|
||||
return sql
|
||||
|
||||
def __check_sma_func(self, func:tuple):
|
||||
sma_func_support = ["min", "max","avg"]
|
||||
if not isinstance(func, str) or not isinstance(func, tuple) or not isinstance(func, list):
|
||||
return False
|
||||
if isinstance(func, str) :
|
||||
if func.split("(")[0] not in sma_func_support:
|
||||
return False
|
||||
|
||||
|
||||
def sma_create_check(self, sma:SMAschema):
|
||||
if self.updatecfgDict["querySmaOptimize"] == 0:
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
tdSql.query("show stables")
|
||||
stb_in_list = False
|
||||
for row in tdSql.queryResult:
|
||||
if sma.tbname == row[0]:
|
||||
stb_in_list = True
|
||||
break
|
||||
if not stb_in_list:
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
if not sma.creation:
|
||||
if not sma.creation or not isinstance(sma.creation, str) or sma.creation.upper() != "CREATE":
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
if not sma.index_flag:
|
||||
if not sma.index_flag or not isinstance(sma.index_flag, str) or sma.index_flag.upper() != "SMA INDEX" :
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
if not sma.index_name:
|
||||
if not sma.index_name or not isinstance(sma.index_name, str):
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
if not sma.operator:
|
||||
if not sma.operator or not isinstance(sma.operator, str) or sma.operator.upper() != "ON":
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
if not sma.tbname:
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
|
@ -203,13 +220,36 @@ class TDTestCase:
|
|||
if sma.other:
|
||||
tdSql.error(self.__create_sma_index(sma))
|
||||
|
||||
@property
|
||||
def __create_sma_sql(self):
|
||||
err_sqls = []
|
||||
cur_sqls = []
|
||||
# err_set
|
||||
# case 1: required fields check
|
||||
err_sqls.append( SMAschema(creation="", tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
err_sqls.append( SMAschema(index_name="",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
err_sqls.append( SMAschema(index_flag="",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
err_sqls.append( SMAschema(operator="",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
err_sqls.append( SMAschema(tbname="", func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
err_sqls.append( SMAschema(func="",tbname=STBNAME ) )
|
||||
err_sqls.append( SMAschema(interval="",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
err_sqls.append( SMAschema(sliding="",tbname=STBNAME, func=(f"min({INT_COL})",f"max({INT_COL})") ) )
|
||||
|
||||
return err_sqls, cur_sqls
|
||||
|
||||
def test_create_sma(self):
|
||||
err_sqls , cur_sqls = self.__create_sma_sql
|
||||
for err_sql in err_sqls:
|
||||
self.sma_create_check(err_sql)
|
||||
|
||||
def all_test(self):
|
||||
self.test_create_sma()
|
||||
|
||||
pass
|
||||
|
||||
def __create_tb(self):
|
||||
tdLog.printNoPrefix("==========step: create table")
|
||||
create_stb_sql = f'''create table stb1(
|
||||
create_stb_sql = f'''create table {STBNAME}(
|
||||
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,
|
||||
|
@ -217,7 +257,7 @@ class TDTestCase:
|
|||
{INT_UN_COL} int unsigned, {BINT_UN_COL} bigint unsigned
|
||||
) tags (tag1 int)
|
||||
'''
|
||||
create_ntb_sql = f'''create table t1(
|
||||
create_ntb_sql = f'''create table {NTBNAME}(
|
||||
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,
|
||||
|
@ -253,6 +293,7 @@ class TDTestCase:
|
|||
return data_set
|
||||
|
||||
def __insert_data(self):
|
||||
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)
|
||||
|
@ -278,7 +319,7 @@ class TDTestCase:
|
|||
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} )")
|
||||
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} )")
|
||||
|
@ -295,28 +336,23 @@ class TDTestCase:
|
|||
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} )")
|
||||
f"insert into {NTBNAME} 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} )")
|
||||
f"insert into {NTBNAME} 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} )")
|
||||
f"insert into {NTBNAME} values ( {NOW - self.rows * int(TIME_STEP * 0.59)}, {null_data} )")
|
||||
|
||||
def run(self):
|
||||
sma1 = SMAschema(func=("min(c1)","max(c2)"))
|
||||
sql1 = self.__create_sma_index(sma1)
|
||||
print("================")
|
||||
print(sql1)
|
||||
# a = DataSet()
|
||||
# return
|
||||
self.rows = 10
|
||||
|
||||
tdLog.printNoPrefix("==========step0:all check")
|
||||
# self.all_test()
|
||||
|
||||
tdLog.printNoPrefix("==========step1:create table in normal database")
|
||||
tdSql.prepare()
|
||||
self.__create_tb()
|
||||
self.__insert_data()
|
||||
self.all_test()
|
||||
|
||||
return
|
||||
|
||||
tdLog.printNoPrefix("==========step2:create table in rollup database")
|
||||
|
|
|
@ -28,7 +28,7 @@ class TDTestCase:
|
|||
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
tdSql.init(conn.cursor(), False)
|
||||
|
||||
def __query_condition(self,tbname):
|
||||
query_condition = []
|
||||
|
|
|
@ -28,7 +28,7 @@ class TDTestCase:
|
|||
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor(), True)
|
||||
tdSql.init(conn.cursor(), False)
|
||||
|
||||
def __query_condition(self,tbname):
|
||||
query_condition = []
|
||||
|
|
|
@ -31,7 +31,7 @@ class TDTestCase:
|
|||
|
||||
def init(self, conn, logSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor())
|
||||
tdSql.init(conn.cursor(),False)
|
||||
|
||||
def __substr_condition(self): # sourcery skip: extract-method
|
||||
substr_condition = []
|
||||
|
|
Loading…
Reference in New Issue