提交 25eb6dbe 编写于 作者: G Ganlin Zhao

fix(query): diff function first param can only be column

TD-16067
上级 0b9c9834
...@@ -675,32 +675,41 @@ static int32_t translateUnique(SFunctionNode* pFunc, char* pErrBuf, int32_t len) ...@@ -675,32 +675,41 @@ static int32_t translateUnique(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
} }
static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
int32_t paraLen = LIST_LENGTH(pFunc->pParameterList); int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
if (paraLen == 0 || paraLen > 2) { if (numOfParams == 0 || numOfParams > 2) {
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
} }
//param1 //param0
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1); SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
if (QUERY_NODE_VALUE != nodeType(pParamNode1)) { if (nodeType(pParamNode0) != QUERY_NODE_COLUMN) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
"The first parameter of DIFF function can only be column");
} }
SValueNode* pValue = (SValueNode*)pParamNode1; uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
if (pValue->datum.i != 0 && pValue->datum.i != 1) { if (!IS_SIGNED_NUMERIC_TYPE(colType) && !IS_FLOAT_TYPE(colType) &&
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR, TSDB_DATA_TYPE_BOOL != colType) {
"Second parameter of DIFF function should be only 0 or 1"); return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
} }
pValue->notReserved = true; //param1
if (numOfParams == 2) {
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
if (QUERY_NODE_VALUE != nodeType(pParamNode1)) {
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
}
//param0 SValueNode* pValue = (SValueNode*)pParamNode1;
SExprNode* p1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0); if (pValue->datum.i != 0 && pValue->datum.i != 1) {
if (!IS_SIGNED_NUMERIC_TYPE(p1->resType.type) && !IS_FLOAT_TYPE(p1->resType.type) && return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
TSDB_DATA_TYPE_BOOL != p1->resType.type) { "Second parameter of DIFF function should be only 0 or 1");
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); }
pValue->notReserved = true;
} }
pFunc->node.resType = p1->resType;
pFunc->node.resType = (SDataType){.bytes = tDataTypes[colType].bytes, .type = colType};
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册