提交 d95ec693 编写于 作者: wmmhello's avatar wmmhello

feat:add new logic for new tag format

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