Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d6478273
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
d6478273
编写于
5月 14, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor:add escape for schemaless
上级
3a3c0867
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
47 deletion
+51
-47
source/client/src/clientSml.c
source/client/src/clientSml.c
+4
-3
source/client/test/smlTest.cpp
source/client/test/smlTest.cpp
+47
-44
未找到文件。
source/client/src/clientSml.c
浏览文件 @
d6478273
...
...
@@ -70,6 +70,7 @@ for (int i = 1; i < keyLen; ++i) { \
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
#define CHAR_SAVE_LENGTH 8
//=================================================================================================
typedef
TSDB_SML_PROTOCOL_TYPE
SMLProtocolType
;
...
...
@@ -259,7 +260,7 @@ static int32_t smlBuildColumnDescription(SSmlKv* field, char* buf, int32_t bufSi
char
tname
[
TSDB_TABLE_NAME_LEN
]
=
{
0
};
memcpy
(
tname
,
field
->
key
,
field
->
keyLen
);
if
(
type
==
TSDB_DATA_TYPE_BINARY
||
type
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
bytes
=
field
->
length
;
// todo
int32_t
bytes
=
field
->
length
>
CHAR_SAVE_LENGTH
?
(
2
*
field
->
length
)
:
CHAR_SAVE_LENGTH
;
int
out
=
snprintf
(
buf
,
bufSize
,
"`%s` %s(%d)"
,
tname
,
tDataTypes
[
field
->
type
].
name
,
bytes
);
*
outBytes
=
out
;
...
...
@@ -459,7 +460,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
SEpSet
ep
=
getEpSet_s
(
&
info
->
taos
->
pAppInfo
->
mgmtEp
);
size_t
superTableLen
=
0
;
void
*
superTable
=
taosHashGetKey
(
tableMetaSml
,
&
superTableLen
);
// todo escape
void
*
superTable
=
taosHashGetKey
(
tableMetaSml
,
&
superTableLen
);
SName
pName
=
{
TSDB_TABLE_NAME_T
,
info
->
taos
->
acctId
,
{
0
},
{
0
}};
strcpy
(
pName
.
dbname
,
info
->
pRequest
->
pDb
);
memcpy
(
pName
.
tname
,
superTable
,
superTableLen
);
...
...
@@ -1305,7 +1306,7 @@ static int32_t smlDealCols(SSmlTableInfo* oneTable, bool dataFormat, SArray *col
}
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
cols
);
i
++
){
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
i
);
taosHashPut
(
kvHash
,
kv
->
key
,
kv
->
keyLen
,
&
kv
,
POINTER_BYTES
);
// todo key need escape, like \=, because find by schema name later
taosHashPut
(
kvHash
,
kv
->
key
,
kv
->
keyLen
,
&
kv
,
POINTER_BYTES
);
}
taosArrayPush
(
oneTable
->
cols
,
&
kvHash
);
...
...
source/client/test/smlTest.cpp
浏览文件 @
d6478273
...
...
@@ -83,15 +83,15 @@ TEST(testCase, smlParseInfluxString_Test) {
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st
,
"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measure
Len
+
1
);
ASSERT_EQ
(
elements
.
tags
,
sql
+
elements
.
measure
TagsLen
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
2
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
elements
.
measureTagsLen
+
1
);
ASSERT_EQ
(
elements
.
colsLen
,
strlen
(
"c1=3i64,c3=
\"
passit hello,c1=2
\"
,c2=false,c4=4f64"
));
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
2
+
elements
.
colsLen
+
1
);
ASSERT_EQ
(
elements
.
timestamp
,
sql
+
elements
.
measureTagsLen
+
1
+
elements
.
colsLen
+
1
);
ASSERT_EQ
(
elements
.
timestampLen
,
strlen
(
"1626006833639000000"
));
// case 5 tag is null
...
...
@@ -100,11 +100,10 @@ TEST(testCase, smlParseInfluxString_Test) {
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
elements
.
measure
,
sql
+
1
);
ASSERT_EQ
(
elements
.
measure
,
sql
+
1
);
ASSERT_EQ
(
elements
.
measureLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
measureTagsLen
,
strlen
(
"st"
));
ASSERT_EQ
(
elements
.
tags
,
sql
+
1
+
elements
.
measureLen
);
ASSERT_EQ
(
elements
.
tagsLen
,
0
);
ASSERT_EQ
(
elements
.
cols
,
sql
+
1
+
elements
.
measureTagsLen
+
3
);
...
...
@@ -125,7 +124,7 @@ TEST(testCase, smlParseInfluxString_Test) {
memcpy
(
sql
,
tmp
,
strlen
(
tmp
)
+
1
);
memset
(
&
elements
,
0
,
sizeof
(
SSmlLineInfo
));
ret
=
smlParseInfluxString
(
sql
,
&
elements
,
&
msgBuf
);
ASSERT_
NE
(
ret
,
0
);
ASSERT_
EQ
(
ret
,
0
);
// case 8 false
tmp
=
", st , "
;
...
...
@@ -238,7 +237,7 @@ TEST(testCase, smlParseCols_tag_Test) {
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cbin"
,
4
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
1
7
);
ASSERT_EQ
(
kv
->
length
,
1
5
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"
\"
passit"
,
7
),
0
);
taosMemoryFree
(
kv
);
...
...
@@ -300,9 +299,9 @@ TEST(testCase, smlParseCols_Test) {
// binary
SSmlKv
*
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cb=in"
,
5
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
keyLen
,
5
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_BINARY
);
ASSERT_EQ
(
kv
->
length
,
1
6
);
ASSERT_EQ
(
kv
->
length
,
1
7
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"pass,it "
,
8
),
0
);
taosMemoryFree
(
kv
);
...
...
@@ -311,7 +310,7 @@ TEST(testCase, smlParseCols_Test) {
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
"cnch"
,
4
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
4
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
7
);
ASSERT_EQ
(
kv
->
length
,
8
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
"ii=sd"
,
5
),
0
);
taosMemoryFree
(
kv
);
...
...
@@ -494,7 +493,7 @@ TEST(testCase, smlProcess_influx_Test) {
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
true
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
11
]
=
{
const
char
*
sql
[]
=
{
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0 1451606400000000000"
,
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0,fuel_consumption=25 1451607400000000000"
,
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 load_capacity=1500,fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,heading=221,grade=0,fuel_consumption=25 1451608400000000000"
,
...
...
@@ -507,18 +506,20 @@ TEST(testCase, smlProcess_influx_Test) {
"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"
,
};
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
int
ret
=
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
ASSERT_EQ
(
ret
,
0
);
TAOS_RES
*
res
=
taos_query
(
taos
,
"select * from t_6885c584b98481584ee13dac399e173d"
);
ASSERT_NE
(
res
,
nullptr
);
int
fieldNum
=
taos_field_count
(
res
);
ASSERT_EQ
(
fieldNum
,
5
);
int
rowNum
=
taos_affected_rows
(
res
);
ASSERT_EQ
(
rowNum
,
2
);
for
(
int
i
=
0
;
i
<
rowNum
;
++
i
)
{
TAOS_ROW
rows
=
taos_fetch_row
(
res
);
}
//
int fieldNum = taos_field_count(res);
//
ASSERT_EQ(fieldNum, 5);
//
int rowNum = taos_affected_rows(res);
//
ASSERT_EQ(rowNum, 2);
//
for (int i = 0; i < rowNum; ++i) {
//
TAOS_ROW rows = taos_fetch_row(res);
//
}
taos_free_result
(
res
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -539,7 +540,7 @@ TEST(testCase, smlParseLine_error_Test) {
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
true
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
2
]
=
{
const
char
*
sql
[]
=
{
"measure,t1=3 c1=8"
,
"measure,t2=3 c1=8u8"
};
...
...
@@ -588,7 +589,7 @@ 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
[
4
]
=
{
const
char
*
sql
[]
=
{
"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 1479496102 1.3E3 network=tcp"
,
...
...
@@ -599,25 +600,26 @@ TEST(testCase, smlProcess_telnet_Test) {
TAOS_RES
*
res
=
taos_query
(
taos
,
"select * from t_8c30283b3c4131a071d1e16cf6d7094a"
);
ASSERT_NE
(
res
,
nullptr
);
int
fieldNum
=
taos_field_count
(
res
);
ASSERT_EQ
(
fieldNum
,
2
);
int
rowNum
=
taos_affected_rows
(
res
);
ASSERT_EQ
(
rowNum
,
1
);
for
(
int
i
=
0
;
i
<
rowNum
;
++
i
)
{
TAOS_ROW
rows
=
taos_fetch_row
(
res
);
}
taos_free_result
(
pR
es
);
//
int fieldNum = taos_field_count(res);
//
ASSERT_EQ(fieldNum, 2);
//
int rowNum = taos_affected_rows(res);
//
ASSERT_EQ(rowNum, 1);
//
for (int i = 0; i < rowNum; ++i) {
//
TAOS_ROW rows = taos_fetch_row(res);
//
}
taos_free_result
(
r
es
);
res
=
taos_query
(
taos
,
"select * from t_6931529054e5637ca92c78a1ad441961"
);
ASSERT_NE
(
res
,
nullptr
);
fieldNum
=
taos_field_count
(
res
);
ASSERT_EQ
(
fieldNum
,
2
);
rowNum
=
taos_affected_rows
(
res
);
ASSERT_EQ
(
rowNum
,
2
);
for
(
int
i
=
0
;
i
<
rowNum
;
++
i
)
{
TAOS_ROW
rows
=
taos_fetch_row
(
res
);
}
taos_free_result
(
pRes
);
// res = taos_query(taos, "select * from t_6931529054e5637ca92c78a1ad441961");
// ASSERT_NE(res, nullptr);
// fieldNum = taos_field_count(res);
// ASSERT_EQ(fieldNum, 2);
// rowNum = taos_affected_rows(res);
// ASSERT_EQ(rowNum, 2);
// for (int i = 0; i < rowNum; ++i) {
// TAOS_ROW rows = taos_fetch_row(res);
// }
// taos_free_result(res);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -670,7 +672,8 @@ TEST(testCase, smlProcess_json1_Test) {
// for (int i = 0; i < rowNum; ++i) {
// TAOS_ROW rows = taos_fetch_row(res);
// }
taos_free_result
(
pRes
);
taos_free_result
(
res
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -714,7 +717,7 @@ TEST(testCase, smlProcess_json2_Test) {
"}"
;
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
ASSERT_EQ
(
ret
,
0
);
taos_free_result
(
pRes
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -786,7 +789,7 @@ TEST(testCase, smlProcess_json3_Test) {
"}"
;
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
ASSERT_EQ
(
ret
,
0
);
taos_free_result
(
pRes
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
@@ -848,7 +851,7 @@ TEST(testCase, smlProcess_json4_Test) {
"}"
;
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
ASSERT_EQ
(
ret
,
0
);
taos_free_result
(
pRes
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录