Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e62c2715
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看板
未验证
提交
e62c2715
编写于
7月 27, 2021
作者:
H
Haojun Liao
提交者:
GitHub
7月 27, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6979 from taosdata/fix/TD-5458-2
[TD-5458]<fix>:add duplicate key check for tag&field
上级
715469bf
1754d664
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
79 addition
and
5 deletion
+79
-5
src/client/src/tscParseLineProtocol.c
src/client/src/tscParseLineProtocol.c
+39
-5
tests/examples/c/schemaless.c
tests/examples/c/schemaless.c
+40
-0
未找到文件。
src/client/src/tscParseLineProtocol.c
浏览文件 @
e62c2715
...
...
@@ -1731,7 +1731,31 @@ static int32_t parseSmlTimeStamp(TAOS_SML_KV **pTS, const char **index) {
return
ret
;
}
static
int32_t
parseSmlKey
(
TAOS_SML_KV
*
pKV
,
const
char
**
index
)
{
static
bool
checkDuplicateKey
(
char
*
key
,
SHashObj
*
pHash
)
{
char
*
val
=
NULL
;
char
*
cur
=
key
;
char
keyLower
[
TSDB_COL_NAME_LEN
];
size_t
keyLen
=
0
;
while
(
*
cur
!=
'\0'
)
{
keyLower
[
keyLen
]
=
tolower
(
*
cur
);
keyLen
++
;
cur
++
;
}
keyLower
[
keyLen
]
=
'\0'
;
val
=
taosHashGet
(
pHash
,
keyLower
,
keyLen
);
if
(
val
)
{
tscError
(
"Duplicate key:%s"
,
keyLower
);
return
true
;
}
uint8_t
dummy_val
=
0
;
taosHashPut
(
pHash
,
keyLower
,
strlen
(
key
),
&
dummy_val
,
sizeof
(
uint8_t
));
return
false
;
}
static
int32_t
parseSmlKey
(
TAOS_SML_KV
*
pKV
,
const
char
**
index
,
SHashObj
*
pHash
)
{
const
char
*
cur
=
*
index
;
char
key
[
TSDB_COL_NAME_LEN
];
uint16_t
len
=
0
;
...
...
@@ -1760,6 +1784,10 @@ static int32_t parseSmlKey(TAOS_SML_KV *pKV, const char **index) {
}
key
[
len
]
=
'\0'
;
if
(
checkDuplicateKey
(
key
,
pHash
))
{
return
TSDB_CODE_TSC_LINE_SYNTAX_ERROR
;
}
pKV
->
key
=
calloc
(
len
+
1
,
1
);
memcpy
(
pKV
->
key
,
key
,
len
+
1
);
//tscDebug("Key:%s|len:%d", pKV->key, len);
...
...
@@ -1863,7 +1891,8 @@ static int32_t isValidChildTableName(const char *pTbName, int16_t len) {
static
int32_t
parseSmlKvPairs
(
TAOS_SML_KV
**
pKVs
,
int
*
num_kvs
,
const
char
**
index
,
bool
isField
,
TAOS_SML_DATA_POINT
*
smlData
)
{
const
char
**
index
,
bool
isField
,
TAOS_SML_DATA_POINT
*
smlData
,
SHashObj
*
pHash
)
{
const
char
*
cur
=
*
index
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
TAOS_SML_KV
*
pkv
;
...
...
@@ -1883,7 +1912,7 @@ static int32_t parseSmlKvPairs(TAOS_SML_KV **pKVs, int *num_kvs,
}
while
(
*
cur
!=
'\0'
)
{
ret
=
parseSmlKey
(
pkv
,
&
cur
);
ret
=
parseSmlKey
(
pkv
,
&
cur
,
pHash
);
if
(
ret
)
{
tscError
(
"Unable to parse key field"
);
goto
error
;
...
...
@@ -1971,31 +2000,36 @@ int32_t tscParseLine(const char* sql, TAOS_SML_DATA_POINT* smlData) {
int32_t
ret
=
TSDB_CODE_SUCCESS
;
uint8_t
has_tags
=
0
;
TAOS_SML_KV
*
timestamp
=
NULL
;
SHashObj
*
keyHashTable
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
false
);
ret
=
parseSmlMeasurement
(
smlData
,
&
index
,
&
has_tags
);
if
(
ret
)
{
tscError
(
"Unable to parse measurement"
);
taosHashCleanup
(
keyHashTable
);
return
ret
;
}
tscDebug
(
"Parse measurement finished, has_tags:%d"
,
has_tags
);
//Parse Tags
if
(
has_tags
)
{
ret
=
parseSmlKvPairs
(
&
smlData
->
tags
,
&
smlData
->
tagNum
,
&
index
,
false
,
smlData
);
ret
=
parseSmlKvPairs
(
&
smlData
->
tags
,
&
smlData
->
tagNum
,
&
index
,
false
,
smlData
,
keyHashTable
);
if
(
ret
)
{
tscError
(
"Unable to parse tag"
);
taosHashCleanup
(
keyHashTable
);
return
ret
;
}
}
tscDebug
(
"Parse tags finished, num of tags:%d"
,
smlData
->
tagNum
);
//Parse fields
ret
=
parseSmlKvPairs
(
&
smlData
->
fields
,
&
smlData
->
fieldNum
,
&
index
,
true
,
smlData
);
ret
=
parseSmlKvPairs
(
&
smlData
->
fields
,
&
smlData
->
fieldNum
,
&
index
,
true
,
smlData
,
keyHashTable
);
if
(
ret
)
{
tscError
(
"Unable to parse field"
);
taosHashCleanup
(
keyHashTable
);
return
ret
;
}
tscDebug
(
"Parse fields finished, num of fields:%d"
,
smlData
->
fieldNum
);
taosHashCleanup
(
keyHashTable
);
//Parse timestamp
ret
=
parseSmlTimeStamp
(
&
timestamp
,
&
index
);
...
...
tests/examples/c/schemaless.c
浏览文件 @
e62c2715
...
...
@@ -157,5 +157,45 @@ int main(int argc, char* argv[]) {
return
-
1
;
}
//Duplicate key check;
char
*
lines_003_1
[]
=
{
"std,id=
\"
std_3_1
\"
,t1=4i64,Id=
\"
std
\"
,t2=true c1=true 1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_1
,
sizeof
(
lines_003_1
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_1 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_003_2
[]
=
{
"std,id=
\"
std_3_2
\"
,tag1=4i64,Tag2=true,tAg3=2,TaG2=
\"
dup!
\"
c1=true 1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_2
,
sizeof
(
lines_003_2
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_2 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_003_3
[]
=
{
"std,id=
\"
std_3_3
\"
,tag1=4i64 field1=true,Field2=2,FIElD1=
\"
dup!
\"
,fIeLd4=true 1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_3
,
sizeof
(
lines_003_3
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_3 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
char
*
lines_003_4
[]
=
{
"std,id=
\"
std_3_4
\"
,tag1=4i64,dupkey=4i16,tag2=T field1=true,dUpkEy=1e3f32,field2=
\"
1234
\"
1626006834s"
};
code
=
taos_insert_lines
(
taos
,
lines_003_4
,
sizeof
(
lines_003_4
)
/
sizeof
(
char
*
));
if
(
0
==
code
)
{
printf
(
"taos_insert_lines() lines_003_4 return code:%d (%s)
\n
"
,
code
,
(
char
*
)
tstrerror
(
code
));
return
-
1
;
}
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录