Skip to content

Commit 06def14

Browse files
authored
Fix crash in the evalengine (#17487)
Signed-off-by: Dirkjan Bussink <[email protected]>
1 parent 6d35e82 commit 06def14

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

go/vt/vtgate/evalengine/arena.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (a *Arena) newEvalEnum(raw []byte, values *EnumSetValues) *evalEnum {
7171
} else {
7272
a.aEnum = append(a.aEnum, evalEnum{})
7373
}
74-
val := &a.aEnum[len(a.aInt64)-1]
74+
val := &a.aEnum[len(a.aEnum)-1]
7575
s := string(raw)
7676
val.string = s
7777
val.value = valueIdx(values, s)
@@ -84,7 +84,7 @@ func (a *Arena) newEvalSet(raw []byte, values *EnumSetValues) *evalSet {
8484
} else {
8585
a.aSet = append(a.aSet, evalSet{})
8686
}
87-
val := &a.aSet[len(a.aInt64)-1]
87+
val := &a.aSet[len(a.aSet)-1]
8888
s := string(raw)
8989
val.string = s
9090
val.set = evalSetBits(values, s)

go/vt/vtgate/evalengine/compiler_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,20 @@ func TestCompilerSingle(t *testing.T) {
760760
expression: `WEEK(timestamp '2024-01-01 10:34:58', 1)`,
761761
result: `INT64(1)`,
762762
},
763+
{
764+
expression: `column0 + 1`,
765+
values: []sqltypes.Value{sqltypes.MakeTrusted(sqltypes.Enum, []byte("foo"))},
766+
// Returns 0, as unknown enums evaluate here to -1. We have this test to
767+
// exercise the path to push enums onto the stack.
768+
result: `FLOAT64(0)`,
769+
},
770+
{
771+
expression: `column0 + 1`,
772+
values: []sqltypes.Value{sqltypes.MakeTrusted(sqltypes.Set, []byte("foo"))},
773+
// Returns 1, as unknown sets evaluate here to 0. We have this test to
774+
// exercise the path to push sets onto the stack.
775+
result: `FLOAT64(1)`,
776+
},
763777
}
764778

765779
tz, _ := time.LoadLocation("Europe/Madrid")

0 commit comments

Comments
 (0)