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

TD-6129<feature> fix json encode error

上级 c93306a8
...@@ -5272,7 +5272,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in ...@@ -5272,7 +5272,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
if(item->type == cJSON_String){ // add json value format: type|data if(item->type == cJSON_String){ // add json value format: type|data
output = 0; output = 0;
*tagVal = item->type; // type *tagVal = item->type; // type
char* tagData = tagVal + CHAR_BYTES; char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES);
if (!taosMbsToUcs4(item->valuestring, strlen(item->valuestring), varDataVal(tagData), TSDB_MAX_TAGS_LEN - VARSTR_HEADER_SIZE, &output)) { if (!taosMbsToUcs4(item->valuestring, strlen(item->valuestring), varDataVal(tagData), TSDB_MAX_TAGS_LEN - VARSTR_HEADER_SIZE, &output)) {
tscError("json string error:%s|%s", strerror(errno), item->string); tscError("json string error:%s|%s", strerror(errno), item->string);
retCode = tscSQLSyntaxErrMsg(errMsg, "serizelize json error", NULL); retCode = tscSQLSyntaxErrMsg(errMsg, "serizelize json error", NULL);
...@@ -5283,7 +5283,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in ...@@ -5283,7 +5283,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal, true); tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal, true);
}else if(item->type == cJSON_Number){ }else if(item->type == cJSON_Number){
*tagVal = item->type; // type *tagVal = item->type; // type
char* tagData = tagVal + CHAR_BYTES; char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES);
*((double *)tagData) = item->valuedouble; *((double *)tagData) = item->valuedouble;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_BIGINT, tagVal, true); tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_BIGINT, tagVal, true);
}else{ }else{
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#pragma pack (push,1) #pragma pack (push,1)
typedef struct jsonMapValue{ typedef struct jsonMapValue{
uint64_t uid; // the unique table ID void* table; // STable *
int16_t colId; // the json col ID. int16_t colId; // the json col ID.
}JsonMapValue; }JsonMapValue;
...@@ -97,6 +97,7 @@ int16_t tsdbGetLastColumnsIndexByColId(STable* pTable, int16_t colId); ...@@ -97,6 +97,7 @@ int16_t tsdbGetLastColumnsIndexByColId(STable* pTable, int16_t colId);
int tsdbUpdateLastColSchema(STable *pTable, STSchema *pNewSchema); int tsdbUpdateLastColSchema(STable *pTable, STSchema *pNewSchema);
STSchema* tsdbGetTableLatestSchema(STable *pTable); STSchema* tsdbGetTableLatestSchema(STable *pTable);
void tsdbFreeLastColumns(STable* pTable); void tsdbFreeLastColumns(STable* pTable);
int tscCompareJsonMapValue(const void* a, const void* b);
static FORCE_INLINE int tsdbCompareSchemaVersion(const void *key1, const void *key2) { static FORCE_INLINE int tsdbCompareSchemaVersion(const void *key1, const void *key2) {
if (*(int16_t *)key1 < schemaVersion(*(STSchema **)key2)) { if (*(int16_t *)key1 < schemaVersion(*(STSchema **)key2)) {
......
...@@ -1083,11 +1083,11 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro ...@@ -1083,11 +1083,11 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro
tsdbUnRefTable(pTable); tsdbUnRefTable(pTable);
} }
static int tscCompareJsonMapValue(const void* a, const void* b) { int tscCompareJsonMapValue(const void* a, const void* b) {
const JsonMapValue* x = (const JsonMapValue*)a; const JsonMapValue* x = (const JsonMapValue*)a;
const JsonMapValue* y = (const JsonMapValue*)b; const JsonMapValue* y = (const JsonMapValue*)b;
if (x->uid > y->uid) return 1; if (x->table > y->table) return 1;
if (x->uid < y->uid) return -1; if (x->table < y->table) return -1;
return 0; return 0;
} }
...@@ -1127,9 +1127,13 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper ...@@ -1127,9 +1127,13 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
} }
tablist = tablistNew; tablist = tablistNew;
} }
JsonMapValue jmvalue = {TABLE_UID(pTable), pColIdx->colId}; JsonMapValue jmvalue = {pTable, pColIdx->colId};
void* p = taosArraySearch(tablist, &jmvalue, tscCompareJsonMapValue, TD_EQ);
if (p == NULL) {
taosArrayPush(tablist, &jmvalue); taosArrayPush(tablist, &jmvalue);
taosArraySort(tablist, tscCompareJsonMapValue); }else{
taosArrayInsert(tablist, TARRAY_ELEM_IDX((SArray*)tablist, p), &jmvalue);
}
} }
}else{ }else{
tSkipListPut(pSTable->pIndex, (void *)pTable); tSkipListPut(pSTable->pIndex, (void *)pTable);
...@@ -1165,7 +1169,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) { ...@@ -1165,7 +1169,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
continue; continue;
} }
JsonMapValue jmvalue = {TABLE_UID(pTable), pColIdx->colId}; JsonMapValue jmvalue = {pTable, pColIdx->colId};
void* p = taosArraySearch(tablist, &jmvalue, tscCompareJsonMapValue, TD_EQ); void* p = taosArraySearch(tablist, &jmvalue, tscCompareJsonMapValue, TD_EQ);
if (p == NULL) { if (p == NULL) {
tsdbError("json tag no tableid error,%d", j); tsdbError("json tag no tableid error,%d", j);
......
...@@ -2676,6 +2676,28 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int ...@@ -2676,6 +2676,28 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
} }
static int32_t getAllTableList(STable* pSuperTable, SArray* list) { static int32_t getAllTableList(STable* pSuperTable, SArray* list) {
STSchema* pTagSchema = tsdbGetTableTagSchema(pSuperTable);
if(pTagSchema->numOfCols == 1 && pTagSchema->columns[0].type == TSDB_DATA_TYPE_JSON){
SArray* pRecord = taosHashIterate(pSuperTable->jsonKeyMap, NULL);
SArray* tablist = taosArrayInit(32, sizeof(JsonMapValue));
while(pRecord){
for (int i = 0; i < taosArrayGetSize(pRecord); ++i) {
void* p = taosArrayGet(pRecord, i);
void* pFind = taosArraySearch(tablist, p, tscCompareJsonMapValue, TD_EQ);
if(pFind == NULL){
taosArrayPush(tablist, p);
}
}
pRecord = taosHashIterate(pSuperTable->jsonKeyMap, pRecord);
}
for (int i = 0; i < taosArrayGetSize(tablist); ++i) {
JsonMapValue* p = taosArrayGet(pRecord, i);
STableKeyInfo info = {.pTable = p->table, .lastKey = TSKEY_INITIAL_VAL};
taosArrayPush(list, &info);
}
taosArrayDestroy(tablist);
}else{
SSkipListIterator* iter = tSkipListCreateIter(pSuperTable->pIndex); SSkipListIterator* iter = tSkipListCreateIter(pSuperTable->pIndex);
while (tSkipListIterNext(iter)) { while (tSkipListIterNext(iter)) {
SSkipListNode* pNode = tSkipListIterGet(iter); SSkipListNode* pNode = tSkipListIterGet(iter);
...@@ -2687,6 +2709,7 @@ static int32_t getAllTableList(STable* pSuperTable, SArray* list) { ...@@ -2687,6 +2709,7 @@ static int32_t getAllTableList(STable* pSuperTable, SArray* list) {
} }
tSkipListDestroyIter(iter); tSkipListDestroyIter(iter);
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -3626,6 +3649,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC ...@@ -3626,6 +3649,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len, int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, const char* pTagCond, size_t len,
STableGroupInfo* pGroupInfo, SColIndex* pColIndex, int32_t numOfCols) { STableGroupInfo* pGroupInfo, SColIndex* pColIndex, int32_t numOfCols) {
SArray* res = NULL;
if (tsdbRLockRepoMeta(tsdb) < 0) goto _error; if (tsdbRLockRepoMeta(tsdb) < 0) goto _error;
STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
...@@ -3647,7 +3671,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons ...@@ -3647,7 +3671,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
} }
//NOTE: not add ref count for super table //NOTE: not add ref count for super table
SArray* res = taosArrayInit(8, sizeof(STableKeyInfo)); res = taosArrayInit(8, sizeof(STableKeyInfo));
STSchema* pTagSchema = tsdbGetTableTagSchema(pTable); STSchema* pTagSchema = tsdbGetTableTagSchema(pTable);
// no tags and tbname condition, all child tables of this stable are involved // no tags and tbname condition, all child tables of this stable are involved
...@@ -3711,6 +3735,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons ...@@ -3711,6 +3735,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
return ret; return ret;
_error: _error:
taosArrayDestroy(res);
return terrno; return terrno;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册