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

evalengine: Fix temporal cases in MAKETIME #15709

Merged
merged 2 commits into from
Apr 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using a lowercase d as the suffix for other decimal related functions, so let's also keep using that here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have Fn_MAKETIME_d for decimal cases, Fn_MAKETIME_D is for the temporal cases, like the one in DATEADD Fn_DATEADD_D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beingnoble03 ah, sorry, you're right!

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
4 changes: 3 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,8 @@ func (call *builtinMaketime) compile(c *compiler) (ctype, error) {
c.asm.Convert_xf(1)
c.asm.Fn_MAKETIME_f()
}
case sqltypes.Datetime, sqltypes.Date, sqltypes.Timestamp, sqltypes.Time:
c.asm.Fn_MAKETIME_D()
beingnoble03 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading