Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e16f4c7c
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看板
提交
e16f4c7c
编写于
5月 17, 2023
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: refactor and save work
上级
51fa363f
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
124 addition
and
96 deletion
+124
-96
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+124
-96
未找到文件。
source/libs/scalar/src/filter.c
浏览文件 @
e16f4c7c
...
...
@@ -22,6 +22,7 @@
#include "sclInt.h"
#include "tcompare.h"
#include "tdatablock.h"
#include "tsimplehash.h"
#include "ttime.h"
bool
filterRangeCompGi
(
const
void
*
minv
,
const
void
*
maxv
,
const
void
*
minr
,
const
void
*
maxr
,
__compar_fn_t
cfunc
)
{
...
...
@@ -3958,10 +3959,7 @@ typedef struct {
SFltSclDatumKind
kind
;
union
{
int64_t
val
;
// for int64, uint64 and double and bool (1 true, 0 false)
struct
{
uint32_t
nData
;
// TODO maybe remove this and make pData len prefixed?
uint8_t
*
pData
;
};
// for varchar, nchar
uint8_t
*
pData
;
// for varchar, nchar
}
datum
;
SDataType
type
;
// TODO: original data type, may not be used?
}
SFltSclDatum
;
...
...
@@ -3979,37 +3977,77 @@ typedef struct {
bool
highExcl
;
}
SFltSclRange
;
int32_t
fltSclCompareDatum
(
SFltSclDatum
*
val1
,
SFltSclDatum
*
val2
)
{
int32_t
fltSclCompareWithFloat64
(
SFltSclDatum
*
val1
,
SFltSclDatum
*
val2
)
{
// val2->kind == int64
switch
(
val1
->
kind
)
{
case
FLT_SCL_DATUM_KIND_NULL
:
{
if
(
val2
->
kind
==
FLT_SCL_DATUM_KIND_NULL
)
return
0
;
else
return
-
1
;
break
;
case
FLT_SCL_DATUM_KIND_UINT64
:
return
compareUint64Double
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
case
FLT_SCL_DATUM_KIND_INT64
:
return
compareInt64Double
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
case
FLT_SCL_DATUM_KIND_FLOAT64
:
{
return
compareDoubleVal
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
}
case
FLT_SCL_DATUM_KIND_MIN
:
{
if
(
val2
->
kind
==
FLT_SCL_DATUM_KIND_NULL
)
return
1
;
else
{
if
(
val2
->
kind
==
FLT_SCL_DATUM_KIND_MIN
)
return
0
;
else
return
-
1
;
//TODO: varchar, nchar
default:
qError
(
"not support comparsion. %d, %d"
,
val1
->
kind
,
val2
->
kind
);
return
(
val1
->
kind
-
val2
->
kind
)
;
}
break
;
}
int32_t
fltSclCompareWithInt64
(
SFltSclDatum
*
val1
,
SFltSclDatum
*
val2
)
{
// val2->kind == int64
switch
(
val1
->
kind
)
{
case
FLT_SCL_DATUM_KIND_UINT64
:
return
compareUint64Int64
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
case
FLT_SCL_DATUM_KIND_INT64
:
return
compareInt64Val
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
case
FLT_SCL_DATUM_KIND_FLOAT64
:
{
return
compareDoubleInt64
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
}
//TODO: varchar, nchar
default:
qError
(
"not support comparsion. %d, %d"
,
val1
->
kind
,
val2
->
kind
);
return
(
val1
->
kind
-
val2
->
kind
);
}
case
FLT_SCL_DATUM_KIND_MAX
:
{
if
(
val2
->
kind
==
FLT_SCL_DATUM_KIND_MAX
)
return
0
;
else
return
1
;
}
int32_t
fltSclCompareWithUInt64
(
SFltSclDatum
*
val1
,
SFltSclDatum
*
val2
)
{
// val2 kind == uint64
switch
(
val1
->
kind
)
{
case
FLT_SCL_DATUM_KIND_UINT64
:
return
compareUint64Val
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
case
FLT_SCL_DATUM_KIND_INT64
:
return
compareInt64Uint64
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
case
FLT_SCL_DATUM_KIND_FLOAT64
:
{
return
compareDoubleUint64
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
}
//TODO: varchar, nchar
default:
qError
(
"not support comparsion. %d, %d"
,
val1
->
kind
,
val2
->
kind
);
return
(
val1
->
kind
-
val2
->
kind
);
}
}
int32_t
fltSclCompareDatum
(
SFltSclDatum
*
val1
,
SFltSclDatum
*
val2
)
{
if
(
val2
->
kind
==
FLT_SCL_DATUM_KIND_NULL
||
val2
->
kind
==
FLT_SCL_DATUM_KIND_MIN
||
val2
->
kind
==
FLT_SCL_DATUM_KIND_MAX
)
{
if
(
val1
->
kind
==
FLT_SCL_DATUM_KIND_NULL
||
val1
->
kind
==
FLT_SCL_DATUM_KIND_MIN
||
val1
->
kind
==
FLT_SCL_DATUM_KIND_MAX
)
{
return
(
val1
->
kind
<
val2
->
kind
)
?
-
1
:
((
val1
->
kind
>
val2
->
kind
)
?
1
:
0
);
}
}
switch
(
val2
->
kind
)
{
case
FLT_SCL_DATUM_KIND_UINT64
:
{
return
compareUint64Val
(
&
val1
->
datum
.
val
,
&
val1
->
datum
.
val
);
return
fltSclCompareWithUInt64
(
val1
,
val2
);
}
case
FLT_SCL_DATUM_KIND_INT64
:
{
return
compareInt64Val
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
return
fltSclCompareWithInt64
(
val1
,
val2
);
}
case
FLT_SCL_DATUM_KIND_FLOAT64
:
{
return
compareFloatDouble
(
&
val1
->
datum
.
val
,
&
val2
->
datum
.
val
);
}
case
FLT_SCL_DATUM_KIND_NCHAR
:
{
return
compareLenPrefixedWStr
(
&
val1
->
datum
.
pData
,
&
val2
->
datum
.
pData
);
//TODO
}
case
FLT_SCL_DATUM_KIND_VARCHAR
:
{
return
compareLenPrefixedStr
(
&
val1
->
datum
.
pData
,
&
val2
->
datum
.
pData
);
//TODO
return
fltSclCompareWithFloat64
(
val1
,
val2
);
}
//TODO: varchar/nchar
default:
fltError
(
"not supported kind. just return 0"
);
return
0
;
...
...
@@ -4018,11 +4056,11 @@ int32_t fltSclCompareDatum(SFltSclDatum* val1, SFltSclDatum* val2) {
return
0
;
}
bool
fltSclLessPoint
(
SFltSclPoint
*
pt1
,
SFltSclPoint
*
pt2
)
{
bool
fltSclLessPoint
(
SFltSclPoint
*
pt1
,
SFltSclPoint
*
pt2
)
{
// first value compare
int32_t
cmp
=
fltSclCompareDatum
(
&
pt1
->
val
,
&
pt2
->
val
);
if
(
cmp
!=
0
)
{
return
cmp
<
0
;
return
cmp
<
0
;
}
if
(
pt1
->
start
&&
pt2
->
start
)
{
...
...
@@ -4035,14 +4073,14 @@ bool fltSclLessPoint(SFltSclPoint* pt1, SFltSclPoint* pt2) {
return
pt1
->
excl
&&
!
pt2
->
excl
;
}
int32_t
fltSclMergeSort
(
SArray
*
pts1
,
SArray
*
pts2
,
SArray
*
result
)
{
int32_t
fltSclMergeSort
(
SArray
*
pts1
,
SArray
*
pts2
,
SArray
*
result
)
{
size_t
len1
=
taosArrayGetSize
(
pts1
);
size_t
len2
=
taosArrayGetSize
(
pts2
);
size_t
i
=
0
;
size_t
j
=
0
;
while
(
i
<
len1
&&
j
<
len2
)
{
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
SFltSclPoint
*
pt2
=
taosArrayGet
(
pts2
,
j
);
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
SFltSclPoint
*
pt2
=
taosArrayGet
(
pts2
,
j
);
bool
less
=
fltSclLessPoint
(
pt1
,
pt2
);
if
(
less
)
{
taosArrayPush
(
result
,
pt1
);
...
...
@@ -4054,7 +4092,7 @@ int32_t fltSclMergeSort(SArray* pts1, SArray* pts2, SArray* result) {
}
if
(
i
<
len1
)
{
for
(;
i
<
len1
;
++
i
)
{
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
taosArrayPush
(
result
,
pt1
);
}
}
...
...
@@ -4068,16 +4106,16 @@ int32_t fltSclMergeSort(SArray* pts1, SArray* pts2, SArray* result) {
}
// pts1 and pts2 must be ordered and de-duplicated and each range can not be a range of another range
int32_t
fltSclMerge
(
SArray
*
pts1
,
SArray
*
pts2
,
bool
isUnion
,
SArray
*
merged
)
{
int32_t
fltSclMerge
(
SArray
*
pts1
,
SArray
*
pts2
,
bool
isUnion
,
SArray
*
merged
)
{
size_t
len1
=
taosArrayGetSize
(
pts1
);
size_t
len2
=
taosArrayGetSize
(
pts2
);
//first merge sort pts1 and pts2
SArray
*
all
=
taosArrayInit
(
len1
+
len2
,
sizeof
(
SFltSclPoint
));
//
first merge sort pts1 and pts2
SArray
*
all
=
taosArrayInit
(
len1
+
len2
,
sizeof
(
SFltSclPoint
));
fltSclMergeSort
(
pts1
,
pts2
,
all
);
int32_t
countRequired
=
(
isUnion
)
?
1
:
2
;
int32_t
count
=
0
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
all
);
++
i
)
{
SFltSclPoint
*
pt
=
taosArrayGet
(
pts1
,
i
);
SFltSclPoint
*
pt
=
taosArrayGet
(
pts1
,
i
);
if
(
pt
->
start
)
{
++
count
;
if
(
count
==
countRequired
)
{
...
...
@@ -4094,49 +4132,39 @@ int32_t fltSclMerge(SArray* pts1, SArray* pts2, bool isUnion, SArray* merged) {
return
0
;
}
int32_t
fltSclIntersect
(
SArray
*
pts1
,
SArray
*
pts2
,
SArray
*
merged
)
{
return
fltSclMerge
(
pts1
,
pts2
,
false
,
merged
);
}
int32_t
fltSclIntersect
(
SArray
*
pts1
,
SArray
*
pts2
,
SArray
*
merged
)
{
return
fltSclMerge
(
pts1
,
pts2
,
false
,
merged
);
}
int32_t
fltSclUnion
(
SArray
*
pts1
,
SArray
*
pts2
,
SArray
*
merged
)
{
return
fltSclMerge
(
pts1
,
pts2
,
true
,
merged
);
}
int32_t
fltSclUnion
(
SArray
*
pts1
,
SArray
*
pts2
,
SArray
*
merged
)
{
return
fltSclMerge
(
pts1
,
pts2
,
true
,
merged
);
}
typedef
struct
{
SColumnNode
*
colNode
;
SValueNode
*
valNode
;
SColumnNode
*
colNode
;
SValueNode
*
valNode
;
EOperatorType
type
;
}
SFltSclScalarOp
;
// simple define it, TODO: implement later
typedef
struct
{
SColumnNode
*
colNode
;
}
SFltSclConstColumn
;
// simple define it, TODO: implement later
typedef
struct
{
SValueNode
*
value
;
}
SFltSclConstant
;
}
SFltSclOperator
;
int32_t
fltSclBuildRangeFromScalarFunc
(
SFltSclScalarOp
*
func
,
SFltSclPoint
*
points
)
{
//TODO: column, constant, operator, and/or/not
int32_t
fltSclBuildRangeFromOperator
(
SFltSclOperator
*
sclOper
,
SSHashObj
*
obj
)
{
switch
(
sclOper
->
type
)
{
case
OP_TYPE_GREATER_THAN
:
{
}
break
;
default:
break
;
}
return
TSDB_CODE_SUCCESS
;
}
typedef
struct
{
bool
useRange
;
SHashObj
*
colRanges
;
SHashObj
*
colRanges
;
}
SFltSclOptCtx
;
static
EDealRes
fltSclMayBeOptimed
(
SNode
*
pNode
,
void
*
pCtx
)
{
SFltSclOptCtx
*
ctx
=
(
SFltSclOptCtx
*
)
pCtx
;
static
EDealRes
fltSclMayBeOptimed
(
SNode
*
pNode
,
void
*
pCtx
)
{
SFltSclOptCtx
*
ctx
=
(
SFltSclOptCtx
*
)
pCtx
;
return
DEAL_RES_CONTINUE
;
}
int32_t
fltOptimizeNodes
(
SFilterInfo
*
pInfo
,
SNode
**
pNode
,
SFltTreeStat
*
pStat
)
{
SFltSclOptCtx
ctx
;
nodesWalkExprPostOrder
(
*
pNode
,
fltSclMayBeOptimed
,
&
ctx
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录