From f6b700ff4581c49aaf740816b8b48cf4b237dbac Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 31 May 2022 22:30:08 +0800 Subject: [PATCH] feat:add new logic for new tag format --- source/common/src/tdataformat.c | 2 +- source/libs/scalar/src/sclvector.c | 22 +++++++++++-------- .../libs/scalar/test/scalar/scalarTests.cpp | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 71842655ec..f946aa3b01 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -672,8 +672,8 @@ static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) { if (IS_VAR_DATA_TYPE(pTagVal->type)) { n += tGetBinary(p + n, &pTagVal->pData, &pTagVal->nData); } else { - n += tDataTypes[pTagVal->type].bytes; memcpy(&(pTagVal->i64), p + n, tDataTypes[pTagVal->type].bytes); + n += tDataTypes[pTagVal->type].bytes; } return n; diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index f84f564b8d..e844b3cdb6 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -922,12 +922,13 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { } } -STagVal *getJsonValue(char *json, STagVal *tagVal) { - bool find = tTagGet(((const STag *)json), tagVal); // json value is null and not exist is different - if(!find){ - return NULL; +STagVal getJsonValue(char *json, char *key, bool *isExist) { + STagVal val = {.pKey = key}; + bool find = tTagGet(((const STag *)json), &val); // json value is null and not exist is different + if(isExist){ + *isExist = find; } - return tagVal; + return val; } void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { @@ -939,6 +940,8 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); char *pRightData = colDataGetVarData(pRight->columnData, 0); + char *jsonKey = taosMemoryCalloc(1, varDataLen(pRightData) + 1); + memcpy(jsonKey, varDataVal(pRightData), varDataLen(pRightData)); for (; i >= 0 && i < pLeft->numOfRows; i += step) { if (colDataIsNull_var(pLeft->columnData, i)) { colDataSetNull_var(pOutputCol, i); @@ -946,14 +949,15 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO continue; } char *pLeftData = colDataGetVarData(pLeft->columnData, i); - STagVal val = {.pKey = pRightData}; - STagVal *value = getJsonValue(pLeftData, &val); - char *data = tTagValToData(value, true); + bool isExist = false; + STagVal value = getJsonValue(pLeftData, jsonKey, &isExist); + char *data = isExist ? tTagValToData(&value, true) : NULL; colDataAppend(pOutputCol, i, data, data == NULL); - if(value && IS_VAR_DATA_TYPE(value->type) && data){ + if(isExist && IS_VAR_DATA_TYPE(value.type) && data){ taosMemoryFree(data); } } + taosMemoryFree(jsonKey); } void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 6ddf4b12b9..e971055a66 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -217,7 +217,7 @@ void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode SOperatorNode *onode = (SOperatorNode *)node; onode->node.resType.type = resType; onode->node.resType.bytes = tDataTypes[resType].bytes; - + onode->opType = opType; onode->pLeft = pLeft; onode->pRight = pRight; -- GitLab