Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: handle INTERVAL HOUR for date arithmetic functions #8146

Merged
merged 3 commits into from Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions expression/builtin_time.go
Expand Up @@ -2577,8 +2577,8 @@ func (du *baseDateArithmitical) getIntervalFromString(ctx sessionctx.Context, ar
if isNull || err != nil {
return "", true, errors.Trace(err)
}
// unit "DAY" has to be specially handled.
if strings.ToLower(unit) == "day" {
// unit "DAY" and "HOUR" has to be specially handled.
if toLower := strings.ToLower(unit); toLower == "day" || toLower == "hour" {
if strings.ToLower(interval) == "true" {
interval = "1"
} else if strings.ToLower(interval) == "false" {
Expand Down
5 changes: 5 additions & 0 deletions expression/integration_test.go
Expand Up @@ -1807,6 +1807,11 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) {
{"\"2009-01-01\"", "6/4", "HOUR_MINUTE", "2009-01-04 12:20:00", "2008-12-28 11:40:00"},
{"\"2009-01-01\"", "6/0", "HOUR_MINUTE", "<nil>", "<nil>"},
{"\"1970-01-01 12:00:00\"", "CAST(6/4 AS DECIMAL(3,1))", "HOUR_MINUTE", "1970-01-01 13:05:00", "1970-01-01 10:55:00"},
//for issue #8077
{"\"2012-01-02\"", "\"prefix8\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
{"\"2012-01-02\"", "\"prefix8prefix\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
{"\"2012-01-02\"", "\"8:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
{"\"2012-01-02\"", "\"8:00:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"},
}
for _, tc := range dateArithmeticalTests {
addDate := fmt.Sprintf("select adddate(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit)
Expand Down