From 9c1813dca7c3d1fda4314a70486fef0683e8544d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 30 Aug 2021 16:08:08 +0800 Subject: [PATCH] [TD-6442]: Support OpenTSDB telnet style data import format --- src/client/inc/tscParseLine.h | 2 -- src/client/src/tscParseOpenTSDB.c | 28 +++++++++++++++++----------- src/inc/taos.h | 2 ++ tests/examples/c/CMakeLists.txt | 2 ++ 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/client/inc/tscParseLine.h b/src/client/inc/tscParseLine.h index 28e5362932..401dcafdfb 100644 --- a/src/client/inc/tscParseLine.h +++ b/src/client/inc/tscParseLine.h @@ -53,13 +53,11 @@ typedef struct { } SSmlLinesInfo; int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info); -int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint); bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info); int32_t isValidChildTableName(const char *pTbName, int16_t len); bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, uint16_t len, SSmlLinesInfo* info); - int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, uint16_t len, SSmlLinesInfo* info); diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index c4e175a0bc..e87fe78b1d 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -11,8 +11,8 @@ #include "tscLog.h" #include "tscParseLine.h" -//========================================================================= -// telnet style API parser + +/* telnet style API parser */ static uint64_t HandleId = 0; uint64_t genUID() { @@ -221,6 +221,7 @@ static bool parseTelnetTagValue(TAOS_SML_KV *pKV, const char **index, } free(value); + *index = (*cur == '\0') ? cur : cur + 1; return TSDB_CODE_SUCCESS; } @@ -266,19 +267,16 @@ static int32_t parseTelnetTagKvs(TAOS_SML_KV **pKVs, int *num_kvs, } //reallocate addtional memory for more kvs - TAOS_SML_KV *more_kvs = NULL; - if ((*num_kvs + 1) > capacity) { + TAOS_SML_KV *more_kvs = NULL; capacity *= 3; capacity /= 2; more_kvs = realloc(*pKVs, capacity * sizeof(TAOS_SML_KV)); - } else { - more_kvs = *pKVs; + if (!more_kvs) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + *pKVs = more_kvs; } - if (!more_kvs) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - *pKVs = more_kvs; //move pKV points to next TAOS_SML_KV block pkv = *pKVs + *num_kvs; } @@ -316,7 +314,7 @@ int32_t tscParseTelnetLine(const char* line, TAOS_SML_DATA_POINT* smlData, SSmlL //Parse tagKVs SHashObj *keyHashTable = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); - ret = parseTelnetTagKvs(&smlData->fields, &smlData->fieldNum, &index, smlData->childTableName, keyHashTable, info); + ret = parseTelnetTagKvs(&smlData->tags, &smlData->tagNum, &index, smlData->childTableName, keyHashTable, info); if (ret) { tscError("SML:0x%"PRIx64" Unable to parse tags", info->id); taosHashCleanup(keyHashTable); @@ -401,3 +399,11 @@ cleanup: free(info); return code; } + +int taos_telnet_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { + SSmlLinesInfo* info = calloc(1, sizeof(SSmlLinesInfo)); + info->id = genUID(); + int code = tscSmlInsert(taos, points, numPoint, info); + free(info); + return code; +} diff --git a/src/inc/taos.h b/src/inc/taos.h index 6fa30737e7..a71e4bf50c 100644 --- a/src/inc/taos.h +++ b/src/inc/taos.h @@ -172,6 +172,8 @@ DLL_EXPORT int taos_load_table_info(TAOS *taos, const char* tableNameList); DLL_EXPORT int taos_insert_lines(TAOS* taos, char* lines[], int numLines); +DLL_EXPORT int taos_insert_telnet_lines(TAOS* taos, char* lines[], int numLines); + #ifdef __cplusplus } #endif diff --git a/tests/examples/c/CMakeLists.txt b/tests/examples/c/CMakeLists.txt index e94de3cbca..8421995980 100644 --- a/tests/examples/c/CMakeLists.txt +++ b/tests/examples/c/CMakeLists.txt @@ -11,6 +11,8 @@ IF (TD_LINUX) TARGET_LINK_LIBRARIES(subscribe taos_static trpc tutil pthread ) ADD_EXECUTABLE(epoll epoll.c) TARGET_LINK_LIBRARIES(epoll taos_static trpc tutil pthread lua) + ADD_EXECUTABLE(opentsdb opentsdb.c) + TARGET_LINK_LIBRARIES(opentsdb taos_static trpc tutil pthread lua) ENDIF () IF (TD_DARWIN) INCLUDE_DIRECTORIES(. ${TD_COMMUNITY_DIR}/src/inc ${TD_COMMUNITY_DIR}/src/client/inc ${TD_COMMUNITY_DIR}/inc) -- GitLab