未验证 提交 68de8077 编写于 作者: S shenglian-zhou 提交者: GitHub

Merge pull request #9496 from taosdata/fix/TD-11983-2.4

[TD-11983]<fix>(query): elapsed function second param time_unit should not contain now keyword
...@@ -2727,7 +2727,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2727,7 +2727,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName)); memset(pExpr->base.aliasName, 0, tListLen(pExpr->base.aliasName));
getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token,sizeof(pExpr->base.aliasName) - 1); getColumnName(pItem, pExpr->base.aliasName, pExpr->base.token,sizeof(pExpr->base.aliasName) - 1);
SColumnList list = createColumnList(1, index.tableIndex, index.columnIndex); SColumnList list = createColumnList(1, index.tableIndex, index.columnIndex);
if (finalResult) { if (finalResult) {
int32_t numOfOutput = tscNumOfFields(pQueryInfo); int32_t numOfOutput = tscNumOfFields(pQueryInfo);
...@@ -2852,6 +2852,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2852,6 +2852,13 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
char val[8] = {0}; char val[8] = {0};
int64_t tickPerSec = 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) { 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; return TSDB_CODE_TSC_INVALID_OPERATION;
} }
...@@ -2866,7 +2873,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col ...@@ -2866,7 +2873,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10);
} else if (tickPerSec <= 0) { } else if (tickPerSec <= 0) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg16); return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg16);
} }
tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES); tscExprAddParams(&pExpr->base, (char*) &tickPerSec, TSDB_DATA_TYPE_BIGINT, LONG_BYTES);
if (functionId == TSDB_FUNC_DERIVATIVE) { if (functionId == TSDB_FUNC_DERIVATIVE) {
...@@ -4906,14 +4913,14 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t ...@@ -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) { if (IS_VAR_DATA_TYPE(pSchema[index].type) || pSchema[index].type == TSDB_DATA_TYPE_JSON) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
char *v = strndup(pRight->exprToken.z, pRight->exprToken.n); char *v = strndup(pRight->exprToken.z, pRight->exprToken.n);
int32_t len = strRmquote(v, pRight->exprToken.n); int32_t len = strRmquote(v, pRight->exprToken.n);
if (len > 0) { if (len > 0) {
uint32_t type = 0; uint32_t type = 0;
tGetToken(v, &type); tGetToken(v, &type);
if (type == TK_NULL) { if (type == TK_NULL) {
free(v); free(v);
return invalidOperationMsg(msgBuf, msg); return invalidOperationMsg(msgBuf, msg);
} }
......
...@@ -140,6 +140,9 @@ class TDTestCase: ...@@ -140,6 +140,9 @@ class TDTestCase:
tdSql.error("select derivative(col, 1s, 1) from tb2") tdSql.error("select derivative(col, 1s, 1) from tb2")
tdSql.error("select derivative(col, 10s, 0) 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, 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")
tdSql.error("select derivative(col, 10s, 1) from stb group by col") tdSql.error("select derivative(col, 10s, 1) from stb group by col")
...@@ -150,6 +153,9 @@ class TDTestCase: ...@@ -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, 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, -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, 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): def run(self):
tdSql.prepare() tdSql.prepare()
......
...@@ -345,7 +345,9 @@ class ElapsedCase: ...@@ -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(*) 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, '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, 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, 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 + 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'") tdSql.error("select elapsed(ts, 1b) from t1 where ts > '2021-11-22 00:00:00' and ts < '2021-11-23 00:00:00'")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册