feat: adapt for interface
This commit is contained in:
parent
59a6b247c4
commit
292d579932
|
@ -60,8 +60,8 @@ int32_t tTSRowBuilderPut(STSRowBuilder *pBuilder, int32_t cid, uint8_t *pData, u
|
|||
int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow);
|
||||
|
||||
// STagVal
|
||||
static FORCE_INLINE void tTagValSet(STagVal *pTagVal, void *key, int8_t type, uint8_t *pData, uint32_t nData,
|
||||
bool isJson);
|
||||
static FORCE_INLINE void tTagValPush(SArray *pTagArray, void *key, int8_t type, uint8_t *pData, uint32_t nData,
|
||||
bool isJson);
|
||||
|
||||
// STag
|
||||
int32_t tTagNew(SArray *pArray, int32_t version, int8_t isJson, STag **ppTag);
|
||||
|
@ -133,17 +133,19 @@ struct STagVal {
|
|||
uint8_t *pData;
|
||||
};
|
||||
|
||||
static FORCE_INLINE void tTagValSet(STagVal *pTagVal, void *key, int8_t type, uint8_t *pData, uint32_t nData,
|
||||
bool isJson) {
|
||||
static FORCE_INLINE void tTagValPush(SArray *pTagArray, void *key, int8_t type, uint8_t *pData, uint32_t nData,
|
||||
bool isJson) {
|
||||
STagVal tagVal = {0};
|
||||
if (isJson) {
|
||||
pTagVal->pKey = (char *)key;
|
||||
tagVal.pKey = (char *)key;
|
||||
} else {
|
||||
pTagVal->cid = *(int16_t *)key;
|
||||
tagVal.cid = *(int16_t *)key;
|
||||
}
|
||||
|
||||
pTagVal->type = type;
|
||||
pTagVal->pData = pData;
|
||||
pTagVal->nData = nData;
|
||||
tagVal.type = type;
|
||||
tagVal.pData = pData;
|
||||
tagVal.nData = nData;
|
||||
taosArrayPush(pTagArray, &tagVal);
|
||||
}
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
|
|
@ -1631,6 +1631,11 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, bool createTb, int64_t suid,
|
||||
const char* stbFullName, int32_t vgId) {
|
||||
SSubmitReq* ret = NULL;
|
||||
SArray* tagArray = taosArrayInit(1, sizeof(STagVal));
|
||||
if(!tagArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// cal size
|
||||
int32_t cap = sizeof(SSubmitReq);
|
||||
|
@ -1652,14 +1657,19 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
createTbReq.type = TSDB_CHILD_TABLE;
|
||||
createTbReq.ctb.suid = suid;
|
||||
|
||||
|
||||
|
||||
STagVal tagVal = {.cid = 1,
|
||||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.pData = (uint8_t*)&pDataBlock->info.groupId,
|
||||
.nData = sizeof(uint64_t)};
|
||||
STag* pTag = NULL;
|
||||
tTagNew(&tagVal, 1, 1, false, &pTag);
|
||||
taosArrayClear(tagArray);
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (!pTag) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
return NULL;
|
||||
}
|
||||
createTbReq.ctb.pTag = (uint8_t*)pTag;
|
||||
|
@ -1669,7 +1679,11 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
|
||||
if (code < 0) return NULL;
|
||||
if (code < 0) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
cap += sizeof(SSubmitBlk) + schemaLen + rows * maxLen;
|
||||
|
@ -1716,10 +1730,13 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
.type = TSDB_DATA_TYPE_UBIGINT,
|
||||
.pData = (uint8_t*)&pDataBlock->info.groupId,
|
||||
.nData = sizeof(uint64_t)};
|
||||
STag* pTag = NULL;
|
||||
tTagNew(&tagVal, 1, 1, false, &pTag);
|
||||
taosArrayClear(tagArray);
|
||||
taosArrayPush(tagArray, &tagVal);
|
||||
STag* pTag = NULL;
|
||||
tTagNew(tagArray, 1, false, &pTag);
|
||||
if (!pTag) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
taosMemoryFreeClear(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1729,6 +1746,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
tEncodeSize(tEncodeSVCreateTbReq, &createTbReq, schemaLen, code);
|
||||
if (code < 0) {
|
||||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
taosArrayDestroy(tagArray);
|
||||
taosMemoryFreeClear(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1740,6 +1758,7 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
tdDestroySVCreateTbReq(&createTbReq);
|
||||
|
||||
if (code < 0) {
|
||||
taosArrayDestroy(tagArray);
|
||||
taosMemoryFreeClear(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1777,5 +1796,6 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
}
|
||||
|
||||
ret->length = htonl(ret->length);
|
||||
taosArrayDestroy(tagArray);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -565,37 +565,32 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
} else {
|
||||
const STag *pOldTag = (const STag *)ctbEntry.ctbEntry.pTags;
|
||||
STag *pNewTag = NULL;
|
||||
STagVal *pTagVals = taosMemoryCalloc(pTagSchema->nCols, sizeof(STagVal));
|
||||
|
||||
if (!pTagVals) {
|
||||
SArray *pTagArray = taosArrayInit(pTagSchema->nCols, sizeof(STagVal));
|
||||
if (!pTagArray) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
int16_t nTags = 0;
|
||||
for (int32_t i = 0; i < pTagSchema->nCols; i++) {
|
||||
SSchema *pCol = &pTagSchema->pSchema[i];
|
||||
STagVal *pTagVal = pTagVals + nTags;
|
||||
if (iCol == i) {
|
||||
tTagValSet(pTagVal, &pCol->colId, pCol->type, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal, false);
|
||||
++nTags;
|
||||
tTagValPush(pTagArray, &pCol->colId, pCol->type, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal, false);
|
||||
} else {
|
||||
STagVal tagVal = {.cid = pCol->colId};
|
||||
if (tTagGet(pOldTag, &tagVal) && tagVal.pData) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
tTagValSet(pTagVal, &pCol->colId, pCol->type, tagVal.pData, varDataTLen(tagVal.pData), false);
|
||||
tTagValPush(pTagArray, &pCol->colId, pCol->type, tagVal.pData, varDataTLen(tagVal.pData), false);
|
||||
} else {
|
||||
tTagValSet(pTagVal, &pCol->colId, pCol->type, tagVal.pData, pCol->bytes, false);
|
||||
tTagValPush(pTagArray, &pCol->colId, pCol->type, tagVal.pData, pCol->bytes, false);
|
||||
}
|
||||
++nTags;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((terrno = tTagNew(pTagVals, nTags, pTagSchema->version, false, &pNewTag)) < 0) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
if ((terrno = tTagNew(pTagArray, pTagSchema->version, false, &pNewTag)) < 0) {
|
||||
taosArrayDestroy(pTagArray);
|
||||
goto _err;
|
||||
}
|
||||
ctbEntry.ctbEntry.pTags = (uint8_t *)pNewTag;
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
}
|
||||
|
||||
// save to table.db
|
||||
|
|
|
@ -54,7 +54,7 @@ typedef struct SInsertParseContext {
|
|||
SMsgBuf msg; // input
|
||||
STableMeta* pTableMeta; // each table
|
||||
SParsedDataColInfo tags; // each table
|
||||
STagVal* pTagVals; // each table
|
||||
SArray* pTagVals; // each table
|
||||
SVCreateTbReq createTblReq; // each table
|
||||
SHashObj* pVgroupsHashObj; // global
|
||||
SHashObj* pTableBlockHashObj; // global
|
||||
|
@ -72,9 +72,8 @@ static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE;
|
|||
static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE;
|
||||
|
||||
typedef struct SKvParam {
|
||||
int16_t nTag;
|
||||
int16_t pos;
|
||||
STagVal* pTagVals;
|
||||
SArray* pTagVals;
|
||||
SSchema* schema;
|
||||
char buf[TSDB_MAX_TAGS_LEN];
|
||||
} SKvParam;
|
||||
|
@ -773,7 +772,7 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, voi
|
|||
|
||||
if (TSDB_DATA_TYPE_BINARY == type) {
|
||||
memcpy(pa->buf + pa->pos, value, len);
|
||||
tTagValSet(pa->pTagVals + pa->nTag++, &colId, type, (uint8_t*)(pa->buf + pa->pos), len, false);
|
||||
tTagValPush(pa->pTagVals, &colId, type, (uint8_t*)(pa->buf + pa->pos), len, false);
|
||||
pa->pos += len;
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == type) {
|
||||
// if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long'
|
||||
|
@ -789,11 +788,11 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, voi
|
|||
snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno));
|
||||
return buildSyntaxErrMsg(pMsgBuf, buf, value);
|
||||
}
|
||||
tTagValSet(pa->pTagVals + pa->nTag++, &colId, type, (uint8_t*)(pa->buf + pa->pos), output, false);
|
||||
tTagValPush(pa->pTagVals, &colId, type, (uint8_t*)(pa->buf + pa->pos), output, false);
|
||||
pa->pos += output;
|
||||
} else {
|
||||
memcpy(pa->buf + pa->pos, value, TYPE_BYTES[type]);
|
||||
tTagValSet(pa->pTagVals + pa->nTag++, &colId, type, (uint8_t*)(pa->buf + pa->pos), TYPE_BYTES[type], false);
|
||||
tTagValPush(pa->pTagVals, &colId, type, (uint8_t*)(pa->buf + pa->pos), TYPE_BYTES[type], false);
|
||||
pa->pos + TYPE_BYTES[type];
|
||||
}
|
||||
ASSERT(pa->pos <= TSDB_MAX_TAGS_LEN);
|
||||
|
@ -813,11 +812,11 @@ static int32_t buildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag*
|
|||
// pSql -> tag1_value, ...)
|
||||
static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint8_t precision, const char* tName) {
|
||||
ASSERT(!pCxt->pTagVals);
|
||||
if (!(pCxt->pTagVals = taosMemoryCalloc(pCxt->tags.numOfBound, sizeof(STagVal)))) {
|
||||
if (!(pCxt->pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal)))) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SKvParam param = {.pTagVals = pCxt->pTagVals, .nTag = 0, .pos = 0};
|
||||
SKvParam param = {.pTagVals = pCxt->pTagVals, .pos = 0};
|
||||
SToken sToken;
|
||||
bool isParseBindParam = false;
|
||||
char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \"
|
||||
|
@ -828,7 +827,6 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
if (sToken.type == TK_NK_QUESTION) {
|
||||
isParseBindParam = true;
|
||||
if (NULL == pCxt->pStmtCb) {
|
||||
taosMemoryFreeClear(pCxt->pTagVals);
|
||||
return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z);
|
||||
}
|
||||
|
||||
|
@ -836,7 +834,6 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
}
|
||||
|
||||
if (isParseBindParam) {
|
||||
taosMemoryFreeClear(pCxt->pTagVals);
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and tag values");
|
||||
}
|
||||
|
||||
|
@ -847,18 +844,15 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
}
|
||||
|
||||
if (isParseBindParam) {
|
||||
taosMemoryFreeClear(pCxt->pTagVals);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// TODO: JSON_TAG_REFACTOR (would be JSON tag or normal tag)
|
||||
STag* pTag = NULL;
|
||||
if (tTagNew(param.pTagVals, param.nTag, 1, false, &pTag) != 0) {
|
||||
taosMemoryFreeClear(pCxt->pTagVals);
|
||||
if (tTagNew(param.pTagVals, 1, false, &pTag) != 0) {
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "out of memory");
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pCxt->pTagVals);
|
||||
return buildCreateTbReq(&pCxt->createTblReq, tName, pTag, pCxt->pTableMeta->suid);
|
||||
}
|
||||
|
||||
|
@ -1078,7 +1072,7 @@ void destroyCreateSubTbReq(SVCreateTbReq* pReq) {
|
|||
static void destroyInsertParseContextForTable(SInsertParseContext* pCxt) {
|
||||
taosMemoryFreeClear(pCxt->pTableMeta);
|
||||
destroyBoundColumnInfo(&pCxt->tags);
|
||||
taosMemoryFreeClear(pCxt->pTagVals);
|
||||
taosArrayDestroy(pCxt->pTagVals);
|
||||
destroyCreateSubTbReq(&pCxt->createTblReq);
|
||||
}
|
||||
|
||||
|
@ -1349,13 +1343,13 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
||||
STagVal* pTagVals = taosMemoryCalloc(tags->numOfBound, sizeof(STagVal));
|
||||
if (!pTagVals) {
|
||||
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
||||
if (!pTagArray) {
|
||||
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||
}
|
||||
|
||||
SSchema* pSchema = pDataBlock->pTableMeta->schema;
|
||||
SKvParam param = {.pTagVals = pTagVals, .nTag = 0, .pos = 0};
|
||||
SKvParam param = {.pTagVals = pTagArray, .pos = 0};
|
||||
|
||||
for (int c = 0; c < tags->numOfBound; ++c) {
|
||||
if (bind[c].is_null && bind[c].is_null[0]) {
|
||||
|
@ -1377,7 +1371,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
STag* pTag = NULL;
|
||||
|
||||
// TODO: JSON_TAG_REFACTOR (if is json or not)?
|
||||
if (0 != tTagNew(pTagVals, param.nTag, 1, false, &pTag)) {
|
||||
if (0 != tTagNew(pTagArray, 1, false, &pTag)) {
|
||||
return buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||
}
|
||||
|
||||
|
@ -1386,7 +1380,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
CHECK_CODE(buildCreateTbMsg(pDataBlock, &tbReq));
|
||||
|
||||
destroyCreateSubTbReq(&tbReq);
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1715,12 +1709,12 @@ static int32_t smlBoundColumnData(SArray* cols, SParsedDataColInfo* pColList, SS
|
|||
* @return int32_t
|
||||
*/
|
||||
static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* pSchema, STag** ppTag, SMsgBuf* msg) {
|
||||
STagVal* pTagVals = taosMemoryCalloc(tags->numOfBound, sizeof(STagVal));
|
||||
if (!pTagVals) {
|
||||
SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal));
|
||||
if (!pTagArray) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SKvParam param = {.pTagVals = pTagVals, .nTag = 0, .pos = 0};
|
||||
SKvParam param = {.pTagVals = pTagArray, .pos = 0};
|
||||
for (int i = 0; i < tags->numOfBound; ++i) {
|
||||
SSchema* pTagSchema = &pSchema[tags->boundColumns[i]];
|
||||
param.schema = pTagSchema;
|
||||
|
@ -1732,12 +1726,12 @@ static int32_t smlBuildTagRow(SArray* cols, SParsedDataColInfo* tags, SSchema* p
|
|||
}
|
||||
}
|
||||
|
||||
if (tTagNew(pTagVals, param.nTag, 1, false, ppTag) != 0) {
|
||||
taosMemoryFree(pTagVals);
|
||||
if (tTagNew(pTagArray, 1, false, ppTag) != 0) {
|
||||
taosArrayDestroy(pTagArray);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
taosMemoryFree(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -4113,8 +4113,8 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, SCreateSubTableClause* pStmt, const STag *pTag,
|
||||
uint64_t suid, SVgroupInfo* pVgInfo) {
|
||||
static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, SCreateSubTableClause* pStmt,
|
||||
const STag* pTag, uint64_t suid, SVgroupInfo* pVgInfo) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
|
||||
strcpy(name.dbname, pStmt->dbName);
|
||||
|
@ -4147,13 +4147,13 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S
|
|||
// static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SSchema* pSchema,
|
||||
// SKVRowBuilder* pBuilder) {
|
||||
#ifdef JSON_TAG_REFACTOR
|
||||
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||
if (pVal->literal && strlen(pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
|
||||
}
|
||||
|
||||
return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId);
|
||||
if (pSchema->type == TSDB_DATA_TYPE_JSON) {
|
||||
if (pVal->literal && strlen(pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) {
|
||||
return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal);
|
||||
}
|
||||
|
||||
return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId);
|
||||
}
|
||||
#endif
|
||||
|
||||
// if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
|
||||
|
@ -4198,10 +4198,10 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_TAGS_NOT_MATCHED);
|
||||
}
|
||||
|
||||
STagVal* pTagVals = (STagVal*)taosMemoryCalloc(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal));
|
||||
char* pTagBuf = taosMemoryCalloc(1, TSDB_MAX_TAGS_LEN);
|
||||
if (!pTagVals || !pTagBuf) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
SArray* pTagArray = taosArrayInit(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal));
|
||||
char* pTagBuf = taosMemoryCalloc(1, TSDB_MAX_TAGS_LEN);
|
||||
if (!pTagArray || !pTagBuf) {
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(pTagBuf);
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_TSC_OUT_OF_MEMORY);
|
||||
}
|
||||
|
@ -4212,7 +4212,6 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
FORBOTH(pTag, pStmt->pSpecificTags, pNode, pStmt->pValsOfTags) {
|
||||
SColumnNode* pCol = (SColumnNode*)pTag;
|
||||
SSchema* pSchema = NULL;
|
||||
STagVal* pTagVal = pTagVals + nTags;
|
||||
for (int32_t i = 0; i < numOfTags; ++i) {
|
||||
if (0 == strcmp(pCol->colName, pTagSchema[i].name)) {
|
||||
pSchema = pTagSchema + i;
|
||||
|
@ -4220,7 +4219,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
}
|
||||
}
|
||||
if (NULL == pSchema) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(pTagBuf);
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TAG_NAME, pCol->colName);
|
||||
}
|
||||
|
@ -4233,7 +4232,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
REPLACE_LIST2_NODE(pVal);
|
||||
}
|
||||
}
|
||||
#ifdef JSON_TAG_REFACTOR
|
||||
#ifdef JSON_TAG_REFACTOR
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addValToKVRow(pCxt, pVal, pSchema, pBuilder);
|
||||
}
|
||||
|
@ -4244,32 +4243,32 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
void* nodeVal = nodesGetValueFromNode(pVal);
|
||||
if (IS_VAR_DATA_TYPE(pSchema->type)) {
|
||||
memcpy(pTagBuf + nBufPos, varDataVal(nodeVal), varDataLen(nodeVal));
|
||||
tTagValSet(pTagVal, &pSchema->colId, pSchema->type, (uint8_t*)pTagBuf + nBufPos, varDataLen(nodeVal), false);
|
||||
tTagValPush(pTagArray, &pSchema->colId, pSchema->type, (uint8_t*)pTagBuf + nBufPos, varDataLen(nodeVal), false);
|
||||
nBufPos += varDataLen(pVal->datum.p);
|
||||
} else {
|
||||
memcpy(pTagBuf + nBufPos, varDataVal(nodeVal), TYPE_BYTES[pSchema->type]);
|
||||
tTagValSet(pTagVal, &pSchema->colId, pSchema->type, (uint8_t*)pTagBuf + nBufPos, TYPE_BYTES[pSchema->type],
|
||||
false);
|
||||
tTagValPush(pTagArray, &pSchema->colId, pSchema->type, (uint8_t*)pTagBuf + nBufPos, TYPE_BYTES[pSchema->type],
|
||||
false);
|
||||
nBufPos += TYPE_BYTES[pSchema->type];
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(pTagBuf);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: JSON_TAG_TODO: version
|
||||
code = tTagNew(pTagVals, nTags, 1, false, ppTag);
|
||||
code = tTagNew(pTagArray, 1, false, ppTag);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(pTagBuf);
|
||||
return code;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(pTagBuf);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -4284,21 +4283,19 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
SNode* pNode;
|
||||
int32_t code = 0;
|
||||
int32_t index = 0;
|
||||
int16_t nTag = 0;
|
||||
STagVal* pTagVals = taosMemoryCalloc(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal));
|
||||
SArray* pTagArray = taosArrayInit(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal));
|
||||
char* pTagBuf = taosMemoryCalloc(1, TSDB_MAX_TAGS_LEN);
|
||||
|
||||
const char* qTagBuf = pTagBuf;
|
||||
|
||||
if (!pTagVals || !pTagBuf) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
if (!pTagArray || !pTagBuf) {
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(qTagBuf);
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_TSC_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
FOREACH(pNode, pStmt->pValsOfTags) {
|
||||
SValueNode* pVal = NULL;
|
||||
STagVal* pTagVal = pTagVals + nTag;
|
||||
SSchema* pTagSchema = pTagSchemas + index;
|
||||
code = translateTagVal(pCxt, pSuperTableMeta->tableInfo.precision, pTagSchema, pNode, &pVal);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -4318,16 +4315,14 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
char* tmpVal = nodesGetValueFromNode(pVal);
|
||||
if (IS_VAR_DATA_TYPE(pTagSchema->type)) {
|
||||
memcpy(pTagBuf, varDataVal(tmpVal), varDataLen(tmpVal));
|
||||
tTagValSet(pTagVal, &pTagSchema->colId, pTagSchema->type, (uint8_t*)pTagBuf, varDataLen(tmpVal),
|
||||
false);
|
||||
tTagValPush(pTagArray, &pTagSchema->colId, pTagSchema->type, (uint8_t*)pTagBuf, varDataLen(tmpVal), false);
|
||||
pTagBuf += varDataLen(tmpVal);
|
||||
} else {
|
||||
memcpy(pTagBuf, tmpVal, TYPE_BYTES[pTagSchema->type]);
|
||||
tTagValSet(pTagVal, &pTagSchema->colId, pTagSchema->type, (uint8_t*)pTagBuf,
|
||||
TYPE_BYTES[pTagSchema->type], false);
|
||||
tTagValPush(pTagArray, &pTagSchema->colId, pTagSchema->type, (uint8_t*)pTagBuf, TYPE_BYTES[pTagSchema->type],
|
||||
false);
|
||||
pTagBuf += TYPE_BYTES[pTagSchema->type];
|
||||
}
|
||||
++nTag;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
|
@ -4335,20 +4330,20 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
|
||||
// TODO: JSON_TAG_TODO remove below codes if code is 0 all the time.
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(qTagBuf);
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, code);
|
||||
}
|
||||
}
|
||||
// TODO: JSON_TAG_TODO: version?
|
||||
// TODO: JSON_TAG_REFACTOR: json or not
|
||||
if (TSDB_CODE_SUCCESS != (code = tTagNew(pTagVals, nTag, 1, false, ppTag))) {
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
if (0 != (code = tTagNew(pTagArray, 1, false, ppTag))) {
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(qTagBuf);
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, code);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pTagVals);
|
||||
taosArrayDestroy(pTagArray);
|
||||
taosMemoryFreeClear(qTagBuf);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue