Skip to content

Commit

Permalink
clean up the codes
Browse files Browse the repository at this point in the history
  • Loading branch information
dbjoa committed Dec 3, 2018
1 parent 253106d commit 7ac5db0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
10 changes: 3 additions & 7 deletions expression/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,9 @@ func GetParamExpression(ctx sessionctx.Context, v *driver.ParamMarkerExpr) (Expr
return value, nil
}

// ConvertToByItemExpr rewrites ByItem.ExprNode to a proper ExprNode.
func ConvertToByItemExpr(n ast.Node) ast.Node {
switch v := n.(type) {
case *driver.ParamMarkerExpr:
return &ast.PositionExpr{P: v}
}
return n
// ConstructPositionExpr constructs PositionExpr with the given ParamMarkerExpr.
func ConstructPositionExpr(p *driver.ParamMarkerExpr) *ast.PositionExpr {
return &ast.PositionExpr{P: p}
}

// PosFromPositionExpr generates a position value from PositionExpr.
Expand Down
8 changes: 4 additions & 4 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -822,9 +822,9 @@ type itemTransformer struct {
}

func (t *itemTransformer) Enter(inNode ast.Node) (ast.Node, bool) {
switch inNode.(type) {
switch n := inNode.(type) {
case *driver.ParamMarkerExpr:
newNode := expression.ConvertToByItemExpr(inNode)
newNode := expression.ConstructPositionExpr(n)
return newNode, true
}
return inNode, false
Expand Down Expand Up @@ -1200,11 +1200,11 @@ type gbyResolver struct {
}

func (g *gbyResolver) Enter(inNode ast.Node) (ast.Node, bool) {
switch inNode.(type) {
switch n := inNode.(type) {
case *ast.SubqueryExpr, *ast.CompareSubqueryExpr, *ast.ExistsSubqueryExpr:
return inNode, true
case *driver.ParamMarkerExpr:
newNode := expression.ConvertToByItemExpr(inNode)
newNode := expression.ConstructPositionExpr(n)
g.isParam = true
return newNode, true
case *driver.ValueExpr, *ast.ColumnNameExpr, *ast.ParenthesesExpr, *ast.ColumnName:
Expand Down

0 comments on commit 7ac5db0

Please sign in to comment.