未验证 提交 1b9ed345 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #7971 from taosdata/enhance/TD-6645

[TD-6645/enhance]: Minor modification to OpenTSDB writing protocol parsing
...@@ -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;
...@@ -1212,7 +1212,7 @@ static bool isTinyInt(char *pVal, uint16_t len) { ...@@ -1212,7 +1212,7 @@ static bool isTinyInt(char *pVal, uint16_t len) {
if (len <= 2) { if (len <= 2) {
return false; return false;
} }
if (!strcmp(&pVal[len - 2], "i8")) { if (!strcasecmp(&pVal[len - 2], "i8")) {
//printf("Type is int8(%s)\n", pVal); //printf("Type is int8(%s)\n", pVal);
return true; return true;
} }
...@@ -1226,7 +1226,7 @@ static bool isTinyUint(char *pVal, uint16_t len) { ...@@ -1226,7 +1226,7 @@ static bool isTinyUint(char *pVal, uint16_t len) {
if (pVal[0] == '-') { if (pVal[0] == '-') {
return false; return false;
} }
if (!strcmp(&pVal[len - 2], "u8")) { if (!strcasecmp(&pVal[len - 2], "u8")) {
//printf("Type is uint8(%s)\n", pVal); //printf("Type is uint8(%s)\n", pVal);
return true; return true;
} }
...@@ -1237,7 +1237,7 @@ static bool isSmallInt(char *pVal, uint16_t len) { ...@@ -1237,7 +1237,7 @@ static bool isSmallInt(char *pVal, uint16_t len) {
if (len <= 3) { if (len <= 3) {
return false; return false;
} }
if (!strcmp(&pVal[len - 3], "i16")) { if (!strcasecmp(&pVal[len - 3], "i16")) {
//printf("Type is int16(%s)\n", pVal); //printf("Type is int16(%s)\n", pVal);
return true; return true;
} }
...@@ -1251,7 +1251,7 @@ static bool isSmallUint(char *pVal, uint16_t len) { ...@@ -1251,7 +1251,7 @@ static bool isSmallUint(char *pVal, uint16_t len) {
if (pVal[0] == '-') { if (pVal[0] == '-') {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "u16") == 0) { if (strcasecmp(&pVal[len - 3], "u16") == 0) {
//printf("Type is uint16(%s)\n", pVal); //printf("Type is uint16(%s)\n", pVal);
return true; return true;
} }
...@@ -1262,7 +1262,7 @@ static bool isInt(char *pVal, uint16_t len) { ...@@ -1262,7 +1262,7 @@ static bool isInt(char *pVal, uint16_t len) {
if (len <= 3) { if (len <= 3) {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "i32") == 0) { if (strcasecmp(&pVal[len - 3], "i32") == 0) {
//printf("Type is int32(%s)\n", pVal); //printf("Type is int32(%s)\n", pVal);
return true; return true;
} }
...@@ -1276,7 +1276,7 @@ static bool isUint(char *pVal, uint16_t len) { ...@@ -1276,7 +1276,7 @@ static bool isUint(char *pVal, uint16_t len) {
if (pVal[0] == '-') { if (pVal[0] == '-') {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "u32") == 0) { if (strcasecmp(&pVal[len - 3], "u32") == 0) {
//printf("Type is uint32(%s)\n", pVal); //printf("Type is uint32(%s)\n", pVal);
return true; return true;
} }
...@@ -1287,7 +1287,7 @@ static bool isBigInt(char *pVal, uint16_t len) { ...@@ -1287,7 +1287,7 @@ static bool isBigInt(char *pVal, uint16_t len) {
if (len <= 3) { if (len <= 3) {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "i64") == 0) { if (strcasecmp(&pVal[len - 3], "i64") == 0) {
//printf("Type is int64(%s)\n", pVal); //printf("Type is int64(%s)\n", pVal);
return true; return true;
} }
...@@ -1301,7 +1301,7 @@ static bool isBigUint(char *pVal, uint16_t len) { ...@@ -1301,7 +1301,7 @@ static bool isBigUint(char *pVal, uint16_t len) {
if (pVal[0] == '-') { if (pVal[0] == '-') {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "u64") == 0) { if (strcasecmp(&pVal[len - 3], "u64") == 0) {
//printf("Type is uint64(%s)\n", pVal); //printf("Type is uint64(%s)\n", pVal);
return true; return true;
} }
...@@ -1312,7 +1312,7 @@ static bool isFloat(char *pVal, uint16_t len) { ...@@ -1312,7 +1312,7 @@ static bool isFloat(char *pVal, uint16_t len) {
if (len <= 3) { if (len <= 3) {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "f32") == 0) { if (strcasecmp(&pVal[len - 3], "f32") == 0) {
//printf("Type is float(%s)\n", pVal); //printf("Type is float(%s)\n", pVal);
return true; return true;
} }
...@@ -1323,7 +1323,7 @@ static bool isDouble(char *pVal, uint16_t len) { ...@@ -1323,7 +1323,7 @@ static bool isDouble(char *pVal, uint16_t len) {
if (len <= 3) { if (len <= 3) {
return false; return false;
} }
if (strcmp(&pVal[len - 3], "f64") == 0) { if (strcasecmp(&pVal[len - 3], "f64") == 0) {
//printf("Type is double(%s)\n", pVal); //printf("Type is double(%s)\n", pVal);
return true; return true;
} }
...@@ -1331,34 +1331,24 @@ static bool isDouble(char *pVal, uint16_t len) { ...@@ -1331,34 +1331,24 @@ static bool isDouble(char *pVal, uint16_t len) {
} }
static bool isBool(char *pVal, uint16_t len, bool *bVal) { static bool isBool(char *pVal, uint16_t len, bool *bVal) {
if ((len == 1) && if ((len == 1) && !strcasecmp(&pVal[len - 1], "t")) {
(pVal[len - 1] == 't' ||
pVal[len - 1] == 'T')) {
//printf("Type is bool(%c)\n", pVal[len - 1]); //printf("Type is bool(%c)\n", pVal[len - 1]);
*bVal = true; *bVal = true;
return true; return true;
} }
if ((len == 1) && if ((len == 1) && !strcasecmp(&pVal[len - 1], "f")) {
(pVal[len - 1] == 'f' ||
pVal[len - 1] == 'F')) {
//printf("Type is bool(%c)\n", pVal[len - 1]); //printf("Type is bool(%c)\n", pVal[len - 1]);
*bVal = false; *bVal = false;
return true; return true;
} }
if((len == 4) && if((len == 4) && !strcasecmp(&pVal[len - 4], "true")) {
(!strcmp(&pVal[len - 4], "true") ||
!strcmp(&pVal[len - 4], "True") ||
!strcmp(&pVal[len - 4], "TRUE"))) {
//printf("Type is bool(%s)\n", &pVal[len - 4]); //printf("Type is bool(%s)\n", &pVal[len - 4]);
*bVal = true; *bVal = true;
return true; return true;
} }
if((len == 5) && if((len == 5) && !strcasecmp(&pVal[len - 5], "false")) {
(!strcmp(&pVal[len - 5], "false") ||
!strcmp(&pVal[len - 5], "False") ||
!strcmp(&pVal[len - 5], "FALSE"))) {
//printf("Type is bool(%s)\n", &pVal[len - 5]); //printf("Type is bool(%s)\n", &pVal[len - 5]);
*bVal = false; *bVal = false;
return true; return true;
...@@ -1384,7 +1374,7 @@ static bool isNchar(char *pVal, uint16_t len) { ...@@ -1384,7 +1374,7 @@ static bool isNchar(char *pVal, uint16_t len) {
if (len < 3) { if (len < 3) {
return false; 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); //printf("Type is nchar(%s)\n", pVal);
return true; return true;
} }
...@@ -1434,7 +1424,7 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) { ...@@ -1434,7 +1424,7 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType) {
return false; 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; errno = 0;
uint8_t type = pVal->type; uint8_t type = pVal->type;
int16_t length = pVal->length; int16_t length = pVal->length;
...@@ -1442,6 +1432,7 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info) ...@@ -1442,6 +1432,7 @@ static bool convertStrToNumber(TAOS_SML_KV *pVal, char*str, SSmlLinesInfo* info)
uint64_t val_u; uint64_t val_u;
double val_d; double val_d;
strntolower_s(str, str, (int32_t)strlen(str));
if (IS_FLOAT_TYPE(type)) { if (IS_FLOAT_TYPE(type)) {
val_d = strtod(str, NULL); val_d = strtod(str, NULL);
} else { } else {
...@@ -1659,9 +1650,19 @@ bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, ...@@ -1659,9 +1650,19 @@ bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
memcpy(pVal->value, &bVal, pVal->length); memcpy(pVal->value, &bVal, pVal->length);
return true; return true;
} }
//Handle default(no appendix) as float //Handle default(no appendix) interger type as BIGINT
if (isValidInteger(value) || isValidFloat(value)) { if (isValidInteger(value)) {
pVal->type = TSDB_DATA_TYPE_FLOAT; 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; pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
if (!convertStrToNumber(pVal, value, info)) { if (!convertStrToNumber(pVal, value, info)) {
return false; return false;
...@@ -1724,6 +1725,7 @@ int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, ...@@ -1724,6 +1725,7 @@ int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
SMLTimeStampType type; SMLTimeStampType type;
int64_t tsVal; int64_t tsVal;
strntolower_s(value, value, len);
if (!isTimeStamp(value, len, &type)) { if (!isTimeStamp(value, len, &type)) {
return TSDB_CODE_TSC_INVALID_TIME_STAMP; return TSDB_CODE_TSC_INVALID_TIME_STAMP;
} }
......
...@@ -38,7 +38,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, ...@@ -38,7 +38,7 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index,
uint16_t len = 0; uint16_t len = 0;
pSml->stableName = tcalloc(TSDB_TABLE_NAME_LEN + 1, 1); // +1 to avoid 1772 line over write 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; return TSDB_CODE_TSC_OUT_OF_MEMORY;
} }
if (isdigit(*cur)) { if (isdigit(*cur)) {
...@@ -58,7 +58,13 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index, ...@@ -58,7 +58,13 @@ static int32_t parseTelnetMetric(TAOS_SML_DATA_POINT *pSml, const char **index,
break; break;
} }
//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; pSml->stableName[len] = *cur;
}
cur++; cur++;
len++; len++;
} }
...@@ -455,6 +461,13 @@ int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlLinesInf ...@@ -455,6 +461,13 @@ int32_t parseMetricFromJSON(cJSON *root, TAOS_SML_DATA_POINT* pSml, SSmlLinesInf
return TSDB_CODE_TSC_INVALID_JSON; 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); tstrncpy(pSml->stableName, metric->valuestring, stableLen + 1);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -485,6 +498,7 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in ...@@ -485,6 +498,7 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in
} }
size_t typeLen = strlen(type->valuestring); size_t typeLen = strlen(type->valuestring);
strntolower_s(type->valuestring, type->valuestring, (int32_t)typeLen);
if (typeLen == 1 && type->valuestring[0] == 's') { if (typeLen == 1 && type->valuestring[0] == 's') {
//seconds //seconds
*tsVal = (int64_t)(*tsVal * 1e9); *tsVal = (int64_t)(*tsVal * 1e9);
...@@ -505,6 +519,8 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in ...@@ -505,6 +519,8 @@ int32_t parseTimestampFromJSONObj(cJSON *root, int64_t *tsVal, SSmlLinesInfo* in
default: default:
return TSDB_CODE_TSC_INVALID_JSON; return TSDB_CODE_TSC_INVALID_JSON;
} }
} else {
return TSDB_CODE_TSC_INVALID_JSON;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -725,16 +741,34 @@ int32_t parseValueFromJSON(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* info) ...@@ -725,16 +741,34 @@ 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->type = TSDB_DATA_TYPE_BIGINT;
pVal->length = (int16_t)tDataTypes[pVal->type].bytes; pVal->length = (int16_t)tDataTypes[pVal->type].bytes;
pVal->value = tcalloc(pVal->length, 1); pVal->value = tcalloc(pVal->length, 1);
*(float *)(pVal->value) = (float)(root->valuedouble); *(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: {
//convert default JSON String type to 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; 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 = wcslen((wchar_t *)root->valuestring) * TSDB_NCHAR_SIZE;
pVal->length = (int16_t)strlen(root->valuestring); pVal->length = (int16_t)strlen(root->valuestring);
pVal->value = tcalloc(pVal->length + 1, 1); pVal->value = tcalloc(pVal->length + 1, 1);
......
...@@ -227,6 +227,9 @@ extern char Compressor[]; ...@@ -227,6 +227,9 @@ extern char Compressor[];
// long query // long query
extern int8_t tsDeadLockKillQuery; extern int8_t tsDeadLockKillQuery;
// schemaless
extern char tsDefaultJSONStrType[];
typedef struct { typedef struct {
char dir[TSDB_FILENAME_LEN]; char dir[TSDB_FILENAME_LEN];
int level; int level;
......
...@@ -282,6 +282,9 @@ char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESS ...@@ -282,6 +282,9 @@ char Compressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESS
// long query death-lock // long query death-lock
int8_t tsDeadLockKillQuery = 0; int8_t tsDeadLockKillQuery = 0;
// default JSON string type
char tsDefaultJSONStrType[7] = "binary";
int32_t (*monStartSystemFp)() = NULL; int32_t (*monStartSystemFp)() = NULL;
void (*monStopSystemFp)() = NULL; void (*monStopSystemFp)() = NULL;
void (*monExecuteSQLFp)(char *sql) = NULL; void (*monExecuteSQLFp)(char *sql) = NULL;
...@@ -1637,6 +1640,17 @@ static void doInitGlobalConfig(void) { ...@@ -1637,6 +1640,17 @@ static void doInitGlobalConfig(void) {
cfg.unitType = TAOS_CFG_UTYPE_NONE; cfg.unitType = TAOS_CFG_UTYPE_NONE;
taosInitConfigOption(cfg); 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 #ifdef TD_TSZ
// lossy compress // lossy compress
cfg.option = "lossyColumns"; cfg.option = "lossyColumns";
......
...@@ -110,7 +110,8 @@ int32_t* taosGetErrno(); ...@@ -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_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 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_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 // mnode
#define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed")
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
extern "C" { extern "C" {
#endif #endif
#define TSDB_CFG_MAX_NUM 123 #define TSDB_CFG_MAX_NUM 124
#define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_PRINT_LEN 23
#define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_OPTION_LEN 24
#define TSDB_CFG_VALUE_LEN 41 #define TSDB_CFG_VALUE_LEN 41
......
...@@ -118,6 +118,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_COLUMN_LENGTH, "Invalid column length ...@@ -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_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, "Invalid JSON format")
TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_JSON_TYPE, "Invalid JSON data type") 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") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_VALUE_OUT_OF_RANGE, "Value out of range")
// mnode // mnode
......
...@@ -1090,9 +1090,10 @@ void verify_telnet_insert(TAOS* taos) { ...@@ -1090,9 +1090,10 @@ void verify_telnet_insert(TAOS* taos) {
//bigint //bigint
char* lines2_3[] = { char* lines2_3[] = {
"stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"", "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) { if (code) {
printf("lines2_3 code: %d, %s.\n", code, tstrerror(code)); printf("lines2_3 code: %d, %s.\n", code, tstrerror(code));
} }
...@@ -1107,11 +1108,10 @@ void verify_telnet_insert(TAOS* taos) { ...@@ -1107,11 +1108,10 @@ void verify_telnet_insert(TAOS* taos) {
"stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"", "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"",
"stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"", "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"",
"stb2_4 1626006833680ms -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 1626006833700ms 3.4E38f32 host=\"host0\"",
"stb2_4 1626006833710ms -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) { if (code) {
printf("lines2_4 code: %d, %s.\n", code, tstrerror(code)); printf("lines2_4 code: %d, %s.\n", code, tstrerror(code));
} }
...@@ -1127,9 +1127,10 @@ void verify_telnet_insert(TAOS* taos) { ...@@ -1127,9 +1127,10 @@ void verify_telnet_insert(TAOS* taos) {
"stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"", "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"",
"stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"", "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"",
"stb2_5 1626006833690ms 1.7E308f64 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) { if (code) {
printf("lines2_5 code: %d, %s.\n", code, tstrerror(code)); printf("lines2_5 code: %d, %s.\n", code, tstrerror(code));
} }
...@@ -1166,7 +1167,7 @@ void verify_telnet_insert(TAOS* taos) { ...@@ -1166,7 +1167,7 @@ void verify_telnet_insert(TAOS* taos) {
//nchar //nchar
char* lines2_8[] = { char* lines2_8[] = {
"stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"", "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); code = taos_insert_telnet_lines(taos, lines2_8, 2);
if (code) { if (code) {
......
...@@ -31,6 +31,27 @@ class TDTestCase: ...@@ -31,6 +31,27 @@ class TDTestCase:
### Default format ### ### 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 ### ### metric value ###
print("============= step1 : test metric value types ================") print("============= step1 : test metric value types ================")
payload = ''' payload = '''
...@@ -50,7 +71,7 @@ class TDTestCase: ...@@ -50,7 +71,7 @@ class TDTestCase:
print("insert_json_payload result {}".format(code)) print("insert_json_payload result {}".format(code))
tdSql.query("describe stb0_0") tdSql.query("describe stb0_0")
tdSql.checkData(1, 1, "FLOAT") tdSql.checkData(1, 1, "BIGINT")
payload = ''' payload = '''
{ {
...@@ -107,12 +128,52 @@ class TDTestCase: ...@@ -107,12 +128,52 @@ class TDTestCase:
print("insert_json_payload result {}".format(code)) print("insert_json_payload result {}".format(code))
tdSql.query("describe stb0_3") tdSql.query("describe stb0_3")
tdSql.checkData(1, 1, "NCHAR") tdSql.checkData(1, 1, "BINARY")
### timestamp 0 ###
payload = ''' payload = '''
{ {
"metric": "stb0_4", "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, "timestamp": 0,
"value": 123, "value": 123,
"tags": { "tags": {
...@@ -127,14 +188,15 @@ class TDTestCase: ...@@ -127,14 +188,15 @@ class TDTestCase:
print("insert_json_payload result {}".format(code)) print("insert_json_payload result {}".format(code))
print("============= step3 : test tags ================")
### ID ### ### ID ###
payload = ''' payload = '''
{ {
"metric": "stb0_5", "metric": "stb0_7",
"timestamp": 0, "timestamp": 0,
"value": 123, "value": 123,
"tags": { "tags": {
"ID": "tb0_5", "ID": "tb0_7",
"t1": true, "t1": true,
"iD": "tb000", "iD": "tb000",
"t2": false, "t2": false,
...@@ -147,10 +209,60 @@ class TDTestCase: ...@@ -147,10 +209,60 @@ class TDTestCase:
code = self._conn.insert_json_payload(payload) code = self._conn.insert_json_payload(payload)
print("insert_json_payload result {}".format(code)) print("insert_json_payload result {}".format(code))
tdSql.query("select tbname from stb0_5") tdSql.query("select tbname from stb0_7")
tdSql.checkData(0, 0, "tb0_5") 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 ### ### Nested format ###
print("============= step4 : test nested format ================")
### timestamp ### ### timestamp ###
#seconds #seconds
payload = ''' payload = '''
......
...@@ -36,13 +36,14 @@ class TDTestCase: ...@@ -36,13 +36,14 @@ class TDTestCase:
"stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", "stb0_0 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
"stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"", "stb0_1 1626006833639000000ns 4i8 host=\"host0\" interface=\"eth0\"",
"stb0_2 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) code = self._conn.insert_telnet_lines(lines0)
print("insert_telnet_lines result {}".format(code)) print("insert_telnet_lines result {}".format(code))
tdSql.query("show stables") tdSql.query("show stables")
tdSql.checkRows(3) tdSql.checkRows(4)
tdSql.query("describe stb0_0") tdSql.query("describe stb0_0")
tdSql.checkRows(4) tdSql.checkRows(4)
...@@ -53,6 +54,9 @@ class TDTestCase: ...@@ -53,6 +54,9 @@ class TDTestCase:
tdSql.query("describe stb0_2") tdSql.query("describe stb0_2")
tdSql.checkRows(4) tdSql.checkRows(4)
tdSql.query("describe _stb0_3_")
tdSql.checkRows(4)
### timestamp ### ### timestamp ###
print("============= step2 : test timestamp ================") print("============= step2 : test timestamp ================")
lines1 = [ lines1 = [
...@@ -122,14 +126,15 @@ class TDTestCase: ...@@ -122,14 +126,15 @@ class TDTestCase:
#bigint #bigint
lines2_3 = [ lines2_3 = [
"stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"", "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) code = self._conn.insert_telnet_lines(lines2_3)
print("insert_telnet_lines result {}".format(code)) print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_3") tdSql.query("select * from stb2_3")
tdSql.checkRows(2) tdSql.checkRows(3)
tdSql.query("describe stb2_3") tdSql.query("describe stb2_3")
tdSql.checkRows(3) tdSql.checkRows(3)
...@@ -145,7 +150,6 @@ class TDTestCase: ...@@ -145,7 +150,6 @@ class TDTestCase:
"stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"", "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"",
"stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"", "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"",
"stb2_4 1626006833680ms -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 1626006833700ms 3.4E38f32 host=\"host0\"",
"stb2_4 1626006833710ms -3.4E38f32 host=\"host0\"" "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\""
] ]
...@@ -154,7 +158,7 @@ class TDTestCase: ...@@ -154,7 +158,7 @@ class TDTestCase:
print("insert_telnet_lines result {}".format(code)) print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_4") tdSql.query("select * from stb2_4")
tdSql.checkRows(11) tdSql.checkRows(10)
tdSql.query("describe stb2_4") tdSql.query("describe stb2_4")
tdSql.checkRows(3) tdSql.checkRows(3)
...@@ -171,14 +175,15 @@ class TDTestCase: ...@@ -171,14 +175,15 @@ class TDTestCase:
"stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"", "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"",
"stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"", "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"",
"stb2_5 1626006833690ms 1.7E308f64 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) code = self._conn.insert_telnet_lines(lines2_5)
print("insert_telnet_lines result {}".format(code)) print("insert_telnet_lines result {}".format(code))
tdSql.query("select * from stb2_5") tdSql.query("select * from stb2_5")
tdSql.checkRows(10) tdSql.checkRows(11)
tdSql.query("describe stb2_5") tdSql.query("describe stb2_5")
tdSql.checkRows(3) tdSql.checkRows(3)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册