提交 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
if(item->type == cJSON_String){ // add json value format: type|data
output = 0;
*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)) {
tscError("json string error:%s|%s", strerror(errno), item->string);
retCode = tscSQLSyntaxErrMsg(errMsg, "serizelize json error", NULL);
......@@ -5283,7 +5283,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_NCHAR, tagVal, true);
}else if(item->type == cJSON_Number){
*tagVal = item->type; // type
char* tagData = tagVal + CHAR_BYTES;
char* tagData = POINTER_SHIFT(tagVal,CHAR_BYTES);
*((double *)tagData) = item->valuedouble;
tdAddColToKVRow(kvRowBuilder, jsonIndex++, TSDB_DATA_TYPE_BIGINT, tagVal, true);
}else{
......
......@@ -20,7 +20,7 @@
#pragma pack (push,1)
typedef struct jsonMapValue{
uint64_t uid; // the unique table ID
void* table; // STable *
int16_t colId; // the json col ID.
}JsonMapValue;
......@@ -97,6 +97,7 @@ int16_t tsdbGetLastColumnsIndexByColId(STable* pTable, int16_t colId);
int tsdbUpdateLastColSchema(STable *pTable, STSchema *pNewSchema);
STSchema* tsdbGetTableLatestSchema(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) {
if (*(int16_t *)key1 < schemaVersion(*(STSchema **)key2)) {
......
......@@ -1083,11 +1083,11 @@ static void tsdbRemoveTableFromMeta(STsdbRepo *pRepo, STable *pTable, bool rmFro
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* y = (const JsonMapValue*)b;
if (x->uid > y->uid) return 1;
if (x->uid < y->uid) return -1;
if (x->table > y->table) return 1;
if (x->table < y->table) return -1;
return 0;
}
......@@ -1127,9 +1127,13 @@ static int tsdbAddTableIntoIndex(STsdbMeta *pMeta, STable *pTable, bool refSuper
}
tablist = tablistNew;
}
JsonMapValue jmvalue = {TABLE_UID(pTable), pColIdx->colId};
taosArrayPush(tablist, &jmvalue);
taosArraySort(tablist, tscCompareJsonMapValue);
JsonMapValue jmvalue = {pTable, pColIdx->colId};
void* p = taosArraySearch(tablist, &jmvalue, tscCompareJsonMapValue, TD_EQ);
if (p == NULL) {
taosArrayPush(tablist, &jmvalue);
}else{
taosArrayInsert(tablist, TARRAY_ELEM_IDX((SArray*)tablist, p), &jmvalue);
}
}
}else{
tSkipListPut(pSTable->pIndex, (void *)pTable);
......@@ -1165,7 +1169,7 @@ static int tsdbRemoveTableFromIndex(STsdbMeta *pMeta, STable *pTable) {
continue;
}
JsonMapValue jmvalue = {TABLE_UID(pTable), pColIdx->colId};
JsonMapValue jmvalue = {pTable, pColIdx->colId};
void* p = taosArraySearch(tablist, &jmvalue, tscCompareJsonMapValue, TD_EQ);
if (p == NULL) {
tsdbError("json tag no tableid error,%d", j);
......
......@@ -2676,17 +2676,40 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
}
static int32_t getAllTableList(STable* pSuperTable, SArray* list) {
SSkipListIterator* iter = tSkipListCreateIter(pSuperTable->pIndex);
while (tSkipListIterNext(iter)) {
SSkipListNode* pNode = tSkipListIterGet(iter);
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);
while (tSkipListIterNext(iter)) {
SSkipListNode* pNode = tSkipListIterGet(iter);
STable* pTable = (STable*) SL_GET_NODE_DATA((SSkipListNode*) pNode);
STable* pTable = (STable*) SL_GET_NODE_DATA((SSkipListNode*) pNode);
STableKeyInfo info = {.pTable = pTable, .lastKey = TSKEY_INITIAL_VAL};
taosArrayPush(list, &info);
}
STableKeyInfo info = {.pTable = pTable, .lastKey = TSKEY_INITIAL_VAL};
taosArrayPush(list, &info);
}
tSkipListDestroyIter(iter);
tSkipListDestroyIter(iter);
}
return TSDB_CODE_SUCCESS;
}
......@@ -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,
STableGroupInfo* pGroupInfo, SColIndex* pColIndex, int32_t numOfCols) {
SArray* res = NULL;
if (tsdbRLockRepoMeta(tsdb) < 0) goto _error;
STable* pTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid);
......@@ -3647,7 +3671,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
}
//NOTE: not add ref count for super table
SArray* res = taosArrayInit(8, sizeof(STableKeyInfo));
res = taosArrayInit(8, sizeof(STableKeyInfo));
STSchema* pTagSchema = tsdbGetTableTagSchema(pTable);
// 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
return ret;
_error:
taosArrayDestroy(res);
return terrno;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册