diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 912ffb78767704b62b2ddedfe1a64881589cdf42..6b74549b62475f4f74c488305f4699e388a08b69 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -64,7 +64,7 @@ static FORCE_INLINE void tTagValSet(STagVal *pTagVal, void *key, int8_t type, ui bool isJson); // STag -int32_t tTagNew(STagVal *pTagVals, int16_t nTag, int32_t version, int8_t isJson, STag **ppTag); +int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag); void tTagFree(STag *pTag); bool tTagGet(const STag *pTag, STagVal *pTagVal); int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index c98317e385a2264375948109e0927658c277f3be..cc612de8893623ccaed0087736eb970a4c7c13ef 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -643,22 +643,23 @@ static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) { return n; } -int32_t tTagNew(STagVal *pTagVals, int16_t nTag, int32_t version, int8_t isJson, STag **ppTag) { +int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag) { int32_t code = 0; uint8_t *p = NULL; int16_t n = 0; + int16_t nTag = taosArrayGetSize(pArray); int32_t szTag = sizeof(STag) + sizeof(int16_t) * nTag; // sort if (isJson) { - qsort(pTagVals, nTag, sizeof(STagVal), tTagValJsonCmprFn); + qsort(pArray->pData, nTag, sizeof(STagVal), tTagValJsonCmprFn); } else { - qsort(pTagVals, nTag, sizeof(STagVal), tTagValCmprFn); + qsort(pArray->pData, nTag, sizeof(STagVal), tTagValCmprFn); } // get size for (int16_t iTag = 0; iTag < nTag; iTag++) { - szTag += tPutTagVal(NULL, &pTagVals[iTag], isJson); + szTag += tPutTagVal(NULL, (STagVal *)taosArrayGet(pArray, iTag), isJson); } // TODO @@ -682,7 +683,7 @@ int32_t tTagNew(STagVal *pTagVals, int16_t nTag, int32_t version, int8_t isJson, n = 0; for (int16_t iTag = 0; iTag < nTag; iTag++) { (*ppTag)->idx[iTag] = n; - n += tPutTagVal(p + n, &pTagVals[iTag], isJson); + n += tPutTagVal(p + n, (STagVal *)taosArrayGet(pArray, iTag), isJson); } debugPrintSTag(*ppTag, __func__, __LINE__); @@ -743,7 +744,7 @@ int32_t tTagToValArray(const STag *pTag, SArray **ppArray) { uint8_t *p = (uint8_t *)&pTag->idx[pTag->nTag]; STagVal tv; - (*ppArray) = taosArrayInit(pTag->nTag, sizeof(STagVal)); + (*ppArray) = taosArrayInit(pTag->nTag + 1, sizeof(STagVal)); if (*ppArray == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err;