From 75df5d47f12b2c8bb6ad00a65929e26cd609ebad Mon Sep 17 00:00:00 2001 From: charles Date: Tue, 13 Aug 2024 15:13:18 +0800 Subject: [PATCH] update test case for TD-30995 by charles --- .../army/query/fill/fill_compare_asc_desc.py | 101 ++++++++++++++++++ tests/parallel_test/cases.task | 1 + 2 files changed, 102 insertions(+) create mode 100644 tests/army/query/fill/fill_compare_asc_desc.py diff --git a/tests/army/query/fill/fill_compare_asc_desc.py b/tests/army/query/fill/fill_compare_asc_desc.py new file mode 100644 index 0000000000..0a80bb1a3a --- /dev/null +++ b/tests/army/query/fill/fill_compare_asc_desc.py @@ -0,0 +1,101 @@ +from frame.log import * +from frame.cases import * +from frame.sql import * +from frame.caseBase import * +from frame import * + + +class TDTestCase(TBase): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), logSql) + + def prepare_data(self): + tdSql.execute("create database db;") + tdSql.execute("use db;") + # data for fill(prev) + tdSql.execute("create stable st_pre (ts timestamp, c1 int) tags(t1 int);") + tdSql.execute("create table ct1 using st_pre tags(1);") + start_ts = 1705783972000 + sql = "insert into ct1 values " + for i in range(100): + sql += f"({start_ts + i * 1000}, {str(i+1)})" + sql += ";" + tdSql.execute(sql) + + # data for fill(next) + tdSql.execute("create stable st_next (ts timestamp, c1 int) tags(t1 int);") + tdSql.execute("create table ct2 using st_next tags(1);") + start_ts = 1705783972000 + sql = "insert into ct1 values " + for i in range(100): + sql += f"({start_ts + i * 1000}, NULL)" + sql += ";" + tdSql.execute(sql) + + # data for fill(linear) + tdSql.execute("create stable st_linear (ts timestamp, c1 int) tags(t1 int);") + tdSql.execute("create table ct3 using st_linear tags(1);") + start_ts = 1705783972000 + sql = "insert into ct1 values " + for i in range(100): + if i % 2 == 0: + sql += f"({start_ts + i * 1000}, {str(i+1)})" + else: + sql += f"({start_ts + i * 1000}, NULL)" + sql += ";" + tdSql.execute(sql) + tdLog.info("prepare data done") + + def test_fill_pre_compare_asc_desc(self): + tdSql.execute("use db;") + for func in ["avg(c1)", "count(c1)", "first(c1)", "last(c1)", "max(c1)", "min(c1)", "sum(c1)"]: + tdSql.query(f"select _wstart, {func} from st_pre where ts between '2024-01-21 04:52:52.000' and '2024-01-21 04:54:31.000' interval(5s) fill(prev) order by _wstart asc;") + res1 = tdSql.res + tdSql.query(f"select _wstart, {func} from st_pre where ts between '2024-01-21 04:52:52.000' and '2024-01-21 04:54:31.000' interval(5s) fill(prev) order by _wstart desc;") + res2 = tdSql.res + assert len(res1) == len(res2) + for i in range(len(res1)): + assert res1[i] in res2 + tdLog.info(f"fill(prev) {func} compare asc and desc done") + tdLog.info("Finish the test case 'test_fill_pre_compare_asc_desc'") + + def test_fill_next_compare_asc_desc(self): + tdSql.execute("use db;") + for func in ["avg(c1)", "count(c1)", "first(c1)", "last(c1)", "max(c1)", "min(c1)", "sum(c1)"]: + tdSql.query(f"select _wstart, {func} from st_next where ts between '2024-01-21 04:52:52.000' and '2024-01-21 04:54:31.000' interval(5s) fill(next) order by _wstart asc;") + res1 = tdSql.res + tdSql.query(f"select _wstart, {func} from st_next where ts between '2024-01-21 04:52:52.000' and '2024-01-21 04:54:31.000' interval(5s) fill(next) order by _wstart desc;") + res2 = tdSql.res + assert len(res1) == len(res2) + for i in range(len(res1)): + assert res1[i] in res2 + tdLog.info(f"fill(next) {func} compare asc and desc done") + tdLog.info("Finish the test case 'test_fill_next_compare_asc_desc'") + + def test_fill_linear_compare_asc_desc(self): + tdSql.execute("use db;") + for func in ["avg(c1)", "count(c1)", "first(c1)", "last(c1)", "max(c1)", "min(c1)", "sum(c1)"]: + tdSql.query(f"select _wstart, {func} from st_linear where ts between '2024-01-21 04:52:52.000' and '2024-01-21 04:54:31.000' interval(5s) fill(linear) order by _wstart asc;") + res1 = tdSql.res + tdSql.query(f"select _wstart, {func} from st_linear where ts between '2024-01-21 04:52:52.000' and '2024-01-21 04:54:31.000' interval(5s) fill(linear) order by _wstart desc;") + res2 = tdSql.res + assert len(res1) == len(res2) + for i in range(len(res1)): + assert res1[i] in res2 + tdLog.info(f"fill(linear) {func} compare asc and desc done") + tdLog.info("Finish the test case 'test_fill_linear_compare_asc_desc'") + + def run(self): + self.prepare_data() + self.test_fill_pre_compare_asc_desc() + self.test_fill_next_compare_asc_desc() + self.test_fill_linear_compare_asc_desc() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index c86676b196..3553f0d913 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -37,6 +37,7 @@ ,,y,army,./pytest.sh python3 ./test.py -f grant/grantBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f query/queryBugs.py -N 3 ,,y,army,./pytest.sh python3 ./test.py -f tmq/tmqBugs.py -N 3 +,,y,army,./pytest.sh python3 ./test.py -f query/fill/fill_compare_asc_desc.py # # system test