Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
14bb977f
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看板
提交
14bb977f
编写于
12月 04, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor into function for one datapoint sml insert
上级
ac45017a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
58 addition
and
47 deletion
+58
-47
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+58
-47
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
14bb977f
...
@@ -184,7 +184,7 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa
...
@@ -184,7 +184,7 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa
uint64_t
digest1
=
*
(
uint64_t
*
)(
context
.
digest
);
uint64_t
digest1
=
*
(
uint64_t
*
)(
context
.
digest
);
uint64_t
digest2
=
*
(
uint64_t
*
)(
context
.
digest
+
8
);
uint64_t
digest2
=
*
(
uint64_t
*
)(
context
.
digest
+
8
);
*
tableNameLen
=
snprintf
(
tableName
,
*
tableNameLen
,
*
tableNameLen
=
snprintf
(
tableName
,
*
tableNameLen
,
"t_%16
lx%16lx"
,
digest1
,
digest2
);
"t_%16
"
PRIx64
"%16"
PRIx64
,
digest1
,
digest2
);
taosStringBuilderDestroy
(
&
sb
);
taosStringBuilderDestroy
(
&
sb
);
tscDebug
(
"SML:0x%"
PRIx64
" child table name: %s"
,
info
->
id
,
tableName
);
tscDebug
(
"SML:0x%"
PRIx64
" child table name: %s"
,
info
->
id
,
tableName
);
return
0
;
return
0
;
...
@@ -1202,6 +1202,60 @@ cleanup:
...
@@ -1202,6 +1202,60 @@ cleanup:
return
code
;
return
code
;
}
}
static
int
doSmlInsertOneDataPoint
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
point
,
SSmlLinesInfo
*
info
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
!
point
->
childTableName
)
{
int
tableNameLen
=
TSDB_TABLE_NAME_LEN
;
point
->
childTableName
=
calloc
(
1
,
tableNameLen
+
1
);
getSmlMd5ChildTableName
(
point
,
point
->
childTableName
,
&
tableNameLen
,
info
);
point
->
childTableName
[
tableNameLen
]
=
'\0'
;
}
STableMeta
*
tableMeta
=
NULL
;
int32_t
ret
=
getSuperTableMetaFromLocalCache
(
taos
,
point
->
stableName
,
&
tableMeta
,
info
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
uint8_t
precision
=
tableMeta
->
tableInfo
.
precision
;
free
(
tableMeta
);
char
*
sql
=
malloc
(
TSDB_MAX_SQL_LEN
+
1
);
int
freeBytes
=
TSDB_MAX_SQL_LEN
;
int
sqlLen
=
0
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
"insert into %s("
,
point
->
childTableName
);
for
(
int
col
=
0
;
col
<
point
->
fieldNum
;
++
col
)
{
TAOS_SML_KV
*
kv
=
point
->
fields
+
col
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
"%s,"
,
kv
->
key
);
}
--
sqlLen
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
") values ("
);
TAOS_SML_KV
*
tsField
=
point
->
fields
+
0
;
int64_t
ts
=
*
(
int64_t
*
)(
tsField
->
value
);
ts
=
convertTimePrecision
(
ts
,
TSDB_TIME_PRECISION_NANO
,
precision
);
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
"%"
PRId64
","
,
ts
);
for
(
int
col
=
1
;
col
<
point
->
fieldNum
;
++
col
)
{
TAOS_SML_KV
*
kv
=
point
->
fields
+
col
;
int32_t
len
=
0
;
converToStr
(
sql
+
sqlLen
,
kv
->
type
,
kv
->
value
,
kv
->
length
,
&
len
);
sqlLen
+=
len
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
","
);
}
--
sqlLen
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
")"
);
sql
[
sqlLen
]
=
0
;
tscDebug
(
"SML:0x%"
PRIx64
" insert child table table %s of super table %s sql: %s"
,
info
->
id
,
point
->
childTableName
,
point
->
stableName
,
sql
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
free
(
sql
);
code
=
taos_errno
(
res
);
info
->
affectedRows
=
taos_affected_rows
(
res
);
taos_free_result
(
res
);
return
code
;
}
int
tscSmlInsert
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
,
SSmlLinesInfo
*
info
)
{
int
tscSmlInsert
(
TAOS
*
taos
,
TAOS_SML_DATA_POINT
*
points
,
int
numPoint
,
SSmlLinesInfo
*
info
)
{
tscDebug
(
"SML:0x%"
PRIx64
" taos_sml_insert. number of points: %d"
,
info
->
id
,
numPoint
);
tscDebug
(
"SML:0x%"
PRIx64
" taos_sml_insert. number of points: %d"
,
info
->
id
,
numPoint
);
...
@@ -1211,52 +1265,9 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine
...
@@ -1211,52 +1265,9 @@ int tscSmlInsert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint, SSmlLine
if
(
numPoint
==
1
)
{
if
(
numPoint
==
1
)
{
TAOS_SML_DATA_POINT
*
point
=
points
+
0
;
TAOS_SML_DATA_POINT
*
point
=
points
+
0
;
if
(
!
point
->
childTableName
)
{
code
=
doSmlInsertOneDataPoint
(
taos
,
point
,
info
);
int
tableNameLen
=
TSDB_TABLE_NAME_LEN
;
if
(
code
==
TSDB_CODE_SUCCESS
)
{
point
->
childTableName
=
calloc
(
1
,
tableNameLen
+
1
);
return
code
;
getSmlMd5ChildTableName
(
point
,
point
->
childTableName
,
&
tableNameLen
,
info
);
point
->
childTableName
[
tableNameLen
]
=
'\0'
;
}
STableMeta
*
tableMeta
;
int32_t
ret
=
getSuperTableMetaFromLocalCache
(
taos
,
point
->
stableName
,
&
tableMeta
,
info
);
if
(
ret
==
TSDB_CODE_SUCCESS
)
{
uint8_t
precision
=
tableMeta
->
tableInfo
.
precision
;
free
(
tableMeta
);
char
*
sql
=
malloc
(
TSDB_MAX_SQL_LEN
+
1
);
int
freeBytes
=
TSDB_MAX_SQL_LEN
;
int
sqlLen
=
0
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
"insert into %s("
,
point
->
childTableName
);
for
(
int
col
=
0
;
col
<
point
->
fieldNum
;
++
col
)
{
TAOS_SML_KV
*
kv
=
point
->
fields
+
col
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
"%s,"
,
kv
->
key
);
}
--
sqlLen
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
") values ("
);
TAOS_SML_KV
*
tsField
=
point
->
fields
+
0
;
int64_t
ts
=
*
(
int64_t
*
)(
tsField
->
value
);
ts
=
convertTimePrecision
(
ts
,
TSDB_TIME_PRECISION_NANO
,
precision
);
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
"%"
PRId64
","
,
ts
);
for
(
int
col
=
1
;
col
<
point
->
fieldNum
;
++
col
)
{
TAOS_SML_KV
*
kv
=
point
->
fields
+
col
;
int32_t
len
=
0
;
converToStr
(
sql
+
sqlLen
,
kv
->
type
,
kv
->
value
,
kv
->
length
,
&
len
);
sqlLen
+=
len
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
","
);
}
--
sqlLen
;
sqlLen
+=
snprintf
(
sql
+
sqlLen
,
freeBytes
-
sqlLen
,
")"
);
sql
[
sqlLen
]
=
0
;
tscDebug
(
"SML:0x%"
PRIx64
" insert child table table %s of super table %s sql: %s"
,
info
->
id
,
point
->
childTableName
,
point
->
stableName
,
sql
);
TAOS_RES
*
res
=
taos_query
(
taos
,
sql
);
free
(
sql
);
code
=
taos_errno
(
res
);
info
->
affectedRows
=
taos_affected_rows
(
res
);
taos_free_result
(
res
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录