diff --git a/src/client/inc/tscParseLine.h b/src/client/inc/tscParseLine.h index 401dcafdfbefd28e79ebdf30d810e194564a5056..e36c0bbc0b2d9c02e798aed1fe1e68dbe02939f5 100644 --- a/src/client/inc/tscParseLine.h +++ b/src/client/inc/tscParseLine.h @@ -54,6 +54,9 @@ typedef struct { int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info); bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlLinesInfo* info); +bool isValidInteger(char *str); +bool isValidFloat(char *str); + int32_t isValidChildTableName(const char *pTbName, int16_t len); bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 297f4680ee79b0091803dd1bc1c4025302b4be41..229ab86ec59655889efa1fd6628232aeb0605942 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -1137,7 +1137,7 @@ static void escapeSpecialCharacter(uint8_t field, const char **pos) { *pos = cur; } -static bool isValidInteger(char *str) { +bool isValidInteger(char *str) { char *c = str; if (*c != '+' && *c != '-' && !isdigit(*c)) { return false; @@ -1152,7 +1152,7 @@ static bool isValidInteger(char *str) { return true; } -static bool isValidFloat(char *str) { +bool isValidFloat(char *str) { char *c = str; uint8_t has_dot, has_exp, has_sign; has_dot = 0; diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index 2ec4eda772697b445615f73a529fb093885704a1..6735462f17013ed4813345964be62e318cdefe2f 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -741,11 +741,20 @@ int32_t parseValueFromJSON(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* info) break; } case cJSON_Number: { - //convert default JSON Number type to float - pVal->type = TSDB_DATA_TYPE_FLOAT; - pVal->length = (int16_t)tDataTypes[pVal->type].bytes; - pVal->value = tcalloc(pVal->length, 1); - *(float *)(pVal->value) = (float)(root->valuedouble); + //convert default JSON Number type to BIGINT/DOUBLE + if (isValidInteger(root->numberstring)) { + pVal->type = TSDB_DATA_TYPE_BIGINT; + pVal->length = (int16_t)tDataTypes[pVal->type].bytes; + pVal->value = tcalloc(pVal->length, 1); + *(int64_t *)(pVal->value) = (int64_t)(root->valuedouble); + } else if (isValidFloat(root->numberstring)) { + pVal->type = TSDB_DATA_TYPE_DOUBLE; + pVal->length = (int16_t)tDataTypes[pVal->type].bytes; + pVal->value = tcalloc(pVal->length, 1); + *(double *)(pVal->value) = (double)(root->valuedouble); + } else { + return TSDB_CODE_TSC_INVALID_JSON_TYPE; + } break; } case cJSON_String: {