From 48e8c6b0bb614d8edb0ce85b2ef261fd532e6d00 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/src/tscParseOpenTSDB.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index 54d492a622..a1aa86d6c1 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -12,6 +12,8 @@ #include "tscParseLine.h" +#define MAX_TELNET_FILEDS_NUM 2 + /* telnet style API parser */ static uint64_t HandleId = 0; @@ -72,7 +74,8 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char char *value = NULL; start = cur = *index; - *pTS = tcalloc(1, sizeof(TAOS_SML_KV)); + //allocate fields for timestamp and value + *pTS = tcalloc(MAX_TELNET_FILEDS_NUM, sizeof(TAOS_SML_KV)); while(*cur != '\0') { if (*cur == ' ') { @@ -108,8 +111,8 @@ static int32_t parseTelnetTimeStamp(TAOS_SML_KV **pTS, int *num_kvs, const char } static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const char **index, SSmlLinesInfo* info) { - //SKip timestamp - TAOS_SML_KV *pVal = *pKVs + sizeof(TAOS_SML_KV); + //skip timestamp + TAOS_SML_KV *pVal = *pKVs + 1; const char *start, *cur; int32_t ret = TSDB_CODE_SUCCESS; int len = 0; @@ -117,7 +120,6 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch char *value = NULL; start = cur = *index; - pVal = tcalloc(1, sizeof(TAOS_SML_KV)); while(*cur != '\0') { if (*cur == ' ') { @@ -131,7 +133,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch value = tcalloc(len + 1, 1); memcpy(value, start, len); } else { - tfree(pVal); + tfree(*pKVs); return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } @@ -139,7 +141,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type", info->id, value); tfree(value); - tfree(pVal); + tfree(*pKVs); return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } tfree(value);