提交 194a1081 编写于 作者: G Ganlin Zhao

[TD-10639]<fix>: allow influxDB line protocol column value contain space/comma inside double quote

上级 befffdf7
...@@ -1871,7 +1871,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1871,7 +1871,7 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
//key field cannot start with digit //key field cannot start with digit
if (isdigit(*cur)) { if (isdigit(*cur)) {
tscError("SML:0x%"PRIx64" Tag key cannnot start with digit", info->id); tscError("SML:0x%"PRIx64" Tag key cannot start with digit", info->id);
return TSDB_CODE_TSC_LINE_SYNTAX_ERROR; return TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
} }
while (*cur != '\0') { while (*cur != '\0') {
...@@ -1885,6 +1885,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1885,6 +1885,8 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
} }
//Escape special character //Escape special character
if (*cur == '\\') { if (*cur == '\\') {
//TODO: escape will work after column & tag
//support spcial characters
escapeSpecialCharacter(2, &cur); escapeSpecialCharacter(2, &cur);
} }
key[len] = *cur; key[len] = *cur;
...@@ -1908,13 +1910,42 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash ...@@ -1908,13 +1910,42 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index, SHashObj *pHash
static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index, static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
bool *is_last_kv, SSmlLinesInfo* info, bool isTag) { bool *is_last_kv, SSmlLinesInfo* info, bool isTag) {
const char *start, *cur; const char *start, *cur;
int32_t ret = TSDB_CODE_SUCCESS;
char *value = NULL; char *value = NULL;
uint16_t len = 0; uint16_t len = 0;
bool searchQuote = false;
start = cur = *index; start = cur = *index;
//if field value is string
if (!isTag) {
if (*cur == '"') {
searchQuote = true;
cur += 1;
len += 1;
} else if (*cur == 'L' && *(cur + 1) == '"') {
searchQuote = true;
cur += 2;
len += 2;
}
}
while (1) { while (1) {
// unescaped ',' or ' ' or '\0' identifies a value // unescaped ',' or ' ' or '\0' identifies a value
if ((*cur == ',' || *cur == ' ' || *cur == '\0') && *(cur - 1) != '\\') { if (((*cur == ',' || *cur == ' ' ) && *(cur - 1) != '\\') || *cur == '\0') {
if (searchQuote == true) {
//first quote ignored while searching
if (*(cur - 1) == '"' && len != 1 && len != 2) {
*is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false;
break;
} else if (*cur == '\0') {
ret = TSDB_CODE_TSC_LINE_SYNTAX_ERROR;
goto error;
} else {
cur++;
len++;
continue;
}
}
//unescaped ' ' or '\0' indicates end of value //unescaped ' ' or '\0' indicates end of value
*is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false; *is_last_kv = (*cur == ' ' || *cur == '\0') ? true : false;
if (*cur == ' ' && *(cur + 1) == ' ') { if (*cur == ' ' && *(cur + 1) == ' ') {
...@@ -1926,7 +1957,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index, ...@@ -1926,7 +1957,7 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
} }
//Escape special character //Escape special character
if (*cur == '\\') { if (*cur == '\\') {
escapeSpecialCharacter(2, &cur); escapeSpecialCharacter(isTag ? 2 : 3, &cur);
} }
cur++; cur++;
len++; len++;
...@@ -1938,16 +1969,20 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index, ...@@ -1938,16 +1969,20 @@ static bool parseSmlValue(TAOS_SML_KV *pKV, const char **index,
if (!convertSmlValueType(pKV, value, len, info, isTag)) { if (!convertSmlValueType(pKV, value, len, info, isTag)) {
tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type", tscError("SML:0x%"PRIx64" Failed to convert sml value string(%s) to any type",
info->id, value); info->id, value);
//free previous alocated key field
free(pKV->key);
pKV->key = NULL;
free(value); free(value);
return TSDB_CODE_TSC_INVALID_VALUE; ret = TSDB_CODE_TSC_INVALID_VALUE;
goto error;
} }
free(value); free(value);
*index = (*cur == '\0') ? cur : cur + 1; *index = (*cur == '\0') ? cur : cur + 1;
return TSDB_CODE_SUCCESS; return ret;
error:
//free previous alocated key field
free(pKV->key);
pKV->key = NULL;
return ret;
} }
static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index, static int32_t parseSmlMeasurement(TAOS_SML_DATA_POINT *pSml, const char **index,
......
...@@ -31,9 +31,9 @@ class TDTestCase: ...@@ -31,9 +31,9 @@ class TDTestCase:
tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)') tdSql.execute('create stable ste(ts timestamp, f int) tags(t1 bigint)')
lines = [ "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000", lines = [ "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"\"\"a pa,\"s si,t \"\"\",c2=false,c4=4f64 1626006833639000000",
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000", "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000",
"ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532", "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\" i,\"a \"m,\"\"\" 1626056811823316532",
"stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000", "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000",
"st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000", "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000",
"ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532", "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册