add function to frame
This commit is contained in:
commit
c48df75b03
|
@ -25,18 +25,18 @@ class TDTestCase(TBase):
|
||||||
|
|
||||||
def prepareData(self):
|
def prepareData(self):
|
||||||
# db
|
# db
|
||||||
tdSql.execute("create database {};".format(self.dbname))
|
tdSql.execute(f"create database {self.dbname};")
|
||||||
tdSql.execute("use {};".format(self.dbname))
|
tdSql.execute(f"use {self.dbname};")
|
||||||
tdLog.debug("Create database %s" % self.dbname)
|
tdLog.debug(f"Create database {self.dbname}")
|
||||||
|
|
||||||
# commont table
|
# commont table
|
||||||
for common_table in self.table_dic["common_table"]:
|
for common_table in self.table_dic["common_table"]:
|
||||||
tdSql.execute("create table {} (ts timestamp, c_ts timestamp, c_int int, c_bigint bigint, c_double double, c_nchar nchar(16));".format(common_table))
|
tdSql.execute(f"create table {common_table} (ts timestamp, c_ts timestamp, c_int int, c_bigint bigint, c_double double, c_nchar nchar(16));")
|
||||||
tdLog.debug("Create common table %s" % common_table)
|
tdLog.debug("Create common table %s" % common_table)
|
||||||
|
|
||||||
# super table
|
# super table
|
||||||
for super_table in self.table_dic["super_table"]:
|
for super_table in self.table_dic["super_table"]:
|
||||||
tdSql.execute("create stable {} (ts timestamp, c_ts timestamp, c_int int, c_bigint bigint, c_double double, c_nchar nchar(16)) tags (t1 timestamp, t2 int, t3 binary(16));".format(super_table))
|
tdSql.execute(f"create stable {super_table} (ts timestamp, c_ts timestamp, c_int int, c_bigint bigint, c_double double, c_nchar nchar(16)) tags (t1 timestamp, t2 int, t3 binary(16));")
|
||||||
tdLog.debug("Create super table %s" % super_table)
|
tdLog.debug("Create super table %s" % super_table)
|
||||||
|
|
||||||
# child table
|
# child table
|
||||||
|
@ -59,38 +59,44 @@ class TDTestCase(TBase):
|
||||||
def test_normal_query(self):
|
def test_normal_query(self):
|
||||||
# only one timestamp
|
# only one timestamp
|
||||||
tdSql.query("select elapsed(ts) from t1 group by c_ts;")
|
tdSql.query("select elapsed(ts) from t1 group by c_ts;")
|
||||||
assert(len(tdSql.queryResult) == self.row_num and tdSql.queryResult[0][0] == 0)
|
tdSql.checkRows(self.row_num)
|
||||||
|
tdSql.checkData(0, 0, 0)
|
||||||
|
|
||||||
tdSql.query("select elapsed(ts, 1m) from t1 group by c_ts;")
|
tdSql.query("select elapsed(ts, 1m) from t1 group by c_ts;")
|
||||||
assert(len(tdSql.queryResult) == self.row_num and tdSql.queryResult[0][0] == 0)
|
tdSql.checkRows(self.row_num)
|
||||||
|
tdSql.checkData(0, 0, 0)
|
||||||
|
|
||||||
# child table with group by
|
# child table with group by
|
||||||
tdSql.query("select elapsed(ts) from ct1_2 group by tbname;")
|
tdSql.query("select elapsed(ts) from ct1_2 group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 1 and tdSql.queryResult[0][0] == 99000)
|
tdSql.checkRows(1)
|
||||||
|
tdSql.checkData(0, 0, 99000)
|
||||||
|
|
||||||
# empty super table
|
# empty super table
|
||||||
tdSql.query("select elapsed(ts, 1s) from st_empty group by tbname;")
|
tdSql.query("select elapsed(ts, 1s) from st_empty group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 0)
|
tdSql.checkRows(0)
|
||||||
|
|
||||||
# empty child table
|
# empty child table
|
||||||
tdSql.query("select elapsed(ts, 1s) from ct1_empty group by tbname;")
|
tdSql.query("select elapsed(ts, 1s) from ct1_empty group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 0)
|
tdSql.checkRows(0)
|
||||||
|
|
||||||
# empty common table
|
# empty common table
|
||||||
tdSql.query("select elapsed(ts, 1s) from t_empty group by tbname;")
|
tdSql.query("select elapsed(ts, 1s) from t_empty group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 0)
|
tdSql.checkRows(0)
|
||||||
|
|
||||||
# unit as second
|
# unit as second
|
||||||
tdSql.query("select elapsed(ts, 1s) from st2 group by tbname;")
|
tdSql.query("select elapsed(ts, 1s) from st2 group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 2 and tdSql.queryResult[0][0] == 99)
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(0, 0, 99)
|
||||||
|
|
||||||
# unit as minute
|
# unit as minute
|
||||||
tdSql.query("select elapsed(ts, 1m) from st2 group by tbname;")
|
tdSql.query("select elapsed(ts, 1m) from st2 group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 2 and tdSql.queryResult[0][0] == 1.65)
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(0, 0, 1.65)
|
||||||
|
|
||||||
# unit as hour
|
# unit as hour
|
||||||
tdSql.query("select elapsed(ts, 1h) from st2 group by tbname;")
|
tdSql.query("select elapsed(ts, 1h) from st2 group by tbname;")
|
||||||
assert(len(tdSql.queryResult) == 2 and tdSql.queryResult[0][0] == 0.0275)
|
tdSql.checkRows(2)
|
||||||
|
tdSql.checkData(0, 0, 0.0275)
|
||||||
|
|
||||||
def test_query_with_filter(self):
|
def test_query_with_filter(self):
|
||||||
end_ts = 1677654000000 + 1000 * 99
|
end_ts = 1677654000000 + 1000 * 99
|
||||||
|
@ -176,12 +182,17 @@ class TDTestCase(TBase):
|
||||||
"res": [(99,)]
|
"res": [(99,)]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for q in query_list:
|
sql_list = []
|
||||||
tdSql.query(q["sql"])
|
res_list = []
|
||||||
if len(q["res"]) == 0:
|
for item in query_list:
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]))
|
sql_list.append(item["sql"])
|
||||||
else:
|
res_list.append(item["res"])
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
tdSql.queryAndCheckResult(sql_list, res_list)
|
||||||
|
# tdSql.query(q["sql"])
|
||||||
|
# if len(q["res"]) == 0:
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]))
|
||||||
|
# else:
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
||||||
|
|
||||||
def test_query_with_other_function(self):
|
def test_query_with_other_function(self):
|
||||||
query_list = [
|
query_list = [
|
||||||
|
@ -194,9 +205,15 @@ class TDTestCase(TBase):
|
||||||
"res": [(3.248833500000000e+06,)]
|
"res": [(3.248833500000000e+06,)]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for q in query_list:
|
sql_list = []
|
||||||
tdSql.query(q["sql"])
|
res_list = []
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
for item in query_list:
|
||||||
|
sql_list.append(item["sql"])
|
||||||
|
res_list.append(item["res"])
|
||||||
|
tdSql.queryAndCheckResult(sql_list, res_list)
|
||||||
|
# for q in query_list:
|
||||||
|
# tdSql.query(q["sql"])
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
||||||
|
|
||||||
def test_query_with_join(self):
|
def test_query_with_join(self):
|
||||||
query_list = [
|
query_list = [
|
||||||
|
@ -245,10 +262,15 @@ class TDTestCase(TBase):
|
||||||
"res": []
|
"res": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
sql_list = []
|
||||||
for q in query_list:
|
res_list = []
|
||||||
tdSql.query(q["sql"])
|
for item in query_list:
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
sql_list.append(item["sql"])
|
||||||
|
res_list.append(item["res"])
|
||||||
|
tdSql.queryAndCheckResult(sql_list, res_list)
|
||||||
|
# for q in query_list:
|
||||||
|
# tdSql.query(q["sql"])
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
||||||
|
|
||||||
def test_query_with_union(self):
|
def test_query_with_union(self):
|
||||||
query_list = [
|
query_list = [
|
||||||
|
@ -305,10 +327,16 @@ class TDTestCase(TBase):
|
||||||
"res": [(99,)]
|
"res": [(99,)]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for q in query_list:
|
sql_list = []
|
||||||
tdSql.query(q["sql"])
|
res_list = []
|
||||||
tdLog.debug(q["sql"] + " with res: " + str(tdSql.queryResult))
|
for item in query_list:
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
sql_list.append(item["sql"])
|
||||||
|
res_list.append(item["res"])
|
||||||
|
tdSql.queryAndCheckResult(sql_list, res_list)
|
||||||
|
# for q in query_list:
|
||||||
|
# tdSql.query(q["sql"])
|
||||||
|
# tdLog.debug(q["sql"] + " with res: " + str(tdSql.queryResult))
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
||||||
|
|
||||||
def test_query_with_window(self):
|
def test_query_with_window(self):
|
||||||
query_list = [
|
query_list = [
|
||||||
|
@ -329,9 +357,15 @@ class TDTestCase(TBase):
|
||||||
"res": []
|
"res": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for q in query_list:
|
sql_list = []
|
||||||
tdSql.query(q["sql"])
|
res_list = []
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
for item in query_list:
|
||||||
|
sql_list.append(item["sql"])
|
||||||
|
res_list.append(item["res"])
|
||||||
|
tdSql.queryAndCheckResult(sql_list, res_list)
|
||||||
|
# for q in query_list:
|
||||||
|
# tdSql.query(q["sql"])
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
||||||
|
|
||||||
def test_nested_query(self):
|
def test_nested_query(self):
|
||||||
query_list = [
|
query_list = [
|
||||||
|
@ -356,10 +390,16 @@ class TDTestCase(TBase):
|
||||||
"res": []
|
"res": []
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
for q in query_list:
|
sql_list = []
|
||||||
tdSql.query(q["sql"])
|
res_list = []
|
||||||
tdLog.debug(q["sql"] + " with res: " + str(tdSql.queryResult))
|
for item in query_list:
|
||||||
assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
sql_list.append(item["sql"])
|
||||||
|
res_list.append(item["res"])
|
||||||
|
tdSql.queryAndCheckResult(sql_list, res_list)
|
||||||
|
# for q in query_list:
|
||||||
|
# tdSql.query(q["sql"])
|
||||||
|
# tdLog.debug(q["sql"] + " with res: " + str(tdSql.queryResult))
|
||||||
|
# assert(len(tdSql.queryResult) == len(q["res"]) and tdSql.queryResult == q["res"])
|
||||||
|
|
||||||
def test_abnormal_query(self):
|
def test_abnormal_query(self):
|
||||||
# incorrect parameter
|
# incorrect parameter
|
||||||
|
|
|
@ -115,6 +115,47 @@ class TDSql:
|
||||||
|
|
||||||
return self.error_info
|
return self.error_info
|
||||||
|
|
||||||
|
def errors(self, sql_list, expected_error_id_list=None, expected_error_info_list=None):
|
||||||
|
"""Execute the sql query and check the error info, expected error id or info should keep the same order with sql list,
|
||||||
|
expected_error_id_list or expected_error_info_list is None, then the error info will not be checked.
|
||||||
|
:param sql_list: the sql list to be executed.
|
||||||
|
:param expected_error_id: the expected error number.
|
||||||
|
:param expected_error_info: the expected error info.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
if len(sql_list) > 0:
|
||||||
|
for i in range(len(sql_list)):
|
||||||
|
if expected_error_id_list and expected_error_info_list:
|
||||||
|
self.error(sql_list[i], expected_error_id_list[i], expected_error_info_list[i])
|
||||||
|
elif expected_error_id_list:
|
||||||
|
self.error(sql_list[i], expectedErrno=expected_error_id_list[i])
|
||||||
|
elif expected_error_info_list:
|
||||||
|
self.error(sql_list[i], expectErrInfo=expected_error_info_list[i])
|
||||||
|
else:
|
||||||
|
self.error(sql_list[i])
|
||||||
|
else:
|
||||||
|
tdLog.exit("sql list is empty")
|
||||||
|
except Exception as ex:
|
||||||
|
tdLog.exit("Failed to execute sql list: %s, error: %s" % (sql_list, ex))
|
||||||
|
|
||||||
|
def queryAndCheckResult(self, sql_list, expect_result_list):
|
||||||
|
"""Execute the sql query and check the result.
|
||||||
|
:param sql_list: the sql list to be executed.
|
||||||
|
:param expect_result_list: the expected result list.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
for index in range(len(sql_list)):
|
||||||
|
self.query(sql_list[index])
|
||||||
|
if len(expect_result_list[index]) == 0:
|
||||||
|
self.checkRows(0)
|
||||||
|
else:
|
||||||
|
self.checkRows(len(expect_result_list[index]))
|
||||||
|
assert(self.queryResult == expect_result_list[index])
|
||||||
|
except Exception as ex:
|
||||||
|
raise(ex)
|
||||||
|
|
||||||
def query(self, sql, row_tag=None, queryTimes=10, count_expected_res=None):
|
def query(self, sql, row_tag=None, queryTimes=10, count_expected_res=None):
|
||||||
self.sql = sql
|
self.sql = sql
|
||||||
i=1
|
i=1
|
||||||
|
|
Loading…
Reference in New Issue