Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
98be827e
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
98be827e
编写于
5月 20, 2022
作者:
wmmhello
提交者:
GitHub
5月 20, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12735 from taosdata/feature/TD-14761
fix:invalid data type in schemaless
上级
60e34d79
621a7623
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
93 addition
and
30 deletion
+93
-30
source/client/src/clientSml.c
source/client/src/clientSml.c
+34
-24
source/client/test/smlTest.cpp
source/client/test/smlTest.cpp
+59
-6
未找到文件。
source/client/src/clientSml.c
浏览文件 @
98be827e
...
...
@@ -65,12 +65,14 @@ for (int i = 1; i < keyLen; ++i) { \
#define OTD_TIMESTAMP_COLUMN_NAME "ts"
#define OTD_METRIC_VALUE_COLUMN_NAME "value"
#define TS "_ts"
#define TS_LEN 3
#define TAG "_tagNone"
#define TAG_LEN 8
#define VALUE "value"
#define VALUE_LEN 5
#define TS "_ts"
#define TS_LEN 3
#define TAG "_tag"
#define TAG_LEN 4
#define TAG_VALUE "NULL"
#define TAG_VALUE_LEN 4
#define VALUE "value"
#define VALUE_LEN 5
#define BINARY_ADD_LEN 2 // "binary" 2 means " "
#define NCHAR_ADD_LEN 3 // L"nchar" 3 means L" "
...
...
@@ -598,25 +600,33 @@ static bool smlParseNumber(SSmlKv *kvVal, SSmlMsgBuf *msg){
kvVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
kvVal
->
f
=
(
float
)
result
;
}
else
if
((
left
==
1
&&
*
endptr
==
'i'
)
||
(
left
==
3
&&
strncasecmp
(
endptr
,
"i64"
,
left
)
==
0
)){
if
(
result
>=
(
double
)
INT64_MAX
){
kvVal
->
i
=
INT64_MAX
;
}
else
if
(
result
<=
(
double
)
INT64_MIN
){
kvVal
->
i
=
INT64_MIN
;
}
else
{
kvVal
->
i
=
result
;
if
(
smlDoubleToInt64OverFlow
(
result
)){
errno
=
0
;
int64_t
tmp
=
taosStr2Int64
(
pVal
,
&
endptr
,
10
);
if
(
errno
==
ERANGE
){
smlBuildInvalidDataMsg
(
msg
,
"big int out of range[-9223372036854775808,9223372036854775807]"
,
pVal
);
return
false
;
}
kvVal
->
type
=
TSDB_DATA_TYPE_BIGINT
;
kvVal
->
i
=
tmp
;
return
true
;
}
kvVal
->
type
=
TSDB_DATA_TYPE_BIGINT
;
kvVal
->
i
=
(
int64_t
)
result
;
}
else
if
((
left
==
3
&&
strncasecmp
(
endptr
,
"u64"
,
left
)
==
0
)){
if
(
result
<
0
){
smlBuildInvalidDataMsg
(
msg
,
"unsigned big int is too large, out of precision"
,
pVal
);
return
false
;
}
if
(
result
>=
(
double
)
UINT64_MAX
){
kvVal
->
u
=
UINT64_MAX
;
}
else
{
kvVal
->
u
=
result
;
if
(
result
>=
(
double
)
UINT64_MAX
||
result
<
0
){
errno
=
0
;
uint64_t
tmp
=
taosStr2UInt64
(
pVal
,
&
endptr
,
10
);
if
(
errno
==
ERANGE
||
result
<
0
){
smlBuildInvalidDataMsg
(
msg
,
"unsigned big int out of range[0,18446744073709551615]"
,
pVal
);
return
false
;
}
kvVal
->
type
=
TSDB_DATA_TYPE_UBIGINT
;
kvVal
->
u
=
tmp
;
return
true
;
}
kvVal
->
type
=
TSDB_DATA_TYPE_UBIGINT
;
kvVal
->
u
=
result
;
}
else
if
(
left
==
3
&&
strncasecmp
(
endptr
,
"i32"
,
left
)
==
0
){
if
(
!
IS_VALID_INT
(
result
)){
smlBuildInvalidDataMsg
(
msg
,
"int out of range[-2147483648,2147483647]"
,
pVal
);
...
...
@@ -1103,8 +1113,7 @@ static int32_t smlParseTelnetString(SSmlHandle *info, const char* sql, SSmlTable
kv
->
keyLen
=
VALUE_LEN
;
kv
->
value
=
value
;
kv
->
length
=
valueLen
;
if
(
!
smlParseValue
(
kv
,
&
info
->
msgBuf
)
||
kv
->
type
==
TSDB_DATA_TYPE_BINARY
||
kv
->
type
==
TSDB_DATA_TYPE_NCHAR
||
kv
->
type
==
TSDB_DATA_TYPE_BOOL
){
if
(
!
smlParseValue
(
kv
,
&
info
->
msgBuf
)){
return
TSDB_CODE_SML_INVALID_DATA
;
}
...
...
@@ -1124,8 +1133,8 @@ static int32_t smlParseCols(const char* data, int32_t len, SArray *cols, char *c
if
(
!
kv
)
return
TSDB_CODE_OUT_OF_MEMORY
;
kv
->
key
=
TAG
;
kv
->
keyLen
=
TAG_LEN
;
kv
->
value
=
TAG
;
kv
->
length
=
TAG_LEN
;
kv
->
value
=
TAG
_VALUE
;
kv
->
length
=
TAG_
VALUE_
LEN
;
kv
->
type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
cols
)
taosArrayPush
(
cols
,
&
kv
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -2264,6 +2273,7 @@ static int32_t smlParseLine(SSmlHandle *info, char* lines[], int numLines){
uError
(
"SML:0x%"
PRIx64
" smlParseJSON failed:%s"
,
info
->
id
,
*
lines
);
return
code
;
}
return
code
;
}
for
(
int32_t
i
=
0
;
i
<
numLines
;
++
i
)
{
...
...
source/client/test/smlTest.cpp
浏览文件 @
98be827e
...
...
@@ -208,6 +208,7 @@ TEST(testCase, smlParseCols_Error_Test) {
memcpy
(
sql
,
data
[
i
],
len
+
1
);
SArray
*
cols
=
taosArrayInit
(
8
,
POINTER_BYTES
);
int32_t
ret
=
smlParseCols
(
sql
,
len
,
cols
,
NULL
,
false
,
dumplicateKey
,
&
msgBuf
);
printf
(
"i:%d
\n
"
,
i
);
ASSERT_NE
(
ret
,
TSDB_CODE_SUCCESS
);
taosHashClear
(
dumplicateKey
);
taosMemoryFree
(
sql
);
...
...
@@ -272,11 +273,11 @@ TEST(testCase, smlParseCols_tag_Test) {
// nchar
kv
=
(
SSmlKv
*
)
taosArrayGetP
(
cols
,
0
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
TAG
,
strlen
(
TAG
)
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
strlen
(
TAG
)
);
ASSERT_EQ
(
strncasecmp
(
kv
->
key
,
TAG
,
TAG_LEN
),
0
);
ASSERT_EQ
(
kv
->
keyLen
,
TAG_LEN
);
ASSERT_EQ
(
kv
->
type
,
TSDB_DATA_TYPE_NCHAR
);
ASSERT_EQ
(
kv
->
length
,
strlen
(
TAG
)
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
TAG
,
strlen
(
TAG
)
),
0
);
ASSERT_EQ
(
kv
->
length
,
TAG_LEN
);
ASSERT_EQ
(
strncasecmp
(
kv
->
value
,
TAG
_VALUE
,
TAG_VALUE_LEN
),
0
);
taosMemoryFree
(
kv
);
taosArrayDestroy
(
cols
);
...
...
@@ -506,7 +507,7 @@ TEST(testCase, smlProcess_influx_Test) {
"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 1451608403000000000"
,
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 fuel_capacity=150,nominal_fuel_consumption=12,latitude=52.31854,longitude=4.72037,elevation=124,velocity=0,heading=221,grade=0,fuel_consumption=25 1451609404000000000"
,
"readings,name=truck_0,fleet=South,driver=Trish,model=H-2,device_version=v2.3 fuel_consumption=25,grade=0 1451619405000000000"
,
"readings,name=truck_1,fleet=South,driver=Albert,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=72.45258,longitude=68.83761,elevation=255,velocity=0,heading=181,grade=0,fuel_consumption=25 145160640600000000"
,
"readings,name=truck_1,fleet=South,driver=Albert,model=F-150,device_version=v1.5 load_capacity=2000,fuel_capacity=200,nominal_fuel_consumption=15,latitude=72.45258,longitude=68.83761,elevation=255,velocity=0,heading=181,grade=0,fuel_consumption=25 145160640600000000
0
"
,
"readings,name=truck_2,driver=Derek,model=F-150,device_version=v1.5 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 1451606407000000000"
,
"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 1451609408000000000"
,
"readings,fleet=South,name=truck_0,driver=Trish,model=H-2,device_version=v2.3 fuel_consumption=25,grade=0 1451629409000000000"
,
...
...
@@ -745,7 +746,7 @@ TEST(testCase, smlProcess_json1_Test) {
" }
\n
"
" }
\n
"
"]"
;
int
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
-
1
);
int
ret
=
smlProcess
(
info
,
(
char
**
)(
&
sql
),
1
);
ASSERT_EQ
(
ret
,
0
);
// case 1
...
...
@@ -1220,4 +1221,56 @@ TEST(testCase, sml_TD15662_Test) {
ASSERT_EQ
(
ts
,
1626006833639000000
);
taos_free_result
(
res
);
}
TEST
(
testCase
,
sml_TD15735_Test
)
{
TAOS
*
taos
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
ASSERT_NE
(
taos
,
nullptr
);
TAOS_RES
*
pRes
=
taos_query
(
taos
,
"create database if not exists sml_db"
);
taos_free_result
(
pRes
);
pRes
=
taos_query
(
taos
,
"use sml_db"
);
taos_free_result
(
pRes
);
SRequestObj
*
request
=
(
SRequestObj
*
)
createRequest
((
STscObj
*
)
taos
,
NULL
,
NULL
,
TSDB_SQL_INSERT
);
ASSERT_NE
(
request
,
nullptr
);
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_TELNET_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[
1
]
=
{
"{'metric': 'pekoiw', 'timestamp': {'value': 1626006833639000000, 'type': 'ns'}, 'value': {'value': False, 'type': 'bool'}, 'tags': {'t0': {'value': True, 'type': 'bool'}, 't1': {'value': 127, 'type': 'tinyint'}, 't2': {'value': 32767, 'type': 'smallint'}, 't3': {'value': 2147483647, 'type': 'int'}, 't4': {'value': 9223372036854775807, 'type': 'bigint'}, 't5': {'value': 11.12345027923584, 'type': 'float'}, 't6': {'value': 22.123456789, 'type': 'double'}, 't7': {'value': 'binaryTagValue', 'type': 'binary'}, 't8': {'value': 'ncharTagValue', 'type': 'nchar'}}}"
,
};
int32_t
ret
=
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
ASSERT_NE
(
ret
,
0
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
TEST
(
testCase
,
sml_TD15742_Test
)
{
TAOS
*
taos
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
ASSERT_NE
(
taos
,
nullptr
);
TAOS_RES
*
pRes
=
taos_query
(
taos
,
"create database if not exists TD15742"
);
taos_free_result
(
pRes
);
pRes
=
taos_query
(
taos
,
"use TD15742"
);
taos_free_result
(
pRes
);
SRequestObj
*
request
=
(
SRequestObj
*
)
createRequest
((
STscObj
*
)
taos
,
NULL
,
NULL
,
TSDB_SQL_INSERT
);
ASSERT_NE
(
request
,
nullptr
);
SSmlHandle
*
info
=
smlBuildSmlInfo
(
taos
,
request
,
TSDB_SML_TELNET_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
);
ASSERT_NE
(
info
,
nullptr
);
const
char
*
sql
[]
=
{
"zgzbix 1626006833641 False id=zgzbix_992_38861 t0=t t1=127i8 t2=32767i16 t3=2147483647i32 t4=9223372036854775807i64 t5=11.12345f32 t6=22.123456789f64 t7=
\"
binaryTagValue
\"
t8=L
\"
ncharTagValue
\"
"
,
};
int
ret
=
smlProcess
(
info
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]));
ASSERT_EQ
(
ret
,
0
);
destroyRequest
(
request
);
smlDestroyInfo
(
info
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录