diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 561f7343eadafd7f7981cc43c30140b5bd30d9b2..09655348baef5ca7d9fece130c0e06f4ae1785b8 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2727,7 +2727,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName)); getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token,sizeof(pExpr->base.aliasName) - 1); - + SColumnList list = createColumnList(1, index.tableIndex, index.columnIndex); if (finalResult) { int32_t numOfOutput = tscNumOfFields(pQueryInfo); @@ -2852,6 +2852,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col char val[8] = {0}; int64_t tickPerSec = 0; + char *exprToken = tcalloc(pParamElem[1].pNode->exprToken.n + 1, sizeof(char)); + memcpy(exprToken, pParamElem[1].pNode->exprToken.z, pParamElem[1].pNode->exprToken.n); + if (pParamElem[1].pNode->exprToken.type == TK_NOW || strstr(exprToken, "now")) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + } + tfree(exprToken); + if ((TSDB_DATA_TYPE_NULL == pParamElem[1].pNode->value.nType) || tVariantDump(&pParamElem[1].pNode->value, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, true) < 0) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -2866,7 +2873,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); } else if (tickPerSec <= 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg16); - } + } tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); if (functionId == TSDB_FUNC_DERIVATIVE) { @@ -4906,14 +4913,14 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t if (IS_VAR_DATA_TYPE(pSchema[index].type) || pSchema[index].type == TSDB_DATA_TYPE_JSON) { return TSDB_CODE_SUCCESS; } - + char *v = strndup(pRight->exprToken.z, pRight->exprToken.n); int32_t len = strRmquote(v, pRight->exprToken.n); if (len > 0) { uint32_t type = 0; tGetToken(v, &type); - if (type == TK_NULL) { + if (type == TK_NULL) { free(v); return invalidOperationMsg(msgBuf, msg); } diff --git a/tests/pytest/functions/function_derivative.py b/tests/pytest/functions/function_derivative.py index a2a458ea290b13ed462d8dcd47a8af16e3af0f82..3696dc24010cdbff6d4e139a4224a23469403041 100644 --- a/tests/pytest/functions/function_derivative.py +++ b/tests/pytest/functions/function_derivative.py @@ -140,6 +140,9 @@ class TDTestCase: tdSql.error("select derivative(col, 1s, 1) from tb2") tdSql.error("select derivative(col, 10s, 0) from tb2") tdSql.error("select derivative(col, 999ms, 0) from tb2") + tdSql.error("select derivative(col, now, 0) from tb2") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, now+3d-8h+6m, 0) from tb2") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, 3d-8h+now+6m, 0) from tb2") #TD-11983 now not allowed in second param tdSql.error("select derivative(col, 10s, 1) from stb") tdSql.error("select derivative(col, 10s, 1) from stb group by col") @@ -150,6 +153,9 @@ class TDTestCase: tdSql.error("select derivative(col, 10y, 0) from stb group by tbname") #TD-10399, DB error: syntax error near '10y, 0) from stb group by tbname;' tdSql.error("select derivative(col, -106752d, 0) from stb group by tbname") #TD-10398 overflow tips tdSql.error("select derivative(col, 106751991168d, 0) from stb group by tbname") #TD-10398 overflow tips + tdSql.error("select derivative(col, now, 1) from stb") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, now+3d-8h+6m, 1) from stb") #TD-11983 now not allowed in second param + tdSql.error("select derivative(col, 3d-8h+now+6m, 1) from stb") #TD-11983 now not allowed in second param def run(self): tdSql.prepare() diff --git a/tests/pytest/functions/function_elapsed_case.py b/tests/pytest/functions/function_elapsed_case.py index 50fbb0fe3244ec214e040f43962321a28ed31d9b..025354f2c3e31d1483f339e0e4f23bbda4c1e997 100644 --- a/tests/pytest/functions/function_elapsed_case.py +++ b/tests/pytest/functions/function_elapsed_case.py @@ -345,7 +345,9 @@ class ElapsedCase: tdSql.error("select elapsed(*) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, '1s') from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, i) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") - #tdSql.error("select elapsed(ts, now) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") + tdSql.error("select elapsed(ts, now) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") + tdSql.error("select elapsed(ts, now-7d+2h-3m+2s) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") + tdSql.error("select elapsed(ts, 7d+2h+now+3m+2s) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, ts) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts + 1) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'") tdSql.error("select elapsed(ts, 1b) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'")