refactor: add json tag function for sql parser

This commit is contained in:
wangmm0220 2022-04-14 19:01:11 +08:00
parent 93cbee6970
commit 8072523561
2 changed files with 5 additions and 4 deletions

View File

@ -738,7 +738,7 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void *value, int32_t len, voi
} }
varDataSetLen(pa->buf, output); varDataSetLen(pa->buf, output);
tdAddColToKVRow(pa->builder, colId, varDataTLen(pa->buf)); tdAddColToKVRow(pa->builder, colId, pa->buf, varDataTLen(pa->buf));
} else { } else {
tdAddColToKVRow(pa->builder, colId, value, TYPE_BYTES[type]); tdAddColToKVRow(pa->builder, colId, value, TYPE_BYTES[type]);
} }

View File

@ -242,6 +242,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) {
j++; j++;
} }
dst[j] = '\0'; dst[j] = '\0';
strtrim(dst);
return j; return j;
} }
@ -259,7 +260,7 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
uint8_t jsonNULL = TSDB_JSON_NULL; uint8_t jsonNULL = TSDB_JSON_NULL;
int jsonIndex = startColId + 1; int jsonIndex = startColId + 1;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonKeyNULL, CHAR_BYTES); // add json null type tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonKeyNULL, CHAR_BYTES); // add json null type
if (!json || strtrim(json) == 0 || strncasecmp(json, "null", 4) == 0){ if (!json || strcasecmp(json, TSDB_DATA_NULL_STR_L) == 0){
tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNULL, CHAR_BYTES); // add json null value tdAddColToKVRow(kvRowBuilder, jsonIndex++, &jsonNULL, CHAR_BYTES); // add json null value
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -281,13 +282,13 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
cJSON* item = cJSON_GetArrayItem(root, i); cJSON* item = cJSON_GetArrayItem(root, i);
if (!item) { if (!item) {
qError("json inner error:%d", i); qError("json inner error:%d", i);
return buildSyntaxErrMsg(pMsgBuf, "json inner error", json); retCode = buildSyntaxErrMsg(pMsgBuf, "json inner error", json);
goto end; goto end;
} }
char *jsonKey = item->string; char *jsonKey = item->string;
if(!isValidateTag(jsonKey)){ if(!isValidateTag(jsonKey)){
retCode = buildSyntaxErrMsg(pMsgBuf, "json key not validate", jsonKey); retCode = buildSyntaxErrMsg(pMsgBuf, "json key not validate", jsonKey);
goto end; goto end;
} }
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){ // if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){