Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
db0ad956
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看板
未验证
提交
db0ad956
编写于
5月 06, 2023
作者:
H
Haojun Liao
提交者:
GitHub
5月 06, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #21152 from taosdata/fix/TS-3303
fix:[TS-3303]use stable name + child table name as key to save uid to…
上级
2ea81179
3fb2d765
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
80 addition
and
4 deletion
+80
-4
source/client/inc/clientSml.h
source/client/inc/clientSml.h
+2
-0
source/client/src/clientSml.c
source/client/src/clientSml.c
+18
-1
source/client/src/clientSmlJson.c
source/client/src/clientSmlJson.c
+1
-1
source/client/src/clientSmlLine.c
source/client/src/clientSmlLine.c
+1
-1
source/client/src/clientSmlTelnet.c
source/client/src/clientSmlTelnet.c
+1
-1
tests/system-test/2-query/sml.py
tests/system-test/2-query/sml.py
+3
-0
utils/test/c/sml_test.c
utils/test/c/sml_test.c
+54
-0
未找到文件。
source/client/inc/clientSml.h
浏览文件 @
db0ad956
...
...
@@ -169,6 +169,7 @@ typedef struct {
int32_t
uid
;
// used for automatic create child table
SHashObj
*
childTables
;
SHashObj
*
tableUids
;
SHashObj
*
superTables
;
SHashObj
*
pVgHash
;
...
...
@@ -242,6 +243,7 @@ int8_t smlGetTsTypeByLen(int32_t len);
SSmlTableInfo
*
smlBuildTableInfo
(
int
numRows
,
const
char
*
measure
,
int32_t
measureLen
);
SSmlSTableMeta
*
smlBuildSTableMeta
(
bool
isDataFormat
);
int32_t
smlSetCTableName
(
SSmlTableInfo
*
oneTable
);
void
getTableUid
(
SSmlHandle
*
info
,
SSmlLineInfo
*
currElement
,
SSmlTableInfo
*
tinfo
);
STableMeta
*
smlGetMeta
(
SSmlHandle
*
info
,
const
void
*
measure
,
int32_t
measureLen
);
int32_t
is_same_child_table_telnet
(
const
void
*
a
,
const
void
*
b
);
int64_t
smlParseOpenTsdbTime
(
SSmlHandle
*
info
,
const
char
*
data
,
int32_t
len
);
...
...
source/client/src/clientSml.c
浏览文件 @
db0ad956
...
...
@@ -195,6 +195,20 @@ int32_t smlSetCTableName(SSmlTableInfo *oneTable) {
return
TSDB_CODE_SUCCESS
;
}
void
getTableUid
(
SSmlHandle
*
info
,
SSmlLineInfo
*
currElement
,
SSmlTableInfo
*
tinfo
){
char
key
[
TSDB_TABLE_NAME_LEN
*
2
+
1
]
=
{
0
};
size_t
nLen
=
strlen
(
tinfo
->
childTableName
);
memcpy
(
key
,
currElement
->
measure
,
currElement
->
measureLen
);
memcpy
(
key
+
currElement
->
measureLen
+
1
,
tinfo
->
childTableName
,
nLen
);
void
*
uid
=
taosHashGet
(
info
->
tableUids
,
key
,
currElement
->
measureLen
+
1
+
nLen
);
// use \0 as separator for stable name and child table name
if
(
uid
==
NULL
)
{
tinfo
->
uid
=
info
->
uid
++
;
taosHashPut
(
info
->
tableUids
,
key
,
currElement
->
measureLen
+
1
+
nLen
,
&
tinfo
->
uid
,
sizeof
(
uint64_t
));
}
else
{
tinfo
->
uid
=
*
(
uint64_t
*
)
uid
;
}
}
SSmlSTableMeta
*
smlBuildSTableMeta
(
bool
isDataFormat
)
{
SSmlSTableMeta
*
meta
=
(
SSmlSTableMeta
*
)
taosMemoryCalloc
(
sizeof
(
SSmlSTableMeta
),
1
);
if
(
!
meta
)
{
...
...
@@ -1142,6 +1156,7 @@ void smlDestroyInfo(SSmlHandle *info) {
taosHashCleanup
(
info
->
pVgHash
);
taosHashCleanup
(
info
->
childTables
);
taosHashCleanup
(
info
->
superTables
);
taosHashCleanup
(
info
->
tableUids
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
info
->
tagJsonArray
);
i
++
)
{
cJSON
*
tags
=
(
cJSON
*
)
taosArrayGetP
(
info
->
tagJsonArray
,
i
);
...
...
@@ -1192,6 +1207,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
info
->
pVgHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
),
true
,
HASH_NO_LOCK
);
info
->
childTables
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
info
->
tableUids
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
info
->
superTables
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
info
->
id
=
smlGenId
();
...
...
@@ -1202,7 +1218,7 @@ SSmlHandle *smlBuildSmlInfo(TAOS *taos) {
info
->
valueJsonArray
=
taosArrayInit
(
8
,
POINTER_BYTES
);
info
->
preLineTagKV
=
taosArrayInit
(
8
,
sizeof
(
SSmlKv
));
if
(
NULL
==
info
->
pVgHash
||
NULL
==
info
->
childTables
||
NULL
==
info
->
superTables
)
{
if
(
NULL
==
info
->
pVgHash
||
NULL
==
info
->
childTables
||
NULL
==
info
->
superTables
||
NULL
==
info
->
tableUids
)
{
uError
(
"create SSmlHandle failed"
);
goto
cleanup
;
}
...
...
@@ -1428,6 +1444,7 @@ int32_t smlClearForRerun(SSmlHandle *info) {
taosHashClear
(
info
->
childTables
);
taosHashClear
(
info
->
superTables
);
taosHashClear
(
info
->
tableUids
);
if
(
!
info
->
dataFormat
)
{
if
(
unlikely
(
info
->
lines
!=
NULL
))
{
...
...
source/client/src/clientSmlJson.c
浏览文件 @
db0ad956
...
...
@@ -778,7 +778,7 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, cJSON *tags, SSmlLineInfo
tinfo
->
tags
=
taosArrayDup
(
preLineKV
,
NULL
);
smlSetCTableName
(
tinfo
);
tinfo
->
uid
=
info
->
uid
++
;
getTableUid
(
info
,
elements
,
tinfo
)
;
if
(
info
->
dataFormat
)
{
info
->
currSTableMeta
->
uid
=
tinfo
->
uid
;
tinfo
->
tableDataCtx
=
smlInitTableDataCtx
(
info
->
pQuery
,
info
->
currSTableMeta
);
...
...
source/client/src/clientSmlLine.c
浏览文件 @
db0ad956
...
...
@@ -312,7 +312,7 @@ static int32_t smlParseTagKv(SSmlHandle *info, char **sql, char *sqlEnd, SSmlLin
}
smlSetCTableName
(
tinfo
);
tinfo
->
uid
=
info
->
uid
++
;
getTableUid
(
info
,
currElement
,
tinfo
)
;
if
(
info
->
dataFormat
)
{
info
->
currSTableMeta
->
uid
=
tinfo
->
uid
;
tinfo
->
tableDataCtx
=
smlInitTableDataCtx
(
info
->
pQuery
,
info
->
currSTableMeta
);
...
...
source/client/src/clientSmlTelnet.c
浏览文件 @
db0ad956
...
...
@@ -206,7 +206,7 @@ static int32_t smlParseTelnetTags(SSmlHandle *info, char *data, char *sqlEnd, SS
tinfo
->
tags
=
taosArrayDup
(
preLineKV
,
NULL
);
smlSetCTableName
(
tinfo
);
tinfo
->
uid
=
info
->
uid
++
;
getTableUid
(
info
,
elements
,
tinfo
)
;
if
(
info
->
dataFormat
)
{
info
->
currSTableMeta
->
uid
=
tinfo
->
uid
;
tinfo
->
tableDataCtx
=
smlInitTableDataCtx
(
info
->
pQuery
,
info
->
currSTableMeta
);
...
...
tests/system-test/2-query/sml.py
浏览文件 @
db0ad956
...
...
@@ -34,6 +34,9 @@ class TDTestCase:
if
ret
!=
0
:
tdLog
.
info
(
"sml_test ret != 0"
)
tdSql
.
query
(
f
"select * from ts3303.stb2"
)
tdSql
.
query
(
f
"select * from ts3303.meters"
)
# tdSql.execute('use sml_db')
tdSql
.
query
(
f
"select * from
{
dbname
}
.t_b7d815c9222ca64cdf2614c61de8f211"
)
tdSql
.
checkRows
(
1
)
...
...
utils/test/c/sml_test.c
浏览文件 @
db0ad956
...
...
@@ -1159,6 +1159,57 @@ int sml_td23881_Test() {
return
code
;
}
int
sml_ts3303_Test
()
{
TAOS
*
taos
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
TAOS_RES
*
pRes
=
taos_query
(
taos
,
"drop database if exists ts3303"
);
taos_free_result
(
pRes
);
pRes
=
taos_query
(
taos
,
"create database if not exists ts3303"
);
taos_free_result
(
pRes
);
const
char
*
sql
[]
=
{
"stb2,t1=1,dataModelName=t0 f1=283i32 1632299372000"
,
"stb2,t1=1,dataModelName=t0 f1=106i32 1632299378000"
,
"stb2,t1=4,dataModelName=t0 f1=144i32 1629716944000"
,
"stb2,t1=4,dataModelName=t0 f1=125i32 1629717012000"
,
"stb2,t1=4,dataModelName=t0 f1=144i32 1629717012000"
,
"stb2,t1=4,dataModelName=t0 f1=107i32 1629717013000"
,
"stb2,t1=6,dataModelName=t0 f1=154i32 1629717140000"
,
"stb2,t1=6,dataModelName=t0 f1=93i32 1629717140000"
,
"stb2,t1=6,dataModelName=t0 f1=134i32 1629717140000"
,
"stb2,t1=4,dataModelName=t0 f1=73i32 1629717140000"
,
"stb2,t1=4,dataModelName=t0 f1=83i32 1629717140000"
,
"stb2,t1=4,dataModelName=t0 f1=72i32 1629717140000"
,
};
const
char
*
sql1
[]
=
{
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=
\"
2022-02-0210:22:22
\"
1626006833339000000"
,
"meters,groupid=2,location=California.LosAngeles current=11.8,voltage=221,phase=
\"
2022-02-0210:22:22
\"
1626006833339000000"
,
};
pRes
=
taos_query
(
taos
,
"use ts3303"
);
taos_free_result
(
pRes
);
pRes
=
taos_schemaless_insert_ttl
(
taos
,
(
char
**
)
sql
,
sizeof
(
sql
)
/
sizeof
(
sql
[
0
]),
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_MILLI_SECONDS
,
20
);
int
code
=
taos_errno
(
pRes
);
printf
(
"%s result0:%s
\n
"
,
__FUNCTION__
,
taos_errstr
(
pRes
));
taos_free_result
(
pRes
);
ASSERT
(
code
==
0
);
pRes
=
taos_schemaless_insert_ttl
(
taos
,
(
char
**
)
sql1
,
sizeof
(
sql1
)
/
sizeof
(
sql1
[
0
]),
TSDB_SML_LINE_PROTOCOL
,
TSDB_SML_TIMESTAMP_NANO_SECONDS
,
20
);
printf
(
"%s result1:%s
\n
"
,
__FUNCTION__
,
taos_errstr
(
pRes
));
taos_free_result
(
pRes
);
taos_close
(
taos
);
return
code
;
}
int
sml_ttl_Test
()
{
TAOS
*
taos
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
...
...
@@ -1336,6 +1387,9 @@ int main(int argc, char *argv[]) {
ASSERT
(
!
ret
);
ret
=
sml_ts2385_Test
();
// this test case need config sml table name using ./sml_test config_file
ASSERT
(
!
ret
);
ret
=
sml_ts3303_Test
();
// this test case need config sml table name using ./sml_test config_file
ASSERT
(
!
ret
);
// for(int i = 0; i < sizeof(str)/sizeof(str[0]); i++){
// printf("str:%s \t %d\n", str[i], smlCalTypeSum(str[i], strlen(str[i])));
// }
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录