From a2ea28e6897b85cdfc66742c4a8a30a7a990f7ad Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Sun, 10 Oct 2021 21:42:15 +0800 Subject: [PATCH] [TD-10532]: schemaless convert tag value to nchar --- src/client/inc/tscParseLine.h | 2 +- src/client/src/tscParseLineProtocol.c | 17 +++++++++++++---- src/client/src/tscParseOpenTSDB.c | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/client/inc/tscParseLine.h b/src/client/inc/tscParseLine.h index 8c7aaad81b..3fc9ad60f5 100644 --- a/src/client/inc/tscParseLine.h +++ b/src/client/inc/tscParseLine.h @@ -66,7 +66,7 @@ bool isValidFloat(char *str); int32_t isValidChildTableName(const char *pTbName, int16_t len, SSmlLinesInfo* info); bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, - uint16_t len, SSmlLinesInfo* info); + uint16_t len, SSmlLinesInfo* info, bool isTag); int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, uint16_t len, SSmlLinesInfo* info); diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index bf48a645e5..6d2bd7a0b5 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1542,11 +1542,20 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char *str, SSmlLinesInfo* info } //len does not include '\0' from value. bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, - uint16_t len, SSmlLinesInfo* info) { + uint16_t len, SSmlLinesInfo* info, bool isTag) { if (len <= 0) { return false; } + //convert tags value to Nchar + if (isTag) { + pVal->type = TSDB_DATA_TYPE_NCHAR; + pVal->length = len; + pVal->value = calloc(pVal->length, 1); + memcpy(pVal->value, value, pVal->length); + return true; + } + //integer number bool has_sign; if (isInteger(value, len, &has_sign)) { @@ -1859,7 +1868,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index, - bool *is_last_kv, SSmlLinesInfo* info) { + bool *is_last_kv, SSmlLinesInfo* info, bool isTag) { const char *start, *cur; char *value = NULL; uint16_t len = 0; @@ -1883,7 +1892,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index, value = calloc(len + 1, 1); memcpy(value, start, len); value[len] = '\0'; - if (!convertSmlValueType(pKV, value, len, info)) { + if (!convertSmlValueType(pKV, value, len, info, isTag)) { tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type", info->id, value); //free previous alocated key field @@ -1989,7 +1998,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs, tscError("SML:0x%"PRIx64" Unable to parse key", info->id); goto error; } - ret = parseSmlValue(pkv, &cur, &is_last_kv, info); + ret = parseSmlValue(pkv, &cur, &is_last_kv, info, !isField); if (ret) { tscError("SML:0x%"PRIx64" Unable to parse value", info->id); goto error; diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index 08d739cae4..e288243ffb 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -153,7 +153,7 @@ static int32_t parseTelnetMetricValue(TAOS_SML_KV **pKVs, int *num_kvs, const ch return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; } - if (!convertSmlValueType(pVal, value, len, info)) { + if (!convertSmlValueType(pVal, value, len, info, false)) { tscError("OTD:0x%"PRIx64" Failed to convert metric value string(%s) to any type", info->id, value); tfree(value); @@ -238,7 +238,7 @@ static int32_t parseTelnetTagValue(TAOS_SML_KV *pKV, const char **index, value = tcalloc(len + 1, 1); memcpy(value, start, len); value[len] = '\0'; - if (!convertSmlValueType(pKV, value, len, info)) { + if (!convertSmlValueType(pKV, value, len, info, true)) { tscError("OTD:0x%"PRIx64" Failed to convert sml value string(%s) to any type", info->id, value); //free previous alocated key field -- GitLab