feat:add new logic for new tag format
This commit is contained in:
parent
f89ce48e66
commit
d95ec693c0
|
@ -136,8 +136,8 @@ struct STagVal {
|
|||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
#define TD_TAG_JSON ((int8_t)0x80) // distinguish JSON string and JSON value with the highest bit
|
||||
#define TD_TAG_LARGE ((int8_t)0x40)
|
||||
#define TD_TAG_JSON ((int8_t)0x40) // distinguish JSON string and JSON value with the highest bit
|
||||
#define TD_TAG_LARGE ((int8_t)0x20)
|
||||
struct STag {
|
||||
int8_t flags;
|
||||
int16_t len;
|
||||
|
|
|
@ -567,6 +567,9 @@ static void debugPrintTagVal(int8_t type, const void *val, int32_t vlen, const c
|
|||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
printf("%s:%d type:%d vlen:%d, val:%" PRIu64 "\n", tag, ln, (int32_t)type, vlen, *(uint64_t *)val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
printf("%s:%d type:%d vlen:%d, val:%" PRIi8 "\n", tag, ln, (int32_t)type, vlen, *(int8_t *)val);
|
||||
break;
|
||||
default:
|
||||
ASSERT(0);
|
||||
break;
|
||||
|
|
|
@ -55,7 +55,7 @@ int32_t getNumOfColumns(const STableMeta* pTableMeta);
|
|||
int32_t getNumOfTags(const STableMeta* pTableMeta);
|
||||
STableComInfo getTableInfo(const STableMeta* pTableMeta);
|
||||
STableMeta* tableMetaDup(const STableMeta* pTableMeta);
|
||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, SMsgBuf* errMsg);
|
||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag **ppTag, SMsgBuf* pMsgBuf);
|
||||
|
||||
int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen);
|
||||
|
||||
|
|
|
@ -959,6 +959,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
SToken sToken;
|
||||
bool isParseBindParam = false;
|
||||
bool isJson = false;
|
||||
STag* pTag = NULL;
|
||||
for (int i = 0; i < pCxt->tags.numOfBound; ++i) {
|
||||
NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken);
|
||||
|
||||
|
@ -990,7 +991,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
taosMemoryFree(tmpTokenBuf);
|
||||
goto end;
|
||||
}
|
||||
code = parseJsontoTagData(sToken.z, pTagVals, &pCxt->msg);
|
||||
code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg);
|
||||
taosMemoryFree(tmpTokenBuf);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
goto end;
|
||||
|
@ -1015,9 +1016,7 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint
|
|||
goto end;
|
||||
}
|
||||
|
||||
STag* pTag = NULL;
|
||||
code = tTagNew(pTagVals, 1, isJson, &pTag);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if(!isJson && (code = tTagNew(pTagVals, 1, false, &pTag)) != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
@ -1528,6 +1527,8 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
SSchema* pSchema = pDataBlock->pTableMeta->schema;
|
||||
|
||||
bool isJson = false;
|
||||
STag* pTag = NULL;
|
||||
|
||||
for (int c = 0; c < tags->numOfBound; ++c) {
|
||||
if (bind[c].is_null && bind[c].is_null[0]) {
|
||||
continue;
|
||||
|
@ -1548,7 +1549,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
isJson = true;
|
||||
char *tmp = taosMemoryCalloc(1, colLen + 1);
|
||||
memcpy(tmp, bind[c].buffer, colLen);
|
||||
code = parseJsontoTagData(tmp, pTagArray, &pBuf);
|
||||
code = parseJsontoTagData(tmp, pTagArray, &pTag, &pBuf);
|
||||
taosMemoryFree(tmp);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
goto end;
|
||||
|
@ -1586,10 +1587,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tN
|
|||
}
|
||||
}
|
||||
|
||||
STag* pTag = NULL;
|
||||
|
||||
if (0 != tTagNew(pTagArray, 1, isJson, &pTag)) {
|
||||
code = buildInvalidOperationMsg(&pBuf, "out of memory");
|
||||
if (!isJson && (code = tTagNew(pTagArray, 1, false, &pTag)) != TSDB_CODE_SUCCESS) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
|
|
@ -4218,7 +4218,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
}
|
||||
|
||||
isJson = true;
|
||||
code = parseJsontoTagData(pVal->literal, pTagArray, &pCxt->msgBuf);
|
||||
code = parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
goto end;
|
||||
}
|
||||
|
@ -4235,7 +4235,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
|
|||
}
|
||||
}
|
||||
|
||||
code = tTagNew(pTagArray, 1, isJson, ppTag);
|
||||
if(!isJson) code = tTagNew(pTagArray, 1, false, ppTag);
|
||||
|
||||
end:
|
||||
if(isJson){
|
||||
|
@ -4285,7 +4285,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
}
|
||||
|
||||
isJson = true;
|
||||
code = parseJsontoTagData(pVal->literal, pTagArray, &pCxt->msgBuf);
|
||||
code = parseJsontoTagData(pVal->literal, pTagArray, ppTag, &pCxt->msgBuf);
|
||||
if(code != TSDB_CODE_SUCCESS){
|
||||
goto end;
|
||||
}
|
||||
|
@ -4302,7 +4302,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
|
|||
}
|
||||
++index;
|
||||
}
|
||||
code = tTagNew(pTagArray, 1, isJson, ppTag);
|
||||
if(!isJson) code = tTagNew(pTagArray, 1, false, ppTag);
|
||||
|
||||
end:
|
||||
if(isJson){
|
||||
|
@ -4580,11 +4580,10 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
STag* pTag = NULL;
|
||||
do{
|
||||
code = parseJsontoTagData(pStmt->pVal->literal, pTagVals, &pCxt->msgBuf);
|
||||
code = parseJsontoTagData(pStmt->pVal->literal, pTagVals, &pTag, &pCxt->msgBuf);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
code = tTagNew(pTagVals, 1, true, &pTag);
|
||||
}while(0);
|
||||
for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) {
|
||||
STagVal *p = (STagVal *)taosArrayGet(pTagVals, i);
|
||||
|
|
|
@ -328,24 +328,27 @@ static bool isValidateTag(char* input) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, SMsgBuf* pMsgBuf) {
|
||||
int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag **ppTag, SMsgBuf* pMsgBuf) {
|
||||
int32_t retCode = TSDB_CODE_SUCCESS;
|
||||
// set json NULL data
|
||||
if (!json || strtrim((char*)json) == 0 || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
retCode = TSDB_CODE_SUCCESS;
|
||||
goto end;
|
||||
}
|
||||
|
||||
// set json real data
|
||||
cJSON* root = cJSON_Parse(json);
|
||||
if (root == NULL) {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "json parse error", json);
|
||||
retCode = buildSyntaxErrMsg(pMsgBuf, "json parse error", json);
|
||||
goto end;
|
||||
}
|
||||
|
||||
int32_t size = cJSON_GetArraySize(root);
|
||||
if (!cJSON_IsObject(root)) {
|
||||
return buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json);
|
||||
retCode = buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json);
|
||||
goto end;
|
||||
}
|
||||
|
||||
int32_t retCode = TSDB_CODE_SUCCESS;
|
||||
SHashObj* keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false);
|
||||
for (int32_t i = 0; i < size; i++) {
|
||||
cJSON* item = cJSON_GetArrayItem(root, i);
|
||||
|
@ -413,6 +416,9 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, SMsgBuf* pMsgBuf)
|
|||
|
||||
end:
|
||||
taosHashCleanup(keyHash);
|
||||
if(retCode == TSDB_CODE_SUCCESS){
|
||||
tTagNew(pTagVals, 1, true, ppTag);
|
||||
}
|
||||
cJSON_Delete(root);
|
||||
return retCode;
|
||||
}
|
||||
|
|
|
@ -1112,9 +1112,8 @@ TEST(columnTest, json_column_arith_op) {
|
|||
char rightv[256] = {0};
|
||||
memcpy(rightv, rightvTmp, strlen(rightvTmp));
|
||||
SArray *tags = taosArrayInit(1, sizeof(STagVal));
|
||||
parseJsontoTagData(rightv, tags, NULL);
|
||||
STag* row = NULL;
|
||||
tTagNew(tags, 1, true, &row);
|
||||
parseJsontoTagData(rightv, tags, &row, NULL);
|
||||
|
||||
const int32_t len = 8;
|
||||
EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV,
|
||||
|
@ -1189,9 +1188,8 @@ TEST(columnTest, json_column_logic_op) {
|
|||
char rightv[256] = {0};
|
||||
memcpy(rightv, rightvTmp, strlen(rightvTmp));
|
||||
SArray *tags = taosArrayInit(1, sizeof(STagVal));
|
||||
parseJsontoTagData(rightv, tags, NULL);
|
||||
STag* row = NULL;
|
||||
tTagNew(tags, 1, true, &row);
|
||||
parseJsontoTagData(rightv, tags, &row, NULL);
|
||||
|
||||
const int32_t len = 9;
|
||||
const int32_t len1 = 4;
|
||||
|
|
Loading…
Reference in New Issue