fix:add json test case

This commit is contained in:
wangmm0220 2022-05-23 19:32:10 +08:00
parent 125c0fa575
commit 70312ba0b3
1 changed files with 28 additions and 19 deletions

View File

@ -605,31 +605,39 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
if (iCol == 0) { if (iCol == 0) {
// TODO : need to update tag index // TODO : need to update tag index
} }
ctbEntry.version = version; ctbEntry.version = version;
SKVRowBuilder kvrb = {0}; if(pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON){
const SKVRow pOldTag = (const SKVRow)ctbEntry.ctbEntry.pTags; ctbEntry.ctbEntry.pTags = taosMemoryMalloc(pAlterTbReq->nTagVal);
SKVRow pNewTag = NULL; if(ctbEntry.ctbEntry.pTags == NULL){
terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _err;
}
memcpy((void*)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal);
}else{
SKVRowBuilder kvrb = {0};
const SKVRow pOldTag = (const SKVRow)ctbEntry.ctbEntry.pTags;
SKVRow pNewTag = NULL;
tdInitKVRowBuilder(&kvrb); tdInitKVRowBuilder(&kvrb);
for (int32_t i = 0; i < pTagSchema->nCols; i++) { for (int32_t i = 0; i < pTagSchema->nCols; i++) {
SSchema *pCol = &pTagSchema->pSchema[i]; SSchema *pCol = &pTagSchema->pSchema[i];
if (iCol == i) { if (iCol == i) {
tdAddColToKVRow(&kvrb, pCol->colId, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal); tdAddColToKVRow(&kvrb, pCol->colId, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal);
} else { } else {
void *p = tdGetKVRowValOfCol(pOldTag, pCol->colId); void *p = tdGetKVRowValOfCol(pOldTag, pCol->colId);
if (p) { if (p) {
if (IS_VAR_DATA_TYPE(pCol->type)) { if (IS_VAR_DATA_TYPE(pCol->type)) {
tdAddColToKVRow(&kvrb, pCol->colId, p, varDataTLen(p)); tdAddColToKVRow(&kvrb, pCol->colId, p, varDataTLen(p));
} else { } else {
tdAddColToKVRow(&kvrb, pCol->colId, p, pCol->bytes); tdAddColToKVRow(&kvrb, pCol->colId, p, pCol->bytes);
}
} }
} }
} }
}
ctbEntry.ctbEntry.pTags = tdGetKVRowFromBuilder(&kvrb); ctbEntry.ctbEntry.pTags = tdGetKVRowFromBuilder(&kvrb);
tdDestroyKVRowBuilder(&kvrb); tdDestroyKVRowBuilder(&kvrb);
}
// save to table.db // save to table.db
metaSaveToTbDb(pMeta, &ctbEntry); metaSaveToTbDb(pMeta, &ctbEntry);
@ -639,6 +647,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
tDecoderClear(&dc1); tDecoderClear(&dc1);
tDecoderClear(&dc2); tDecoderClear(&dc2);
if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void*)ctbEntry.ctbEntry.pTags);
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf); if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf); if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
tdbTbcClose(pTbDbc); tdbTbcClose(pTbDbc);