Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3d703199
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看板
提交
3d703199
编写于
7月 12, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create child table with tags
上级
93c6fee9
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
25 deletion
+50
-25
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+49
-24
tests/examples/c/apitest.c
tests/examples/c/apitest.c
+1
-1
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
3d703199
...
...
@@ -377,39 +377,66 @@ int32_t getChildTableName(TAOS_SML_DATA_POINT* point, char* tableName, int* tabl
return
0
;
}
int32_t
getPreparedSQL
(
const
char
*
sTableName
,
SArray
*
tagsSchema
,
SArray
*
colsSchema
,
char
*
result
,
int16_t
freeBytes
)
{
int32_t
creatChildTableIfNotExists
(
TAOS
*
taos
,
const
char
*
cTableName
,
const
char
*
sTableName
,
SArray
*
tagsSchema
,
SArray
*
tagsBind
)
{
size_t
numTags
=
taosArrayGetSize
(
tagsSchema
);
size_t
numCols
=
taosArrayGetSize
(
colsSchema
);
sprintf
(
result
,
"insert into ? using %s"
,
sTableName
);
char
sql
[
TSDB_MAX_BINARY_LEN
]
=
{
0
};
int
freeBytes
=
TSDB_MAX_BINARY_LEN
;
sprintf
(
sql
,
"create table if not exists %s using %s"
,
cTableName
,
sTableName
);
// snprintf(result+strlen(result), freeBytes-strlen(result
), "(");
//
for (int i = 0; i < numTags; ++i) {
//
SSchema* tagSchema = taosArrayGet(tagsSchema, i);
// snprintf(result+strlen(result), freeBytes-strlen(result
), "%s,", tagSchema->name);
//
}
// snprintf(result + strlen(result)-1, freeBytes-strlen(result
)+1, ")");
snprintf
(
sql
+
strlen
(
sql
),
freeBytes
-
strlen
(
sql
),
"("
);
for
(
int
i
=
0
;
i
<
numTags
;
++
i
)
{
SSchema
*
tagSchema
=
taosArrayGet
(
tagsSchema
,
i
);
snprintf
(
sql
+
strlen
(
sql
),
freeBytes
-
strlen
(
sql
),
"%s,"
,
tagSchema
->
name
);
}
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
snprintf
(
result
+
strlen
(
result
),
freeBytes
-
strlen
(
result
),
" tags ("
);
snprintf
(
sql
+
strlen
(
sql
),
freeBytes
-
strlen
(
sql
),
" tags ("
);
for
(
int
i
=
0
;
i
<
numTags
;
++
i
)
{
snprintf
(
result
+
strlen
(
result
),
freeBytes
-
strlen
(
result
),
"?,"
);
snprintf
(
sql
+
strlen
(
sql
),
freeBytes
-
strlen
(
sql
),
"?,"
);
}
snprintf
(
result
+
strlen
(
result
)
-
1
,
freeBytes
-
strlen
(
result
)
+
1
,
") ("
);
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
int32_t
code
;
code
=
taos_stmt_prepare
(
stmt
,
sql
,
strlen
(
sql
));
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
}
code
=
taos_stmt_bind_param
(
stmt
,
TARRAY_GET_START
(
tagsBind
));
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
}
code
=
taos_stmt_execute
(
stmt
);
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
}
TAOS_RES
*
res
=
taos_stmt_use_result
(
stmt
);
return
taos_errno
(
res
);
}
int32_t
insertBatch
(
TAOS
*
taos
,
char
*
cTableName
,
SArray
*
colsSchema
,
SArray
*
rowsBind
)
{
size_t
numCols
=
taosArrayGetSize
(
colsSchema
);
char
sql
[
TSDB_MAX_BINARY_LEN
];
int32_t
freeBytes
=
TSDB_MAX_BINARY_LEN
;
sprintf
(
sql
,
"insert into ? ("
);
for
(
int
i
=
0
;
i
<
numCols
;
++
i
)
{
SSchema
*
colSchema
=
taosArrayGet
(
colsSchema
,
i
);
snprintf
(
result
+
strlen
(
result
),
freeBytes
-
strlen
(
result
),
"%s,"
,
colSchema
->
name
);
snprintf
(
sql
+
strlen
(
sql
),
freeBytes
-
strlen
(
sql
),
"%s,"
,
colSchema
->
name
);
}
snprintf
(
result
+
strlen
(
result
)
-
1
,
freeBytes
-
strlen
(
result
)
+
1
,
") values ("
);
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
") values ("
);
for
(
int
i
=
0
;
i
<
numCols
;
++
i
)
{
snprintf
(
result
+
strlen
(
result
),
freeBytes
-
strlen
(
result
),
"?,"
);
snprintf
(
sql
+
strlen
(
sql
),
freeBytes
-
strlen
(
sql
),
"?,"
);
}
snprintf
(
result
+
strlen
(
result
)
-
1
,
freeBytes
-
strlen
(
result
)
+
1
,
")"
);
return
0
;
}
snprintf
(
sql
+
strlen
(
sql
)
-
1
,
freeBytes
-
strlen
(
sql
)
+
1
,
")"
);
int32_t
insertBatch
(
TAOS
*
taos
,
char
*
sql
,
char
*
cTableName
,
SArray
*
tagsBind
,
SArray
*
rowsBind
)
{
TAOS_STMT
*
stmt
=
taos_stmt_init
(
taos
);
int32_t
code
;
code
=
taos_stmt_prepare
(
stmt
,
sql
,
strlen
(
sql
));
...
...
@@ -418,7 +445,7 @@ int32_t insertBatch(TAOS* taos, char* sql, char* cTableName, SArray* tagsBind, S
return
code
;
}
code
=
taos_stmt_set_tbname
_tags
(
stmt
,
cTableName
,
TARRAY_GET_START
(
tagsBind
)
);
code
=
taos_stmt_set_tbname
(
stmt
,
cTableName
);
if
(
code
!=
0
)
{
printf
(
"%s"
,
taos_stmt_errstr
(
stmt
));
return
code
;
...
...
@@ -478,7 +505,6 @@ int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints)
TAOS_SML_DATA_POINT
*
point
=
taosArrayGetP
(
cTablePoints
,
0
);
int32_t
numTags
=
taosArrayGetSize
(
point
->
schema
->
tags
);
int32_t
numCols
=
taosArrayGetSize
(
point
->
schema
->
fields
);
char
*
stableName
=
point
->
stableName
;
char
*
ctableName
=
point
->
childTableName
;
SArray
*
tagBinds
=
taosArrayInit
(
numTags
,
sizeof
(
TAOS_BIND
));
...
...
@@ -523,9 +549,8 @@ int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints)
taosArrayPush
(
rowsBind
,
&
colBinds
);
}
char
sql
[
TSDB_MAX_BINARY_LEN
];
getPreparedSQL
(
stableName
,
point
->
schema
->
tags
,
point
->
schema
->
fields
,
sql
,
TSDB_MAX_BINARY_LEN
);
insertBatch
(
taos
,
sql
,
ctableName
,
tagBinds
,
rowsBind
);
creatChildTableIfNotExists
(
taos
,
point
->
childTableName
,
point
->
stableName
,
point
->
schema
->
tags
,
tagBinds
);
insertBatch
(
taos
,
ctableName
,
point
->
schema
->
fields
,
rowsBind
);
pCTablePoints
=
taosHashIterate
(
cname2points
,
pCTablePoints
);
}
...
...
tests/examples/c/apitest.c
浏览文件 @
3d703199
...
...
@@ -956,7 +956,7 @@ int32_t verify_schema_less(TAOS* taos) {
"st,t1=4i,t2=5,t3=
\"
t4
\"
c1=3i,c3=L
\"
passitagain
\"
,c2=true,c4=5 1626006833640"
,
"st,t1=4i,t2=5,t3=
\"
t4
\"
c1=3i,c3=L
\"
passitagain
\"
,c2=true,c4=5 1626006833642"
};
int
code
=
taos_insert_by_lines
(
taos
,
lines
,
2
);
int
code
=
taos_insert_by_lines
(
taos
,
lines
,
3
);
return
code
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录