From 7a18acc7f760432288e73f6d69995bb0068cb2bd Mon Sep 17 00:00:00 2001 From: wangjiaming0909 Date: Wed, 25 Dec 2024 14:42:08 +0800 Subject: [PATCH 1/2] fix wrong rows returned with sma filtering --- source/libs/scalar/src/filter.c | 4 ++-- tests/pytest/util/sql.py | 2 +- tests/system-test/2-query/smaTest.py | 35 ++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index b329bbbd44..6689e12edd 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -5128,8 +5128,8 @@ static int32_t fltSclCollectOperatorFromNode(SNode *pNode, SArray *sclOpList) { SOperatorNode *pOper = (SOperatorNode *)pNode; - SValueNode *valNode = (SValueNode *)pOper->pRight; - if (IS_NUMERIC_TYPE(valNode->node.resType.type) || valNode->node.resType.type == TSDB_DATA_TYPE_TIMESTAMP) { + SExprNode* pLeft = (SExprNode*)pOper->pLeft; + if (IS_NUMERIC_TYPE(pLeft->resType.type) || pLeft->resType.type == TSDB_DATA_TYPE_TIMESTAMP) { SNode* pLeft = NULL, *pRight = NULL; int32_t code = nodesCloneNode(pOper->pLeft, &pLeft); if (TSDB_CODE_SUCCESS != code) { diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index bb7b8411f9..cdfe3ce8a0 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -100,7 +100,7 @@ class TDSql: if drop: s = f'drop database if exists {dbname}' self.cursor.execute(s) - s = f'create database {dbname}' + s = f'create database {dbname} stt_trigger 1' for k, v in kwargs.items(): s += f" {k} {v}" if "duration" not in kwargs: diff --git a/tests/system-test/2-query/smaTest.py b/tests/system-test/2-query/smaTest.py index 04fb893e75..355ac04707 100644 --- a/tests/system-test/2-query/smaTest.py +++ b/tests/system-test/2-query/smaTest.py @@ -39,6 +39,27 @@ class TDTestCase: self.create_tables(); self.ts = 1500000000000 + def test_TD_33336(self): + sql = "flush database db" + tdSql.execute(sql) + time.sleep(5) + sql = f'select last(ts) + 1d, last(ts) - 1d from db.t1' + tdSql.query(sql, queryTimes=1) + lastTs_add1d = tdSql.queryResult[0][0] + lastTs_sub1d = tdSql.queryResult[0][1] + + sql = f'select count(*) from db.t1 where ts < "{lastTs_add1d}" and vc1 = 1' + tdSql.query(sql, queryTimes=1) + all_row_count = tdSql.queryResult[0][0] + tdLog.debug(f"all rows: {all_row_count}") + + sql = f'select count(*) from db.t1 where ts < "{lastTs_sub1d}" and vc1 = 1' + tdSql.query(sql, queryTimes=1) + row_count_sub1d = tdSql.queryResult[0][0] + tdLog.debug(f"row_count_sub1d: {row_count_sub1d}") + + if row_count_sub1d > all_row_count: + tdLog.exit(f' err rows returned for sql: {sql} row_count_sub1d: {row_count_sub1d} > all_row_count: {all_row_count}') # run case def run(self): @@ -53,6 +74,8 @@ class TDTestCase: # self.test_case2() tdLog.debug(" LIMIT test_case2 ............ [OK]") + self.test_TD_33336() + # stop def stop(self): tdSql.close() @@ -65,11 +88,11 @@ class TDTestCase: # create table def create_tables(self, dbname="db"): # super table - tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int) tags(area int)") + tdSql.execute(f"create table {dbname}.st(ts timestamp, i1 int,i2 int, vc1 varchar(255)) tags(area int)") # child table tdSql.execute(f"create table {dbname}.t1 using {dbname}.st tags(1)") - tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int) tags(area int) sma(i2) ") + tdSql.execute(f"create table {dbname}.st1(ts timestamp, i1 int ,i2 int, vc1 varchar(255)) tags(area int) sma(i2) ") tdSql.execute(f"create table {dbname}.t4 using {dbname}.st1 tags(1)") return @@ -98,7 +121,11 @@ class TDTestCase: sql = pre_insert tdLog.debug("insert table %s rows=%d ..." % (tbname, count)) for i in range(count): - sql += " (%d,%d,%d)" % (ts_start + i*1000, i, i+1) + if random.randint(0, 4) > 2: + tail = '' + else: + tail = 'asd' + sql += " (%d,%d,%d,%s)" % (ts_start + i*1000, i, i+1, '"' + str(random.randint(0,5)) + f'{tail}"') if i > 0 and i % 20000 == 0: tdLog.info("%d rows inserted" % i) tdSql.execute(sql) @@ -125,4 +152,4 @@ class TDTestCase: # add case with filename # tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file +tdCases.addLinux(__file__, TDTestCase()) From 222cd3a39b7d945ca218aa0fee5e90d49058e6df Mon Sep 17 00:00:00 2001 From: wangjiaming0909 Date: Wed, 25 Dec 2024 17:36:45 +0800 Subject: [PATCH 2/2] fix clientTest --- source/client/test/clientTests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 3e4667fbe7..60f0a72e39 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -126,6 +126,10 @@ void fetchCallback(void* param, void* res, int32_t numOfRow) { void queryCallback(void* param, void* res, int32_t code) { if (code != TSDB_CODE_SUCCESS) { (void)printf("failed to execute, reason:%s\n", taos_errstr(res)); + taos_free_result(res); + tsem_t *sem = (tsem_t *)param; + tsem_post(sem); + return; } (void)printf("start to fetch data\n"); taos_fetch_raw_block_a(res, fetchCallback, param);