Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
336e82b4
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看板
提交
336e82b4
编写于
9月 06, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6443]<feature>: Support OpenTSDB HTTP JSON data import format
上级
f0e4dea1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
95 addition
and
87 deletion
+95
-87
src/client/src/tscParseOpenTSDB.c
src/client/src/tscParseOpenTSDB.c
+95
-87
未找到文件。
src/client/src/tscParseOpenTSDB.c
浏览文件 @
336e82b4
...
@@ -543,17 +543,96 @@ int32_t parseTimestampFromJSON(cJSON *root, TAOS_SML_KV **pTS, int *num_kvs, SSm
...
@@ -543,17 +543,96 @@ int32_t parseTimestampFromJSON(cJSON *root, TAOS_SML_KV **pTS, int *num_kvs, SSm
}
}
int32_t
convertJSONBoolValue
(
TAOS_SML_KV
*
pVal
,
char
*
typeStr
,
int64_t
valueInt
,
SSmlLinesInfo
*
info
)
{
int32_t
convertJSONBool
(
TAOS_SML_KV
*
pVal
,
char
*
typeStr
,
int64_t
valueInt
,
SSmlLinesInfo
*
info
)
{
if
(
strcasecmp
(
typeStr
,
"bool"
)
!=
0
)
{
if
(
strcasecmp
(
typeStr
,
"bool"
)
!=
0
)
{
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) in JSON payload"
,
info
->
id
,
typeStr
);
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) for JSON Bool"
,
info
->
id
,
typeStr
);
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
}
pVal
->
type
=
TSDB_DATA_TYPE_BOOL
;
pVal
->
type
=
TSDB_DATA_TYPE_BOOL
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
bool
*
)(
pVal
->
value
)
=
valueInt
?
true
:
false
;
*
(
bool
*
)(
pVal
->
value
)
=
valueInt
?
true
:
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
convertJSONNumber
(
TAOS_SML_KV
*
pVal
,
char
*
typeStr
,
cJSON
*
value
,
SSmlLinesInfo
*
info
)
{
//tinyint
if
(
strcasecmp
(
typeStr
,
"i8"
)
==
0
)
{
if
(
!
IS_VALID_TINYINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(tinyint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_TINYINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int8_t
*
)(
pVal
->
value
)
=
(
int8_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//smallint
if
(
strcasecmp
(
typeStr
,
"i16"
)
==
0
)
{
if
(
!
IS_VALID_SMALLINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(smallint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_SMALLINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int16_t
*
)(
pVal
->
value
)
=
(
int16_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//int
if
(
strcasecmp
(
typeStr
,
"i32"
)
==
0
)
{
if
(
!
IS_VALID_INT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(int)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_INT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int32_t
*
)(
pVal
->
value
)
=
(
int32_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//bigint
if
(
strcasecmp
(
typeStr
,
"i64"
)
==
0
)
{
if
(
!
IS_VALID_BIGINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(bigint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_BIGINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int64_t
*
)(
pVal
->
value
)
=
(
int64_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//float
if
(
strcasecmp
(
typeStr
,
"f32"
)
==
0
)
{
if
(
!
IS_VALID_FLOAT
(
value
->
valuedouble
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%f) cannot fit in type(float)"
,
info
->
id
,
value
->
valuedouble
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)(
value
->
valuedouble
);
return
TSDB_CODE_SUCCESS
;
}
//double
if
(
strcasecmp
(
typeStr
,
"f64"
)
==
0
)
{
if
(
!
IS_VALID_DOUBLE
(
value
->
valuedouble
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%f) cannot fit in type(double)"
,
info
->
id
,
value
->
valuedouble
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
double
*
)(
pVal
->
value
)
=
(
double
)(
value
->
valuedouble
);
return
TSDB_CODE_SUCCESS
;
}
//if reach here means type is unsupported
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) for JSON number"
,
info
->
id
,
typeStr
);
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
}
int32_t
parseValueFromJSONObj
(
cJSON
*
root
,
TAOS_SML_KV
*
pVal
,
SSmlLinesInfo
*
info
)
{
int32_t
parseValueFromJSONObj
(
cJSON
*
root
,
TAOS_SML_KV
*
pVal
,
SSmlLinesInfo
*
info
)
{
...
@@ -577,89 +656,18 @@ int32_t parseValueFromJSONObj(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* inf
...
@@ -577,89 +656,18 @@ int32_t parseValueFromJSONObj(cJSON *root, TAOS_SML_KV *pVal, SSmlLinesInfo* inf
switch
(
value
->
type
)
{
switch
(
value
->
type
)
{
case
cJSON_True
:
case
cJSON_True
:
case
cJSON_False
:
{
case
cJSON_False
:
{
ret
=
convertJSONBool
Value
(
pVal
,
type
->
valuestring
,
value
->
valueint
,
info
);
ret
=
convertJSONBool
(
pVal
,
type
->
valuestring
,
value
->
valueint
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
break
;
break
;
}
}
case
cJSON_Number
:
{
case
cJSON_Number
:
{
//tinyint
ret
=
convertJSONNumber
(
pVal
,
type
->
valuestring
,
value
,
info
);
if
(
strcasecmp
(
type
->
valuestring
,
"i8"
)
==
0
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
!
IS_VALID_TINYINT
(
value
->
valueint
))
{
return
ret
;
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(tinyint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_TINYINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int8_t
*
)(
pVal
->
value
)
=
(
int8_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//smallint
if
(
strcasecmp
(
type
->
valuestring
,
"i16"
)
==
0
)
{
if
(
!
IS_VALID_SMALLINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(smallint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_SMALLINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int16_t
*
)(
pVal
->
value
)
=
(
int16_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//int
if
(
strcasecmp
(
type
->
valuestring
,
"i32"
)
==
0
)
{
if
(
!
IS_VALID_INT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(int)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_INT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int32_t
*
)(
pVal
->
value
)
=
(
int32_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//bigint
if
(
strcasecmp
(
type
->
valuestring
,
"i64"
)
==
0
)
{
if
(
!
IS_VALID_BIGINT
(
value
->
valueint
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%ld) cannot fit in type(bigint)"
,
info
->
id
,
value
->
valueint
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_BIGINT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
int64_t
*
)(
pVal
->
value
)
=
(
int64_t
)(
value
->
valueint
);
return
TSDB_CODE_SUCCESS
;
}
//float
if
(
strcasecmp
(
type
->
valuestring
,
"f32"
)
==
0
)
{
if
(
!
IS_VALID_FLOAT
(
value
->
valuedouble
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%f) cannot fit in type(float)"
,
info
->
id
,
value
->
valuedouble
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)(
value
->
valuedouble
);
return
TSDB_CODE_SUCCESS
;
}
//double
if
(
strcasecmp
(
type
->
valuestring
,
"f64"
)
==
0
)
{
if
(
!
IS_VALID_DOUBLE
(
value
->
valuedouble
))
{
tscError
(
"OTD:0x%"
PRIx64
" JSON value(%f) cannot fit in type(double)"
,
info
->
id
,
value
->
valuedouble
);
return
TSDB_CODE_TSC_VALUE_OUT_OF_RANGE
;
}
pVal
->
type
=
TSDB_DATA_TYPE_DOUBLE
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
double
*
)(
pVal
->
value
)
=
(
double
)(
value
->
valuedouble
);
return
TSDB_CODE_SUCCESS
;
}
}
break
;
//if reach here means type string is not supported
tscError
(
"OTD:0x%"
PRIx64
" invalid type(%s) in JSON payload"
,
info
->
id
,
type
->
valuestring
);
return
TSDB_CODE_TSC_INVALID_JSON_TYPE
;
}
}
case
cJSON_String
:
{
case
cJSON_String
:
{
if
(
strcasecmp
(
type
->
valuestring
,
"binary"
)
==
0
)
{
if
(
strcasecmp
(
type
->
valuestring
,
"binary"
)
==
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录