diff --git a/source/client/inc/clientSml.h b/source/client/inc/clientSml.h index 311260e3fb1eec8b6a1118bb88cf3180ba5e68de..3dcba673bfa843823561e565ddbe58586d82b774 100644 --- a/source/client/inc/clientSml.h +++ b/source/client/inc/clientSml.h @@ -99,6 +99,7 @@ typedef struct { char *tags; char *cols; char *timestamp; + char *measureTag; int32_t measureLen; int32_t measureTagsLen; @@ -114,7 +115,7 @@ typedef struct { int32_t sTableNameLen; char childTableName[TSDB_TABLE_NAME_LEN]; uint64_t uid; - void *key; // for openTsdb +// void *key; // for openTsdb SArray *tags; @@ -166,8 +167,8 @@ typedef struct { int32_t ttl; int32_t uid; // used for automatic create child table - NodeList *childTables; - NodeList *superTables; + SHashObj *childTables; + SHashObj *superTables; SHashObj *pVgHash; STscObj *taos; diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index e21fcd64b8bf33bfa474e44d618813b12bc5f25d..db8cdccbf64728e6470b7c79be25edf7d8b4fd8b 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -759,13 +759,13 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { conn.requestObjRefId = info->pRequest->self; conn.mgmtEps = getEpSet_s(&info->taos->pAppInfo->mgmtEp); - NodeList *tmp = info->superTables; + SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL); while (tmp) { - SSmlSTableMeta *sTableData = (SSmlSTableMeta *)tmp->data.value; + SSmlSTableMeta *sTableData = *tmp; bool needCheckMeta = false; // for multi thread - size_t superTableLen = (size_t)tmp->data.keyLen; - const void *superTable = tmp->data.key; + size_t superTableLen = 0; + void *superTable = taosHashGetKey(tmp, &superTableLen); memset(pName.tname, 0, TSDB_TABLE_NAME_LEN); memcpy(pName.tname, superTable, superTableLen); @@ -914,7 +914,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle *info) { sTableData->tableMeta = pTableMeta; - tmp = tmp->next; + tmp = (SSmlSTableMeta **)taosHashIterate(info->superTables, tmp); } return 0; @@ -1017,11 +1017,11 @@ void smlDestroyTableInfo(SSmlHandle *info, SSmlTableInfo *tag) { taosHashCleanup(kvHash); } - if (info->parseJsonByLib) { - SSmlLineInfo *key = (SSmlLineInfo *)(tag->key); - if (key != NULL) taosMemoryFree(key->tags); - } - taosMemoryFree(tag->key); +// if (info->parseJsonByLib) { +// SSmlLineInfo *key = (SSmlLineInfo *)(tag->key); +// if (key != NULL) taosMemoryFree(key->tags); +// } +// taosMemoryFree(tag->key); taosArrayDestroy(tag->cols); taosArrayDestroy(tag->tags); taosMemoryFree(tag); @@ -1042,29 +1042,23 @@ void smlDestroyInfo(SSmlHandle *info) { qDestroyQuery(info->pQuery); // destroy info->childTables - NodeList *tmp = info->childTables; - while (tmp) { - if (tmp->data.used) { - smlDestroyTableInfo(info, (SSmlTableInfo *)tmp->data.value); - } - NodeList *t = tmp->next; - taosMemoryFree(tmp); - tmp = t; + SSmlTableInfo **oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL); + while (oneTable) { + smlDestroyTableInfo(info, *oneTable); + oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable); } // destroy info->superTables - tmp = info->superTables; - while (tmp) { - if (tmp->data.used) { - smlDestroySTableMeta((SSmlSTableMeta *)tmp->data.value); - } - NodeList *t = tmp->next; - taosMemoryFree(tmp); - tmp = t; + SSmlSTableMeta **oneSTable = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL); + while (oneSTable) { + smlDestroySTableMeta(*oneSTable); + oneSTable = (SSmlSTableMeta **)taosHashIterate(info->superTables, oneSTable); } // destroy info->pVgHash taosHashCleanup(info->pVgHash); + taosHashCleanup(info->childTables); + taosHashCleanup(info->superTables); for (int i = 0; i < taosArrayGetSize(info->tagJsonArray); i++) { cJSON *tags = (cJSON *)taosArrayGetP(info->tagJsonArray, i); @@ -1088,6 +1082,8 @@ void smlDestroyInfo(SSmlHandle *info) { if (info->parseJsonByLib) { taosMemoryFree(info->lines[i].tags); } + if(info->lines[i].measureTagsLen != 0) + taosMemoryFree(info->lines[i].measureTag); } taosMemoryFree(info->lines); } @@ -1112,6 +1108,9 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) { } info->pVgHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + info->childTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + info->superTables = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + info->id = smlGenId(); info->pQuery = smlInitHandle(); info->dataFormat = true; @@ -1122,7 +1121,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) { info->maxTagKVs = taosArrayInit(8, sizeof(SSmlKv)); info->preLineColKV = taosArrayInit(8, sizeof(SSmlKv)); - if (NULL == info->pVgHash) { + if (NULL == info->pVgHash || NULL == info->childTables || NULL == info->superTables) { uError("create SSmlHandle failed"); goto cleanup; } @@ -1156,11 +1155,11 @@ static int32_t smlParseLineBottom(SSmlHandle *info) { SSmlLineInfo *elements = info->lines + i; SSmlTableInfo *tinfo = NULL; if (info->protocol == TSDB_SML_LINE_PROTOCOL) { - tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements->measure, elements->measureTagsLen, NULL); + tinfo = *(SSmlTableInfo **)taosHashGet(info->childTables, elements->measure, elements->measureTagsLen); } else if (info->protocol == TSDB_SML_TELNET_PROTOCOL) { - tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet); + tinfo = *(SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureLen + elements->tagsLen); } else { - tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet); + tinfo = *(SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureLen + elements->tagsLen); } if (tinfo == NULL) { @@ -1184,12 +1183,12 @@ static int32_t smlParseLineBottom(SSmlHandle *info) { return ret; } - SSmlSTableMeta *tableMeta = - (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL); + SSmlSTableMeta **tableMeta = + (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen); if (tableMeta) { // update meta - ret = smlUpdateMeta(tableMeta->colHash, tableMeta->cols, elements->colArray, false, &info->msgBuf); + ret = smlUpdateMeta((*tableMeta)->colHash, (*tableMeta)->cols, elements->colArray, false, &info->msgBuf); if (ret == TSDB_CODE_SUCCESS) { - ret = smlUpdateMeta(tableMeta->tagHash, tableMeta->tags, tinfo->tags, true, &info->msgBuf); + ret = smlUpdateMeta((*tableMeta)->tagHash, (*tableMeta)->tags, tinfo->tags, true, &info->msgBuf); } if (ret != TSDB_CODE_SUCCESS) { uError("SML:0x%" PRIx64 " smlUpdateMeta failed", info->id); @@ -1205,7 +1204,7 @@ static int32_t smlParseLineBottom(SSmlHandle *info) { SSmlSTableMeta *meta = smlBuildSTableMeta(info->dataFormat); smlInsertMeta(meta->tagHash, meta->tags, tinfo->tags); smlInsertMeta(meta->colHash, meta->cols, elements->colArray); - nodeListSet(&info->superTables, elements->measure, elements->measureLen, meta, NULL); + taosHashPut(info->superTables, elements->measure, elements->measureLen, &meta, POINTER_BYTES); } } @@ -1215,9 +1214,9 @@ static int32_t smlParseLineBottom(SSmlHandle *info) { static int32_t smlInsertData(SSmlHandle *info) { int32_t code = TSDB_CODE_SUCCESS; - NodeList *tmp = info->childTables; - while (tmp) { - SSmlTableInfo *tableData = (SSmlTableInfo *)tmp->data.value; + SSmlTableInfo **oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL); + while (oneTable) { + SSmlTableInfo *tableData = *oneTable; SName pName = {TSDB_TABLE_NAME_T, info->taos->acctId, {0}, {0}}; tstrncpy(pName.dbname, info->pRequest->pDb, sizeof(pName.dbname)); @@ -1237,25 +1236,25 @@ static int32_t smlInsertData(SSmlHandle *info) { } taosHashPut(info->pVgHash, (const char *)&vg.vgId, sizeof(vg.vgId), (char *)&vg, sizeof(vg)); - SSmlSTableMeta *pMeta = - (SSmlSTableMeta *)nodeListGet(info->superTables, tableData->sTableName, tableData->sTableNameLen, NULL); - if (unlikely(NULL == pMeta || NULL == pMeta->tableMeta)) { + SSmlSTableMeta **pMeta = + (SSmlSTableMeta **)taosHashGet(info->superTables, tableData->sTableName, tableData->sTableNameLen); + if (unlikely(NULL == pMeta || NULL == (*pMeta)->tableMeta)) { uError("SML:0x%" PRIx64 " NULL == pMeta. table name: %s", info->id, tableData->childTableName); return TSDB_CODE_SML_INTERNAL_ERROR; } // use tablemeta of stable to save vgid and uid of child table - pMeta->tableMeta->vgId = vg.vgId; - pMeta->tableMeta->uid = tableData->uid; // one table merge data block together according uid + (*pMeta)->tableMeta->vgId = vg.vgId; + (*pMeta)->tableMeta->uid = tableData->uid; // one table merge data block together according uid - code = smlBindData(info->pQuery, info->dataFormat, tableData->tags, pMeta->cols, tableData->cols, pMeta->tableMeta, + code = smlBindData(info->pQuery, info->dataFormat, tableData->tags, (*pMeta)->cols, tableData->cols, (*pMeta)->tableMeta, tableData->childTableName, tableData->sTableName, tableData->sTableNameLen, info->ttl, info->msgBuf.buf, info->msgBuf.len); if (code != TSDB_CODE_SUCCESS) { uError("SML:0x%" PRIx64 " smlBindData failed", info->id); return code; } - tmp = tmp->next; + oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable); } code = smlBuildOutput(info->pQuery, info->pVgHash); @@ -1288,25 +1287,22 @@ static void smlPrintStatisticInfo(SSmlHandle *info) { int32_t smlClearForRerun(SSmlHandle *info) { info->reRun = false; // clear info->childTables - NodeList *pList = info->childTables; - while (pList) { - if (pList->data.used) { - smlDestroyTableInfo(info, (SSmlTableInfo *)pList->data.value); - pList->data.used = false; - } - pList = pList->next; + SSmlTableInfo **oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, NULL); + while (oneTable) { + smlDestroyTableInfo(info, *oneTable); + oneTable = (SSmlTableInfo **)taosHashIterate(info->childTables, oneTable); } // clear info->superTables - pList = info->superTables; - while (pList) { - if (pList->data.used) { - smlDestroySTableMeta((SSmlSTableMeta *)pList->data.value); - pList->data.used = false; - } - pList = pList->next; + SSmlSTableMeta **oneSTable = (SSmlSTableMeta **)taosHashIterate(info->superTables, NULL); + while (oneSTable) { + smlDestroySTableMeta(*oneSTable); + oneSTable = (SSmlSTableMeta **)taosHashIterate(info->superTables, oneSTable); } + taosHashClear(info->childTables); + taosHashClear(info->superTables); + if (!info->dataFormat) { if (unlikely(info->lines != NULL)) { uError("SML:0x%" PRIx64 " info->lines != NULL", info->id); @@ -1375,6 +1371,7 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char *rawLine, char if (info->dataFormat) { SSmlLineInfo element = {0}; code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, &element); + if(element.measureTagsLen != 0) taosMemoryFree(element.measureTag); } else { code = smlParseTelnetString(info, (char *)tmp, (char *)tmp + len, info->lines + i); } @@ -1418,15 +1415,15 @@ static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawL } info->cost.lineNum = info->lineNum; - info->cost.numOfSTables = nodeListSize(info->superTables); - info->cost.numOfCTables = nodeListSize(info->childTables); + info->cost.numOfSTables = taosHashGetSize(info->superTables); + info->cost.numOfCTables = taosHashGetSize(info->childTables); info->cost.schemaTime = taosGetTimestampUs(); do { code = smlModifyDBSchemas(info); if (code == 0) break; - } while (retryNum++ < nodeListSize(info->superTables) * MAX_RETRY_TIMES); + } while (retryNum++ < taosHashGetSize(info->superTables) * MAX_RETRY_TIMES); if (code != 0) { uError("SML:0x%" PRIx64 " smlModifyDBSchemas error : %s", info->id, tstrerror(code)); @@ -1504,7 +1501,7 @@ TAOS_RES *taos_schemaless_insert_inner(TAOS *taos, char *lines[], char *rawLine, request->code = code; info->cost.endTime = taosGetTimestampUs(); info->cost.code = code; - // smlPrintStatisticInfo(info); + smlPrintStatisticInfo(info); end: smlDestroyInfo(info); diff --git a/source/client/src/clientSmlJson.c b/source/client/src/clientSmlJson.c index 228f8d40f3a810e820aae2b589e78b0e61941f08..a437fd238c11471ed465b2d7ab4049a0f284e5a8 100644 --- a/source/client/src/clientSmlJson.c +++ b/source/client/src/clientSmlJson.c @@ -694,9 +694,9 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo SArray *superKV = NULL; if(info->dataFormat){ if(unlikely(!isSameMeasure)){ - SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL); - - if(unlikely(sMeta == NULL)){ + SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen); + SSmlSTableMeta *sMeta = NULL; + if(unlikely(tmp == NULL)){ STableMeta * pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen); if(pTableMeta == NULL){ info->dataFormat = false; @@ -705,10 +705,11 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo } sMeta = smlBuildSTableMeta(info->dataFormat); sMeta->tableMeta = pTableMeta; - nodeListSet(&info->superTables, elements->measure, elements->measureLen, sMeta, NULL); + taosHashPut(info->superTables, elements->measure, elements->measureLen, &sMeta, POINTER_BYTES); + tmp = &sMeta; } - info->currSTableMeta = sMeta->tableMeta; - superKV = sMeta->tags; + info->currSTableMeta = (*tmp)->tableMeta; + superKV = (*tmp)->tags; if(unlikely(taosArrayGetSize(superKV) == 0)){ isSuperKVInit = false; @@ -761,13 +762,13 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo SSmlKv *maxKV = (SSmlKv *)taosArrayGet(maxKVs, cnt); if(unlikely(kv.length > maxKV->length)){ maxKV->length = kv.length; - SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL); + SSmlSTableMeta **tableMeta = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen); if(unlikely(NULL == tableMeta)){ uError("SML:0x%" PRIx64 " NULL == tableMeta", info->id); return TSDB_CODE_SML_INTERNAL_ERROR; } - SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->tags, cnt); + SSmlKv *oldKV = (SSmlKv *)taosArrayGet((*tableMeta)->tags, cnt); oldKV->length = kv.length; info->needModifySchema = true; } @@ -808,8 +809,14 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo cnt++; } - SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet); - if (unlikely(tinfo == NULL)) { + elements->measureTag = (char*)taosMemoryMalloc(elements->measureLen + elements->tagsLen); + memcpy(elements->measureTag, elements->measure, elements->measureLen); + memcpy(elements->measureTag + elements->measureLen, elements->tags, elements->tagsLen); + elements->measureTagsLen = elements->measureLen + elements->tagsLen; + + SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureLen + elements->tagsLen); + SSmlTableInfo *tinfo = NULL; + if (unlikely(tmp == NULL)) { tinfo = smlBuildTableInfo(1, elements->measure, elements->measureLen); if (unlikely(!tinfo)) { return TSDB_CODE_OUT_OF_MEMORY; @@ -828,17 +835,18 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo } } - SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo)); - *key = *elements; - if(info->parseJsonByLib){ - key->tags = taosMemoryMalloc(elements->tagsLen + 1); - memcpy(key->tags, elements->tags, elements->tagsLen); - key->tags[elements->tagsLen] = 0; - } - tinfo->key = key; - nodeListSet(&info->childTables, key, POINTER_BYTES, tinfo, is_same_child_table_telnet); +// SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo)); +// *key = *elements; +// if(info->parseJsonByLib){ +// key->tags = taosMemoryMalloc(elements->tagsLen + 1); +// memcpy(key->tags, elements->tags, elements->tagsLen); +// key->tags[elements->tagsLen] = 0; +// } +// tinfo->key = key; + taosHashPut(info->childTables, elements->measureTag, elements->measureLen + elements->tagsLen, &tinfo, POINTER_BYTES); + tmp = &tinfo; } - if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx; + if (info->dataFormat) info->currTableDataCtx = (*tmp)->tableDataCtx; return ret; } @@ -1011,6 +1019,8 @@ static int32_t smlParseJSONStringExt(SSmlHandle *info, cJSON *root, SSmlLineInfo elements->tags = NULL; return ret; } + }else{ + elements->measureTag = info->preLine.measureTag; } if(needFree){ @@ -1189,6 +1199,8 @@ static int32_t smlParseJSONString(SSmlHandle *info, char **start, SSmlLineInfo * uError("OTD:0x%" PRIx64 " Unable to parse tags from JSON payload", info->id); return ret; } + }else{ + elements->measureTag = info->preLine.measureTag; } if(unlikely(info->reRun)){ @@ -1259,7 +1271,7 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) { if(info->dataFormat) { SSmlLineInfo element = {0}; ret = smlParseJSONString(info, &dataPointStart, &element); - if(element.measure == NULL) break; + if(element.measureTagsLen != 0) taosMemoryFree(element.measureTag); }else{ if(cnt >= payloadNum){ payloadNum = payloadNum << 1; diff --git a/source/client/src/clientSmlLine.c b/source/client/src/clientSmlLine.c index 890245f53d5f7cbf52613ca7804da3c43e9543f8..e1fd8c2a81724ffae00ee045b57797274d02d70e 100644 --- a/source/client/src/clientSmlLine.c +++ b/source/client/src/clientSmlLine.c @@ -148,9 +148,9 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SArray *superKV = NULL; if(info->dataFormat){ if(unlikely(!isSameMeasure)){ - SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL); - - if(unlikely(sMeta == NULL)){ + SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen); + SSmlSTableMeta *sMeta = NULL; + if(unlikely(tmp == NULL)){ STableMeta * pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen); if(pTableMeta == NULL){ info->dataFormat = false; @@ -159,10 +159,11 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, } sMeta = smlBuildSTableMeta(info->dataFormat); sMeta->tableMeta = pTableMeta; - nodeListSet(&info->superTables, currElement->measure, currElement->measureLen, sMeta, NULL); + taosHashPut(info->superTables, currElement->measure, currElement->measureLen, &sMeta, POINTER_BYTES); + tmp = &sMeta; } - info->currSTableMeta = sMeta->tableMeta; - superKV = sMeta->tags; + info->currSTableMeta = (*tmp)->tableMeta; + superKV = (*tmp)->tags; if(unlikely(taosArrayGetSize(superKV) == 0)){ isSuperKVInit = false; @@ -258,13 +259,13 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlKv *maxKV = (SSmlKv *)taosArrayGet(maxKVs, cnt); if(unlikely(kv.length > maxKV->length)){ maxKV->length = kv.length; - SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL); + SSmlSTableMeta **tableMeta = (SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen); if(unlikely(NULL == tableMeta)){ uError("SML:0x%" PRIx64 " NULL == tableMeta", info->id); return TSDB_CODE_SML_INTERNAL_ERROR; } - SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->tags, cnt); + SSmlKv *oldKV = (SSmlKv *)taosArrayGet((*tableMeta)->tags, cnt); oldKV->length = kv.length; info->needModifySchema = true; } @@ -310,7 +311,7 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, (*sql)++; } - void* oneTable = nodeListGet(info->childTables, currElement->measure, currElement->measureTagsLen, NULL); + void* oneTable = taosHashGet(info->childTables, currElement->measure, currElement->measureTagsLen); if ((oneTable != NULL)) { return TSDB_CODE_SUCCESS; } @@ -332,7 +333,7 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, } } - nodeListSet(&info->childTables, currElement->measure, currElement->measureTagsLen, tinfo, NULL); + taosHashPut(info->childTables, currElement->measure, currElement->measureTagsLen, &tinfo, POINTER_BYTES); return TSDB_CODE_SUCCESS; } @@ -345,18 +346,18 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, SArray *superKV = NULL; if(info->dataFormat){ if(unlikely(!isSameCTable)){ - SSmlTableInfo *oneTable = (SSmlTableInfo *)nodeListGet(info->childTables, currElement->measure, currElement->measureTagsLen, NULL); + SSmlTableInfo **oneTable = (SSmlTableInfo **)taosHashGet(info->childTables, currElement->measure, currElement->measureTagsLen); if (unlikely(oneTable == NULL)) { smlBuildInvalidDataMsg(&info->msgBuf, "child table should inside", currElement->measure); return TSDB_CODE_SML_INVALID_DATA; } - info->currTableDataCtx = oneTable->tableDataCtx; + info->currTableDataCtx = (*oneTable)->tableDataCtx; } if(unlikely(!isSameMeasure)){ - SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL); - - if(unlikely(sMeta == NULL)){ + SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen); + SSmlSTableMeta *sMeta = NULL; + if(unlikely(tmp == NULL)){ STableMeta * pTableMeta = smlGetMeta(info, currElement->measure, currElement->measureLen); if(pTableMeta == NULL){ info->dataFormat = false; @@ -365,10 +366,11 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, } sMeta = smlBuildSTableMeta(info->dataFormat); sMeta->tableMeta = pTableMeta; - nodeListSet(&info->superTables, currElement->measure, currElement->measureLen, sMeta, NULL); + taosHashPut(info->superTables, currElement->measure, currElement->measureLen, &sMeta, POINTER_BYTES); + tmp = &sMeta; } - info->currSTableMeta = sMeta->tableMeta; - superKV = sMeta->cols; + info->currSTableMeta = (*tmp)->tableMeta; + superKV = (*tmp)->cols; if(unlikely(taosArrayGetSize(superKV) == 0)){ isSuperKVInit = false; } @@ -487,13 +489,13 @@ static int32_t smlParseColKv(SSmlHandle *info, char **sql, char *sqlEnd, if(unlikely(IS_VAR_DATA_TYPE(kv.type) && kv.length > maxKV->length)){ maxKV->length = kv.length; - SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, currElement->measure, currElement->measureLen, NULL); + SSmlSTableMeta **tableMeta = (SSmlSTableMeta **)taosHashGet(info->superTables, currElement->measure, currElement->measureLen); if(unlikely(NULL == tableMeta)){ uError("SML:0x%" PRIx64 " NULL == tableMeta", info->id); return TSDB_CODE_SML_INTERNAL_ERROR; } - SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->cols, cnt); + SSmlKv *oldKV = (SSmlKv *)taosArrayGet((*tableMeta)->cols, cnt); oldKV->length = kv.length; info->needModifySchema = true; } diff --git a/source/client/src/clientSmlTelnet.c b/source/client/src/clientSmlTelnet.c index d43ab6c9f97ca7d1c4523f03ff2bb9c73556fc4b..7f669ffead9cb2545809776f6100a8d1a83bdb51 100644 --- a/source/client/src/clientSmlTelnet.c +++ b/source/client/src/clientSmlTelnet.c @@ -71,6 +71,7 @@ static void smlParseTelnetElement(char **sql, char *sqlEnd, char **data, int32_t static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SSmlLineInfo *elements, SSmlMsgBuf *msg) { if(is_same_child_table_telnet(elements, &info->preLine) == 0){ + elements->measureTag = info->preLine.measureTag; return TSDB_CODE_SUCCESS; } @@ -83,9 +84,9 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS SArray *superKV = NULL; if(info->dataFormat){ if(!isSameMeasure){ - SSmlSTableMeta *sMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL); - - if(unlikely(sMeta == NULL)){ + SSmlSTableMeta **tmp = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen); + SSmlSTableMeta *sMeta = NULL; + if(unlikely(tmp == NULL)){ STableMeta * pTableMeta = smlGetMeta(info, elements->measure, elements->measureLen); if(pTableMeta == NULL){ info->dataFormat = false; @@ -94,10 +95,11 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS } sMeta = smlBuildSTableMeta(info->dataFormat); sMeta->tableMeta = pTableMeta; - nodeListSet(&info->superTables, elements->measure, elements->measureLen, sMeta, NULL); + taosHashPut(info->superTables, elements->measure, elements->measureLen, &sMeta, POINTER_BYTES); + tmp = &sMeta; } - info->currSTableMeta = sMeta->tableMeta; - superKV = sMeta->tags; + info->currSTableMeta = (*tmp)->tableMeta; + superKV = (*tmp)->tags; if(unlikely(taosArrayGetSize(superKV) == 0)){ isSuperKVInit = false; @@ -183,13 +185,13 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS SSmlKv *maxKV = (SSmlKv *)taosArrayGet(maxKVs, cnt); if(unlikely(kv.length > maxKV->length)){ maxKV->length = kv.length; - SSmlSTableMeta *tableMeta = (SSmlSTableMeta *)nodeListGet(info->superTables, elements->measure, elements->measureLen, NULL); + SSmlSTableMeta **tableMeta = (SSmlSTableMeta **)taosHashGet(info->superTables, elements->measure, elements->measureLen); if(unlikely(NULL == tableMeta)){ uError("SML:0x%" PRIx64 " NULL == tableMeta", info->id); return TSDB_CODE_SML_INTERNAL_ERROR; } - SSmlKv *oldKV = (SSmlKv *)taosArrayGet(tableMeta->tags, cnt); + SSmlKv *oldKV = (SSmlKv *)taosArrayGet((*tableMeta)->tags, cnt); oldKV->length = kv.length; info->needModifySchema = true; } @@ -229,8 +231,15 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS taosArrayPush(preLineKV, &kv); cnt++; } - SSmlTableInfo *tinfo = (SSmlTableInfo *)nodeListGet(info->childTables, elements, POINTER_BYTES, is_same_child_table_telnet); - if (unlikely(tinfo == NULL)) { + + elements->measureTag = (char*)taosMemoryMalloc(elements->measureLen + elements->tagsLen); + memcpy(elements->measureTag, elements->measure, elements->measureLen); + memcpy(elements->measureTag + elements->measureLen, elements->tags, elements->tagsLen); + elements->measureTagsLen = elements->measureLen + elements->tagsLen; + + SSmlTableInfo **tmp = (SSmlTableInfo **)taosHashGet(info->childTables, elements->measureTag, elements->measureLen + elements->tagsLen); + SSmlTableInfo *tinfo = NULL; + if (unlikely(tmp == NULL)) { tinfo = smlBuildTableInfo(1, elements->measure, elements->measureLen); if (!tinfo) { return TSDB_CODE_OUT_OF_MEMORY; @@ -249,12 +258,13 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS } } - SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo)); - *key = *elements; - tinfo->key = key; - nodeListSet(&info->childTables, key, POINTER_BYTES, tinfo, is_same_child_table_telnet); +// SSmlLineInfo *key = (SSmlLineInfo *)taosMemoryMalloc(sizeof(SSmlLineInfo)); +// *key = *elements; +// tinfo->key = key; + taosHashPut(info->childTables, elements->measureTag, elements->measureLen + elements->tagsLen, &tinfo, POINTER_BYTES); + tmp = &tinfo; } - if (info->dataFormat) info->currTableDataCtx = tinfo->tableDataCtx; + if (info->dataFormat) info->currTableDataCtx = (*tmp)->tableDataCtx; return TSDB_CODE_SUCCESS; }