提交 8a8b7d71 编写于 作者: G Ganlin Zhao

[schemaless] removed line protocol timestamp appendix

上级 83a7f5ba
...@@ -1435,17 +1435,25 @@ static bool isNchar(char *pVal, uint16_t len) { ...@@ -1435,17 +1435,25 @@ static bool isNchar(char *pVal, uint16_t len) {
return false; return false;
} }
static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType, SSmlLinesInfo* info) { static int32_t isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType, SSmlLinesInfo* info) {
if (len == 0) { if (len == 0) {
return true; return TSDB_CODE_SUCCESS;
} }
if ((len == 1) && pVal[0] == '0') { if ((len == 1) && pVal[0] == '0') {
*tsType = SML_TIME_STAMP_NOW; *tsType = SML_TIME_STAMP_NOW;
return true; return TSDB_CODE_SUCCESS;
}
for (int i = 0; i < len; ++i) {
if(!isdigit(pVal[i])) {
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
}
} }
//Default no appendix /* For InfluxDB line protocol use user passed timestamp precision
if (isdigit(pVal[len - 1]) && isdigit(pVal[len - 2])) { * For OpenTSDB protocols only 10 digit(seconds) or 13 digits(milliseconds)
* precision allowed
*/
if (info->protocol == TSDB_SML_LINE_PROTOCOL) { if (info->protocol == TSDB_SML_LINE_PROTOCOL) {
if (info->tsType != SML_TIME_STAMP_NOT_CONFIGURED) { if (info->tsType != SML_TIME_STAMP_NOT_CONFIGURED) {
*tsType = info->tsType; *tsType = info->tsType;
...@@ -1461,32 +1469,31 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType, SSml ...@@ -1461,32 +1469,31 @@ static bool isTimeStamp(char *pVal, uint16_t len, SMLTimeStampType *tsType, SSml
return TSDB_CODE_TSC_INVALID_TIME_STAMP; return TSDB_CODE_TSC_INVALID_TIME_STAMP;
} }
} }
return true; return TSDB_CODE_SUCCESS;
}
if (pVal[len - 1] == 's') { //if (pVal[len - 1] == 's') {
switch (pVal[len - 2]) { // switch (pVal[len - 2]) {
case 'm': // case 'm':
*tsType = SML_TIME_STAMP_MILLI_SECONDS; // *tsType = SML_TIME_STAMP_MILLI_SECONDS;
break; // break;
case 'u': // case 'u':
*tsType = SML_TIME_STAMP_MICRO_SECONDS; // *tsType = SML_TIME_STAMP_MICRO_SECONDS;
break; // break;
case 'n': // case 'n':
*tsType = SML_TIME_STAMP_NANO_SECONDS; // *tsType = SML_TIME_STAMP_NANO_SECONDS;
break; // break;
default: // default:
if (isdigit(pVal[len - 2])) { // if (isdigit(pVal[len - 2])) {
*tsType = SML_TIME_STAMP_SECONDS; // *tsType = SML_TIME_STAMP_SECONDS;
break; // break;
} else { // } else {
return false; // return false;
} // }
} // }
//printf("Type is timestamp(%s)\n", pVal); // //printf("Type is timestamp(%s)\n", pVal);
return true; // return true;
} //}
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) {
...@@ -1750,14 +1757,6 @@ bool convertSmlValueType(TAOS_SML_KV *pVal, char *value, ...@@ -1750,14 +1757,6 @@ bool convertSmlValueType(TAOS_SML_KV *pVal, char *value,
static int32_t getTimeStampValue(char *value, uint16_t len, static int32_t getTimeStampValue(char *value, uint16_t len,
SMLTimeStampType type, int64_t *ts, SSmlLinesInfo* info) { SMLTimeStampType type, int64_t *ts, SSmlLinesInfo* info) {
if (len >= 2) {
for (int i = 0; i < len - 2; ++i) {
if(!isdigit(value[i])) {
return TSDB_CODE_TSC_INVALID_TIME_STAMP;
}
}
}
//No appendix or no timestamp given (len = 0) //No appendix or no timestamp given (len = 0)
if (len != 0 && type != SML_TIME_STAMP_NOW) { if (len != 0 && type != SML_TIME_STAMP_NOW) {
*ts = (int64_t)strtoll(value, NULL, 10); *ts = (int64_t)strtoll(value, NULL, 10);
...@@ -1806,13 +1805,13 @@ int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value, ...@@ -1806,13 +1805,13 @@ int32_t convertSmlTimeStamp(TAOS_SML_KV *pVal, char *value,
SMLTimeStampType type; SMLTimeStampType type;
int64_t tsVal; int64_t tsVal;
strntolower_s(value, value, len); ret = isTimeStamp(value, len, &type, info);
if (!isTimeStamp(value, len, &type, info)) { if (ret != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_TIME_STAMP; return ret;
} }
ret = getTimeStampValue(value, len, type, &tsVal, info); ret = getTimeStampValue(value, len, type, &tsVal, info);
if (ret) { if (ret != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
tscDebug("SML:0x%"PRIx64"Timestamp after conversion:%"PRId64, info->id, tsVal); tscDebug("SML:0x%"PRIx64"Timestamp after conversion:%"PRId64, info->id, tsVal);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册