Skip to content

Commit

Permalink
*: support ast
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Nov 6, 2015
1 parent 69b2c31 commit 7eb1f45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 20 additions & 6 deletions ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,26 +338,40 @@ func (n *FuncTrimExpr) IsStatic() bool {
return n.Str.IsStatic() && n.RemStr.IsStatic()
}

// DateArithType is type for DateArith option.
// DateArithType is type for DateArith type.
type DateArithType byte

const (
// AddDate is to run adddate function option.
// See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_adddate
AddDate DateArithType = iota + 1
// DateAdd is to run date_add function option.
// See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-add
DateAdd DateArithType = iota + 1
DateAdd
// DateSub is to run date_sub function option.
// See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-sub
DateSub
// SubDate is to run subdate function option.
// See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_subdate
SubDate
// DateArithDaysForm is to run adddate or subdate function with days form.
DateArithDaysForm
)

// DateArithInterval is the struct of DateArith interval part.
type DateArithInterval struct {
Form DateArithType
Unit string
Interval ExprNode
}

// FuncDateArithExpr is the struct for date arithmetic functions.
type FuncDateArithExpr struct {
funcNode

Op DateArithType
Unit string
Date ExprNode
Interval ExprNode
Op DateArithType
Date ExprNode
DateArithInterval
}

// Accept implements Node Accept interface.
Expand Down
3 changes: 3 additions & 0 deletions optimizer/convert_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ func (c *expressionConverter) funcDateArith(v *ast.FuncDateArithExpr) {
case ast.DateSub:
oldDateArith.Op = expression.DateSub
}
if v.Form == ast.DateArithDaysForm {
oldDateArith.Form = expression.DateArithDaysForm
}
c.exprMap[v] = oldDateArith
}

Expand Down

0 comments on commit 7eb1f45

Please sign in to comment.