Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ad299634
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看板
提交
ad299634
编写于
4月 18, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: modify json compare in where condition
上级
24f805c5
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
93 addition
and
59 deletion
+93
-59
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+71
-1
source/libs/scalar/inc/filterInt.h
source/libs/scalar/inc/filterInt.h
+0
-2
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+22
-56
未找到文件。
source/client/src/clientImpl.c
浏览文件 @
ad299634
...
...
@@ -619,7 +619,7 @@ void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
int32_t
bytes
=
pResultInfo
->
fields
[
i
].
bytes
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
if
(
pCol
->
offset
[
pResultInfo
->
current
]
!=
-
1
)
{
if
(
!
colDataIsNull_var
(
pCol
,
pResultInfo
->
current
)
)
{
char
*
pStart
=
pResultInfo
->
pCol
[
i
].
offset
[
pResultInfo
->
current
]
+
pResultInfo
->
pCol
[
i
].
pData
;
pResultInfo
->
length
[
i
]
=
varDataLen
(
pStart
);
...
...
@@ -725,6 +725,76 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
pResultInfo
->
pCol
[
i
].
pData
=
pResultInfo
->
convertBuf
[
i
];
pResultInfo
->
row
[
i
]
=
pResultInfo
->
pCol
[
i
].
pData
;
}
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
char
*
p
=
taosMemoryRealloc
(
pResultInfo
->
convertBuf
[
i
],
colLength
[
i
]);
if
(
p
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pResultInfo
->
convertBuf
[
i
]
=
p
;
int32_t
len
=
0
;
SResultColumn
*
pCol
=
&
pResultInfo
->
pCol
[
i
];
for
(
int32_t
j
=
0
;
j
<
numOfRows
;
++
j
)
{
if
(
pCol
->
offset
[
j
]
!=
-
1
)
{
char
*
pStart
=
pCol
->
offset
[
j
]
+
pCol
->
pData
;
int32_t
jsonInnerType
=
*
pStart
;
char
*
jsonInnerData
=
pStart
+
CHAR_BYTES
;
char
dst
[
TSDB_MAX_JSON_TAG_LEN
]
=
{
0
};
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NULL
){
sprintf
(
varDataVal
(
dst
),
"%s"
,
TSDB_DATA_NULL_STR_L
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_JSON
){
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
jsonInnerData
),
varDataLen
(
jsonInnerData
),
varDataVal
(
dst
));
if
(
length
<=
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
varDataVal
(
jsonInnerData
));
length
=
0
;
}
varDataSetLen
(
dst
,
length
);
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NCHAR
)
{
// value -> "value"
*
(
char
*
)
varDataVal
(
dst
)
=
'\"'
;
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
jsonInnerData
),
varDataLen
(
jsonInnerData
),
varDataVal
(
dst
)
+
CHAR_BYTES
);
if
(
length
<=
0
)
{
tscError
(
"charset:%s to %s. val:%s convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
varDataVal
(
jsonInnerData
));
length
=
0
;
}
varDataSetLen
(
dst
,
length
+
CHAR_BYTES
*
2
);
*
(
char
*
)(
varDataVal
(
dst
),
length
+
CHAR_BYTES
)
=
'\"'
;
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_DOUBLE
){
double
jsonVd
=
*
(
double
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%.9lf"
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BIGINT
){
int64_t
jsonVd
=
*
(
int64_t
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%"
PRId64
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BOOL
){
sprintf
(
varDataVal
(
dst
),
"%s"
,
(
*
((
char
*
)
jsonInnerData
)
==
1
)
?
"true"
:
"false"
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
{
ASSERT
(
0
);
}
if
(
len
+
varDataTLen
(
dst
)
>
colLength
[
i
]){
p
=
taosMemoryRealloc
(
pResultInfo
->
convertBuf
[
i
],
len
+
varDataTLen
(
dst
));
if
(
p
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pResultInfo
->
convertBuf
[
i
]
=
p
;
}
p
=
pResultInfo
->
convertBuf
[
i
]
+
len
;
memcpy
(
p
,
dst
,
varDataTLen
(
dst
));
pCol
->
offset
[
j
]
=
len
;
len
+=
varDataTLen
(
dst
);
}
}
pResultInfo
->
pCol
[
i
].
pData
=
pResultInfo
->
convertBuf
[
i
];
pResultInfo
->
row
[
i
]
=
pResultInfo
->
pCol
[
i
].
pData
;
}
}
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/scalar/inc/filterInt.h
浏览文件 @
ad299634
...
...
@@ -308,7 +308,6 @@ struct SFilterInfo {
#define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri)))
#define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type)
#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data)
#define FILTER_GET_JSON_VAL_FIELD_DATA(fi) ((char *)(fi)->desc)
#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX)
#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid])
...
...
@@ -321,7 +320,6 @@ struct SFilterInfo {
#define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u))
#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_JSON_VAL_DATA(i, u) FILTER_GET_JSON_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u))
#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx)
#define FILTER_UNIT_OPTR(u) ((u)->compare.optr)
#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func)
...
...
source/libs/scalar/src/filter.c
浏览文件 @
ad299634
...
...
@@ -63,22 +63,18 @@ OptrStr gOptrStr[] = {
bool
filterRangeCompGi
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
maxv
,
minr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
>=
0
;
}
bool
filterRangeCompGe
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
maxv
,
minr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
>
0
;
}
bool
filterRangeCompLi
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
minv
,
maxr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
<=
0
;
}
bool
filterRangeCompLe
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
int32_t
result
=
cfunc
(
minv
,
maxr
);
//if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false;
return
result
<
0
;
}
bool
filterRangeCompii
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
...
...
@@ -1783,7 +1779,7 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
bytes
=
(
len
+
1
)
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
;
fi
->
data
=
taosMemoryCalloc
(
1
,
bytes
);
}
else
if
(
type
!=
TSDB_DATA_TYPE_JSON
)
{
}
else
{
if
(
dType
->
type
==
TSDB_DATA_TYPE_VALUE_ARRAY
)
{
//TIME RANGE
/*
fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes);
...
...
@@ -1796,11 +1792,8 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
}
else
{
fi
->
data
=
taosMemoryCalloc
(
1
,
sizeof
(
int64_t
));
}
}
else
{
// type == TSDB_DATA_TYPE_JSON
// fi->data = null; use fi->desc as data, because json value is variable, so use tVariant (fi->desc)
}
if
(
type
!=
TSDB_DATA_TYPE_JSON
)
{
if
(
dType
->
type
==
type
)
{
assignVal
(
fi
->
data
,
nodesGetValueFromNode
(
var
),
dType
->
bytes
,
type
);
}
else
{
...
...
@@ -1821,7 +1814,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
memcpy
(
fi
->
data
,
out
.
columnData
->
pData
,
out
.
columnData
->
info
.
bytes
);
}
}
// match/nmatch for nchar type need convert from ucs4 to mbs
if
(
type
==
TSDB_DATA_TYPE_NCHAR
&&
...
...
@@ -2561,11 +2553,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) {
info
->
cunits
[
i
].
colId
=
FILTER_UNIT_COL_ID
(
info
,
unit
);
if
(
unit
->
right
.
type
==
FLD_TYPE_VALUE
)
{
if
(
FILTER_UNIT_DATA_TYPE
(
unit
)
==
TSDB_DATA_TYPE_JSON
){
// json value is tVariant
info
->
cunits
[
i
].
valData
=
FILTER_UNIT_JSON_VAL_DATA
(
info
,
unit
);
}
else
{
info
->
cunits
[
i
].
valData
=
FILTER_UNIT_VAL_DATA
(
info
,
unit
);
}
}
else
{
info
->
cunits
[
i
].
valData
=
NULL
;
}
...
...
@@ -2891,18 +2879,8 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows,
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
uint32_t
uidx
=
info
->
groups
[
0
].
unitIdxs
[
0
];
void
*
colData
=
colDataGetData
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
i
);
if
(
info
->
cunits
[
uidx
].
dataType
==
TSDB_DATA_TYPE_JSON
){
if
(
!
colData
){
// for json->'key' is null
(
*
p
)[
i
]
=
1
;
}
else
if
(
*
(
char
*
)
colData
==
TSDB_DATA_TYPE_JSON
){
// for json is null
colData
=
POINTER_SHIFT
(
colData
,
CHAR_BYTES
);
(
*
p
)[
i
]
=
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
);
}
else
{
(
*
p
)[
i
]
=
0
;
}
}
else
{
(
*
p
)[
i
]
=
((
colData
==
NULL
)
||
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
));
}
if
((
*
p
)[
i
]
==
0
)
{
all
=
false
;
}
...
...
@@ -2926,19 +2904,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows
uint32_t
uidx
=
info
->
groups
[
0
].
unitIdxs
[
0
];
void
*
colData
=
colDataGetData
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
i
);
if
(
info
->
cunits
[
uidx
].
dataType
==
TSDB_DATA_TYPE_JSON
){
if
(
!
colData
)
{
// for json->'key' is not null
(
*
p
)[
i
]
=
0
;
}
else
if
(
*
(
char
*
)
colData
==
TSDB_DATA_TYPE_JSON
){
// for json is not null
colData
=
POINTER_SHIFT
(
colData
,
CHAR_BYTES
);
(
*
p
)[
i
]
=
!
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
);
}
else
{
// for json->'key' is not null
(
*
p
)[
i
]
=
1
;
}
}
else
{
(
*
p
)[
i
]
=
((
colData
!=
NULL
)
&&
!
colDataIsNull
((
SColumnInfoData
*
)
info
->
cunits
[
uidx
].
colData
,
0
,
i
,
NULL
));
}
if
((
*
p
)[
i
]
==
0
)
{
all
=
false
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录