Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a030a9f3
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看板
提交
a030a9f3
编写于
5月 09, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(query):support selectivity function and normal column data query.
上级
06fb98f0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
419 addition
and
158 deletion
+419
-158
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+23
-18
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+4
-2
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+10
-10
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+382
-128
未找到文件。
source/libs/executor/src/executorimpl.c
浏览文件 @
a030a9f3
...
@@ -13,6 +13,7 @@
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include <libs/function/function.h>
#include "filter.h"
#include "filter.h"
#include "function.h"
#include "function.h"
#include "functionMgt.h"
#include "functionMgt.h"
...
@@ -803,7 +804,8 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunction
...
@@ -803,7 +804,8 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunction
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfExprs
;
++
k
)
{
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfExprs
;
++
k
)
{
if
(
functionNeedToExecute
(
&
pCtx
[
k
]))
{
if
(
functionNeedToExecute
(
&
pCtx
[
k
]))
{
pCtx
[
k
].
startTs
=
startTs
;
// this can be set during create the struct
pCtx
[
k
].
startTs
=
startTs
;
// this can be set during create the struct
pCtx
[
k
].
fpSet
.
process
(
&
pCtx
[
k
]);
if
(
pCtx
[
k
].
fpSet
.
process
!=
NULL
)
pCtx
[
k
].
fpSet
.
process
(
&
pCtx
[
k
]);
}
}
}
}
}
}
...
@@ -1074,35 +1076,36 @@ void setBlockStatisInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock*
...
@@ -1074,35 +1076,36 @@ void setBlockStatisInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock*
// set the output buffer for the selectivity + tag query
// set the output buffer for the selectivity + tag query
static
int32_t
setCtxTagColumnInfo
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
static
int32_t
setCtxTagColumnInfo
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
int32_t
num
=
0
;
int32_t
num
=
0
;
int16_t
tagLen
=
0
;
SqlFunctionCtx
*
p
=
NULL
;
SqlFunctionCtx
*
p
=
NULL
;
SqlFunctionCtx
**
p
Tag
Ctx
=
taosMemoryCalloc
(
numOfOutput
,
POINTER_BYTES
);
SqlFunctionCtx
**
p
Val
Ctx
=
taosMemoryCalloc
(
numOfOutput
,
POINTER_BYTES
);
if
(
p
Tag
Ctx
==
NULL
)
{
if
(
p
Val
Ctx
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
}
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
strcmp
(
pCtx
[
i
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
pValCtx
[
num
++
]
=
&
pCtx
[
i
];
if
(
functionId
==
FUNCTION_TAG_DUMMY
||
functionId
==
FUNCTION_TS_DUMMY
)
{
tagLen
+=
pCtx
[
i
].
resDataInfo
.
bytes
;
pTagCtx
[
num
++
]
=
&
pCtx
[
i
];
}
else
if
(
1
/*(aAggs[functionId].status & FUNCSTATE_SELECTIVITY) != 0*/
)
{
p
=
&
pCtx
[
i
];
}
else
if
(
functionId
==
FUNCTION_TS
||
functionId
==
FUNCTION_TAG
)
{
// tag function may be the group by tag column
// ts may be the required primary timestamp column
continue
;
}
else
{
}
else
{
// the column may be the normal column, group by normal_column, the functionId is FUNCTION_PRJ
p
=
&
pCtx
[
i
];
}
}
// if (functionId == FUNCTION_TAG_DUMMY || functionId == FUNCTION_TS_DUMMY) {
// tagLen += pCtx[i].resDataInfo.bytes;
// pTagCtx[num++] = &pCtx[i];
// } else if (functionId == FUNCTION_TS || functionId == FUNCTION_TAG) {
// // tag function may be the group by tag column
// // ts may be the required primary timestamp column
// continue;
// } else {
// // the column may be the normal column, group by normal_column, the functionId is FUNCTION_PRJ
// }
}
}
if
(
p
!=
NULL
)
{
if
(
p
!=
NULL
)
{
p
->
subsidiaries
.
pCtx
=
p
Tag
Ctx
;
p
->
subsidiaries
.
pCtx
=
p
Val
Ctx
;
p
->
subsidiaries
.
num
=
num
;
p
->
subsidiaries
.
num
=
num
;
}
else
{
}
else
{
taosMemoryFreeClear
(
p
Tag
Ctx
);
taosMemoryFreeClear
(
p
Val
Ctx
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -2219,6 +2222,8 @@ int32_t doCopyToSDataBlock(SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbased
...
@@ -2219,6 +2222,8 @@ int32_t doCopyToSDataBlock(SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbased
pCtx
[
j
].
resultInfo
=
getResultCell
(
pRow
,
j
,
rowCellOffset
);
pCtx
[
j
].
resultInfo
=
getResultCell
(
pRow
,
j
,
rowCellOffset
);
if
(
pCtx
[
j
].
fpSet
.
process
)
{
if
(
pCtx
[
j
].
fpSet
.
process
)
{
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
}
else
if
(
strcmp
(
pCtx
[
j
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
// do nothing, todo refactor
}
else
{
}
else
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
...
...
source/libs/function/inc/builtinsimpl.h
浏览文件 @
a030a9f3
...
@@ -37,11 +37,11 @@ bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
...
@@ -37,11 +37,11 @@ bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t
sumFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
sumFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
sumInvertFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
sumInvertFunction
(
SqlFunctionCtx
*
pCtx
);
bool
minFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
minmaxFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
maxFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
getMinmaxFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
getMinmaxFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
int32_t
minFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
minFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
maxFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
maxFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
minmaxFunctionFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getAvgFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
getAvgFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
avgFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
avgFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
...
@@ -82,6 +82,8 @@ bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultIn
...
@@ -82,6 +82,8 @@ bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultIn
int32_t
histogramFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
histogramFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
histogramFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
int32_t
histogramFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getSelectivityFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/function/src/builtins.c
浏览文件 @
a030a9f3
...
@@ -509,9 +509,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -509,9 +509,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
translateFunc
=
translateInOutNum
,
.
translateFunc
=
translateInOutNum
,
.
dataRequiredFunc
=
statisDataRequired
,
.
dataRequiredFunc
=
statisDataRequired
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
minFunctionSetup
,
.
initFunc
=
min
max
FunctionSetup
,
.
processFunc
=
minFunction
,
.
processFunc
=
minFunction
,
.
finalizeFunc
=
f
unctionFinalize
.
finalizeFunc
=
minmaxF
unctionFinalize
},
},
{
{
.
name
=
"max"
,
.
name
=
"max"
,
...
@@ -520,9 +520,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -520,9 +520,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
translateFunc
=
translateInOutNum
,
.
translateFunc
=
translateInOutNum
,
.
dataRequiredFunc
=
statisDataRequired
,
.
dataRequiredFunc
=
statisDataRequired
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
maxFunctionSetup
,
.
initFunc
=
m
inm
axFunctionSetup
,
.
processFunc
=
maxFunction
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
f
unctionFinalize
.
finalizeFunc
=
minmaxF
unctionFinalize
},
},
{
{
.
name
=
"stddev"
,
.
name
=
"stddev"
,
...
@@ -562,7 +562,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -562,7 +562,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateApercentile
,
.
translateFunc
=
translateApercentile
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
maxFunctionSetup
,
.
initFunc
=
m
inm
axFunctionSetup
,
.
processFunc
=
maxFunction
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
functionFinalize
.
finalizeFunc
=
functionFinalize
},
},
...
@@ -581,8 +581,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -581,8 +581,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
type
=
FUNCTION_TYPE_BOTTOM
,
.
type
=
FUNCTION_TYPE_BOTTOM
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateBottom
,
.
translateFunc
=
translateBottom
,
.
getEnvFunc
=
get
Minmax
FuncEnv
,
.
getEnvFunc
=
get
TopBot
FuncEnv
,
.
initFunc
=
maxF
unctionSetup
,
.
initFunc
=
f
unctionSetup
,
.
processFunc
=
maxFunction
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
functionFinalize
.
finalizeFunc
=
functionFinalize
},
},
...
@@ -603,7 +603,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -603,7 +603,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
,
.
translateFunc
=
translateLastRow
,
.
translateFunc
=
translateLastRow
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
maxFunctionSetup
,
.
initFunc
=
m
inm
axFunctionSetup
,
.
processFunc
=
maxFunction
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
functionFinalize
.
finalizeFunc
=
functionFinalize
},
},
...
@@ -1032,8 +1032,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -1032,8 +1032,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
type
=
FUNCTION_TYPE_SELECT_VALUE
,
.
type
=
FUNCTION_TYPE_SELECT_VALUE
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
,
.
translateFunc
=
translateSelectValue
,
.
translateFunc
=
translateSelectValue
,
.
getEnvFunc
=
NULL
,
.
getEnvFunc
=
getSelectivityFuncEnv
,
// todo remove this function later.
.
initFunc
=
NULL
,
.
initFunc
=
functionSetup
,
.
sprocessFunc
=
NULL
,
.
sprocessFunc
=
NULL
,
.
finalizeFunc
=
NULL
.
finalizeFunc
=
NULL
}
}
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
a030a9f3
...
@@ -37,13 +37,15 @@ typedef struct SAvgRes {
...
@@ -37,13 +37,15 @@ typedef struct SAvgRes {
int64_t
count
;
int64_t
count
;
}
SAvgRes
;
}
SAvgRes
;
typedef
struct
STuplePos
{
int32_t
pageId
;
int32_t
offset
;
}
STuplePos
;
typedef
struct
STopBotResItem
{
typedef
struct
STopBotResItem
{
SVariant
v
;
SVariant
v
;
uint64_t
uid
;
// it is a table uid, used to extract tag data during building of the final result for the tag data
uint64_t
uid
;
// it is a table uid, used to extract tag data during building of the final result for the tag data
struct
{
STuplePos
tuplePos
;
// tuple data of this chosen row
int32_t
pageId
;
int32_t
offset
;
}
tuplePos
;
// tuple data of this chosen row
}
STopBotResItem
;
}
STopBotResItem
;
typedef
struct
STopBotRes
{
typedef
struct
STopBotRes
{
...
@@ -616,101 +618,25 @@ EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin
...
@@ -616,101 +618,25 @@ EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin
return
FUNC_DATA_REQUIRED_STATIS_LOAD
;
return
FUNC_DATA_REQUIRED_STATIS_LOAD
;
}
}
bool
maxFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
typedef
struct
SMinmaxResInfo
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
bool
assign
;
// assign the first value or not
return
false
;
int64_t
v
;
}
STuplePos
tuplePos
;
}
SMinmaxResInfo
;
char
*
buf
=
GET_ROWCELL_INTERBUF
(
pResultInfo
);
switch
(
pCtx
->
resDataInfo
.
type
)
{
case
TSDB_DATA_TYPE_INT
:
*
((
int32_t
*
)
buf
)
=
INT32_MIN
;
break
;
case
TSDB_DATA_TYPE_UINT
:
*
((
uint32_t
*
)
buf
)
=
0
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
*
((
float
*
)
buf
)
=
-
FLT_MAX
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
SET_DOUBLE_VAL
(((
double
*
)
buf
),
-
DBL_MAX
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
((
int64_t
*
)
buf
)
=
INT64_MIN
;
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
((
uint64_t
*
)
buf
)
=
0
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
((
int16_t
*
)
buf
)
=
INT16_MIN
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
((
uint16_t
*
)
buf
)
=
0
;
break
;
case
TSDB_DATA_TYPE_TINYINT
:
*
((
int8_t
*
)
buf
)
=
INT8_MIN
;
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
((
uint8_t
*
)
buf
)
=
0
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
*
((
int8_t
*
)
buf
)
=
0
;
break
;
default:
assert
(
0
);
}
return
true
;
}
bool
minFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
bool
min
max
FunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
return
false
;
// not initialized since it has been initialized
return
false
;
// not initialized since it has been initialized
}
}
char
*
buf
=
GET_ROWCELL_INTERBUF
(
pResultInfo
);
SMinmaxResInfo
*
buf
=
GET_ROWCELL_INTERBUF
(
pResultInfo
);
switch
(
pCtx
->
resDataInfo
.
type
)
{
buf
->
assign
=
false
;
case
TSDB_DATA_TYPE_TINYINT
:
buf
->
tuplePos
.
pageId
=
-
1
;
*
((
int8_t
*
)
buf
)
=
INT8_MAX
;
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
*
(
uint8_t
*
)
buf
=
UINT8_MAX
;
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
*
((
int16_t
*
)
buf
)
=
INT16_MAX
;
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
*
((
uint16_t
*
)
buf
)
=
UINT16_MAX
;
break
;
case
TSDB_DATA_TYPE_INT
:
*
((
int32_t
*
)
buf
)
=
INT32_MAX
;
break
;
case
TSDB_DATA_TYPE_UINT
:
*
((
uint32_t
*
)
buf
)
=
UINT32_MAX
;
break
;
case
TSDB_DATA_TYPE_BIGINT
:
*
((
int64_t
*
)
buf
)
=
INT64_MAX
;
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
*
((
uint64_t
*
)
buf
)
=
UINT64_MAX
;
break
;
case
TSDB_DATA_TYPE_FLOAT
:
*
((
float
*
)
buf
)
=
FLT_MAX
;
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
SET_DOUBLE_VAL
(((
double
*
)
buf
),
DBL_MAX
);
break
;
case
TSDB_DATA_TYPE_BOOL
:
*
((
int8_t
*
)
buf
)
=
1
;
break
;
default:
assert
(
0
);
}
return
true
;
return
true
;
}
}
bool
getMinmaxFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
bool
getMinmaxFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
int64_t
);
pEnv
->
calcMemSize
=
sizeof
(
SMinmaxResInfo
);
return
true
;
return
true
;
}
}
...
@@ -758,6 +684,9 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
...
@@ -758,6 +684,9 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
} \
} \
} while (0)
} while (0)
static
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
);
static
void
copyTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
);
int32_t
doMinMaxHelper
(
SqlFunctionCtx
*
pCtx
,
int32_t
isMinFunc
)
{
int32_t
doMinMaxHelper
(
SqlFunctionCtx
*
pCtx
,
int32_t
isMinFunc
)
{
int32_t
numOfElems
=
0
;
int32_t
numOfElems
=
0
;
...
@@ -768,7 +697,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
...
@@ -768,7 +697,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
int32_t
type
=
pCol
->
info
.
type
;
int32_t
type
=
pCol
->
info
.
type
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
char
*
b
uf
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SMinmaxResInfo
*
pB
uf
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
// data in current data block are qualified to the query
// data in current data block are qualified to the query
if
(
pInput
->
colDataAggIsSet
)
{
if
(
pInput
->
colDataAggIsSet
)
{
...
@@ -795,11 +724,11 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
...
@@ -795,11 +724,11 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
if
(
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
type
))
{
int64_t
prev
=
0
;
int64_t
prev
=
0
;
GET_TYPED_DATA
(
prev
,
int64_t
,
type
,
buf
);
GET_TYPED_DATA
(
prev
,
int64_t
,
type
,
pBuf
->
v
);
int64_t
val
=
GET_INT64_VAL
(
tval
);
int64_t
val
=
GET_INT64_VAL
(
tval
);
if
((
prev
<
val
)
^
isMinFunc
)
{
if
((
prev
<
val
)
^
isMinFunc
)
{
*
(
int64_t
*
)
buf
=
val
;
pBuf
->
v
=
val
;
for
(
int32_t
i
=
0
;
i
<
(
pCtx
)
->
subsidiaries
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
(
pCtx
)
->
subsidiaries
.
num
;
++
i
)
{
SqlFunctionCtx
*
__ctx
=
pCtx
->
subsidiaries
.
pCtx
[
i
];
SqlFunctionCtx
*
__ctx
=
pCtx
->
subsidiaries
.
pCtx
[
i
];
if
(
__ctx
->
functionId
==
FUNCTION_TS_DUMMY
)
{
// TODO refactor
if
(
__ctx
->
functionId
==
FUNCTION_TS_DUMMY
)
{
// TODO refactor
...
@@ -809,14 +738,16 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
...
@@ -809,14 +738,16 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
__ctx
->
fpSet
.
process
(
__ctx
);
__ctx
->
fpSet
.
process
(
__ctx
);
}
}
saveTupleData
(
pCtx
,
index
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
uint64_t
prev
=
0
;
uint64_t
prev
=
0
;
GET_TYPED_DATA
(
prev
,
uint64_t
,
type
,
buf
);
GET_TYPED_DATA
(
prev
,
uint64_t
,
type
,
pBuf
->
v
);
uint64_t
val
=
GET_UINT64_VAL
(
tval
);
uint64_t
val
=
GET_UINT64_VAL
(
tval
);
if
((
prev
<
val
)
^
isMinFunc
)
{
if
((
prev
<
val
)
^
isMinFunc
)
{
*
(
uint64_t
*
)
buf
=
val
;
pBuf
->
v
=
val
;
for
(
int32_t
i
=
0
;
i
<
(
pCtx
)
->
subsidiaries
.
num
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
(
pCtx
)
->
subsidiaries
.
num
;
++
i
)
{
SqlFunctionCtx
*
__ctx
=
pCtx
->
subsidiaries
.
pCtx
[
i
];
SqlFunctionCtx
*
__ctx
=
pCtx
->
subsidiaries
.
pCtx
[
i
];
if
(
__ctx
->
functionId
==
FUNCTION_TS_DUMMY
)
{
// TODO refactor
if
(
__ctx
->
functionId
==
FUNCTION_TS_DUMMY
)
{
// TODO refactor
...
@@ -829,12 +760,13 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
...
@@ -829,12 +760,13 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
}
}
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
double
val
=
GET_DOUBLE_VAL
(
tval
);
double
val
=
GET_DOUBLE_VAL
(
tval
);
UPDATE_DATA
(
pCtx
,
*
(
double
*
)
buf
,
val
,
numOfElems
,
isMinFunc
,
key
);
UPDATE_DATA
(
pCtx
,
*
(
double
*
)
&
pBuf
->
v
,
val
,
numOfElems
,
isMinFunc
,
key
);
}
else
if
(
type
==
TSDB_DATA_TYPE_FLOAT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_FLOAT
)
{
double
val
=
GET_DOUBLE_VAL
(
tval
);
double
val
=
GET_DOUBLE_VAL
(
tval
);
UPDATE_DATA
(
pCtx
,
*
(
float
*
)
buf
,
val
,
numOfElems
,
isMinFunc
,
key
);
UPDATE_DATA
(
pCtx
,
*
(
float
*
)
&
pBuf
->
v
,
val
,
numOfElems
,
isMinFunc
,
key
);
}
}
pBuf
->
assign
=
true
;
return
numOfElems
;
return
numOfElems
;
}
}
...
@@ -843,47 +775,318 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
...
@@ -843,47 +775,318 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
if
(
IS_SIGNED_NUMERIC_TYPE
(
type
)
||
type
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
type
)
||
type
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_BOOL
)
{
if
(
type
==
TSDB_DATA_TYPE_TINYINT
||
type
==
TSDB_DATA_TYPE_BOOL
)
{
LOOPCHECK_N
(
*
(
int8_t
*
)
buf
,
pCol
,
pCtx
,
int8_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
int8_t
*
pData
=
(
int8_t
*
)
pCol
->
pData
;
int8_t
*
val
=
(
int8_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_SMALLINT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_SMALLINT
)
{
LOOPCHECK_N
(
*
(
int16_t
*
)
buf
,
pCol
,
pCtx
,
int16_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
int16_t
*
pData
=
(
int16_t
*
)
pCol
->
pData
;
int16_t
*
val
=
(
int16_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_INT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_INT
)
{
int32_t
*
pData
=
(
int32_t
*
)
pCol
->
pData
;
int32_t
*
pData
=
(
int32_t
*
)
pCol
->
pData
;
int32_t
*
val
=
(
int32_t
*
)
buf
;
int32_t
*
val
=
(
int32_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
continue
;
}
}
if
(
(
*
val
<
pData
[
i
])
^
isMinFunc
)
{
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
*
val
=
pData
[
i
];
TSKEY
ts
=
(
pCtx
->
ptsList
!=
NULL
)
?
GET_TS_DATA
(
pCtx
,
i
)
:
0
;
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
DO_UPDATE_SUBSID_RES
(
pCtx
,
ts
);
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
}
numOfElems
+=
1
;
numOfElems
+=
1
;
}
}
#if defined(_DEBUG_VIEW)
qDebug
(
"max value updated:%d"
,
*
retVal
);
#endif
}
else
if
(
type
==
TSDB_DATA_TYPE_BIGINT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_BIGINT
)
{
LOOPCHECK_N
(
*
(
int64_t
*
)
buf
,
pCol
,
pCtx
,
int64_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
int64_t
*
pData
=
(
int64_t
*
)
pCol
->
pData
;
int64_t
*
val
=
(
int64_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
}
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
type
))
{
if
(
type
==
TSDB_DATA_TYPE_UTINYINT
)
{
if
(
type
==
TSDB_DATA_TYPE_UTINYINT
)
{
LOOPCHECK_N
(
*
(
uint8_t
*
)
buf
,
pCol
,
pCtx
,
uint8_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
uint8_t
*
pData
=
(
uint8_t
*
)
pCol
->
pData
;
uint8_t
*
val
=
(
uint8_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_USMALLINT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_USMALLINT
)
{
LOOPCHECK_N
(
*
(
uint16_t
*
)
buf
,
pCol
,
pCtx
,
uint16_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
uint16_t
*
pData
=
(
uint16_t
*
)
pCol
->
pData
;
uint16_t
*
val
=
(
uint16_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_UINT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_UINT
)
{
LOOPCHECK_N
(
*
(
uint32_t
*
)
buf
,
pCol
,
pCtx
,
uint32_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
uint32_t
*
pData
=
(
uint32_t
*
)
pCol
->
pData
;
uint32_t
*
val
=
(
uint32_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_UBIGINT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_UBIGINT
)
{
LOOPCHECK_N
(
*
(
uint64_t
*
)
buf
,
pCol
,
pCtx
,
uint64_t
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
uint64_t
*
pData
=
(
uint64_t
*
)
pCol
->
pData
;
uint64_t
*
val
=
(
uint64_t
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
}
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
LOOPCHECK_N
(
*
(
double
*
)
buf
,
pCol
,
pCtx
,
double
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
double
*
pData
=
(
double
*
)
pCol
->
pData
;
double
*
val
=
(
double
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
else
if
(
type
==
TSDB_DATA_TYPE_FLOAT
)
{
}
else
if
(
type
==
TSDB_DATA_TYPE_FLOAT
)
{
LOOPCHECK_N
(
*
(
float
*
)
buf
,
pCol
,
pCtx
,
float
,
numOfRows
,
start
,
isMinFunc
,
numOfElems
);
float
*
pData
=
(
float
*
)
pCol
->
pData
;
float
*
val
=
(
float
*
)
&
pBuf
->
v
;
for
(
int32_t
i
=
start
;
i
<
start
+
numOfRows
;
++
i
)
{
if
((
pCol
->
hasNull
)
&&
colDataIsNull_f
(
pCol
->
nullbitmap
,
i
))
{
continue
;
}
if
(
!
pBuf
->
assign
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
pBuf
->
assign
=
true
;
}
else
{
// ignore the equivalent data value
if
((
*
val
)
==
pData
[
i
])
{
continue
;
}
if
((
*
val
<
pData
[
i
])
^
isMinFunc
)
{
*
val
=
pData
[
i
];
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
&
pBuf
->
tuplePos
);
}
}
}
numOfElems
+=
1
;
}
}
}
return
numOfElems
;
return
numOfElems
;
...
@@ -901,6 +1104,53 @@ int32_t maxFunction(SqlFunctionCtx* pCtx) {
...
@@ -901,6 +1104,53 @@ int32_t maxFunction(SqlFunctionCtx* pCtx) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
minmaxFunctionFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
SMinmaxResInfo
*
pRes
=
GET_ROWCELL_INTERBUF
(
pEntryInfo
);
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
// todo assign the tag value
int32_t
currentRow
=
pBlock
->
info
.
rows
;
colDataAppend
(
pCol
,
currentRow
,
(
const
char
*
)
&
pRes
->
v
,
false
);
int32_t
pageId
=
pRes
->
tuplePos
.
pageId
;
int32_t
offset
=
pRes
->
tuplePos
.
offset
;
if
(
pRes
->
tuplePos
.
pageId
!=
-
1
)
{
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
pageId
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
offset
);
char
*
pStart
=
(
char
*
)(
nullList
+
pCtx
->
pSrcBlock
->
info
.
numOfCols
*
sizeof
(
bool
));
// todo set the offset value to optimize the performance.
for
(
int32_t
j
=
0
;
j
<
pCtx
->
subsidiaries
.
num
;
++
j
)
{
SqlFunctionCtx
*
pc
=
pCtx
->
subsidiaries
.
pCtx
[
j
];
SFunctParam
*
pFuncParam
=
&
pc
->
pExpr
->
base
.
pParam
[
0
];
int32_t
srcSlotId
=
pFuncParam
->
pCol
->
slotId
;
int32_t
dstSlotId
=
pc
->
pExpr
->
base
.
resSchema
.
slotId
;
int32_t
ps
=
0
;
for
(
int32_t
k
=
0
;
k
<
srcSlotId
;
++
k
)
{
SColumnInfoData
*
pSrcCol
=
taosArrayGet
(
pCtx
->
pSrcBlock
->
pDataBlock
,
k
);
ps
+=
pSrcCol
->
info
.
bytes
;
}
SColumnInfoData
*
pDstCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
dstSlotId
);
if
(
nullList
[
srcSlotId
])
{
colDataAppendNULL
(
pDstCol
,
currentRow
);
}
else
{
colDataAppend
(
pDstCol
,
currentRow
,
(
pStart
+
ps
),
false
);
}
}
}
return
pEntryInfo
->
numOfRes
;
}
bool
getStddevFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
bool
getStddevFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
SStddevRes
);
pEnv
->
calcMemSize
=
sizeof
(
SStddevRes
);
return
true
;
return
true
;
...
@@ -1244,6 +1494,14 @@ bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
...
@@ -1244,6 +1494,14 @@ bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
return
true
;
return
true
;
}
}
bool
getSelectivityFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
SColumnNode
*
pNode
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
pEnv
->
calcMemSize
=
pNode
->
node
.
resType
.
bytes
;
return
true
;
}
static
FORCE_INLINE
TSKEY
getRowPTs
(
SColumnInfoData
*
pTsColInfo
,
int32_t
rowIndex
)
{
static
FORCE_INLINE
TSKEY
getRowPTs
(
SColumnInfoData
*
pTsColInfo
,
int32_t
rowIndex
)
{
if
(
pTsColInfo
==
NULL
)
{
if
(
pTsColInfo
==
NULL
)
{
return
0
;
return
0
;
...
@@ -1624,9 +1882,6 @@ static STopBotRes* getTopBotOutputInfo(SqlFunctionCtx* pCtx) {
...
@@ -1624,9 +1882,6 @@ static STopBotRes* getTopBotOutputInfo(SqlFunctionCtx* pCtx) {
static
void
doAddIntoResult
(
SqlFunctionCtx
*
pCtx
,
void
*
pData
,
int32_t
rowIndex
,
SSDataBlock
*
pSrcBlock
,
uint16_t
type
,
static
void
doAddIntoResult
(
SqlFunctionCtx
*
pCtx
,
void
*
pData
,
int32_t
rowIndex
,
SSDataBlock
*
pSrcBlock
,
uint16_t
type
,
uint64_t
uid
,
SResultRowEntryInfo
*
pEntryInfo
);
uint64_t
uid
,
SResultRowEntryInfo
*
pEntryInfo
);
static
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STopBotResItem
*
pItem
);
static
void
copyTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STopBotResItem
*
pItem
);
int32_t
topFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
topFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
numOfElems
=
0
;
int32_t
numOfElems
=
0
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
...
@@ -1701,7 +1956,7 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
...
@@ -1701,7 +1956,7 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
pItem
->
uid
=
uid
;
pItem
->
uid
=
uid
;
// save the data of this tuple
// save the data of this tuple
saveTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
pItem
);
saveTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
// allocate the buffer and keep the data of this row into the new allocated buffer
// allocate the buffer and keep the data of this row into the new allocated buffer
pEntryInfo
->
numOfRes
++
;
pEntryInfo
->
numOfRes
++
;
...
@@ -1716,15 +1971,14 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
...
@@ -1716,15 +1971,14 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
pItem
->
uid
=
uid
;
pItem
->
uid
=
uid
;
// save the data of this tuple by over writing the old data
// save the data of this tuple by over writing the old data
copyTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
pItem
);
copyTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
taosheapadjust
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
0
,
pEntryInfo
->
numOfRes
-
1
,
(
const
void
*
)
&
type
,
taosheapadjust
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
0
,
pEntryInfo
->
numOfRes
-
1
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
NULL
,
false
);
topBotResComparFn
,
NULL
,
false
);
}
}
}
}
}
}
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
ST
opBotResItem
*
pItem
)
{
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
ST
uplePos
*
pPos
)
{
SFilePage
*
pPage
=
NULL
;
SFilePage
*
pPage
=
NULL
;
int32_t
completeRowSize
=
pSrcBlock
->
info
.
rowSize
+
pSrcBlock
->
info
.
numOfCols
*
sizeof
(
bool
);
int32_t
completeRowSize
=
pSrcBlock
->
info
.
rowSize
+
pSrcBlock
->
info
.
numOfCols
*
sizeof
(
bool
);
...
@@ -1740,7 +1994,7 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
...
@@ -1740,7 +1994,7 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
}
}
}
}
p
Item
->
tuplePos
.
pageId
=
pCtx
->
curBufPage
;
p
Pos
->
pageId
=
pCtx
->
curBufPage
;
// keep the current row data, extract method
// keep the current row data, extract method
int32_t
offset
=
0
;
int32_t
offset
=
0
;
...
@@ -1764,17 +2018,17 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
...
@@ -1764,17 +2018,17 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
offset
+=
pCol
->
info
.
bytes
;
offset
+=
pCol
->
info
.
bytes
;
}
}
p
Item
->
tuplePos
.
offset
=
pPage
->
num
;
p
Pos
->
offset
=
pPage
->
num
;
pPage
->
num
+=
completeRowSize
;
pPage
->
num
+=
completeRowSize
;
setBufPageDirty
(
pPage
,
true
);
setBufPageDirty
(
pPage
,
true
);
releaseBufPage
(
pCtx
->
pBuf
,
pPage
);
releaseBufPage
(
pCtx
->
pBuf
,
pPage
);
}
}
void
copyTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
ST
opBotResItem
*
pItem
)
{
void
copyTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
ST
uplePos
*
pPos
)
{
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
p
Item
->
tuplePos
.
pageId
);
SFilePage
*
pPage
=
getBufPage
(
pCtx
->
pBuf
,
p
Pos
->
pageId
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
p
Item
->
tuplePos
.
offset
);
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
p
Pos
->
offset
);
char
*
pStart
=
(
char
*
)(
nullList
+
pSrcBlock
->
info
.
numOfCols
*
sizeof
(
bool
));
char
*
pStart
=
(
char
*
)(
nullList
+
pSrcBlock
->
info
.
numOfCols
*
sizeof
(
bool
));
int32_t
offset
=
0
;
int32_t
offset
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录