Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4b9b44d0
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看板
提交
4b9b44d0
编写于
9月 06, 2021
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-6443]<feature>: Support OpenTSDB HTTP JSON data import format
上级
c0a554e0
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
36 addition
and
46 deletion
+36
-46
src/client/src/tscParseOpenTSDB.c
src/client/src/tscParseOpenTSDB.c
+36
-46
未找到文件。
src/client/src/tscParseOpenTSDB.c
浏览文件 @
4b9b44d0
...
...
@@ -495,24 +495,17 @@ int32_t parseTimestampFromJSON(cJSON *root, TAOS_SML_KV **pTS, int *num_kvs, SSm
}
int32_t
parseMetricValueFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
**
pKVs
,
int
*
num_kvs
,
SSmlLinesInfo
*
info
)
{
//skip timestamp
TAOS_SML_KV
*
pVal
=
*
pKVs
+
1
;
char
key
[]
=
OTS_METRIC_VALUE_COLUMN_NAME
;
cJSON
*
metricVal
=
cJSON_GetObjectItem
(
root
,
"value"
);
if
(
metricVal
==
NULL
)
{
tscError
(
"OTD:0x%"
PRIx64
" failed to parse metric value from JSON Payload"
,
info
->
id
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
int32_t
parseValueFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
*
pVal
)
{
int
type
=
root
->
type
;
switch
(
metricVal
->
type
)
{
switch
(
type
)
{
case
cJSON_True
:
case
cJSON_False
:
{
pVal
->
type
=
TSDB_DATA_TYPE_BOOL
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
bool
*
)(
pVal
->
value
)
=
metricVal
->
type
?
true
:
false
;
*
(
bool
*
)(
pVal
->
value
)
=
type
?
true
:
false
;
break
;
}
case
cJSON_Number
:
{
...
...
@@ -520,21 +513,40 @@ int32_t parseMetricValueFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs,
pVal
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pVal
->
length
=
(
int16_t
)
tDataTypes
[
pVal
->
type
].
bytes
;
pVal
->
value
=
tcalloc
(
pVal
->
length
,
1
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)(
metricVal
->
valuedouble
);
*
(
float
*
)(
pVal
->
value
)
=
(
float
)(
root
->
valuedouble
);
break
;
}
case
cJSON_String
:
{
//convert default JSON String type to nchar
pVal
->
type
=
TSDB_DATA_TYPE_NCHAR
;
pVal
->
length
=
wcslen
((
wchar_t
*
)
metricVal
->
valuestring
)
*
TSDB_NCHAR_SIZE
;
pVal
->
length
=
wcslen
((
wchar_t
*
)
root
->
valuestring
)
*
TSDB_NCHAR_SIZE
;
pVal
->
value
=
tcalloc
(
pVal
->
length
+
1
,
1
);
memcpy
(
pVal
->
value
,
metricVal
->
valuestring
,
pVal
->
length
);
memcpy
(
pVal
->
value
,
root
->
valuestring
,
pVal
->
length
);
break
;
}
default:
return
TSDB_CODE_TSC_INVALID_JSON
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseMetricValueFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
**
pKVs
,
int
*
num_kvs
,
SSmlLinesInfo
*
info
)
{
//skip timestamp
TAOS_SML_KV
*
pVal
=
*
pKVs
+
1
;
char
key
[]
=
OTS_METRIC_VALUE_COLUMN_NAME
;
cJSON
*
metricVal
=
cJSON_GetObjectItem
(
root
,
"value"
);
if
(
metricVal
==
NULL
)
{
tscError
(
"OTD:0x%"
PRIx64
" failed to parse metric value from JSON Payload"
,
info
->
id
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
int32_t
ret
=
parseValueFromJSON
(
metricVal
,
pVal
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
pVal
->
key
=
tcalloc
(
sizeof
(
key
),
1
);
memcpy
(
pVal
->
key
,
key
,
sizeof
(
key
));
...
...
@@ -544,6 +556,7 @@ int32_t parseMetricValueFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs,
}
int32_t
parseTagsFromJSON
(
cJSON
*
root
,
TAOS_SML_KV
**
pKVs
,
int
*
num_kvs
,
char
**
childTableName
,
SSmlLinesInfo
*
info
)
{
int32_t
ret
;
cJSON
*
tags
=
cJSON_GetObjectItem
(
root
,
"tags"
);
if
(
tags
==
NULL
||
tags
->
type
!=
cJSON_Object
)
{
...
...
@@ -554,8 +567,8 @@ int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, char **
cJSON
*
id
=
cJSON_GetObjectItem
(
root
,
"ID"
);
if
(
id
!=
NULL
)
{
int32_t
idLen
=
strlen
(
id
->
string
);
int32_t
ret
=
isValidChildTableName
(
id
->
string
,
idLen
);
if
(
ret
)
{
ret
=
isValidChildTableName
(
id
->
string
,
idLen
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
*
childTableName
=
tcalloc
(
idLen
+
1
,
sizeof
(
char
));
...
...
@@ -577,39 +590,16 @@ int32_t parseTagsFromJSON(cJSON *root, TAOS_SML_KV **pKVs, int *num_kvs, char **
for
(
int32_t
i
=
0
;
i
<
tagNum
;
++
i
)
{
cJSON
*
tag
=
cJSON_GetArrayItem
(
tags
,
i
);
//key
pkv
->
key
=
tcalloc
(
strlen
(
tag
->
string
)
+
1
,
sizeof
(
char
));
strncpy
(
pkv
->
key
,
tag
->
string
,
strlen
(
tag
->
string
));
int32_t
keyLen
=
strlen
(
tag
->
string
);
pkv
->
key
=
tcalloc
(
keyLen
+
1
,
sizeof
(
char
));
strncpy
(
pkv
->
key
,
tag
->
string
,
keyLen
);
//value
switch
(
tag
->
type
)
{
case
cJSON_True
:
case
cJSON_False
:
{
pkv
->
type
=
TSDB_DATA_TYPE_BOOL
;
pkv
->
length
=
(
int16_t
)
tDataTypes
[
pkv
->
type
].
bytes
;
pkv
->
value
=
tcalloc
(
pkv
->
length
,
1
);
*
(
bool
*
)(
pkv
->
value
)
=
tag
->
type
?
true
:
false
;
break
;
}
case
cJSON_Number
:
{
//convert default JSON Number type to float
pkv
->
type
=
TSDB_DATA_TYPE_FLOAT
;
pkv
->
length
=
(
int16_t
)
tDataTypes
[
pkv
->
type
].
bytes
;
pkv
->
value
=
tcalloc
(
pkv
->
length
,
1
);
*
(
float
*
)(
pkv
->
value
)
=
(
float
)(
tag
->
valuedouble
);
break
;
}
case
cJSON_String
:
{
//convert default JSON String type to nchar
pkv
->
type
=
TSDB_DATA_TYPE_NCHAR
;
pkv
->
length
=
wcslen
((
wchar_t
*
)
tag
->
valuestring
)
*
TSDB_NCHAR_SIZE
;
pkv
->
value
=
tcalloc
(
pkv
->
length
+
1
,
1
);
memcpy
(
pkv
->
value
,
tag
->
valuestring
,
pkv
->
length
);
break
;
}
default:
tfree
(
pkv
->
key
);
return
TSDB_CODE_TSC_INVALID_JSON
;
ret
=
parseValueFromJSON
(
tag
,
pkv
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
*
num_kvs
+=
1
;
pkv
++
;
}
return
TSDB_CODE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录