Skip to content

Commit

Permalink
Merge pull request #9029 from ritwizsinha/extract-func
Browse files Browse the repository at this point in the history
Support extract function
  • Loading branch information
GuptaManan100 authored Oct 25, 2021
2 parents b337828 + f4a021c commit 7f6e627
Show file tree
Hide file tree
Showing 16 changed files with 5,235 additions and 4,534 deletions.
9 changes: 9 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ type (
Table TableName
Wild string
}
// IntervalTypes is an enum to get types of intervals
IntervalTypes int8

// OtherRead represents a DESCRIBE, or EXPLAIN statement.
// It should be used only as an indicator. It does not contain
Expand Down Expand Up @@ -1893,6 +1895,12 @@ type (
Unit string
}

// ExtractFuncExpr represents the function and arguments for EXTRACT(YEAR FROM '2019-07-02') type functions.
ExtractFuncExpr struct {
IntervalTypes IntervalTypes
Expr Expr
}

// CollateExpr represents dynamic collate operator.
CollateExpr struct {
Expr Expr
Expand Down Expand Up @@ -2020,6 +2028,7 @@ func (*IntervalExpr) iExpr() {}
func (*CollateExpr) iExpr() {}
func (*FuncExpr) iExpr() {}
func (*TimestampFuncExpr) iExpr() {}
func (*ExtractFuncExpr) iExpr() {}
func (*CurTimeFuncExpr) iExpr() {}
func (*CaseExpr) iExpr() {}
func (*ValuesFuncExpr) iExpr() {}
Expand Down
14 changes: 14 additions & 0 deletions go/vt/sqlparser/ast_clone.go

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

24 changes: 24 additions & 0 deletions go/vt/sqlparser/ast_equals.go

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

5 changes: 5 additions & 0 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,11 @@ func (node *TimestampFuncExpr) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%s(%s, %v, %v)", node.Name, node.Unit, node.Expr1, node.Expr2)
}

// Format formats the node.
func (node *ExtractFuncExpr) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "extract(%s from %v)", node.IntervalTypes.ToString(), node.Expr)
}

// Format formats the node.
func (node *CurTimeFuncExpr) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%s(%v)", node.Name.String(), node.Fsp)
Expand Down
9 changes: 9 additions & 0 deletions go/vt/sqlparser/ast_format_fast.go

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

48 changes: 48 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,54 @@ func (ty ExplainType) ToString() string {
}
}

// ToString returns the type as a string
func (ty IntervalTypes) ToString() string {
switch ty {
case IntervalYear:
return YearStr
case IntervalQuarter:
return QuarterStr
case IntervalMonth:
return MonthStr
case IntervalWeek:
return WeekStr
case IntervalDay:
return DayStr
case IntervalHour:
return HourStr
case IntervalMinute:
return MinuteStr
case IntervalSecond:
return SecondStr
case IntervalMicrosecond:
return MicrosecondStr
case IntervalYearMonth:
return YearMonthStr
case IntervalDayHour:
return DayHourStr
case IntervalDayMinute:
return DayMinuteStr
case IntervalDaySecond:
return DaySecondStr
case IntervalHourMinute:
return HourMinuteStr
case IntervalHourSecond:
return HourSecondStr
case IntervalMinuteSecond:
return MinuteSecondStr
case IntervalDayMicrosecond:
return DayMicrosecondStr
case IntervalHourMicrosecond:
return HourMicrosecondStr
case IntervalMinuteMicrosecond:
return MinuteMicrosecondStr
case IntervalSecondMicrosecond:
return SecondMicrosecondStr
default:
return "Unknown IntervalType"
}
}

// ToString returns the type as a string
func (sel SelectIntoType) ToString() string {
switch sel {
Expand Down
31 changes: 31 additions & 0 deletions go/vt/sqlparser/ast_rewrite.go

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

16 changes: 16 additions & 0 deletions go/vt/sqlparser/ast_visit.go

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

14 changes: 14 additions & 0 deletions go/vt/sqlparser/cached_size.go

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

46 changes: 46 additions & 0 deletions go/vt/sqlparser/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,28 @@ const (
SharedTypeStr = "shared"
DefaultTypeStr = "default"
ExclusiveTypeStr = "exclusive"

// IntervalTypes strings
DayStr = "day"
WeekStr = "week"
MonthStr = "month"
YearStr = "year"
DayHourStr = "day_hour"
DayMicrosecondStr = "day_microsecond"
DayMinuteStr = "day_minute"
DaySecondStr = "day_second"
HourStr = "hour"
HourMicrosecondStr = "hour_microsecond"
HourMinuteStr = "hour_minute"
HourSecondStr = "hour_second"
MicrosecondStr = "microsecond"
MinuteStr = "minute"
MinuteMicrosecondStr = "minute_microsecond"
MinuteSecondStr = "minute_second"
QuarterStr = "quarter"
SecondStr = "second"
SecondMicrosecondStr = "second_microsecond"
YearMonthStr = "year_month"
)

// Constants for Enum type - AccessMode
Expand Down Expand Up @@ -533,3 +555,27 @@ const (
VirtualStorage ColumnStorage = iota
StoredStorage
)

// IntervalTypes constants
const (
IntervalYear IntervalTypes = iota
IntervalQuarter
IntervalMonth
IntervalWeek
IntervalDay
IntervalHour
IntervalMinute
IntervalSecond
IntervalMicrosecond
IntervalYearMonth
IntervalDayHour
IntervalDayMinute
IntervalDaySecond
IntervalHourMinute
IntervalHourSecond
IntervalMinuteSecond
IntervalDayMicrosecond
IntervalHourMicrosecond
IntervalMinuteMicrosecond
IntervalSecondMicrosecond
)
Loading

0 comments on commit 7f6e627

Please sign in to comment.