Skip to content

Commit

Permalink
sqlparser: Remove INTERVAL as general expression
Browse files Browse the repository at this point in the history
INTERVAL is not a possible general expression, but only used in specific
cases. With the previous change, we already have it all handled for date
functions. The only remaining cases are for + and - where this is
handled.

Those cases are a bit special. You can have an interval on both sides of
a +, but for a - it can only be done on the right hand side.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
  • Loading branch information
dbussink committed May 29, 2023
1 parent 0d9384d commit 9c2a16f
Show file tree
Hide file tree
Showing 14 changed files with 4,920 additions and 5,121 deletions.
46 changes: 17 additions & 29 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,7 @@ type (
// More information available here: https://dev.mysql.com/doc/refman/8.0/en/window-functions-frames.html
FramePoint struct {
Type FramePointType
Unit IntervalTypes
Expr Expr
}

Expand Down Expand Up @@ -2194,6 +2195,16 @@ type (
FromFirstLastType int8
)

// DateAddExprType is an enum to get types of DateAddExpr.
// This can be one of ADDDATE, DATE_ADD or a '+' operator
// with an interval left or right.
type DateAddExprType int8

// DateSubExprType is an enum to get types of DateAddExpr.
// This can be one of SUBDATE, DATE_SUB or a '-' operator
// with an interval right.
type DateSubExprType int8

// *********** Expressions
type (
// Expr represents an expression.
Expand Down Expand Up @@ -2340,12 +2351,6 @@ type (
Expr Expr
}

// IntervalExpr represents a date-time INTERVAL expression.
IntervalExpr struct {
Expr Expr
Unit IntervalTypes
}

// TimestampFuncExpr represents the function and arguments for TIMESTAMP{ADD,DIFF} functions.
TimestampFuncExpr struct {
Name string
Expand Down Expand Up @@ -3005,33 +3010,21 @@ type (
MatchType Expr
}

// AdddateExpr represents ADDDATE()
// For more information, see https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_adddate
AdddateExpr struct {
Date Expr
Unit IntervalTypes
Expr Expr
}

// DateAddExpr represents DATE_ADD()
// DateAddExpr represents ADDDATE(), DATE_ADD()
// and additions with an interval on the left and right.
// For more information, see https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add
DateAddExpr struct {
Type DateAddExprType
Date Expr
Unit IntervalTypes
Expr Expr
}

// DateSubExpr represents DATE_SUB()
// DateSubExpr represents SUBDATE(), DATE_SUB()
// and subtractions with an interval on the right.
// For more information, see https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-sub
DateSubExpr struct {
Date Expr
Unit IntervalTypes
Expr Expr
}

// SubdateExpr represents SUBDATE()
// For more information, see https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-sub
SubdateExpr struct {
Type DateSubExprType
Date Expr
Unit IntervalTypes
Expr Expr
Expand Down Expand Up @@ -3163,7 +3156,6 @@ func (ListArg) iExpr() {}
func (*BinaryExpr) iExpr() {}
func (*UnaryExpr) iExpr() {}
func (*IntroducerExpr) iExpr() {}
func (*IntervalExpr) iExpr() {}
func (*CollateExpr) iExpr() {}
func (*FuncExpr) iExpr() {}
func (*TimestampFuncExpr) iExpr() {}
Expand Down Expand Up @@ -3210,10 +3202,8 @@ func (*RegexpInstrExpr) iExpr() {}
func (*RegexpLikeExpr) iExpr() {}
func (*RegexpReplaceExpr) iExpr() {}
func (*RegexpSubstrExpr) iExpr() {}
func (*AdddateExpr) iExpr() {}
func (*DateAddExpr) iExpr() {}
func (*DateSubExpr) iExpr() {}
func (*SubdateExpr) iExpr() {}
func (*ArgumentLessWindowExpr) iExpr() {}
func (*FirstOrLastValueExpr) iExpr() {}
func (*NtileExpr) iExpr() {}
Expand Down Expand Up @@ -3305,10 +3295,8 @@ func (*RegexpInstrExpr) iCallable() {}
func (*RegexpLikeExpr) iCallable() {}
func (*RegexpReplaceExpr) iCallable() {}
func (*RegexpSubstrExpr) iCallable() {}
func (*AdddateExpr) iCallable() {}
func (*DateAddExpr) iCallable() {}
func (*DateSubExpr) iCallable() {}
func (*SubdateExpr) iCallable() {}
func (*ArgumentLessWindowExpr) iCallable() {}
func (*FirstOrLastValueExpr) iCallable() {}
func (*NtileExpr) iCallable() {}
Expand Down
48 changes: 0 additions & 48 deletions go/vt/sqlparser/ast_clone.go

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

86 changes: 0 additions & 86 deletions go/vt/sqlparser/ast_copy_on_rewrite.go

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

Loading

0 comments on commit 9c2a16f

Please sign in to comment.