提交 1949ceb6 编写于 作者: G Ganlin Zhao

[TD-6645/enhance]: Add default type convertion for numeric values for

JSON numbers.
Interger number -> BIGINT (contains only digits and '+' '-')
Floating number -> DOUBLE (including decimal point format or scientific
notation format)
上级 0377f007
...@@ -54,6 +54,9 @@ typedef struct { ...@@ -54,6 +54,9 @@ typedef struct {
int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info); int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLinesInfo* info);
bool checkDuplicateKey(char *key, SHashObj *pHash, 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); int32_t isValidChildTableName(const char *pTbName, int16_t len);
bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
......
...@@ -1137,7 +1137,7 @@ static void escapeSpecialCharacter(uint8_t field, const char **pos) { ...@@ -1137,7 +1137,7 @@ static void escapeSpecialCharacter(uint8_t field, const char **pos) {
*pos = cur; *pos = cur;
} }
static bool isValidInteger(char *str) { bool isValidInteger(char *str) {
char *c = str; char *c = str;
if (*c != '+' && *c != '-' && !isdigit(*c)) { if (*c != '+' && *c != '-' && !isdigit(*c)) {
return false; return false;
...@@ -1152,7 +1152,7 @@ static bool isValidInteger(char *str) { ...@@ -1152,7 +1152,7 @@ static bool isValidInteger(char *str) {
return true; return true;
} }
static bool isValidFloat(char *str) { bool isValidFloat(char *str) {
char *c = str; char *c = str;
uint8_t has_dot, has_exp, has_sign; uint8_t has_dot, has_exp, has_sign;
has_dot = 0; has_dot = 0;
......
...@@ -741,11 +741,20 @@ int32_t parseValueFromJSON(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* info) ...@@ -741,11 +741,20 @@ int32_t parseValueFromJSON(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* info)
break; break;
} }
case cJSON_Number: { case cJSON_Number: {
//convert default JSON Number type to float //convert default JSON Number type to BIGINT/DOUBLE
pVal->type = TSDB_DATA_TYPE_FLOAT; if (isValidInteger(root->numberstring)) {
pVal->length = (int16_t)tDataTypes[pVal->type].bytes; pVal->type = TSDB_DATA_TYPE_BIGINT;
pVal->value = tcalloc(pVal->length, 1); pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
*(float *)(pVal->value) = (float)(root->valuedouble); 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; break;
} }
case cJSON_String: { case cJSON_String: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册