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 e26e439492cec9c83b624c2bbb2bbc3a95de97b0..22392ba306faeed05af5d695ca0090057ac211cf 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; @@ -1212,7 +1212,7 @@ static bool isTinyInt(char *pVal, uint16_t len) { if (len <= 2) { return false; } - if (!strcmp(&pVal[len - 2], "i8")) { + if (!strcasecmp(&pVal[len - 2], "i8")) { //printf("Type is int8(%s)\n", pVal); return true; } @@ -1226,7 +1226,7 @@ static bool isTinyUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (!strcmp(&pVal[len - 2], "u8")) { + if (!strcasecmp(&pVal[len - 2], "u8")) { //printf("Type is uint8(%s)\n", pVal); return true; } @@ -1237,7 +1237,7 @@ static bool isSmallInt(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (!strcmp(&pVal[len - 3], "i16")) { + if (!strcasecmp(&pVal[len - 3], "i16")) { //printf("Type is int16(%s)\n", pVal); return true; } @@ -1251,7 +1251,7 @@ static bool isSmallUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (strcmp(&pVal[len - 3], "u16") == 0) { + if (strcasecmp(&pVal[len - 3], "u16") == 0) { //printf("Type is uint16(%s)\n", pVal); return true; } @@ -1262,7 +1262,7 @@ static bool isInt(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "i32") == 0) { + if (strcasecmp(&pVal[len - 3], "i32") == 0) { //printf("Type is int32(%s)\n", pVal); return true; } @@ -1276,7 +1276,7 @@ static bool isUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (strcmp(&pVal[len - 3], "u32") == 0) { + if (strcasecmp(&pVal[len - 3], "u32") == 0) { //printf("Type is uint32(%s)\n", pVal); return true; } @@ -1287,7 +1287,7 @@ static bool isBigInt(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "i64") == 0) { + if (strcasecmp(&pVal[len - 3], "i64") == 0) { //printf("Type is int64(%s)\n", pVal); return true; } @@ -1301,7 +1301,7 @@ static bool isBigUint(char *pVal, uint16_t len) { if (pVal[0] == '-') { return false; } - if (strcmp(&pVal[len - 3], "u64") == 0) { + if (strcasecmp(&pVal[len - 3], "u64") == 0) { //printf("Type is uint64(%s)\n", pVal); return true; } @@ -1312,7 +1312,7 @@ static bool isFloat(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "f32") == 0) { + if (strcasecmp(&pVal[len - 3], "f32") == 0) { //printf("Type is float(%s)\n", pVal); return true; } @@ -1323,7 +1323,7 @@ static bool isDouble(char *pVal, uint16_t len) { if (len <= 3) { return false; } - if (strcmp(&pVal[len - 3], "f64") == 0) { + if (strcasecmp(&pVal[len - 3], "f64") == 0) { //printf("Type is double(%s)\n", pVal); return true; } @@ -1331,34 +1331,24 @@ static bool isDouble(char *pVal, uint16_t len) { } static bool isBool(char *pVal, uint16_t len, bool *bVal) { - if ((len == 1) && - (pVal[len - 1] == 't' || - pVal[len - 1] == 'T')) { + if ((len == 1) && !strcasecmp(&pVal[len - 1], "t")) { //printf("Type is bool(%c)\n", pVal[len - 1]); *bVal = true; return true; } - if ((len == 1) && - (pVal[len - 1] == 'f' || - pVal[len - 1] == 'F')) { + if ((len == 1) && !strcasecmp(&pVal[len - 1], "f")) { //printf("Type is bool(%c)\n", pVal[len - 1]); *bVal = false; return true; } - if((len == 4) && - (!strcmp(&pVal[len - 4], "true") || - !strcmp(&pVal[len - 4], "True") || - !strcmp(&pVal[len - 4], "TRUE"))) { + if((len == 4) && !strcasecmp(&pVal[len - 4], "true")) { //printf("Type is bool(%s)\n", &pVal[len - 4]); *bVal = true; return true; } - if((len == 5) && - (!strcmp(&pVal[len - 5], "false") || - !strcmp(&pVal[len - 5], "False") || - !strcmp(&pVal[len - 5], "FALSE"))) { + if((len == 5) && !strcasecmp(&pVal[len - 5], "false")) { //printf("Type is bool(%s)\n", &pVal[len - 5]); *bVal = false; return true; @@ -1384,7 +1374,7 @@ static bool isNchar(char *pVal, uint16_t len) { if (len < 3) { return false; } - if (pVal[0] == 'L' && pVal[1] == '"' && pVal[len - 1] == '"') { + if ((pVal[0] == 'l' || pVal[0] == 'L')&& pVal[1] == '"' && pVal[len - 1] == '"') { //printf("Type is nchar(%s)\n", pVal); return true; } @@ -1434,7 +1424,7 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) { return false; } -static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) { +static bool convertStrToNumber(TAOS_SML_KV *pVal, char *str, SSmlLinesInfo* info) { errno = 0; uint8_t type = pVal->type; int16_t length = pVal->length; @@ -1442,6 +1432,7 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) uint64_t val_u; double val_d; + strntolower_s(str, str, (int32_t)strlen(str)); if (IS_FLOAT_TYPE(type)) { val_d = strtod(str, NULL); } else { @@ -1659,9 +1650,19 @@ bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, memcpy(pVal->value, &bVal, pVal->length); return true; } - //Handle default(no appendix) as float - if (isValidInteger(value) || isValidFloat(value)) { - pVal->type = TSDB_DATA_TYPE_FLOAT; + //Handle default(no appendix) interger type as BIGINT + if (isValidInteger(value)) { + pVal->type = TSDB_DATA_TYPE_BIGINT; + pVal->length = (int16_t)tDataTypes[pVal->type].bytes; + if (!convertStrToNumber(pVal, value, info)) { + return false; + } + return true; + } + + //Handle default(no appendix) floating number type as DOUBLE + if (isValidFloat(value)) { + pVal->type = TSDB_DATA_TYPE_DOUBLE; pVal->length = (int16_t)tDataTypes[pVal->type].bytes; if (!convertStrToNumber(pVal, value, info)) { return false; @@ -1724,6 +1725,7 @@ int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, SMLTimeStampType type; int64_t tsVal; + strntolower_s(value, value, len); if (!isTimeStamp(value, len, &type)) { return TSDB_CODE_TSC_INVALID_TIME_STAMP; } diff --git a/src/client/src/tscParseOpenTSDB.c b/src/client/src/tscParseOpenTSDB.c index 8e0322cab07ba462b7320cef02011b27b18785d5..14693ae361b533287e3377e644908c5c8a613c79 100644 --- a/src/client/src/tscParseOpenTSDB.c +++ b/src/client/src/tscParseOpenTSDB.c @@ -38,7 +38,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, uint16_t len = 0; pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + 1, 1); // +1 to avoid 1772 line over write - if (pSml->stableName == NULL){ + if (pSml->stableName == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } if (isdigit(*cur)) { @@ -58,7 +58,13 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, break; } - pSml->stableName[len] = *cur; + //convert dot to underscore for now, will be removed once dot is allowed in tbname. + if (*cur == '.') { + pSml->stableName[len] = '_'; + } else { + pSml->stableName[len] = *cur; + } + cur++; len++; } @@ -455,6 +461,13 @@ int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlLinesInf return TSDB_CODE_TSC_INVALID_JSON; } + //convert dot to underscore for now, will be removed once dot is allowed in tbname. + for (int i = 0; i < strlen(metric->valuestring); ++i) { + if (metric->valuestring[i] == '.') { + metric->valuestring[i] = '_'; + } + } + tstrncpy(pSml->stableName, metric->valuestring, stableLen + 1); return TSDB_CODE_SUCCESS; @@ -485,6 +498,7 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in } size_t typeLen = strlen(type->valuestring); + strntolower_s(type->valuestring, type->valuestring, (int32_t)typeLen); if (typeLen == 1 && type->valuestring[0] == 's') { //seconds *tsVal = (int64_t)(*tsVal * 1e9); @@ -505,6 +519,8 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in default: return TSDB_CODE_TSC_INVALID_JSON; } + } else { + return TSDB_CODE_TSC_INVALID_JSON; } return TSDB_CODE_SUCCESS; @@ -725,16 +741,34 @@ 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: { - //convert default JSON String type to nchar - pVal->type = TSDB_DATA_TYPE_NCHAR; + /* set default JSON type to binary/nchar according to + * user configured parameter tsDefaultJSONStrType + */ + if (strcasecmp(tsDefaultJSONStrType, "binary") == 0) { + pVal->type = TSDB_DATA_TYPE_BINARY; + } else if (strcasecmp(tsDefaultJSONStrType, "nchar") == 0) { + pVal->type = TSDB_DATA_TYPE_NCHAR; + } else { + tscError("OTD:0x%"PRIx64" Invalid default JSON string type set from config %s", info->id, tsDefaultJSONStrType); + return TSDB_CODE_TSC_INVALID_JSON_CONFIG; + } //pVal->length = wcslen((wchar_t *)root->valuestring) * TSDB_NCHAR_SIZE; pVal->length = (int16_t)strlen(root->valuestring); pVal->value = tcalloc(pVal->length + 1, 1); diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 604ce89432bcf662b319fb2ec11f55026450a2be..beeb4e8b243e21e33f4162b07ec218c40e4029f9 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -216,7 +216,7 @@ extern int32_t cqDebugFlag; extern int32_t debugFlag; #ifdef TD_TSZ -// lossy +// lossy extern char lossyColumns[]; extern double fPrecision; extern double dPrecision; @@ -224,9 +224,12 @@ extern uint32_t maxRange; extern uint32_t curRange; extern char Compressor[]; #endif -// long query +// long query extern int8_t tsDeadLockKillQuery; +// schemaless +extern char tsDefaultJSONStrType[]; + typedef struct { char dir[TSDB_FILENAME_LEN]; int level; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 339fa35bb3009db96c9c6e0cabea6b60881f05c5..7d352a9dc1f0a9a97c7c1920f898fb286a01497f 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -282,6 +282,9 @@ char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESS // long query death-lock int8_t tsDeadLockKillQuery = 0; +// default JSON string type +char tsDefaultJSONStrType[7] = "binary"; + int32_t (*monStartSystemFp)() = NULL; void (*monStopSystemFp)() = NULL; void (*monExecuteSQLFp)(char *sql) = NULL; @@ -1637,6 +1640,17 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + // default JSON string type option "binary"/"nchar" + cfg.option = "defaultJSONStrType"; + cfg.ptr = tsDefaultJSONStrType; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = tListLen(tsDefaultJSONStrType); + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + #ifdef TD_TSZ // lossy compress cfg.option = "lossyColumns"; diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index d59b88c7e698b3e965b5923efdc760e0289f7250..887c51f10c5a6c10e213bb893725a837a0be77cd 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -110,7 +110,8 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_DUP_TAG_NAMES TAOS_DEF_ERROR_CODE(0, 0x0220) //"duplicated tag names") #define TSDB_CODE_TSC_INVALID_JSON TAOS_DEF_ERROR_CODE(0, 0x0221) //"Invalid JSON format") #define TSDB_CODE_TSC_INVALID_JSON_TYPE TAOS_DEF_ERROR_CODE(0, 0x0222) //"Invalid JSON data type") -#define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0223) //"Value out of range") +#define TSDB_CODE_TSC_INVALID_JSON_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0223) //"Invalid JSON configuration") +#define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0224) //"Value out of range") // mnode #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index 2c632d4a17f5394dc28df72414948855b89bc001..2ba4b964c04b0a1ca9f883cd619aae2b7fcbe1d7 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define TSDB_CFG_MAX_NUM 123 +#define TSDB_CFG_MAX_NUM 124 #define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_VALUE_LEN 41 diff --git a/src/util/src/terror.c b/src/util/src/terror.c index e3d022a6b0a4a929b6c06b2c305fb71b6980a865..404d4ad0c18944826abebf6d0e73c573dbe54756 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -118,6 +118,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_COLUMN_LENGTH, "Invalid column length TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DUP_TAG_NAMES, "duplicated tag names") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_JSON, "Invalid JSON format") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_JSON_TYPE, "Invalid JSON data type") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_JSON_CONFIG, "Invalid JSON configuration") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_VALUE_OUT_OF_RANGE, "Value out of range") // mnode diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index 03123afb3584ea94417c88e55edd9f8e232b0fe9..c886c6d2fe332380e9f519bfc1133d3d5b4106fa 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -1090,9 +1090,10 @@ void verify_telnet_insert(TAOS* taos) { //bigint char* lines2_3[] = { "stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"", - "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\"" + "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\"", + "stb2_3 1626006833662ms 9223372036854775807 host=\"host0\"" }; - code = taos_insert_telnet_lines(taos, lines2_3, 2); + code = taos_insert_telnet_lines(taos, lines2_3, 3); if (code) { printf("lines2_3 code: %d, %s.\n", code, tstrerror(code)); } @@ -1107,11 +1108,10 @@ void verify_telnet_insert(TAOS* taos) { "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"", "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"", "stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"", - "stb2_4 1626006833690ms 3.15 host=\"host0\"", "stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"", "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\"" }; - code = taos_insert_telnet_lines(taos, lines2_4, 11); + code = taos_insert_telnet_lines(taos, lines2_4, 10); if (code) { printf("lines2_4 code: %d, %s.\n", code, tstrerror(code)); } @@ -1127,9 +1127,10 @@ void verify_telnet_insert(TAOS* taos) { "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"", "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"", "stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"", - "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"" + "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"", + "stb2_5 1626006833710ms 3.15 host=\"host0\"" }; - code = taos_insert_telnet_lines(taos, lines2_5, 10); + code = taos_insert_telnet_lines(taos, lines2_5, 11); if (code) { printf("lines2_5 code: %d, %s.\n", code, tstrerror(code)); } @@ -1166,7 +1167,7 @@ void verify_telnet_insert(TAOS* taos) { //nchar char* lines2_8[] = { "stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"", - "stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\"", + "stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\"" }; code = taos_insert_telnet_lines(taos, lines2_8, 2); if (code) { diff --git a/tests/pytest/insert/insertJSONPayload.py b/tests/pytest/insert/insertJSONPayload.py index 30f34446a93237f9b7b610efc9b1b5507ba09f4a..88b03cf3f526a380a97acf2a45b86a2c64b66069 100644 --- a/tests/pytest/insert/insertJSONPayload.py +++ b/tests/pytest/insert/insertJSONPayload.py @@ -31,6 +31,27 @@ class TDTestCase: ### Default format ### + ### metric ### + print("============= step0 : test metric ================") + payload = ''' + { + "metric": ".stb.0.", + "timestamp": 1626006833610123, + "value": 10, + "tags": { + "t1": true, + "t2": false, + "t3": 10, + "t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>" + } + } + ''' + code = self._conn.insert_json_payload(payload) + print("insert_json_payload result {}".format(code)) + + tdSql.query("describe _stb_0_") + tdSql.checkRows(6) + ### metric value ### print("============= step1 : test metric value types ================") payload = ''' @@ -50,7 +71,7 @@ class TDTestCase: print("insert_json_payload result {}".format(code)) tdSql.query("describe stb0_0") - tdSql.checkData(1, 1, "FLOAT") + tdSql.checkData(1, 1, "BIGINT") payload = ''' { @@ -107,12 +128,52 @@ class TDTestCase: print("insert_json_payload result {}".format(code)) tdSql.query("describe stb0_3") - tdSql.checkData(1, 1, "NCHAR") + tdSql.checkData(1, 1, "BINARY") - ### timestamp 0 ### payload = ''' { "metric": "stb0_4", + "timestamp": 1626006833610123, + "value": 3.14, + "tags": { + "t1": true, + "t2": false, + "t3": 10, + "t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>" + } + } + ''' + code = self._conn.insert_json_payload(payload) + print("insert_json_payload result {}".format(code)) + + tdSql.query("describe stb0_4") + tdSql.checkData(1, 1, "DOUBLE") + + payload = ''' + { + "metric": "stb0_5", + "timestamp": 1626006833610123, + "value": 3.14E-2, + "tags": { + "t1": true, + "t2": false, + "t3": 10, + "t4": "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>" + } + } + ''' + code = self._conn.insert_json_payload(payload) + print("insert_json_payload result {}".format(code)) + + tdSql.query("describe stb0_5") + tdSql.checkData(1, 1, "DOUBLE") + + + print("============= step2 : test timestamp ================") + ### timestamp 0 ### + payload = ''' + { + "metric": "stb0_6", "timestamp": 0, "value": 123, "tags": { @@ -127,14 +188,15 @@ class TDTestCase: print("insert_json_payload result {}".format(code)) + print("============= step3 : test tags ================") ### ID ### payload = ''' { - "metric": "stb0_5", + "metric": "stb0_7", "timestamp": 0, "value": 123, "tags": { - "ID": "tb0_5", + "ID": "tb0_7", "t1": true, "iD": "tb000", "t2": false, @@ -147,10 +209,60 @@ class TDTestCase: code = self._conn.insert_json_payload(payload) print("insert_json_payload result {}".format(code)) - tdSql.query("select tbname from stb0_5") - tdSql.checkData(0, 0, "tb0_5") + tdSql.query("select tbname from stb0_7") + tdSql.checkData(0, 0, "tb0_7") + + ### Default tag numeric types ### + payload = ''' + { + "metric": "stb0_8", + "timestamp": 0, + "value": 123, + "tags": { + "t1": 123 + } + } + ''' + code = self._conn.insert_json_payload(payload) + print("insert_json_payload result {}".format(code)) + + tdSql.query("describe stb0_8") + tdSql.checkData(2, 1, "BIGINT") + + payload = ''' + { + "metric": "stb0_9", + "timestamp": 0, + "value": 123, + "tags": { + "t1": 123.00 + } + } + ''' + code = self._conn.insert_json_payload(payload) + print("insert_json_payload result {}".format(code)) + + tdSql.query("describe stb0_9") + tdSql.checkData(2, 1, "DOUBLE") + + payload = ''' + { + "metric": "stb0_10", + "timestamp": 0, + "value": 123, + "tags": { + "t1": 123E-1 + } + } + ''' + code = self._conn.insert_json_payload(payload) + print("insert_json_payload result {}".format(code)) + + tdSql.query("describe stb0_10") + tdSql.checkData(2, 1, "DOUBLE") ### Nested format ### + print("============= step4 : test nested format ================") ### timestamp ### #seconds payload = ''' diff --git a/tests/pytest/insert/insertTelnetLines.py b/tests/pytest/insert/insertTelnetLines.py index 4041b309a1007c1177f26d28b022f4e314dcf9ba..b47a74249bbad57ef758e886c513a7eea78b7634 100644 --- a/tests/pytest/insert/insertTelnetLines.py +++ b/tests/pytest/insert/insertTelnetLines.py @@ -36,13 +36,14 @@ class TDTestCase: "stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", "stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", "stb0_2 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", + ".stb0.3. 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", ] code = self._conn.insert_telnet_lines(lines0) print("insert_telnet_lines result {}".format(code)) tdSql.query("show stables") - tdSql.checkRows(3) + tdSql.checkRows(4) tdSql.query("describe stb0_0") tdSql.checkRows(4) @@ -53,6 +54,9 @@ class TDTestCase: tdSql.query("describe stb0_2") tdSql.checkRows(4) + tdSql.query("describe _stb0_3_") + tdSql.checkRows(4) + ### timestamp ### print("============= step2 : test timestamp ================") lines1 = [ @@ -122,14 +126,15 @@ class TDTestCase: #bigint lines2_3 = [ "stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"", - "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\"" + "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\"", + "stb2_3 1626006833662ms 9223372036854775807 host=\"host0\"" ] code = self._conn.insert_telnet_lines(lines2_3) print("insert_telnet_lines result {}".format(code)) tdSql.query("select * from stb2_3") - tdSql.checkRows(2) + tdSql.checkRows(3) tdSql.query("describe stb2_3") tdSql.checkRows(3) @@ -145,7 +150,6 @@ class TDTestCase: "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"", "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"", "stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"", - "stb2_4 1626006833690ms 3.15 host=\"host0\"", "stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"", "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\"" ] @@ -154,7 +158,7 @@ class TDTestCase: print("insert_telnet_lines result {}".format(code)) tdSql.query("select * from stb2_4") - tdSql.checkRows(11) + tdSql.checkRows(10) tdSql.query("describe stb2_4") tdSql.checkRows(3) @@ -171,14 +175,15 @@ class TDTestCase: "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"", "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"", "stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"", - "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"" + "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"", + "stb2_5 1626006833710ms 3.15 host=\"host0\"" ] code = self._conn.insert_telnet_lines(lines2_5) print("insert_telnet_lines result {}".format(code)) tdSql.query("select * from stb2_5") - tdSql.checkRows(10) + tdSql.checkRows(11) tdSql.query("describe stb2_5") tdSql.checkRows(3)