Skip to content

Commit

Permalink
*: add parser and definition for: (#2667)
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu authored Feb 19, 2017
1 parent faf74ee commit 41afe4e
Show file tree
Hide file tree
Showing 6 changed files with 513 additions and 24 deletions.
32 changes: 25 additions & 7 deletions ast/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,47 +102,65 @@ const (
Truncate = "truncate"

// time functions
AddDate = "adddate"
AddTime = "addtime"
ConvertTz = "convert_tz"
Curdate = "curdate"
CurrentDate = "current_date"
CurrentTime = "current_time"
CurrentTimestamp = "current_timestamp"
Curtime = "curtime"
Date = "date"
DateDiff = "datediff"
DateAdd = "date_add"
AddDate = "adddate"
DateSub = "date_sub"
SubDate = "subdate"
DateFormat = "date_format"
DateSub = "date_sub"
DateDiff = "datediff"
Day = "day"
DayName = "dayname"
DayOfMonth = "dayofmonth"
DayOfWeek = "dayofweek"
DayOfYear = "dayofyear"
FromDays = "from_days"
Extract = "extract"
FromDays = "from_days"
FromUnixTime = "from_unixtime"
GetFormat = "get_format"
Hour = "hour"
LocalTime = "localtime"
LocalTimestamp = "localtimestamp"
MakeDate = "makedate"
MakeTime = "maketime"
MicroSecond = "microsecond"
Minute = "minute"
Month = "month"
MonthName = "monthname"
Now = "now"
PeriodAdd = "period_add"
PeriodDiff = "period_diff"
Quarter = "quarter"
SecToTime = "sec_to_time"
Second = "second"
StrToDate = "str_to_date"
SubDate = "subdate"
SubTime = "subtime"
Sysdate = "sysdate"
Time = "time"
TimeFormat = "time_format"
TimeToSec = "time_to_sec"
TimeDiff = "timediff"
Timestamp = "timestamp"
TimestampAdd = "timestampadd"
TimestampDiff = "timestampdiff"
ToDays = "to_days"
ToSeconds = "to_seconds"
UnixTimestamp = "unix_timestamp"
UTCDate = "utc_date"
UTCTime = "utc_time"
UTCTimestamp = "utc_timestamp"
UnixTimestamp = "unix_timestamp"
Week = "week"
Weekday = "weekday"
WeekOfYear = "weekofyear"
Year = "year"
YearWeek = "yearweek"
FromUnixTime = "from_unixtime"

// string functions
ASCII = "ascii"
Expand Down
41 changes: 29 additions & 12 deletions expression/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,47 +164,64 @@ var funcs = map[string]functionClass{
ast.Truncate: &truncateFunctionClass{baseFunctionClass{ast.Truncate, 2, 2}},

// time functions
ast.AddDate: &dateArithFunctionClass{baseFunctionClass{ast.AddDate, 3, 3}, ast.DateArithAdd},
ast.AddTime: &addTimeFunctionClass{baseFunctionClass{ast.AddTime, 2, 2}},
ast.ConvertTz: &convertTzFunctionClass{baseFunctionClass{ast.ConvertTz, 3, 3}},
ast.Curdate: &currentDateFunctionClass{baseFunctionClass{ast.Curdate, 0, 0}},
ast.CurrentDate: &currentDateFunctionClass{baseFunctionClass{ast.CurrentDate, 0, 0}},
ast.CurrentTime: &currentTimeFunctionClass{baseFunctionClass{ast.CurrentTime, 0, 1}},
ast.CurrentTimestamp: &nowFunctionClass{baseFunctionClass{ast.CurrentTimestamp, 0, 1}},
ast.Curtime: &currentTimeFunctionClass{baseFunctionClass{ast.Curtime, 0, 1}},
ast.Date: &dateFunctionClass{baseFunctionClass{ast.Date, 1, 1}},
ast.DateDiff: &dateDiffFunctionClass{baseFunctionClass{ast.DateDiff, 2, 2}},
ast.DateAdd: &dateArithFunctionClass{baseFunctionClass{ast.DateAdd, 3, 3}, ast.DateArithAdd},
ast.AddDate: &dateArithFunctionClass{baseFunctionClass{ast.AddDate, 3, 3}, ast.DateArithAdd},
ast.DateSub: &dateArithFunctionClass{baseFunctionClass{ast.DateSub, 3, 3}, ast.DateArithSub},
ast.SubDate: &dateArithFunctionClass{baseFunctionClass{ast.SubDate, 3, 3}, ast.DateArithSub},
ast.DateFormat: &dateFormatFunctionClass{baseFunctionClass{ast.DateFormat, 2, 2}},
ast.CurrentTimestamp: &nowFunctionClass{baseFunctionClass{ast.CurrentTimestamp, 0, 1}},
ast.Now: &nowFunctionClass{baseFunctionClass{ast.Now, 0, 1}},
ast.Curtime: &currentTimeFunctionClass{baseFunctionClass{ast.Curtime, 0, 1}},
ast.DateSub: &dateArithFunctionClass{baseFunctionClass{ast.DateSub, 3, 3}, ast.DateArithSub},
ast.DateDiff: &dateDiffFunctionClass{baseFunctionClass{ast.DateDiff, 2, 2}},
ast.Day: &dayOfMonthFunctionClass{baseFunctionClass{ast.Day, 1, 1}},
ast.DayName: &dayNameFunctionClass{baseFunctionClass{ast.DayName, 1, 1}},
ast.DayOfMonth: &dayOfMonthFunctionClass{baseFunctionClass{ast.DayOfMonth, 1, 1}},
ast.DayOfWeek: &dayOfWeekFunctionClass{baseFunctionClass{ast.DayOfWeek, 1, 1}},
ast.DayOfYear: &dayOfYearFunctionClass{baseFunctionClass{ast.DayOfYear, 1, 1}},
ast.FromDays: &fromDaysFunctionClass{baseFunctionClass{ast.FromDays, 1, 1}},
ast.Extract: &extractFunctionClass{baseFunctionClass{ast.Extract, 2, 2}},
ast.FromDays: &fromDaysFunctionClass{baseFunctionClass{ast.FromDays, 1, 1}},
ast.FromUnixTime: &fromUnixTimeFunctionClass{baseFunctionClass{ast.FromUnixTime, 1, 2}},
ast.Hour: &hourFunctionClass{baseFunctionClass{ast.Hour, 1, 1}},
ast.LocalTime: &nowFunctionClass{baseFunctionClass{ast.LocalTime, 0, 1}},
ast.LocalTimestamp: &nowFunctionClass{baseFunctionClass{ast.LocalTimestamp, 0, 1}},
ast.MakeDate: &makeDateFunctionClass{baseFunctionClass{ast.MakeDate, 2, 2}},
ast.MakeTime: &makeTimeFunctionClass{baseFunctionClass{ast.MakeTime, 3, 3}},
ast.MicroSecond: &microSecondFunctionClass{baseFunctionClass{ast.MicroSecond, 1, 1}},
ast.Minute: &minuteFunctionClass{baseFunctionClass{ast.Minute, 1, 1}},
ast.Month: &monthFunctionClass{baseFunctionClass{ast.Month, 1, 1}},
ast.MonthName: &monthNameFunctionClass{baseFunctionClass{ast.MonthName, 1, 1}},
ast.Now: &nowFunctionClass{baseFunctionClass{ast.Now, 0, 1}},
ast.PeriodAdd: &periodAddFunctionClass{baseFunctionClass{ast.PeriodAdd, 2, 2}},
ast.PeriodDiff: &periodDiffFunctionClass{baseFunctionClass{ast.PeriodDiff, 2, 2}},
ast.Quarter: &quarterFunctionClass{baseFunctionClass{ast.Quarter, 1, 1}},
ast.SecToTime: &secToTimeFunctionClass{baseFunctionClass{ast.SecToTime, 1, 1}},
ast.Second: &secondFunctionClass{baseFunctionClass{ast.Second, 1, 1}},
ast.StrToDate: &strToDateFunctionClass{baseFunctionClass{ast.StrToDate, 2, 2}},
ast.SubDate: &dateArithFunctionClass{baseFunctionClass{ast.SubDate, 3, 3}, ast.DateArithSub},
ast.SubTime: &subTimeFunctionClass{baseFunctionClass{ast.SubTime, 2, 2}},
ast.Sysdate: &sysDateFunctionClass{baseFunctionClass{ast.Sysdate, 0, 1}},
ast.Time: &timeFunctionClass{baseFunctionClass{ast.Time, 1, 1}},
ast.TimeFormat: &timeFormatFunctionClass{baseFunctionClass{ast.TimeFormat, 2, 2}},
ast.TimeToSec: &timeToSecFunctionClass{baseFunctionClass{ast.TimeToSec, 1, 1}},
ast.TimeDiff: &timeDiffFunctionClass{baseFunctionClass{ast.TimeDiff, 2, 2}},
ast.Timestamp: &timestampFunctionClass{baseFunctionClass{ast.Timestamp, 1, 2}},
ast.TimestampAdd: &timestampAddFunctionClass{baseFunctionClass{ast.TimestampAdd, 3, 3}},
ast.TimestampDiff: &timestampDiffFunctionClass{baseFunctionClass{ast.TimestampDiff, 3, 3}},
ast.ToDays: &toDaysFunctionClass{baseFunctionClass{ast.ToDays, 1, 1}},
ast.ToSeconds: &toSecondsFunctionClass{baseFunctionClass{ast.ToSeconds, 1, 1}},
ast.UnixTimestamp: &unixTimestampFunctionClass{baseFunctionClass{ast.UnixTimestamp, 0, 1}},
ast.UTCDate: &utcDateFunctionClass{baseFunctionClass{ast.UTCDate, 0, 0}},
ast.UTCTime: &utcTimeFunctionClass{baseFunctionClass{ast.UTCTime, 0, 1}},
ast.UTCTimestamp: &utcTimestampFunctionClass{baseFunctionClass{ast.UnixTimestamp, 0, 1}},
ast.Week: &weekFunctionClass{baseFunctionClass{ast.Week, 1, 2}},
ast.Weekday: &weekDayFunctionClass{baseFunctionClass{ast.Weekday, 1, 1}},
ast.WeekOfYear: &weekOfYearFunctionClass{baseFunctionClass{ast.WeekOfYear, 1, 1}},
ast.Year: &yearFunctionClass{baseFunctionClass{ast.Year, 1, 1}},
ast.YearWeek: &yearWeekFunctionClass{baseFunctionClass{ast.YearWeek, 1, 2}},
ast.FromUnixTime: &fromUnixTimeFunctionClass{baseFunctionClass{ast.FromUnixTime, 1, 2}},
ast.TimeDiff: &timeDiffFunctionClass{baseFunctionClass{ast.TimeDiff, 2, 2}},
ast.TimestampDiff: &timestampDiffFunctionClass{baseFunctionClass{ast.TimestampDiff, 3, 3}},
ast.UnixTimestamp: &unixTimestampFunctionClass{baseFunctionClass{ast.UnixTimestamp, 0, 1}},

// string functions
ast.ASCII: &asciiFunctionClass{baseFunctionClass{ast.ASCII, 1, 1}},
Expand Down
Loading

0 comments on commit 41afe4e

Please sign in to comment.