From 7396a7c09cc0db4919144fc7d1cd8e48d63b5d1b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 24 Aug 2023 17:11:05 +0800 Subject: [PATCH 1/3] fix: fix where ts < now used in nested query report invalid timestamp --- source/libs/function/src/builtins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 844bfb07fc..252d7db8e1 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -3221,7 +3221,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "now", .type = FUNCTION_TYPE_NOW, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC | FUNC_MGT_KEEP_ORDER_FUNC, .translateFunc = translateNowToday, .getEnvFunc = NULL, .initFunc = NULL, @@ -3231,7 +3231,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "today", .type = FUNCTION_TYPE_TODAY, - .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC, + .classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC | FUNC_MGT_KEEP_ORDER_FUNC, .translateFunc = translateNowToday, .getEnvFunc = NULL, .initFunc = NULL, From 2a5f4a3bc498532cb540871aa24e9e2e3a7451a6 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 24 Aug 2023 17:11:58 +0800 Subject: [PATCH 2/3] add cases --- tests/system-test/2-query/Now.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/system-test/2-query/Now.py b/tests/system-test/2-query/Now.py index db97cdad64..c9b0406700 100644 --- a/tests/system-test/2-query/Now.py +++ b/tests/system-test/2-query/Now.py @@ -101,6 +101,18 @@ class TDTestCase: self.now_check_ntb() self.now_check_stb() + ## TD-25540 + tdSql.execute(f'create database db1') + tdSql.execute(f'use db1') + tdSql.execute(f"create table tb (ts timestamp, c0 int)") + tdSql.execute(f'insert into db1.tb values(now + 1h, 1)') + + for func in {"NOW", "NOW()", "TODAY()", "1", "'1970-01-01 00:00:00'"}: + tdSql.query(f"SELECT _wstart, count(*) FROM (SELECT ts, LAST(c0) FROM tb WHERE ts > {func}) interval(1d);") + tdSql.checkRows(1) + + + def stop(self): tdSql.close() tdLog.success(f"{__file__} successfully executed") From b5172e8589f9481e602236309ce2336b4a220518 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 24 Aug 2023 17:11:58 +0800 Subject: [PATCH 3/3] add cases --- tests/system-test/2-query/Now.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/system-test/2-query/Now.py b/tests/system-test/2-query/Now.py index c9b0406700..21ff1f4e06 100644 --- a/tests/system-test/2-query/Now.py +++ b/tests/system-test/2-query/Now.py @@ -104,11 +104,11 @@ class TDTestCase: ## TD-25540 tdSql.execute(f'create database db1') tdSql.execute(f'use db1') - tdSql.execute(f"create table tb (ts timestamp, c0 int)") + tdSql.execute(f"create table db1.tb (ts timestamp, c0 int)") tdSql.execute(f'insert into db1.tb values(now + 1h, 1)') for func in {"NOW", "NOW()", "TODAY()", "1", "'1970-01-01 00:00:00'"}: - tdSql.query(f"SELECT _wstart, count(*) FROM (SELECT ts, LAST(c0) FROM tb WHERE ts > {func}) interval(1d);") + tdSql.query(f"SELECT _wstart, count(*) FROM (SELECT ts, LAST(c0) FROM db1.tb WHERE ts > {func}) interval(1d);") tdSql.checkRows(1)