Skip to content

Commit

Permalink
evalengine: Fix temporal cases in MAKETIME
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Apr 15, 2024
1 parent 9e40015 commit 7c28ced
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
28 changes: 28 additions & 0 deletions go/vt/vtgate/evalengine/compiler_asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3934,6 +3934,34 @@ func (asm *assembler) Fn_MAKETIME_i() {
}, "FN MAKETIME INT64(SP-3) INT64(SP-2) INT64(SP-1)")
}

func (asm *assembler) Fn_MAKETIME_D() {
asm.adjustStack(-2)
asm.emit(func(env *ExpressionEnv) int {
h := env.vm.stack[env.vm.sp-3].(*evalInt64)
m := env.vm.stack[env.vm.sp-2].(*evalInt64)
sec := env.vm.stack[env.vm.sp-1].(*evalTemporal)

s := newEvalDecimalWithPrec(sec.toDecimal(), int32(sec.prec))

d, ok := makeTime_d(h.i, m.i, s.dec)
if !ok {
env.vm.stack[env.vm.sp-3] = nil
env.vm.sp -= 2
return 1
}
t, l, ok := datetime.ParseTimeDecimal(d, s.length, -1)
if !ok {
env.vm.stack[env.vm.sp-3] = nil
env.vm.sp -= 2
return 1
}

env.vm.stack[env.vm.sp-3] = env.vm.arena.newEvalTime(t, l)
env.vm.sp -= 2
return 1
}, "FN MAKETIME INT64(SP-3) INT64(SP-2) TEMPORAL(SP-1)")
}

func (asm *assembler) Fn_MAKETIME_d() {
asm.adjustStack(-2)
asm.emit(func(env *ExpressionEnv) int {
Expand Down
10 changes: 9 additions & 1 deletion go/vt/vtgate/evalengine/fn_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ func (b *builtinMaketime) eval(env *ExpressionEnv) (eval, error) {
}

m := evalToInt64(min).i
s := evalToNumeric(sec, false)
s := evalToNumeric(sec, true)

var ok bool
var t datetime.Time
Expand Down Expand Up @@ -1106,6 +1106,14 @@ func (call *builtinMaketime) compile(c *compiler) (ctype, error) {
c.asm.Convert_xf(1)
c.asm.Fn_MAKETIME_f()
}
case sqltypes.Datetime:
c.asm.Fn_MAKETIME_D()
case sqltypes.Date:
c.asm.Fn_MAKETIME_D()
case sqltypes.Time:
c.asm.Fn_MAKETIME_D()
case sqltypes.Timestamp:
c.asm.Fn_MAKETIME_D()
default:
c.asm.Convert_xf(1)
c.asm.Fn_MAKETIME_f()
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 @@ -106,7 +106,7 @@ var inputConversions = []string{
"20000101103458", "20000101103458.1234", "20000101103458.123456", "20000101", "103458", "103458.123456",
"'20000101103458'", "'20000101103458.1234'", "'20000101103458.123456'", "'20000101'", "'103458'", "'103458.123456'",
"'20000101103458foo'", "'20000101103458.1234foo'", "'20000101103458.123456foo'", "'20000101foo'", "'103458foo'", "'103458.123456foo'",
"time '-10:04:58'", "time '-31:34:58'", "time '-32:34:58'",
"time '-10:04:58'", "time '-31:34:58'", "time '-32:34:58'", "time'00:00:01.0000'", "time'00:00:59.01011'", "time'00:00:59.2132234'",
"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'", "'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)",
Expand Down

0 comments on commit 7c28ced

Please sign in to comment.