Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3a3c0867
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
3a3c0867
编写于
5月 14, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor:add escape for schemaless
上级
68d439f6
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
187 addition
and
166 deletion
+187
-166
source/client/src/clientSml.c
source/client/src/clientSml.c
+137
-130
source/client/test/smlTest.cpp
source/client/test/smlTest.cpp
+50
-36
未找到文件。
source/client/src/clientSml.c
浏览文件 @
3a3c0867
...
...
@@ -9,7 +9,6 @@
#include "tdef.h"
#include "tlog.h"
#include "tmsg.h"
#include "tstrbuild.h"
#include "ttime.h"
#include "ttypes.h"
#include "tcommon.h"
...
...
@@ -26,6 +25,35 @@
#define SLASH '\\'
#define tsMaxSQLStringLen (1024*1024)
#define JUMP_SPACE(sql) while (*sql != '\0'){if(*sql == SPACE) sql++;else break;}
// comma ,
#define IS_SLASH_COMMA(sql) (*(sql) == COMMA && *((sql) - 1) == SLASH)
#define IS_COMMA(sql) (*(sql) == COMMA && *((sql) - 1) != SLASH)
// space
#define IS_SLASH_SPACE(sql) (*(sql) == SPACE && *((sql) - 1) == SLASH)
#define IS_SPACE(sql) (*(sql) == SPACE && *((sql) - 1) != SLASH)
// equal =
#define IS_SLASH_EQUAL(sql) (*(sql) == EQUAL && *((sql) - 1) == SLASH)
#define IS_EQUAL(sql) (*(sql) == EQUAL && *((sql) - 1) != SLASH)
// quote "
#define IS_SLASH_QUOTE(sql) (*(sql) == QUOTE && *((sql) - 1) == SLASH)
#define IS_QUOTE(sql) (*(sql) == QUOTE && *((sql) - 1) != SLASH)
// SLASH
#define IS_SLASH_SLASH(sql) (*(sql) == SLASH && *((sql) - 1) == SLASH)
#define IS_SLASH_LETTER(sql) (IS_SLASH_COMMA(sql) || IS_SLASH_SPACE(sql) || IS_SLASH_EQUAL(sql) || IS_SLASH_QUOTE(sql) || IS_SLASH_SLASH(sql))
#define MOVE_FORWARD_ONE(sql,len) (memmove((void*)((sql) - 1), (sql), len))
#define PROCESS_SLASH(key,keyLen) \
for (int i = 1; i < keyLen; ++i) { \
if(IS_SLASH_LETTER(key+i)){ \
MOVE_FORWARD_ONE(key+i, keyLen-i); \
i--; \
keyLen--; \
} \
}
#define OTD_MAX_FIELDS_NUM 2
#define OTD_JSON_SUB_FIELDS_NUM 2
#define OTD_JSON_FIELDS_NUM 4
...
...
@@ -760,7 +788,7 @@ static int64_t smlParseInfluxTime(SSmlHandle* info, const char* data, int32_t le
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"invalid timestamp precision"
,
NULL
);
return
-
1
;
}
if
(
!
data
){
if
(
len
==
0
){
return
smlGetTimeNow
(
tsType
);
}
...
...
@@ -850,66 +878,56 @@ static bool smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) {
static
int32_t
smlParseInfluxString
(
const
char
*
sql
,
SSmlLineInfo
*
elements
,
SSmlMsgBuf
*
msg
){
if
(
!
sql
)
return
TSDB_CODE_SML_INVALID_DATA
;
while
(
*
sql
!=
'\0'
)
{
// jump the space at the begining
if
(
*
sql
!=
SPACE
)
{
JUMP_SPACE
(
sql
)
if
(
*
sql
==
COMMA
)
return
TSDB_CODE_SML_INVALID_DATA
;
elements
->
measure
=
sql
;
break
;
}
sql
++
;
}
if
(
!
elements
->
measure
||
*
sql
==
COMMA
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// parse measure
and tag
// parse measure
while
(
*
sql
!=
'\0'
)
{
if
(
elements
->
measureLen
==
0
&&
*
sql
==
COMMA
&&
*
(
sql
-
1
)
!=
SLASH
)
{
// find the first comma
elements
->
measureLen
=
sql
-
elements
->
measure
;
sql
++
;
elements
->
tags
=
sql
;
if
(
IS_SLASH_LETTER
(
sql
)){
MOVE_FORWARD_ONE
(
sql
,
strlen
(
sql
)
+
1
);
continue
;
}
if
(
*
sql
==
SPACE
&&
*
(
sql
-
1
)
!=
SLASH
)
{
// find the first space
if
(
elements
->
measureLen
==
0
)
{
elements
->
measureLen
=
sql
-
elements
->
measure
;
elements
->
tags
=
sql
;
}
elements
->
tagsLen
=
sql
-
elements
->
tags
;
elements
->
measureTagsLen
=
sql
-
elements
->
measure
;
if
(
IS_COMMA
(
sql
)){
break
;
}
sql
++
;
if
(
IS_SPACE
(
sql
)){
break
;
}
if
(
elements
->
tagsLen
==
0
){
// measure, cols1=a measure cols1=a
elements
->
measureTagsLen
=
elements
->
measureLen
;
sql
++
;
}
elements
->
measureLen
=
sql
-
elements
->
measure
;
if
(
elements
->
measureLen
==
0
)
{
smlBuildInvalidDataMsg
(
msg
,
"
invalid measure"
,
elements
->
measure
);
smlBuildInvalidDataMsg
(
msg
,
"
measure is empty"
,
NULL
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// parse cols
// parse tag
if
(
*
sql
==
SPACE
){
elements
->
tagsLen
=
0
;
}
else
{
if
(
*
sql
==
COMMA
)
sql
++
;
elements
->
tags
=
sql
;
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
!=
SPACE
)
{
elements
->
cols
=
sql
;
if
(
IS_SPACE
(
sql
)){
break
;
}
sql
++
;
}
if
(
!
elements
->
cols
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid columns"
,
elements
->
cols
);
return
TSDB_CODE_SML_INVALID_DATA
;
elements
->
tagsLen
=
sql
-
elements
->
tags
;
}
elements
->
measureTagsLen
=
sql
-
elements
->
measure
;
// parse cols
JUMP_SPACE
(
sql
)
elements
->
cols
=
sql
;
bool
isInQuote
=
false
;
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
==
QUOTE
&&
*
(
sql
-
1
)
!=
SLASH
){
if
(
IS_QUOTE
(
sql
)
){
isInQuote
=
!
isInQuote
;
}
if
(
!
isInQuote
&&
*
sql
==
SPACE
&&
*
(
sql
-
1
)
!=
SLASH
)
{
if
(
!
isInQuote
&&
IS_SPACE
(
sql
))
{
break
;
}
sql
++
;
...
...
@@ -919,20 +937,21 @@ static int32_t smlParseInfluxString(const char* sql, SSmlLineInfo *elements, SSm
return
TSDB_CODE_SML_INVALID_DATA
;
}
elements
->
colsLen
=
sql
-
elements
->
cols
;
if
(
elements
->
colsLen
==
0
)
{
smlBuildInvalidDataMsg
(
msg
,
"cols is empty"
,
NULL
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// parse ts,ts can be empty
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
!=
SPACE
&&
elements
->
timestamp
==
NULL
)
{
// parse timestamp
JUMP_SPACE
(
sql
)
elements
->
timestamp
=
sql
;
}
if
(
*
sql
==
SPACE
&&
elements
->
timestamp
!=
NULL
){
while
(
*
sql
!=
'\0'
)
{
if
(
*
sql
==
SPACE
){
break
;
}
sql
++
;
}
if
(
elements
->
timestamp
){
elements
->
timestampLen
=
sql
-
elements
->
timestamp
;
}
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -949,43 +968,58 @@ static void smlParseTelnetElement(const char **sql, const char **data, int32_t *
}
}
static
int32_t
smlParseTelnetTags
(
const
char
*
data
,
int32_t
len
,
SArray
*
cols
,
SHashObj
*
dumplicateKey
,
SSmlMsgBuf
*
msg
){
for
(
int
i
=
0
;
i
<
len
;
i
++
){
// parse key
const
char
*
key
=
data
+
i
;
static
int32_t
smlParseTelnetTags
(
const
char
*
data
,
SArray
*
cols
,
SHashObj
*
dumplicateKey
,
SSmlMsgBuf
*
msg
){
const
char
*
sql
=
data
;
while
(
*
sql
!=
'\0'
){
JUMP_SPACE
(
sql
)
const
char
*
key
=
sql
;
int32_t
keyLen
=
0
;
while
(
i
<
len
){
if
(
data
[
i
]
==
EQUAL
){
keyLen
=
data
+
i
-
key
;
// parse key
while
(
*
sql
!=
'\0'
){
if
(
*
sql
==
SPACE
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
*
sql
==
EQUAL
)
{
keyLen
=
sql
-
key
;
sql
++
;
break
;
}
i
++
;
sql
++
;
}
if
(
keyLen
==
0
||
keyLen
>=
TSDB_COL_NAME_LEN
){
smlBuildInvalidDataMsg
(
msg
,
"invalid key or key is too long than 64"
,
key
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
smlCheckDuplicateKey
(
key
,
keyLen
,
dumplicateKey
)){
smlBuildInvalidDataMsg
(
msg
,
"dumplicate key"
,
key
);
return
TSDB_CODE_TSC_DUP_TAG_NAMES
;
}
// parse value
i
++
;
const
char
*
value
=
data
+
i
;
while
(
i
<
len
){
if
(
data
[
i
]
==
SPACE
){
const
char
*
value
=
sql
;
int32_t
valueLen
=
0
;
while
(
*
sql
!=
'\0'
)
{
// parse value
if
(
*
sql
==
SPACE
)
{
break
;
}
i
++
;
if
(
*
sql
==
EQUAL
)
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
sql
++
;
}
int32_t
valueLen
=
data
+
i
-
value
;
valueLen
=
sql
-
value
;
sql
++
;
JUMP_SPACE
(
sql
)
if
(
valueLen
==
0
){
smlBuildInvalidDataMsg
(
msg
,
"invalid value"
,
value
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
// add kv to SSmlKv
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosMemoryCalloc
(
sizeof
(
SSmlKv
),
1
);
if
(
!
kv
)
return
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -993,13 +1027,14 @@ static int32_t smlParseTelnetTags(const char* data, int32_t len, SArray *cols, S
kv
->
keyLen
=
keyLen
;
kv
->
value
=
value
;
kv
->
length
=
valueLen
;
kv
->
type
=
TSDB_DATA_TYPE_NCHAR
;
//todo
kv
->
type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
cols
)
taosArrayPush
(
cols
,
&
kv
);
}
return
TSDB_CODE_SUCCESS
;
}
// format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
static
int32_t
smlParseTelnetString
(
SSmlHandle
*
info
,
const
char
*
sql
,
SSmlTableInfo
*
tinfo
,
SArray
*
cols
){
if
(
!
sql
)
return
TSDB_CODE_SML_INVALID_DATA
;
...
...
@@ -1048,10 +1083,7 @@ static int32_t smlParseTelnetString(SSmlHandle *info, const char* sql, SSmlTable
}
// parse tags
while
(
*
sql
==
SPACE
){
sql
++
;
}
ret
=
smlParseTelnetTags
(
sql
,
strlen
(
sql
),
tinfo
->
tags
,
info
->
dumplicateKey
,
&
info
->
msgBuf
);
ret
=
smlParseTelnetTags
(
sql
,
tinfo
->
tags
,
info
->
dumplicateKey
,
&
info
->
msgBuf
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
smlBuildInvalidDataMsg
(
&
info
->
msgBuf
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
...
...
@@ -1073,49 +1105,67 @@ static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, bool is
return
TSDB_CODE_SUCCESS
;
}
for
(
int
i
=
0
;
i
<
len
;
i
++
){
// parse key
const
char
*
key
=
data
+
i
;
const
char
*
sql
=
data
;
while
(
sql
<
data
+
len
){
const
char
*
key
=
sql
;
int32_t
keyLen
=
0
;
while
(
i
<
len
){
if
(
data
[
i
]
==
EQUAL
&&
i
>
0
&&
data
[
i
-
1
]
!=
SLASH
){
keyLen
=
data
+
i
-
key
;
while
(
sql
<
data
+
len
){
// parse key
if
(
IS_COMMA
(
sql
))
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
IS_EQUAL
(
sql
))
{
keyLen
=
sql
-
key
;
sql
++
;
break
;
}
i
++
;
sql
++
;
}
if
(
keyLen
==
0
||
keyLen
>=
TSDB_COL_NAME_LEN
){
smlBuildInvalidDataMsg
(
msg
,
"invalid key or key is too long than 64"
,
key
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
if
(
smlCheckDuplicateKey
(
key
,
keyLen
,
dumplicateKey
)){
smlBuildInvalidDataMsg
(
msg
,
"dumplicate key"
,
key
);
return
TSDB_CODE_TSC_DUP_TAG_NAMES
;
}
// parse value
i
++
;
const
char
*
value
=
data
+
i
;
const
char
*
value
=
sql
;
int32_t
valueLen
=
0
;
bool
isInQuote
=
false
;
while
(
i
<
len
){
if
(
!
isTag
&&
data
[
i
]
==
QUOTE
&&
data
[
i
-
1
]
!=
SLASH
){
while
(
sql
<
data
+
len
)
{
// parse value
if
(
!
isTag
&&
IS_QUOTE
(
sql
)){
isInQuote
=
!
isInQuote
;
sql
++
;
continue
;
}
if
(
!
isInQuote
&&
data
[
i
]
==
COMMA
&&
i
>
0
&&
data
[
i
-
1
]
!=
SLASH
)
{
if
(
!
isInQuote
&&
IS_COMMA
(
sql
))
{
break
;
}
i
++
;
if
(
!
isInQuote
&&
IS_EQUAL
(
sql
))
{
smlBuildInvalidDataMsg
(
msg
,
"invalid data"
,
sql
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
sql
++
;
}
if
(
!
isTag
&&
isInQuote
){
valueLen
=
sql
-
value
;
sql
++
;
if
(
isInQuote
){
smlBuildInvalidDataMsg
(
msg
,
"only one quote"
,
value
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
int32_t
valueLen
=
data
+
i
-
value
;
if
(
valueLen
==
0
){
smlBuildInvalidDataMsg
(
msg
,
"invalid value"
,
value
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
PROCESS_SLASH
(
key
,
keyLen
)
PROCESS_SLASH
(
value
,
valueLen
)
// add kv to SSmlKv
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosMemoryCalloc
(
sizeof
(
SSmlKv
),
1
);
...
...
@@ -1138,49 +1188,6 @@ static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, bool is
return
TSDB_CODE_SUCCESS
;
}
//static int32_t parseSmlCols(const char* data, SArray *cols){
// while(*data != '\0'){
// if(*data == EQUAL) return TSDB_CODE_SML_INVALID_DATA;
// const char *key = data;
// int32_t keyLen = 0;
// while(*data != '\0'){
// if(*data == EQUAL && *(data-1) != SLASH){
// keyLen = data - key;
// data ++;
// break;
// }
// data++;
// }
// if(keyLen == 0){
// return TSDB_CODE_SML_INVALID_DATA;
// }
//
// if(*data == COMMA) return TSDB_CODE_SML_INVALID_DATA;
// const char *value = data;
// int32_t valueLen = 0;
// while(*data != '\0'){
// if(*data == COMMA && *(data-1) != SLASH){
// valueLen = data - value;
// data ++;
// break;
// }
// data++;
// }
// if(valueLen == 0){
// return TSDB_CODE_SML_INVALID_DATA;
// }
//
// TAOS_SML_KV *kv = taosMemoryCalloc(sizeof(TAOS_SML_KV), 1);
// kv->key = key;
// kv->keyLen = keyLen;
// kv->value = value;
// kv->valueLen = valueLen;
// kv->type = TSDB_DATA_TYPE_NCHAR;
// if(cols) taosArrayPush(cols, &kv);
// }
// return TSDB_CODE_SUCCESS;
//}
static
bool
smlUpdateMeta
(
SHashObj
*
metaHash
,
SArray
*
metaArray
,
SArray
*
cols
,
SSmlMsgBuf
*
msg
){
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
cols
);
++
i
)
{
//jump timestamp
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
i
);
...
...
source/client/test/smlTest.cpp
浏览文件 @
3a3c0867
...
...
@@ -41,12 +41,14 @@ TEST(testCase, smlParseInfluxString_Test) {
SSmlLineInfo
elements
=
{
0
};
// case 1
char
*
sql
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 ,32,c=3"
;
char
*
tmp
=
"
\\
,st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 ,32,c=3"
;
char
*
sql
=
(
char
*
)
taosMemoryCalloc
(
256
,
1
);
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
int
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st,t1=3,t2=4,t3=t3"
));
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"
,
st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"
,
st,t1=3,t2=4,t3=t3"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
+
1
);
ASSERT_EQ
(
elements
.
tagsLen
,
strlen
(
"t1=3,t2=4,t3=t3"
));
...
...
@@ -58,21 +60,24 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 2 false
sql
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
tmp
=
"st,t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_NE
(
ret
,
0
);
// case 3 false
sql
=
"st, t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
tmp
=
"st, t1=3,t2=4,t3=t3 c1=3i64,c3=
\"
passit hello,c1=2,c2=false,c4=4f64 1626006833639000000"
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
2
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
1
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"t1=3,t2=4,t3=t3"
));
// case 4 tag is null
sql
=
"st, c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000"
;
tmp
=
"st, c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000"
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
...
...
@@ -90,44 +95,45 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 5 tag is null
sql
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 "
;
tmp
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 1626006833639000000 "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
sql
++
;
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measure
,
sql
+
1
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measureLen
);
ASSERT_EQ
(
elements
.
tags
,
sql
+
1
+
elements
.
measureLen
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
1
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
3
+
elements
.
colsLen
+
2
);
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
1
+
elements
.
measureTagsLen
+
3
+
elements
.
colsLen
+
2
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 6
sql
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 "
;
tmp
=
" st c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64 "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
// case 7
sql
=
" st , "
;
tmp
=
" st , "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
sql
++
;
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
3
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
","
));
ASSERT_NE
(
ret
,
0
);
// case 8 false
sql
=
", st , "
;
tmp
=
", st , "
;
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_NE
(
ret
,
0
);
taosMemoryFree
(
sql
);
}
TEST
(
testCase
,
smlParseCols_Error_Test
)
{
...
...
@@ -188,7 +194,8 @@ TEST(testCase, smlParseCols_Error_Test) {
"c=-3.402823466e+39u64"
,
"c=-339u64"
,
"c=18446744073709551616u64"
,
"c=1,c=2"
"c=1,c=2"
,
"c=1=2"
};
SHashObj
*
dumplicateKey
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
...
...
@@ -198,9 +205,12 @@ TEST(testCase, smlParseCols_Error_Test) {
msgBuf
.
buf
=
msg
;
msgBuf
.
len
=
256
;
int32_t
len
=
strlen
(
data
[
i
]);
int32_t
ret
=
smlParseCols
(
data
[
i
],
len
,
NULL
,
false
,
dumplicateKey
,
&
msgBuf
);
char
*
sql
=
(
char
*
)
taosMemoryCalloc
(
256
,
1
);
memcpy
(
sql
,
data
[
i
],
len
+
1
);
int32_t
ret
=
smlParseCols
(
sql
,
len
,
NULL
,
false
,
dumplicateKey
,
&
msgBuf
);
ASSERT_NE
(
ret
,
TSDB_CODE_SUCCESS
);
taosHashClear
(
dumplicateKey
);
taosMemoryFree
(
sql
);
}
taosHashCleanup
(
dumplicateKey
);
}
...
...
@@ -216,7 +226,7 @@ TEST(testCase, smlParseCols_tag_Test) {
SHashObj
*
dumplicateKey
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
const
char
*
data
=
"cbin=
\"
passit helloc
=2
\"
,cnch=L
\"
iisdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
"cbin=
\"
passit helloc
\"
,cnch=L
\"
iisdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
int32_t
len
=
strlen
(
data
);
int32_t
ret
=
smlParseCols
(
data
,
len
,
cols
,
true
,
dumplicateKey
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
TSDB_CODE_SUCCESS
);
...
...
@@ -278,20 +288,22 @@ TEST(testCase, smlParseCols_Test) {
SHashObj
*
dumplicateKey
=
taosHashInit
(
32
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
const
char
*
data
=
"cb
in=
\"
passit hello,c=2
\"
,cnch=L
\"
ii
sdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
const
char
*
data
=
"cb
\\
=in=
\"
pass
\\
,it hello,c=2
\"
,cnch=L
\"
ii
\\
=
sdfsf
\"
,cbool=false,cf64=4.31f64,cf64_=8.32,cf32=8.23f32,ci8=-34i8,cu8=89u8,ci16=233i16,cu16=898u16,ci32=98289i32,cu32=12323u32,ci64=-89238i64,ci=989i,cu64=8989323u64,cbooltrue=true,cboolt=t,cboolf=f,cnch_=l
\"
iuwq
\"
"
;
int32_t
len
=
strlen
(
data
);
int32_t
ret
=
smlParseCols
(
data
,
len
,
cols
,
false
,
dumplicateKey
,
&
msgBuf
);
char
*
sql
=
(
char
*
)
taosMemoryCalloc
(
1024
,
1
);
memcpy
(
sql
,
data
,
len
+
1
);
int32_t
ret
=
smlParseCols
(
sql
,
len
,
cols
,
false
,
dumplicateKey
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
TSDB_CODE_SUCCESS
);
int32_t
size
=
taosArrayGetSize
(
cols
);
ASSERT_EQ
(
size
,
19
);
// binary
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cb
in"
,
4
),
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cb
=in"
,
5
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_BINARY
);
ASSERT_EQ
(
kv
->
length
,
16
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"pass
it"
,
6
),
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"pass
,it "
,
8
),
0
);
taosMemoryFree
(
kv
);
// nchar
...
...
@@ -300,7 +312,7 @@ TEST(testCase, smlParseCols_Test) {
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
7
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"ii
sd"
,
4
),
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"ii
=sd"
,
5
),
0
);
taosMemoryFree
(
kv
);
// bool
...
...
@@ -463,6 +475,7 @@ TEST(testCase, smlParseCols_Test) {
taosArrayDestroy
(
cols
);
taosHashCleanup
(
dumplicateKey
);
taosMemoryFree
(
sql
);
}
TEST
(
testCase
,
smlProcess_influx_Test
)
{
...
...
@@ -492,7 +505,7 @@ TEST(testCase, smlProcess_influx_Test) {
"readings,name=truck_2,fleet=North,driver=Derek,model=F-150 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=24.5208,longitude=28.09377,elevation=428,velocity=0,heading=304,grade=0,fuel_consumption=25 1451609400000000000"
,
"readings,fleet=South,name=truck_0,driver=Trish,model=H-2,device_version=v2.3 fuel_consumption=25,grade=0 1451629400000000000"
,
"stable,t1=t1,t2=t2,t3=t3 c1=1,c2=2,c3=3,c4=4 1451629500000000000"
,
"stable,t2=t2,t1=t1,t3=t3 c1=1,c3=3,c4=4 1451629600000000000"
"stable,t2=t2,t1=t1,t3=t3 c1=1,c3=3,c4=4 1451629600000000000"
,
};
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
...
...
@@ -575,12 +588,11 @@ TEST(testCase, smlProcess_telnet_Test) {
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_TELNET_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
true
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
5
]
=
{
const
char
*
sql
[
4
]
=
{
"sys.if.bytes.out 1479496100 1.3E0 host=web01 interface=eth0"
,
"sys.if.bytes.out
1479496101 1.3E1 interface=eth0 host=web01
"
,
"sys.if.bytes.out
1479496101 1.3E1 interface=eth0 host=web01
"
,
"sys.if.bytes.out 1479496102 1.3E3 network=tcp"
,
"sys.procs.running 1479496100 42 host=web01 "
,
" sys.procs.running 1479496200 42 host=web01=4"
" sys.procs.running 1479496100 42 host=web01 "
};
int
ret
=
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
ASSERT_EQ
(
ret
,
0
);
...
...
@@ -857,7 +869,7 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
ASSERT_NE
(
info
,
nullptr
);
int32_t
ret
=
0
;
const
char
*
sql
[
19
]
=
{
const
char
*
sql
[]
=
{
"sys.procs.running 14794961040 42 host=web01"
,
"sys.procs.running 14791040 42 host=web01"
,
"sys.procs.running erere 42 host=web01"
,
...
...
@@ -877,6 +889,8 @@ TEST(testCase, smlParseTelnetLine_error_Test) {
"sys.procs.running 1479496100 42 host=web01 cpu= "
,
"sys.procs.running 1479496100 42 host=web01 host=w2"
,
"sys.procs.running 1479496100 42 host=web01 host"
,
"sys.procs.running 1479496100 42 host=web01=er"
,
"sys.procs.running 1479496100 42 host= web01"
,
};
for
(
int
i
=
0
;
i
<
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]);
i
++
){
ret
=
smlParseTelnetLine
(
info
,
(
void
*
)
sql
[
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录