Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22fa00199
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22fa00199
Commits
5c0ac48e
Unverified
Commit
5c0ac48e
authored
3 years ago
by
ou yuanning
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Change args in case function (#2763)
parent
efa7e1d1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/sql/plan2/build_expr.go
+28
-33
28 additions, 33 deletions
pkg/sql/plan2/build_expr.go
with
28 additions
and
33 deletions
pkg/sql/plan2/build_expr.go
+
28
−
33
View file @
5c0ac48e
...
...
@@ -229,62 +229,57 @@ func buildCastExpr(astExpr *tree.CastExpr, ctx CompilerContext, query *Query, no
func
buildCaseExpr
(
astExpr
*
tree
.
CaseExpr
,
ctx
CompilerContext
,
query
*
Query
,
node
*
Node
,
binderCtx
*
BinderContext
,
needAgg
bool
)
(
expr
*
Expr
,
isAgg
bool
,
err
error
)
{
var
args
[]
*
Expr
var
caseExpr
*
Expr
if
astExpr
.
Expr
!=
nil
{
caseExpr
,
_
,
err
:
=
buildExpr
(
astExpr
.
Expr
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
caseExpr
,
_
,
err
=
buildExpr
(
astExpr
.
Expr
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
args
=
append
(
args
,
caseExpr
)
}
isAgg
=
true
whenList
:=
make
([]
*
Expr
,
len
(
astExpr
.
Whens
))
for
idx
,
whenExpr
:=
range
astExpr
.
Whens
{
exprs
:=
make
([]
*
Expr
,
2
)
expr
,
paramIsAgg
,
err
:=
buildExpr
(
whenExpr
.
Cond
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
for
_
,
whenExpr
:=
range
astExpr
.
Whens
{
condExpr
,
paramIsAgg
,
err
:=
buildExpr
(
whenExpr
.
Cond
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
isAgg
=
isAgg
&&
paramIsAgg
exprs
[
0
]
=
expr
expr
,
paramIsAgg
,
err
=
buildExpr
(
whenExpr
.
Val
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
if
caseExpr
!=
nil
{
// rewrite "case col when 1 then '1' else '2'" to "case when col=1 then '1' else '2'"
condExpr
,
_
,
err
=
getFunctionExprByNameAndPlanExprs
(
"="
,
[]
*
Expr
{
caseExpr
,
condExpr
})
if
err
!=
nil
{
return
nil
,
false
,
err
}
}
args
=
append
(
args
,
condExpr
)
valExpr
,
paramIsAgg
,
err
:=
buildExpr
(
whenExpr
.
Val
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
isAgg
=
isAgg
&&
paramIsAgg
exprs
[
1
]
=
expr
whenList
[
idx
]
=
&
Expr
{
Expr
:
&
plan
.
Expr_List
{
List
:
&
plan
.
ExprList
{
List
:
exprs
,
},
},
Typ
:
&
plan
.
Type
{
Id
:
plan
.
Type_TUPLE
,
},
}
}
whenExpr
:=
&
Expr
{
Expr
:
&
plan
.
Expr_List
{
List
:
&
plan
.
ExprList
{
List
:
whenList
,
},
},
Typ
:
&
plan
.
Type
{
Id
:
plan
.
Type_TUPLE
,
},
args
=
append
(
args
,
valExpr
)
}
args
=
append
(
args
,
whenExpr
)
if
astExpr
.
Else
!=
nil
{
elseExpr
,
paramIsAgg
,
err
:=
buildExpr
(
astExpr
.
Else
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
elseExpr
,
_
,
err
:=
buildExpr
(
astExpr
.
Else
,
ctx
,
query
,
node
,
binderCtx
,
needAgg
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
isAgg
=
isAgg
&&
paramIsAgg
args
=
append
(
args
,
elseExpr
)
}
else
{
args
=
append
(
args
,
&
Expr
{
Expr
:
&
plan
.
Expr_C
{
C
:
&
Const
{
Isnull
:
true
,
},
},
Typ
:
&
plan
.
Type
{
Id
:
plan
.
Type_ANY
,
Nullable
:
true
,
},
})
}
return
getFunctionExprByNameAndPlanExprs
(
"case"
,
args
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment