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
)
{
...
...
@@ -260,7 +261,7 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) {
comparFn
=
19
;
}
else
if
(
optr
==
OP_TYPE_NMATCH
)
{
comparFn
=
20
;
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
/* wildcard query using like operator */
}
else
if
(
optr
==
OP_TYPE_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
7
;
}
else
if
(
optr
==
OP_TYPE_NOT_LIKE
)
{
/* wildcard query using like operator */
comparFn
=
26
;
...
...
@@ -1633,7 +1634,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
SDataType
*
dType
=
&
var
->
node
.
resType
;
qDebug
(
"VAL%d => [type:%d][val:%"
PRIx64
"]"
,
i
,
dType
->
type
,
var
->
datum
.
i
);
// TODO
}
else
if
(
field
->
data
)
{
qDebug
(
"VAL%d => [type:NIL][val:NIL]"
,
i
);
// TODO
qDebug
(
"VAL%d => [type:NIL][val:NIL]"
,
i
);
// TODO
}
}
...
...
@@ -3957,59 +3958,96 @@ typedef enum {
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
int64_t
val
;
// for int64, uint64 and double and bool (1 true, 0 false)
uint8_t
*
pData
;
// for varchar, nchar
}
datum
;
SDataType
type
;
// TODO: original data type, may not be used?
SDataType
type
;
// TODO: original data type, may not be used?
}
SFltSclDatum
;
typedef
struct
{
SFltSclDatum
val
;
bool
excl
;
bool
start
;
bool
excl
;
bool
start
;
}
SFltSclPoint
;
typedef
struct
{
SFltSclDatum
low
;
SFltSclDatum
high
;
bool
lowExcl
;
bool
highExcl
;
bool
lowExcl
;
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
;
}
break
;
//TODO: varchar, nchar
default:
qError
(
"not support comparsion. %d, %d"
,
val1
->
kind
,
val2
->
kind
);
return
(
val1
->
kind
-
val2
->
kind
);
}
}
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
);
}
case
FLT_SCL_DATUM_KIND_MAX
:
{
if
(
val2
->
kind
==
FLT_SCL_DATUM_KIND_MAX
)
return
0
;
else
return
1
;
//TODO: varchar, nchar
default:
qError
(
"not support comparsion. %d, %d"
,
val1
->
kind
,
val2
->
kind
);
return
(
val1
->
kind
-
val2
->
kind
);
}
}
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,125 +4056,115 @@ 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
)
{
return
!
pt1
->
excl
&&
pt2
->
excl
;
}
else
if
(
pt1
->
start
)
{
return
pt1
->
excl
&&
!
pt2
->
excl
;
}
else
if
(
pt2
->
start
)
{
return
pt1
->
excl
||
pt2
->
excl
;
}
return
!
pt1
->
excl
&&
pt2
->
excl
;
}
else
if
(
pt1
->
start
)
{
return
pt1
->
excl
&&
!
pt2
->
excl
;
}
else
if
(
pt2
->
start
)
{
return
pt1
->
excl
||
pt2
->
excl
;
}
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
);
bool
less
=
fltSclLessPoint
(
pt1
,
pt2
);
if
(
less
)
{
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
SFltSclPoint
*
pt2
=
taosArrayGet
(
pts2
,
j
);
bool
less
=
fltSclLessPoint
(
pt1
,
pt2
);
if
(
less
)
{
taosArrayPush
(
result
,
pt1
);
++
i
;
}
else
{
}
else
{
taosArrayPush
(
result
,
pt2
);
++
j
;
}
}
}
if
(
i
<
len1
)
{
for
(;
i
<
len1
;
++
i
)
{
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
for
(;
i
<
len1
;
++
i
)
{
SFltSclPoint
*
pt1
=
taosArrayGet
(
pts1
,
i
);
taosArrayPush
(
result
,
pt1
);
}
}
}
if
(
j
<
len2
)
{
for
(;
j
<
len2
;
++
j
)
{
for
(;
j
<
len2
;
++
j
)
{
SFltSclPoint
*
pt2
=
taosArrayGet
(
pts2
,
j
);
taosArrayPush
(
result
,
pt2
);
}
}
}
return
0
;
}
// 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
);
if
(
pt
->
start
)
{
++
count
;
if
(
count
==
countRequired
)
{
taosArrayPush
(
merged
,
pt
);
}
}
else
{
if
(
count
==
countRequired
)
{
taosArrayPush
(
merged
,
pt
);
}
--
count
;
SFltSclPoint
*
pt
=
taosArrayGet
(
pts1
,
i
);
if
(
pt
->
start
)
{
++
count
;
if
(
count
==
countRequired
)
{
taosArrayPush
(
merged
,
pt
);
}
}
else
{
if
(
count
==
countRequired
)
{
taosArrayPush
(
merged
,
pt
);
}
--
count
;
}
}
taosArrayDestroy
(
all
);
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
;
bool
useRange
;
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录