From ed6eae4d5894295ecded05b828c6fd729b0a8e13 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 26 May 2022 17:13:13 +0800 Subject: [PATCH 1/2] fix(query): fix elapsed function time_unit cannot be smaller than db precision TD-16018 --- source/libs/function/src/builtins.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index 8914dca639..f5fa7b8855 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -318,6 +318,11 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len if (!IS_INTEGER_TYPE(paraType)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } + + if (pValue->datum.i == 0) { + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "ELAPSED function time unit parameter should be greater than db precision"); + } } pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE}; From f08365e2b00d02ac8135d3124f1f5ea1fab75e96 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 26 May 2022 17:30:00 +0800 Subject: [PATCH 2/2] fix(query): fix cast function error msg TD-16016 --- source/libs/function/src/builtins.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index f5fa7b8855..64b4c48a35 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -808,9 +808,14 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { (para2Type == TSDB_DATA_TYPE_BINARY && para1Type == TSDB_DATA_TYPE_NCHAR)) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } + int32_t para2Bytes = pFunc->node.resType.bytes; + if (IS_VAR_DATA_TYPE(para2Type)) { + para2Bytes -= VARSTR_HEADER_SIZE; + } if (para2Bytes <= 0 || para2Bytes > 1000) { // cast dst var type length limits to 1000 - return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, + "CAST function converted length should be in range [0, 1000]"); } return TSDB_CODE_SUCCESS; }