Skip to content

Commit

Permalink
evalEngine: Fix the UNIX_TIMESTAMP and CONVERT_TZ func limits
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Feb 6, 2024
1 parent 33ff855 commit cb27206
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions go/vt/vtgate/evalengine/fn_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,15 @@ type builtinConvertTz struct {
var _ IR = (*builtinConvertTz)(nil)

func convertTz(dt datetime.DateTime, from, to *time.Location, now time.Time) (datetime.DateTime, bool) {
t := dt.ToStdTime(now)
lowerBoundTz := time.Date(1970, 01, 01, 0, 0, 0, 0, time.UTC)
upperBoundTz := time.Date(3001, 1, 19, 3, 14, 7, 99999, time.UTC)
if t.Before(lowerBoundTz) || t.After(upperBoundTz) {
return dt, true
}

buf := datetime.DateTime_YYYY_MM_DD_hh_mm_ss.Format(dt, datetime.DefaultPrecision)
ts, err := time.ParseInLocation(time.DateTime, hack.String(buf), from)
if err != nil {
return datetime.DateTime{}, false
}

if ts.Unix() < 0 || ts.Unix() >= maxUnixtime {
return dt, true
}
return datetime.NewDateTimeFromStd(ts.In(to)), true
}

Expand Down Expand Up @@ -1501,9 +1498,7 @@ func dateTimeUnixTimestamp(env *ExpressionEnv, date eval) evalNumeric {
}

ts := dt.dt.ToStdTime(env.now)
lowerBoundTimestamp := time.Date(1970, 01, 01, 0, 0, 0, 0, time.UTC)
upperBoundTimestamp := time.Date(3001, 1, 19, 3, 14, 7, 99999, time.UTC)
if ts.Before(lowerBoundTimestamp) || ts.After(upperBoundTimestamp) {
if ts.Unix() < 0 || ts.Unix() >= maxUnixtime {
return newEvalInt64(0)
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/evalengine/testcases/inputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ var inputConversions = []string{
"'20000101103458foo'", "'20000101103458.1234foo'", "'20000101103458.123456foo'", "'20000101foo'", "'103458foo'", "'103458.123456foo'",
"time '-10:04:58'", "time '-31:34:58'", "time '-32:34:58'",
"time '-101:34:58'", "time '-5 10:34:58'",
"'10:04:58'", "'101:34:58'", "'5 10:34:58'", "'2000-01-01'", "'2000-01-01 12:34:58'", "'0000-02-29'", "'0000-01-03'", "'1969-02-18'",
"'10:04:58'", "'101:34:58'", "'5 10:34:58'", "'2000-01-01'", "'2000-01-01 12:34:58'", "'0000-02-29'", "'0000-01-03'", "'1969-02-18'", "'1970-01-01 00:00:01'", "'3001-02-19 00:00:00'", "'3001-02-18 23:59:59'",
"cast(0 as json)", "cast(1 as json)",
"cast(true as json)", "cast(false as json)",
"cast('{}' as json)", "cast('[]' as json)",
Expand Down

0 comments on commit cb27206

Please sign in to comment.