diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 28ef7eeb1c626c558537ba1d94fa99109997615e..727f5d42d1ccf62381cc84e4dea1fd0f5c140929 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7576,7 +7576,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char* int32_t validateFunctionFromUpstream(SQueryInfo* pQueryInfo, char* msg) { - const char* msg1 = "TWA/Diff/Derivative/Irate are not allowed to apply to super table without group by tbname"; + const char* msg1 = "TWA/Diff/Derivative/Irate/elapsed are not allowed to apply to super table without group by tbname"; const char* msg2 = "group by not supported in nested interp query"; const char* msg3 = "order by not supported in nested interp query"; const char* msg4 = "first column should be timestamp for interp query"; @@ -7589,7 +7589,7 @@ int32_t validateFunctionFromUpstream(SQueryInfo* pQueryInfo, char* msg) { SExprInfo* pExpr = tscExprGet(pQueryInfo, i); int32_t f = pExpr->base.functionId; - if (f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_TWA || f == TSDB_FUNC_IRATE || f == TSDB_FUNC_DIFF) { + if (f == TSDB_FUNC_DERIVATIVE || f == TSDB_FUNC_TWA || f == TSDB_FUNC_IRATE || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ELAPSED) { for (int32_t j = 0; j < upNum; ++j) { SQueryInfo* pUp = taosArrayGetP(pQueryInfo->pUpstream, j); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pUp, 0); diff --git a/tests/pytest/functions/function_elapsed.py b/tests/pytest/functions/function_elapsed.py index f4f748620350576e49fdae75ccd8a1804ad9ecb1..6bc54bfc1c7fc173bf9447da1a9b0aa4aba3e525 100644 --- a/tests/pytest/functions/function_elapsed.py +++ b/tests/pytest/functions/function_elapsed.py @@ -50,6 +50,9 @@ class TDTestCase: tdSql.query("select count(*) from t1") tdSql.checkEqual(int(tdSql.getData(0, 0)), 1000) + # empty normal table + tdSql.execute("create table t2(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp)") + tdSql.execute("create database wxy_db_ns precision \"ns\"") tdSql.execute("use wxy_db_ns") tdSql.execute("create table t1 (ts timestamp, f float)") @@ -73,6 +76,12 @@ class TDTestCase: tdSql.checkEqual(int(tdSql.getData(0, 0)), 500) tdSql.query("select count(*) from st1s2") tdSql.checkEqual(int(tdSql.getData(0, 0)), 500) + # empty super table + tdSql.execute("create stable st2(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)") + tdSql.execute("create table st2s1 using st1 tags(1)") + tdSql.execute("create table st2s2 using st1 tags(2)") + + tdSql.execute("create stable st3(ts timestamp, i int, b bigint, f float, d double, bin binary(10), s smallint, t tinyint, bl bool, n nchar(10), ts1 timestamp) tags(id int)") def run(self): tdSql.prepare() diff --git a/tests/pytest/functions/function_elapsed_case.py b/tests/pytest/functions/function_elapsed_case.py index 1e84dbcaae1c4347fd70741e778e2669553ac1f2..56610a9347c3ab90a9addc64dd62a6ed60758abf 100644 --- a/tests/pytest/functions/function_elapsed_case.py +++ b/tests/pytest/functions/function_elapsed_case.py @@ -72,6 +72,10 @@ class ElapsedCase: tdSql.checkCols(6) # append tbname tdSql.checkEqual(int(tdSql.getData(0, 2)), 0) + tdSql.query("select elapsed(ts), tbname from st1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' group by tbname") + tdSql.checkRows(2) + tdSql.checkCols(3) # additional append tbname + tdSql.execute("use wxy_db_ns") tdSql.query("select elapsed(ts, 1b), elapsed(ts, 1u) from t1") tdSql.checkRows(1) @@ -267,7 +271,12 @@ class ElapsedCase: self.fromCheck("select elapsed(ts) from %s where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00' interval(40s)", "t1") tdSql.query("select * from (select elapsed(ts) from t1 interval(10s)) where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.query("select * from (select elapsed(ts) from t1)") + # empty table test + tdSql.checkEqual(tdSql.query("select elapsed(ts) from t2"), 0) + tdSql.checkEqual(tdSql.query("select elapsed(ts) from st2 group by tbname"), 0) + tdSql.checkEqual(tdSql.query("select elapsed(ts) from st3 group by tbname"), 0) # Tags not allowed for table query, so there is no need to test super table. + tdSql.error("select elapsed(ts) from (select * from st1)") def joinCheck(self, sqlTemplate, rtable): tdSql.checkEqual(tdSql.getResult(sqlTemplate % (rtable, "")), tdSql.getResult(sqlTemplate % ("t1, %s t2" % rtable, "t1.ts = t2.ts and ")))