diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 065e7a750d..c25561814b 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -441,14 +441,14 @@ static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq) { funcInfo.signature = pFunc->signature; funcInfo.commentSize = pFunc->commentSize; funcInfo.codeSize = pFunc->codeSize; - funcInfo.pCode = taosMemoryCalloc(1, sizeof(funcInfo.codeSize)); + funcInfo.pCode = taosMemoryCalloc(1, funcInfo.codeSize); if (funcInfo.pCode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto RETRIEVE_FUNC_OVER; } memcpy(funcInfo.pCode, pFunc->pCode, pFunc->codeSize); if (funcInfo.commentSize > 0) { - funcInfo.pComment = taosMemoryCalloc(1, sizeof(funcInfo.commentSize)); + funcInfo.pComment = taosMemoryCalloc(1, funcInfo.commentSize); if (funcInfo.pComment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto RETRIEVE_FUNC_OVER; diff --git a/source/dnode/mnode/impl/test/func/func.cpp b/source/dnode/mnode/impl/test/func/func.cpp index 22b0387d8b..1569976105 100644 --- a/source/dnode/mnode/impl/test/func/func.cpp +++ b/source/dnode/mnode/impl/test/func/func.cpp @@ -32,6 +32,7 @@ void MndTestFunc::SetCode(SCreateFuncReq* pReq, const char* pCode) { int32_t len = strlen(pCode); pReq->pCode = (char*)taosMemoryCalloc(1, len + 1); strcpy(pReq->pCode, pCode); + pReq->codeLen = len; } void MndTestFunc::SetComment(SCreateFuncReq* pReq, const char* pComment) { @@ -60,21 +61,6 @@ TEST_F(MndTestFunc, 02_Create_Func) { ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_NAME); } - { - SCreateFuncReq createReq = {0}; - strcpy(createReq.name, "f1"); - SetCode(&createReq, "code1"); - - int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSCreateFuncReq(pReq, contLen, &createReq); - tFreeSCreateFuncReq(&createReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT); - } - { SCreateFuncReq createReq = {0}; strcpy(createReq.name, "f1"); @@ -90,22 +76,6 @@ TEST_F(MndTestFunc, 02_Create_Func) { ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_CODE); } - { - SCreateFuncReq createReq = {0}; - strcpy(createReq.name, "f1"); - SetCode(&createReq, "code1"); - SetComment(&createReq, ""); - - int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSCreateFuncReq(pReq, contLen, &createReq); - tFreeSCreateFuncReq(&createReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT); - } - { SCreateFuncReq createReq = {0}; strcpy(createReq.name, "f1"); @@ -329,7 +299,6 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { EXPECT_EQ(pFuncInfo->bufSize, 6); EXPECT_EQ(pFuncInfo->signature, 18); EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1); - EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1); EXPECT_STREQ("comment2", pFuncInfo->pComment); EXPECT_STREQ("code2", pFuncInfo->pCode); @@ -368,7 +337,6 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { EXPECT_EQ(pFuncInfo->bufSize, 6); EXPECT_EQ(pFuncInfo->signature, 18); EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1); - EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1); EXPECT_STREQ("comment2", pFuncInfo->pComment); EXPECT_STREQ("code2", pFuncInfo->pCode); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index ec4aa37db9..ab6d57edc0 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -1349,6 +1349,22 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } +static int32_t translateSetOperatorImpl(STranslateContext* pCxt, SSetOperator* pSetOperator) { + // todo + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSetOperator(STranslateContext* pCxt, SSetOperator* pSetOperator) { + int32_t code = translateQuery(pCxt, pSetOperator->pLeft); + if (TSDB_CODE_SUCCESS == code) { + code = translateQuery(pCxt, pSetOperator->pRight); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateSetOperatorImpl(pCxt, pSetOperator); + } + return code; +} + static int64_t getUnitPerMinute(uint8_t precision) { switch (precision) { case TSDB_TIME_PRECISION_MILLI: @@ -2650,6 +2666,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_SELECT_STMT: code = translateSelect(pCxt, (SSelectStmt*)pNode); break; + case QUERY_NODE_SET_OPERATOR: + code = translateSetOperator(pCxt, (SSetOperator*)pNode); + break; case QUERY_NODE_CREATE_DATABASE_STMT: code = translateCreateDatabase(pCxt, (SCreateDatabaseStmt*)pNode); break; diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 5427749d09..78adea15ce 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -768,6 +768,22 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele return code; } +static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { + SLogicNode* pRoot = NULL; + int32_t code = createQueryLogicNode(pCxt, pSetOperator->pLeft, &pRoot); + if (TSDB_CODE_SUCCESS == code) { + code = createQueryLogicNode(pCxt, pSetOperator->pRight, &pRoot); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = pRoot; + } else { + nodesDestroyNode(pRoot); + } + + return code; +} + static int32_t getMsgType(ENodeType sqlType) { return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType) ? TDMT_VND_CREATE_TABLE : TDMT_VND_SUBMIT; } @@ -791,6 +807,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt, pLogicNode); case QUERY_NODE_EXPLAIN_STMT: return createQueryLogicNode(pCxt, ((SExplainStmt*)pStmt)->pQuery, pLogicNode); + case QUERY_NODE_SET_OPERATOR: + return createSetOperatorLogicNode(pCxt, (SSetOperator*)pStmt, pLogicNode); default: break; }