Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e0340e56
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看板
提交
e0340e56
编写于
11月 09, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add json compare function support
上级
ccb65c4c
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
50 addition
and
21 deletion
+50
-21
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+4
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+10
-5
src/inc/tsdb.h
src/inc/tsdb.h
+1
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+3
-3
src/query/src/qExtbuffer.c
src/query/src/qExtbuffer.c
+7
-2
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+1
-4
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+7
-2
src/util/src/tcompare.c
src/util/src/tcompare.c
+7
-2
tests/pytest/stable/json_tag.py
tests/pytest/stable/json_tag.py
+9
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
e0340e56
...
...
@@ -391,7 +391,7 @@ char* cloneCurrentDBName(SSqlObj* pSql);
int
parseJsontoTagData
(
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
char
*
errMsg
,
int16_t
startColId
);
char
*
parseTagDatatoJson
(
void
*
p
);
void
getJsonTagValueElment
(
STable
*
data
,
char
*
key
,
int32_t
keyLen
,
char
*
out
,
int16_t
bytes
);
void
*
getJsonTagValueElment
(
STable
*
data
,
char
*
key
,
int32_t
keyLen
,
char
*
out
,
int16_t
bytes
);
void
getJsonTagValueAll
(
void
*
data
,
void
*
dst
,
int16_t
bytes
);
int8_t
jsonType2DbType
(
double
data
,
int
jsonType
);
...
...
src/client/src/tscSubquery.c
浏览文件 @
e0340e56
...
...
@@ -721,8 +721,11 @@ int32_t tagValCompar(const void* p1, const void* p2) {
const
STidTags
*
t1
=
(
const
STidTags
*
)
varDataVal
(
p1
);
const
STidTags
*
t2
=
(
const
STidTags
*
)
varDataVal
(
p2
);
if
(
t1
->
padding
==
TSDB_DATA_TYPE_JSON
){
__compar_fn_t
func
=
getComparFunc
(
t1
->
tag
[
0
],
0
);
return
func
(
t1
->
tag
+
CHAR_BYTES
,
t2
->
tag
+
CHAR_BYTES
);
}
__compar_fn_t
func
=
getComparFunc
(
t1
->
padding
,
0
);
return
func
(
t1
->
tag
,
t2
->
tag
);
}
...
...
src/client/src/tscUtil.c
浏览文件 @
e0340e56
...
...
@@ -5372,31 +5372,36 @@ char* cloneCurrentDBName(SSqlObj* pSql) {
return
p
;
}
void
getJsonTagValueElment
(
STable
*
data
,
char
*
key
,
int32_t
keyLen
,
char
*
dst
,
int16_t
bytes
){
void
*
getJsonTagValueElment
(
STable
*
data
,
char
*
key
,
int32_t
keyLen
,
char
*
dst
,
int16_t
bytes
){
char
keyMd5
[
TSDB_MAX_JSON_KEY_MD5_LEN
]
=
{
0
};
jsonKeyMd5
(
key
,
keyLen
,
keyMd5
);
void
*
result
=
getJsonTagValue
(
data
,
keyMd5
,
TSDB_MAX_JSON_KEY_MD5_LEN
,
NULL
);
if
(
result
==
NULL
){
// json key no result
if
(
!
dst
)
return
NULL
;
*
(
char
*
)
dst
=
TSDB_DATA_TYPE_NCHAR
;
setNull
(
dst
+
CHAR_BYTES
,
TSDB_DATA_TYPE_JSON
,
0
);
return
;
return
dst
;
}
char
*
realData
=
POINTER_SHIFT
(
result
,
CHAR_BYTES
);
if
(
*
(
char
*
)
result
==
TSDB_DATA_TYPE_NCHAR
||
*
(
char
*
)
result
==
TSDB_DATA_TYPE_BINARY
)
{
assert
(
varDataTLen
(
realData
)
<
bytes
);
if
(
!
dst
)
return
realData
;
memcpy
(
dst
,
result
,
CHAR_BYTES
+
varDataTLen
(
realData
));
return
;
return
dst
;
}
else
if
(
*
(
char
*
)
result
==
TSDB_DATA_TYPE_DOUBLE
||
*
(
char
*
)
result
==
TSDB_DATA_TYPE_BIGINT
)
{
if
(
!
dst
)
return
realData
;
memcpy
(
dst
,
result
,
CHAR_BYTES
+
LONG_BYTES
);
return
;
return
dst
;
}
else
if
(
*
(
char
*
)
result
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
!
dst
)
return
realData
;
memcpy
(
dst
,
result
,
CHAR_BYTES
+
CHAR_BYTES
);
return
;
return
dst
;
}
else
{
assert
(
0
);
}
return
realData
;
}
void
getJsonTagValueAll
(
void
*
data
,
void
*
dst
,
int16_t
bytes
)
{
...
...
src/inc/tsdb.h
浏览文件 @
e0340e56
...
...
@@ -118,7 +118,7 @@ typedef struct {
void
tsdbClearTableCfg
(
STableCfg
*
config
);
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
);
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
);
char
*
tsdbGetTableName
(
void
*
pTable
);
#define TSDB_TABLEID(_table) ((STableId*) (_table))
...
...
src/query/src/qExecutor.c
浏览文件 @
e0340e56
...
...
@@ -3381,7 +3381,7 @@ static void doSetTagValueInParam(void* pTable, char* param, int32_t paramLen, in
val
=
tsdbGetTableName
(
pTable
);
assert
(
val
!=
NULL
);
}
else
{
val
=
tsdbGetTableTagVal
(
pTable
,
tagColId
,
type
,
bytes
);
val
=
tsdbGetTableTagVal
(
pTable
,
tagColId
,
type
);
}
if
(
val
==
NULL
||
isNull
(
val
,
type
))
{
...
...
@@ -7218,7 +7218,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
if
(
pExprInfo
->
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
data
=
tsdbGetTableName
(
item
->
pTable
);
}
else
{
data
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
->
base
.
colInfo
.
colId
,
type
,
bytes
);
data
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
->
base
.
colInfo
.
colId
,
type
);
if
(
type
==
TSDB_DATA_TYPE_JSON
){
if
(
pExprInfo
->
base
.
numOfParams
>
0
){
// tag-> operation
getJsonTagValueElment
(
item
->
pTable
,
pExprInfo
->
base
.
param
[
0
].
pz
,
pExprInfo
->
base
.
param
[
0
].
nLen
,
output
,
bytes
);
...
...
@@ -7267,7 +7267,7 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
if
(
pExprInfo
[
j
].
base
.
colInfo
.
colId
==
TSDB_TBNAME_COLUMN_INDEX
)
{
data
=
tsdbGetTableName
(
item
->
pTable
);
}
else
{
data
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
[
j
].
base
.
colInfo
.
colId
,
type
,
bytes
);
data
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
[
j
].
base
.
colInfo
.
colId
,
type
);
if
(
type
==
TSDB_DATA_TYPE_JSON
){
if
(
pExprInfo
[
j
].
base
.
numOfParams
>
0
){
// tag-> operation
getJsonTagValueElment
(
item
->
pTable
,
pExprInfo
[
j
].
base
.
param
[
0
].
pz
,
pExprInfo
[
j
].
base
.
param
[
0
].
nLen
,
dst
,
bytes
);
...
...
src/query/src/qExtbuffer.c
浏览文件 @
e0340e56
...
...
@@ -367,6 +367,12 @@ static int32_t tsCompareFunc(TSKEY k1, TSKEY k2, int32_t order) {
}
int32_t
columnValueAscendingComparator
(
char
*
f1
,
char
*
f2
,
int32_t
type
,
int32_t
bytes
)
{
if
(
type
==
TSDB_DATA_TYPE_JSON
){
assert
(
*
f1
==
*
f2
);
type
=
*
f1
;
f1
=
POINTER_SHIFT
(
f1
,
CHAR_BYTES
);
f2
=
POINTER_SHIFT
(
f2
,
CHAR_BYTES
);
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_INT
:
DEFAULT_COMP
(
GET_INT32_VAL
(
f1
),
GET_INT32_VAL
(
f2
));
case
TSDB_DATA_TYPE_DOUBLE
:
DEFAULT_DOUBLE_COMP
(
GET_DOUBLE_VAL
(
f1
),
GET_DOUBLE_VAL
(
f2
));
...
...
@@ -391,8 +397,7 @@ int32_t columnValueAscendingComparator(char *f1, char *f2, int32_t type, int32_t
}
};
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_JSON
:
{
// todo handle the var string compare
case
TSDB_DATA_TYPE_NCHAR
:
{
// todo handle the var string compare
int32_t
len1
=
varDataLen
(
f1
);
int32_t
len2
=
varDataLen
(
f2
);
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
e0340e56
...
...
@@ -204,7 +204,7 @@ _err:
return
-
1
;
}
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
,
int16_t
bytes
)
{
void
*
tsdbGetTableTagVal
(
const
void
*
pTable
,
int32_t
colId
,
int16_t
type
)
{
// TODO: this function should be changed also
STSchema
*
pSchema
=
tsdbGetTableTagSchema
((
STable
*
)
pTable
);
...
...
@@ -220,9 +220,6 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_
val
=
tdGetKVRowValOfCol
(((
STable
*
)
pTable
)
->
tagVal
,
colId
);
assert
(
type
==
pCol
->
type
);
}
// if (val != NULL && IS_VAR_DATA_TYPE(type)) {
// assert(varDataLen(val) < pCol->bytes);
// }
return
val
;
}
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
e0340e56
...
...
@@ -3515,8 +3515,13 @@ static int32_t tableGroupComparFn(const void *p1, const void *p2, const void *pa
STColumn
*
pCol
=
schemaColAt
(
pTableGroupSupp
->
pTagSchema
,
colIndex
);
bytes
=
pCol
->
bytes
;
type
=
pCol
->
type
;
f1
=
tdGetKVRowValOfCol
(
pTable1
->
tagVal
,
pCol
->
colId
);
f2
=
tdGetKVRowValOfCol
(
pTable2
->
tagVal
,
pCol
->
colId
);
if
(
type
==
TSDB_DATA_TYPE_JSON
){
f1
=
getJsonTagValueElment
(
pTable1
,
pColIndex
->
name
,
strlen
(
pColIndex
->
name
),
NULL
,
TSDB_MAX_JSON_TAGS_LEN
);
f2
=
getJsonTagValueElment
(
pTable2
,
pColIndex
->
name
,
strlen
(
pColIndex
->
name
),
NULL
,
TSDB_MAX_JSON_TAGS_LEN
);
}
else
{
f1
=
tdGetKVRowValOfCol
(
pTable1
->
tagVal
,
pCol
->
colId
);
f2
=
tdGetKVRowValOfCol
(
pTable2
->
tagVal
,
pCol
->
colId
);
}
}
}
...
...
src/util/src/tcompare.c
浏览文件 @
e0340e56
...
...
@@ -576,6 +576,12 @@ __compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order) {
}
int32_t
doCompare
(
const
char
*
f1
,
const
char
*
f2
,
int32_t
type
,
size_t
size
)
{
if
(
type
==
TSDB_DATA_TYPE_JSON
){
assert
(
*
f1
==
*
f2
);
type
=
*
f1
;
f1
=
POINTER_SHIFT
(
f1
,
CHAR_BYTES
);
f2
=
POINTER_SHIFT
(
f2
,
CHAR_BYTES
);
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_INT
:
DEFAULT_COMP
(
GET_INT32_VAL
(
f1
),
GET_INT32_VAL
(
f2
));
case
TSDB_DATA_TYPE_DOUBLE
:
DEFAULT_DOUBLE_COMP
(
GET_DOUBLE_VAL
(
f1
),
GET_DOUBLE_VAL
(
f2
));
...
...
@@ -588,8 +594,7 @@ int32_t doCompare(const char* f1, const char* f2, int32_t type, size_t size) {
case
TSDB_DATA_TYPE_USMALLINT
:
DEFAULT_COMP
(
GET_UINT16_VAL
(
f1
),
GET_UINT16_VAL
(
f2
));
case
TSDB_DATA_TYPE_UINT
:
DEFAULT_COMP
(
GET_UINT32_VAL
(
f1
),
GET_UINT32_VAL
(
f2
));
case
TSDB_DATA_TYPE_UBIGINT
:
DEFAULT_COMP
(
GET_UINT64_VAL
(
f1
),
GET_UINT64_VAL
(
f2
));
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_JSON
:{
case
TSDB_DATA_TYPE_NCHAR
:{
tstr
*
t1
=
(
tstr
*
)
f1
;
tstr
*
t2
=
(
tstr
*
)
f2
;
...
...
tests/pytest/stable/json_tag.py
浏览文件 @
e0340e56
...
...
@@ -278,9 +278,18 @@ class TDTestCase:
tdSql
.
execute
(
"INSERT INTO db_json_tag_test.jsons1_20 using db_json_tag_test.jsons1 tags('{
\"
tagint
\"
:1}') values(now, 1, false,
\"
你就会
\"
)"
)
tdSql
.
execute
(
"INSERT INTO db_json_tag_test.jsons1_21 using db_json_tag_test.jsons1 tags('{
\"
tagint
\"
:11}') values(now, 11, false,
\"
你就会
\"
)"
)
tdSql
.
execute
(
"INSERT INTO db_json_tag_test.jsons1_22 using db_json_tag_test.jsons1 tags('{
\"
tagint
\"
:2}') values(now, 2, false,
\"
你就会
\"
)"
)
tdSql
.
query
(
"select avg(dataint),count(*) from db_json_tag_test.jsons1 group by jtag->'tagint' order by jtag->'tagint' desc"
)
//
tdSql
.
checkData
(
1
,
0
,
2.5
)
# test json->'key'=null
tdSql
.
execute
(
"insert into db_json_tag_test.jsons1_9 values('2020-04-17 15:20:00.000', 5, false, 'json19')"
)
tdSql
.
query
(
"select * from db_json_tag_test.jsons1"
)
tdSql
.
checkRows
(
9
)
tdSql
.
query
(
"select * from db_json_tag_test.jsons1 where jtag->'time' is null"
)
tdSql
.
checkRows
(
8
)
tdSql
.
query
(
"select * from db_json_tag_test.jsons1 where jtag->'time'=null"
)
tdSql
.
checkRows
(
1
)
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录