Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5495be27
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看板
提交
5495be27
编写于
10月 19, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-6129<feature> add taos json key hash free function
上级
53bcb31c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
28 addition
and
1 deletion
+28
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+7
-1
src/util/inc/tutil.h
src/util/inc/tutil.h
+1
-0
src/util/src/tutil.c
src/util/src/tutil.c
+11
-0
tests/pytest/stable/json_tag.py
tests/pytest/stable/json_tag.py
+9
-0
未找到文件。
src/client/src/tscUtil.c
浏览文件 @
5495be27
...
...
@@ -5285,6 +5285,7 @@ end:
}
int
parseJsontoTagData
(
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
char
*
errMsg
,
int16_t
startColId
){
// set json NULL data
uint8_t
nullTypeVal
[
CHAR_BYTES
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
]
=
{
0
};
uint8_t
jsonNULL
=
TSDB_DATA_JSON_NULL
;
int
jsonIndex
=
startColId
+
1
;
...
...
@@ -5302,6 +5303,7 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
*
(
uint8_t
*
)(
varDataVal
(
nullTypeVal
+
CHAR_BYTES
))
=
jsonNotNull
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
TSDB_DATA_TYPE_NCHAR
,
&
nullTypeVal
,
true
);
// add json type
// set json real data
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
){
tscError
(
"json parse error"
);
...
...
@@ -5329,7 +5331,11 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
if
(
item
->
type
==
cJSON_NULL
){
continue
;
}
if
(
!
isValidateTag
(
jsonKey
)){
tscError
(
"json key not validate"
);
retCode
=
tscSQLSyntaxErrMsg
(
errMsg
,
"json key not validate"
,
NULL
);
goto
end
;
}
if
(
strlen
(
jsonKey
)
>
TSDB_MAX_JSON_KEY_LEN
){
tscError
(
"json key too long error"
);
retCode
=
tscSQLSyntaxErrMsg
(
errMsg
,
"json key too long, more than 256"
,
NULL
);
...
...
src/util/inc/tutil.h
浏览文件 @
5495be27
...
...
@@ -46,6 +46,7 @@ int taosCheckVersion(char *input_client_version, char *input_server_version, in
char
*
taosIpStr
(
uint32_t
ipInt
);
uint32_t
ip2uint
(
const
char
*
const
ip_addr
);
void
jsonKeyMd5
(
void
*
pMsg
,
int
msgLen
,
void
*
pKey
);
bool
isValidateTag
(
char
*
input
);
static
FORCE_INLINE
void
taosEncryptPass
(
uint8_t
*
inBuf
,
size_t
inLen
,
char
*
target
)
{
MD5_CTX
context
;
...
...
src/util/src/tutil.c
浏览文件 @
5495be27
...
...
@@ -466,6 +466,17 @@ void jsonKeyMd5(void *pMsg, int msgLen, void *pKey) {
memcpy
(
pKey
,
context
.
digest
,
sizeof
(
context
.
digest
));
}
bool
isValidateTag
(
char
*
input
)
{
if
(
!
input
)
return
false
;
int
len
=
strlen
(
input
);
if
(
len
==
0
)
return
false
;
if
(
input
[
0
]
!=
'_'
||
isalpha
(
input
[
0
])
==
0
)
return
false
;
for
(
int
i
=
1
;
i
<
len
;
++
i
)
{
if
(
input
[
0
]
!=
'_'
||
isalnum
(
input
[
0
])
==
0
)
return
false
;
}
return
true
;
}
FORCE_INLINE
float
taos_align_get_float
(
const
char
*
pBuf
)
{
#if __STDC_VERSION__ >= 201112L
static_assert
(
sizeof
(
float
)
==
sizeof
(
uint32_t
),
"sizeof(float) must equal to sizeof(uint32_t)"
);
...
...
tests/pytest/stable/json_tag.py
浏览文件 @
5495be27
...
...
@@ -33,6 +33,9 @@ class TDTestCase:
tdSql
.
execute
(
"create table if not exists db_json_tag_test.jsons1(ts timestamp, dataInt int, dataBool bool, dataStr nchar(50)) tags(jtag json)"
)
tdSql
.
execute
(
"CREATE TABLE if not exists db_json_tag_test.jsons1_1 using db_json_tag_test.jsons1 tags('{
\"
loc
\"
:
\"
fff
\"
,
\"
id
\"
:5}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags(3333)"
)
tdSql
.
error
(
"CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags('{
\"
1loc
\"
:
\"
fff
\"
,
\"
;id
\"
:5}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags('{
\"
。loc
\"
:
\"
fff
\"
,
\"
fsd
\"
:5}')"
)
tdSql
.
error
(
"CREATE TABLE if not exists db_json_tag_test.jsons1_3 using db_json_tag_test.jsons1 tags('{
\"
试试
\"
:
\"
fff
\"
,
\"
;id
\"
:5}')"
)
tdSql
.
execute
(
"insert into db_json_tag_test.jsons1_2 using db_json_tag_test.jsons1 tags('{
\"
num
\"
:5,
\"
location
\"
:
\"
beijing
\"
}') values (now, 2, true, 'json2')"
)
tdSql
.
error
(
"insert into db_json_tag_test.jsons1_4 using db_json_tag_test.jsons1 tags(3)"
)
tdSql
.
execute
(
"insert into db_json_tag_test.jsons1_1 values(now, 1, false, 'json1')"
)
...
...
@@ -228,6 +231,12 @@ class TDTestCase:
tdSql
.
query
(
"select distinct jtag from db_json_tag_test.jsons1"
)
tdSql
.
checkRows
(
6
)
tdSql
.
query
(
"select distinct jtag->'location' from db_json_tag_test.jsons1"
)
tdSql
.
checkRows
(
3
)
# test chinese
tdSql
.
execute
(
"CREATE TABLE if not exists db_json_tag_test.jsons1_11 using db_json_tag_test.jsons1 tags('{
\"
k1
\"
:
\"
中国
\"
,
\"
k2
\"
:
\"
是是是
\"
}')"
)
def
stop
(
self
):
tdSql
.
close
()
tdLog
.
success
(
"%s successfully executed"
%
__file__
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录