From 7c28ced240a1e7c5566541a610695cf8ff2b2d85 Mon Sep 17 00:00:00 2001 From: Noble Mittal Date: Mon, 15 Apr 2024 12:38:23 +0530 Subject: [PATCH] evalengine: Fix temporal cases in MAKETIME Signed-off-by: Noble Mittal --- go/vt/vtgate/evalengine/compiler_asm.go | 28 +++++++++++++++++++++ go/vt/vtgate/evalengine/fn_time.go | 10 +++++++- go/vt/vtgate/evalengine/testcases/inputs.go | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/go/vt/vtgate/evalengine/compiler_asm.go b/go/vt/vtgate/evalengine/compiler_asm.go index babf23feb5a..b45ac10b194 100644 --- a/go/vt/vtgate/evalengine/compiler_asm.go +++ b/go/vt/vtgate/evalengine/compiler_asm.go @@ -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 { diff --git a/go/vt/vtgate/evalengine/fn_time.go b/go/vt/vtgate/evalengine/fn_time.go index fe8b7d3770f..19342bfdef2 100644 --- a/go/vt/vtgate/evalengine/fn_time.go +++ b/go/vt/vtgate/evalengine/fn_time.go @@ -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 @@ -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() diff --git a/go/vt/vtgate/evalengine/testcases/inputs.go b/go/vt/vtgate/evalengine/testcases/inputs.go index c4ab2fdb92d..eb94235d9b4 100644 --- a/go/vt/vtgate/evalengine/testcases/inputs.go +++ b/go/vt/vtgate/evalengine/testcases/inputs.go @@ -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)",