Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0022a766
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看板
提交
0022a766
编写于
9月 26, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: support case when
上级
1cbd1f4c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
134 addition
and
6 deletion
+134
-6
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+5
-0
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+129
-6
未找到文件。
source/libs/scalar/src/filter.c
浏览文件 @
0022a766
...
...
@@ -3786,6 +3786,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
if
(
QUERY_NODE_CASE_WHEN
==
nodeType
(
*
pNode
)
||
QUERY_NODE_WHEN_THEN
==
nodeType
(
*
pNode
))
{
stat
->
scalarMode
=
true
;
return
DEAL_RES_CONTINUE
;
}
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
SOperatorNode
*
node
=
(
SOperatorNode
*
)
*
pNode
;
if
(
!
FLT_IS_COMPARISON_OPERATOR
(
node
->
opType
))
{
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
0022a766
...
...
@@ -532,6 +532,10 @@ _return:
SCL_RET
(
code
);
}
int32_t
sclGetNodeRes
(
SNode
*
node
,
SArray
*
pBlockList
,
SScalarParam
**
res
)
{
}
int32_t
sclExecFunction
(
SFunctionNode
*
node
,
SScalarCtx
*
ctx
,
SScalarParam
*
output
)
{
SScalarParam
*
params
=
NULL
;
int32_t
rowNum
=
0
;
...
...
@@ -688,6 +692,47 @@ _return:
SCL_RET
(
code
);
}
int32_t
sclExecCaseWhen
(
SCaseWhenNode
*
node
,
SScalarCtx
*
ctx
,
SScalarParam
*
output
)
{
int32_t
rowNum
=
0
;
int32_t
code
=
0
;
SScalarParam
*
pCase
=
NULL
;
SScalarParam
*
pElse
=
NULL
;
if
(
node
->
pCase
)
{
SCL_ERR_RET
(
sclGetNodeRes
(
node
->
pCase
,
ctx
->
pBlockList
,
&
pCase
));
}
SNode
*
tnode
=
NULL
;
FOREACH
(
tnode
,
node
->
pWhenThenList
)
{
if
(
QUERY_NODE_VALUE
==
tnode
->
type
)
{
return
DEAL_RES_CONTINUE
;
}
}
if
(
output
->
columnData
==
NULL
)
{
code
=
sclCreateColumnInfoData
(
&
node
->
node
.
resType
,
rowNum
,
output
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
SCL_ERR_JRET
(
code
);
}
}
_bin_scalar_fn_t
OperatorFn
=
getBinScalarOperatorFn
(
node
->
opType
);
int32_t
paramNum
=
scalarGetOperatorParamNum
(
node
->
opType
);
SScalarParam
*
pLeft
=
&
params
[
0
];
SScalarParam
*
pRight
=
paramNum
>
1
?
&
params
[
1
]
:
NULL
;
terrno
=
TSDB_CODE_SUCCESS
;
OperatorFn
(
pLeft
,
pRight
,
output
,
TSDB_ORDER_ASC
);
code
=
terrno
;
_return:
sclFreeParamList
(
params
,
paramNum
);
SCL_RET
(
code
);
}
EDealRes
sclRewriteNullInOptr
(
SNode
**
pNode
,
SScalarCtx
*
ctx
,
EOperatorType
opType
)
{
if
(
opType
<=
OP_TYPE_CALC_MAX
)
{
SValueNode
*
res
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
...
...
@@ -951,9 +996,65 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) {
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclRewriteCaseWhen
(
SNode
**
pNode
,
SScalarCtx
*
ctx
)
{
SCaseWhenNode
*
node
=
(
SCaseWhenNode
*
)
*
pNode
;
if
((
!
SCL_IS_CONST_NODE
(
node
->
pCase
))
||
(
!
SCL_IS_CONST_NODE
(
node
->
pElse
)))
{
return
DEAL_RES_CONTINUE
;
}
SNode
*
tnode
=
NULL
;
FOREACH
(
tnode
,
node
->
pWhenThenList
)
{
if
(
!
SCL_IS_CONST_NODE
(
tnode
))
{
return
DEAL_RES_CONTINUE
;
}
}
SScalarParam
output
=
{
0
};
ctx
->
code
=
sclExecCaseWhen
(
node
,
ctx
,
&
output
);
if
(
ctx
->
code
)
{
return
DEAL_RES_ERROR
;
}
SValueNode
*
res
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
if
(
NULL
==
res
)
{
sclError
(
"make value node failed"
);
sclFreeParam
(
&
output
);
ctx
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
res
->
translate
=
true
;
res
->
node
.
resType
=
node
->
node
.
resType
;
if
(
colDataIsNull_s
(
output
.
columnData
,
0
))
{
res
->
isNull
=
true
;
res
->
node
.
resType
=
node
->
node
.
resType
;
}
else
{
int32_t
type
=
output
.
columnData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
// todo refactor
res
->
datum
.
p
=
output
.
columnData
->
pData
;
output
.
columnData
->
pData
=
NULL
;
}
else
{
nodesSetValueNodeValue
(
res
,
output
.
columnData
->
pData
);
}
}
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
res
;
sclFreeParam
(
&
output
);
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclConstantsRewriter
(
SNode
**
pNode
,
void
*
pContext
)
{
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
return
sclRewriteOperator
(
pNode
,
ctx
);
}
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
*
pNode
))
{
return
sclRewriteFunction
(
pNode
,
ctx
);
}
...
...
@@ -962,8 +1063,8 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
return
sclRewriteLogic
(
pNode
,
ctx
);
}
if
(
QUERY_NODE_
OPERATOR
==
nodeType
(
*
pNode
))
{
return
sclRewrite
Operator
(
pNode
,
ctx
);
if
(
QUERY_NODE_
CASE_WHEN
==
nodeType
(
pNode
))
{
return
sclRewrite
CaseWhen
(
pNode
,
ctx
);
}
return
DEAL_RES_CONTINUE
;
...
...
@@ -1070,12 +1171,34 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) {
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclWalkCaseWhen
(
SNode
*
pNode
,
SScalarCtx
*
ctx
)
{
SCaseWhenNode
*
node
=
(
SCaseWhenNode
*
)
pNode
;
SScalarParam
output
=
{
0
};
ctx
->
code
=
sclExecCaseWhen
(
node
,
ctx
,
&
output
);
if
(
ctx
->
code
)
{
return
DEAL_RES_ERROR
;
}
if
(
taosHashPut
(
ctx
->
pRes
,
&
pNode
,
POINTER_BYTES
,
&
output
,
sizeof
(
output
)))
{
ctx
->
code
=
TSDB_CODE_QRY_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
return
DEAL_RES_CONTINUE
;
}
EDealRes
sclCalcWalker
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_VALUE
==
nodeType
(
pNode
)
||
QUERY_NODE_NODE_LIST
==
nodeType
(
pNode
)
||
QUERY_NODE_COLUMN
==
nodeType
(
pNode
)
||
QUERY_NODE_LEFT_VALUE
==
nodeType
(
pNode
))
{
return
DEAL_RES_CONTINUE
;
}
SScalarCtx
*
ctx
=
(
SScalarCtx
*
)
pContext
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
pNode
))
{
return
sclWalkOperator
(
pNode
,
ctx
);
}
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
))
{
return
sclWalkFunction
(
pNode
,
ctx
);
}
...
...
@@ -1084,14 +1207,14 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
return
sclWalkLogic
(
pNode
,
ctx
);
}
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
pNode
))
{
return
sclWalkOperator
(
pNode
,
ctx
);
}
if
(
QUERY_NODE_TARGET
==
nodeType
(
pNode
))
{
return
sclWalkTarget
(
pNode
,
ctx
);
}
if
(
QUERY_NODE_CASE_WHEN
==
nodeType
(
pNode
))
{
return
sclWalkCaseWhen
(
pNode
,
ctx
);
}
sclError
(
"invalid node type for scalar calculating, type:%d"
,
nodeType
(
pNode
));
ctx
->
code
=
TSDB_CODE_QRY_INVALID_INPUT
;
return
DEAL_RES_ERROR
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录