Skip to content

Commit

Permalink
[parser] parser,ast: fix the TiDB issue #8153 (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbjoa authored and ti-chi-bot committed Oct 9, 2021
1 parent ad9281a commit 4924685
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
9 changes: 8 additions & 1 deletion parser/ast/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ func (n *ParenthesesExpr) Accept(v Visitor) (Node, bool) {
type PositionExpr struct {
exprNode
// N is the position, started from 1 now.
N int
N ExprNode
// Refer is the result field the position refers to.
Refer *ResultField
}
Expand All @@ -716,6 +716,13 @@ func (n *PositionExpr) Accept(v Visitor) (Node, bool) {
return v.Leave(newNode)
}
n = newNode.(*PositionExpr)
if n.N != nil {
node, ok := n.N.Accept(v)
if !ok {
return n, false
}
n.N = node.(ExprNode)
}
return v.Leave(n)
}

Expand Down
10 changes: 4 additions & 6 deletions parser/parser.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions parser/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -3187,13 +3187,11 @@ ByItem:
Expression Order
{
expr := $1
valueExpr, ok := expr.(ast.ValueExpr)
if ok {
position, isPosition := valueExpr.GetValue().(int64)
if isPosition {
expr = &ast.PositionExpr{N: int(position)}
}
}
if valueExpr, ok := expr.(ast.ValueExpr); ok {
expr = &ast.PositionExpr{N: valueExpr}
} else if paramExpr, ok := expr.(ast.ParamMarkerExpr); ok {
expr = &ast.PositionExpr{N: paramExpr}
}
$$ = &ast.ByItem{Expr: expr, Desc: $2.(bool)}
}

Expand Down

0 comments on commit 4924685

Please sign in to comment.