Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f872ef97
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
未验证
提交
f872ef97
编写于
5月 09, 2022
作者:
H
Haojun Liao
提交者:
GitHub
5月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12274 from taosdata/feature/3.0_liaohj
enh(query):support selectivity function and normal column data query.
上级
39226496
09f07dbb
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
566 addition
and
252 deletion
+566
-252
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+29
-19
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+6
-1
source/libs/executor/src/sortoperator.c
source/libs/executor/src/sortoperator.c
+4
-1
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+5
-2
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+16
-15
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+504
-213
tests/script/tsim/insert/basic0.sim
tests/script/tsim/insert/basic0.sim
+2
-1
未找到文件。
source/libs/executor/src/executorimpl.c
浏览文件 @
f872ef97
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libs/function/function.h>
#include "filter.h"
#include "function.h"
#include "functionMgt.h"
...
...
@@ -803,7 +804,8 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunction
for
(
int32_t
k
=
0
;
k
<
pOperator
->
numOfExprs
;
++
k
)
{
if
(
functionNeedToExecute
(
&
pCtx
[
k
]))
{
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*
// set the output buffer for the selectivity + tag query
static
int32_t
setCtxTagColumnInfo
(
SqlFunctionCtx
*
pCtx
,
int32_t
numOfOutput
)
{
int32_t
num
=
0
;
int16_t
tagLen
=
0
;
SqlFunctionCtx
*
p
=
NULL
;
SqlFunctionCtx
**
p
Tag
Ctx
=
taosMemoryCalloc
(
numOfOutput
,
POINTER_BYTES
);
if
(
p
Tag
Ctx
==
NULL
)
{
SqlFunctionCtx
**
p
Val
Ctx
=
taosMemoryCalloc
(
numOfOutput
,
POINTER_BYTES
);
if
(
p
Val
Ctx
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
for
(
int32_t
i
=
0
;
i
<
numOfOutput
;
++
i
)
{
int32_t
functionId
=
pCtx
[
i
].
functionId
;
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
;
if
(
strcmp
(
pCtx
[
i
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
pValCtx
[
num
++
]
=
&
pCtx
[
i
];
}
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
)
{
p
->
subsidiaries
.
pCtx
=
p
Tag
Ctx
;
p
->
subsidiaries
.
pCtx
=
p
Val
Ctx
;
p
->
subsidiaries
.
num
=
num
;
}
else
{
taosMemoryFreeClear
(
p
Tag
Ctx
);
taosMemoryFreeClear
(
p
Val
Ctx
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -2219,6 +2222,8 @@ int32_t doCopyToSDataBlock(SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbased
pCtx
[
j
].
resultInfo
=
getResultCell
(
pRow
,
j
,
rowCellOffset
);
if
(
pCtx
[
j
].
fpSet
.
process
)
{
pCtx
[
j
].
fpSet
.
finalize
(
&
pCtx
[
j
],
pBlock
);
}
else
if
(
strcmp
(
pCtx
[
j
].
pExpr
->
pExpr
->
_function
.
functionName
,
"_select_value"
)
==
0
)
{
// do nothing, todo refactor
}
else
{
SColumnInfoData
*
pColInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
...
...
@@ -3974,6 +3979,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
SSDataBlock
*
pRes
=
pInfo
->
pRes
;
blockDataCleanup
(
pRes
);
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
return
NULL
;
}
...
...
@@ -4037,9 +4043,13 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
setInputDataBlock
(
pOperator
,
pInfo
->
pCtx
,
pBlock
,
order
,
false
);
blockDataEnsureCapacity
(
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
+
pBlock
->
info
.
rows
);
projectApplyFunctions
(
pOperator
->
pExpr
,
pInfo
->
pRes
,
pBlock
,
pInfo
->
pCtx
,
pOperator
->
numOfExprs
,
p
TaskInfo
->
code
=
p
rojectApplyFunctions
(
pOperator
->
pExpr
,
pInfo
->
pRes
,
pBlock
,
pInfo
->
pCtx
,
pOperator
->
numOfExprs
,
pProjectInfo
->
pPseudoColInfo
);
if
(
pTaskInfo
->
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
pTaskInfo
->
code
);
}
int32_t
status
=
handleLimitOffset
(
pOperator
,
pBlock
);
if
(
status
==
PROJECT_RETRIEVE_CONTINUE
)
{
continue
;
...
...
source/libs/executor/src/groupoperator.c
浏览文件 @
f872ef97
...
...
@@ -262,6 +262,8 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
return
NULL
;
}
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SGroupbyOperatorInfo
*
pInfo
=
pOperator
->
info
;
SSDataBlock
*
pRes
=
pInfo
->
binfo
.
pRes
;
...
...
@@ -289,7 +291,10 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
if
(
pInfo
->
pScalarExprInfo
!=
NULL
)
{
projectApplyFunctions
(
pInfo
->
pScalarExprInfo
,
pBlock
,
pBlock
,
pInfo
->
pScalarFuncCtx
,
pInfo
->
numOfScalarExpr
,
NULL
);
pTaskInfo
->
code
=
projectApplyFunctions
(
pInfo
->
pScalarExprInfo
,
pBlock
,
pBlock
,
pInfo
->
pScalarFuncCtx
,
pInfo
->
numOfScalarExpr
,
NULL
);
if
(
pTaskInfo
->
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pTaskInfo
->
env
,
pTaskInfo
->
code
);
}
}
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfExprs);
...
...
source/libs/executor/src/sortoperator.c
浏览文件 @
f872ef97
...
...
@@ -114,7 +114,10 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) {
SOperatorInfo
*
pOperator
=
param
;
SSortOperatorInfo
*
pSort
=
pOperator
->
info
;
if
(
pOperator
->
pExpr
!=
NULL
)
{
projectApplyFunctions
(
pOperator
->
pExpr
,
pBlock
,
pBlock
,
pSort
->
binfo
.
pCtx
,
pOperator
->
numOfExprs
,
NULL
);
int32_t
code
=
projectApplyFunctions
(
pOperator
->
pExpr
,
pBlock
,
pBlock
,
pSort
->
binfo
.
pCtx
,
pOperator
->
numOfExprs
,
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pOperator
->
pTaskInfo
->
env
,
code
);
}
}
}
...
...
source/libs/function/inc/builtinsimpl.h
浏览文件 @
f872ef97
...
...
@@ -37,11 +37,11 @@ bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
int32_t
sumFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
sumInvertFunction
(
SqlFunctionCtx
*
pCtx
);
bool
minFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
maxFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
minmaxFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
getMinmaxFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
int32_t
minFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
maxFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
minmaxFunctionFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getAvgFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
avgFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
...
...
@@ -70,6 +70,7 @@ int32_t lastFunction(SqlFunctionCtx *pCtx);
bool
getTopBotFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
);
int32_t
topFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
bottomFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
topBotFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getSpreadFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
...
...
@@ -82,6 +83,8 @@ bool histogramFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultIn
int32_t
histogramFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
histogramFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getSelectivityFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/function/src/builtins.c
浏览文件 @
f872ef97
...
...
@@ -207,7 +207,8 @@ static int32_t translateTop(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
}
static
int32_t
translateBottom
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
// todo
SDataType
*
pType
=
&
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
;
pFunc
->
node
.
resType
=
(
SDataType
){.
bytes
=
pType
->
bytes
,
.
type
=
pType
->
type
};
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -509,9 +510,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
translateFunc
=
translateInOutNum
,
.
dataRequiredFunc
=
statisDataRequired
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
minFunctionSetup
,
.
initFunc
=
min
max
FunctionSetup
,
.
processFunc
=
minFunction
,
.
finalizeFunc
=
f
unctionFinalize
.
finalizeFunc
=
minmaxF
unctionFinalize
},
{
.
name
=
"max"
,
...
...
@@ -520,9 +521,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
translateFunc
=
translateInOutNum
,
.
dataRequiredFunc
=
statisDataRequired
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
maxFunctionSetup
,
.
initFunc
=
m
inm
axFunctionSetup
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
f
unctionFinalize
.
finalizeFunc
=
minmaxF
unctionFinalize
},
{
.
name
=
"stddev"
,
...
...
@@ -562,14 +563,14 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
translateFunc
=
translateApercentile
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
maxFunctionSetup
,
.
initFunc
=
m
inm
axFunctionSetup
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
functionFinalize
},
{
.
name
=
"top"
,
.
type
=
FUNCTION_TYPE_TOP
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
,
.
translateFunc
=
translateTop
,
.
getEnvFunc
=
getTopBotFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -579,12 +580,12 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"bottom"
,
.
type
=
FUNCTION_TYPE_BOTTOM
,
.
classification
=
FUNC_MGT_AGG_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
,
.
translateFunc
=
translateBottom
,
.
getEnvFunc
=
get
Minmax
FuncEnv
,
.
initFunc
=
maxF
unctionSetup
,
.
processFunc
=
max
Function
,
.
finalizeFunc
=
function
Finalize
.
getEnvFunc
=
get
TopBot
FuncEnv
,
.
initFunc
=
f
unctionSetup
,
.
processFunc
=
bottom
Function
,
.
finalizeFunc
=
topBot
Finalize
},
{
.
name
=
"spread"
,
...
...
@@ -603,7 +604,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
,
.
translateFunc
=
translateLastRow
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
maxFunctionSetup
,
.
initFunc
=
m
inm
axFunctionSetup
,
.
processFunc
=
maxFunction
,
.
finalizeFunc
=
functionFinalize
},
...
...
@@ -1032,8 +1033,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
type
=
FUNCTION_TYPE_SELECT_VALUE
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
,
.
translateFunc
=
translateSelectValue
,
.
getEnvFunc
=
NULL
,
.
initFunc
=
NULL
,
.
getEnvFunc
=
getSelectivityFuncEnv
,
// todo remove this function later.
.
initFunc
=
functionSetup
,
.
sprocessFunc
=
NULL
,
.
finalizeFunc
=
NULL
}
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
f872ef97
此差异已折叠。
点击以展开。
tests/script/tsim/insert/basic0.sim
浏览文件 @
f872ef97
...
...
@@ -140,7 +140,8 @@ endi
if $data00 != -13 then
return -1
endi
if $data01 != -2.30000 then
if $data01 != -2.30000 then
print expect -2.30000, actual: $data01
return -1
endi
if $data02 != -3.300000000 then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录