Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5821c1f8
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看板
提交
5821c1f8
编写于
4月 29, 2022
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
schemaless improvement with pure sql
上级
5da9d427
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
25 deletion
+46
-25
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+46
-25
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
5821c1f8
...
...
@@ -794,7 +794,7 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu
}
static
int32_t
addChildTableDataPointsToInsertSql
(
char
*
cTableName
,
char
*
sTableName
,
SSmlSTableSchema
*
sTableSchema
,
SArray
*
cTablePoints
,
char
*
sql
,
int32_t
capacity
,
int32_t
*
cTableSqlLen
,
SSmlLinesInfo
*
info
)
{
char
*
sql
,
int32_t
capacity
,
int32_t
*
cTableSqlLen
,
int
fromIndex
,
int
*
nextIndex
,
SSmlLinesInfo
*
info
)
{
size_t
numTags
=
taosArrayGetSize
(
sTableSchema
->
tags
);
size_t
numCols
=
taosArrayGetSize
(
sTableSchema
->
fields
);
size_t
rows
=
taosArrayGetSize
(
cTablePoints
);
...
...
@@ -845,7 +845,11 @@ static int32_t addChildTableDataPointsToInsertSql(char* cTableName, char* sTable
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
") values "
);
TAOS_SML_KV
**
colKVs
=
malloc
(
numCols
*
sizeof
(
TAOS_SML_KV
*
));
for
(
int
r
=
0
;
r
<
rows
;
++
r
)
{
int
r
=
fromIndex
;
for
(;
r
<
rows
;
++
r
)
{
if
(
freeBytes
-
totalLen
<
1024
*
16
)
{
break
;
}
totalLen
+=
snprintf
(
sql
+
totalLen
,
freeBytes
-
totalLen
,
"("
);
memset
(
colKVs
,
0
,
numCols
*
sizeof
(
TAOS_SML_KV
*
));
...
...
@@ -873,6 +877,10 @@ static int32_t addChildTableDataPointsToInsertSql(char* cTableName, char* sTable
}
free
(
colKVs
);
if
(
r
==
fromIndex
)
{
tscError
(
"buf can not fit one line"
);
}
*
nextIndex
=
r
;
*
cTableSqlLen
=
totalLen
;
return
0
;
...
...
@@ -981,11 +989,12 @@ static int32_t applyDataPointsWithSqlInsert(TAOS* taos, TAOS_SML_DATA_POINT* poi
info
->
numBatches
=
0
;
SSmlSqlInsertBatch
*
batch
=
info
->
batches
;
batch
->
sql
=
malloc
(
tsMaxSQLStringLen
+
1
);
//TODO batch->sql allocation errror
int32_t
freeBytes
=
tsMaxSQLStringLen
;
int32_t
usedBytes
=
sprintf
(
batch
->
sql
,
"insert into"
);
freeBytes
-=
usedBytes
;
int32_t
cTableSqlLen
=
0
;
SArray
**
pCTablePoints
=
taosHashIterate
(
cname2points
,
NULL
);
while
(
pCTablePoints
)
{
SArray
*
cTablePoints
=
*
pCTablePoints
;
...
...
@@ -993,37 +1002,49 @@ static int32_t applyDataPointsWithSqlInsert(TAOS* taos, TAOS_SML_DATA_POINT* poi
TAOS_SML_DATA_POINT
*
point
=
taosArrayGetP
(
cTablePoints
,
0
);
SSmlSTableSchema
*
sTableSchema
=
taosArrayGet
(
stableSchemas
,
point
->
schemaIdx
);
tscDebug
(
"SML:0x%"
PRIx64
" add child table points to SQL. child table: %s of super table %s"
,
info
->
id
,
point
->
childTableName
,
point
->
stableName
);
int32_t
cTableSqlLen
=
0
;
code
=
addChildTableDataPointsToInsertSql
(
point
->
childTableName
,
point
->
stableName
,
sTableSchema
,
cTablePoints
,
batch
->
sql
+
usedBytes
,
freeBytes
,
&
cTableSqlLen
,
info
);
int32_t
safeBound
=
1024
*
24
;
if
(
cTableSqlLen
<
freeBytes
-
safeBound
)
{
int32_t
nextIndex
=
0
;
int32_t
fromIndex
=
nextIndex
;
while
(
nextIndex
!=
taosArrayGetSize
(
cTablePoints
))
{
fromIndex
=
nextIndex
;
code
=
addChildTableDataPointsToInsertSql
(
point
->
childTableName
,
point
->
stableName
,
sTableSchema
,
cTablePoints
,
batch
->
sql
+
usedBytes
,
freeBytes
,
&
cTableSqlLen
,
fromIndex
,
&
nextIndex
,
info
);
tscDebug
(
"SML:0x%"
PRIx64
" add child table points to SQL. child table: %s of super table %s. range[%d-%d)."
,
info
->
id
,
point
->
childTableName
,
point
->
stableName
,
fromIndex
,
nextIndex
);
usedBytes
+=
cTableSqlLen
;
freeBytes
-=
cTableSqlLen
;
}
else
{
batch
->
sql
[
usedBytes
]
=
'\0'
;
info
->
numBatches
++
;
if
(
info
->
numBatches
>=
MAX_SML_SQL_INSERT_BATCHES
)
{
tscError
(
"SML:0x%"
PRIx64
" Apply points failed. exceeds max sql insert batches"
,
info
->
id
);
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
cleanup
;
}
if
(
nextIndex
!=
taosArrayGetSize
(
cTablePoints
))
{
batch
->
sql
[
usedBytes
]
=
'\0'
;
info
->
numBatches
++
;
tscDebug
(
"SML:0x%"
PRIx64
" sql: %s"
,
info
->
id
,
batch
->
sql
);
if
(
info
->
numBatches
>=
MAX_SML_SQL_INSERT_BATCHES
)
{
tscError
(
"SML:0x%"
PRIx64
" Apply points failed. exceeds max sql insert batches"
,
info
->
id
);
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
cleanup
;
}
batch
=
&
info
->
batches
[
info
->
numBatches
];
batch
->
sql
=
malloc
(
tsMaxSQLStringLen
+
1
);
freeBytes
=
tsMaxSQLStringLen
;
usedBytes
=
sprintf
(
batch
->
sql
,
"insert into"
);
freeBytes
-=
usedBytes
;
//TODO deal with one child table rows exceeds columns
code
=
addChildTableDataPointsToInsertSql
(
point
->
childTableName
,
point
->
stableName
,
sTableSchema
,
cTablePoints
,
batch
->
sql
+
usedBytes
,
freeBytes
,
&
cTableSqlLen
,
info
);
batch
=
&
info
->
batches
[
info
->
numBatches
];
batch
->
sql
=
malloc
(
tsMaxSQLStringLen
+
1
);
freeBytes
=
tsMaxSQLStringLen
;
usedBytes
=
sprintf
(
batch
->
sql
,
"insert into"
);
freeBytes
-=
usedBytes
;
}
}
pCTablePoints
=
taosHashIterate
(
cname2points
,
pCTablePoints
);
}
usedBytes
+=
cTableSqlLen
;
freeBytes
-=
cTableSqlLen
;
batch
->
sql
[
usedBytes
]
=
'\0'
;
info
->
numBatches
++
;
tscDebug
(
"SML:0x%"
PRIx64
" sql: %s"
,
info
->
id
,
batch
->
sql
);
if
(
info
->
numBatches
>=
MAX_SML_SQL_INSERT_BATCHES
)
{
tscError
(
"SML:0x%"
PRIx64
" Apply points failed. exceeds max sql insert batches"
,
info
->
id
);
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
cleanup
;
}
bool
batchesExecuted
[
MAX_SML_SQL_INSERT_BATCHES
]
=
{
false
};
for
(
int
i
=
0
;
i
<
info
->
numBatches
;
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录