Skip to content

Commit 8c356b3

Browse files
committed
use another way to fix
1 parent 771411f commit 8c356b3

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

pkg/expression/chunk_executor.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package expression
1616

1717
import (
18+
"github.com/pingcap/errors"
1819
"github.com/pingcap/tidb/pkg/parser/ast"
1920
"github.com/pingcap/tidb/pkg/parser/mysql"
2021
"github.com/pingcap/tidb/pkg/sessionctx"
@@ -179,7 +180,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
179180
if result.IsNull(i) {
180181
buf.AppendNull()
181182
} else {
182-
buf.AppendEnum(types.Enum{Value: 0, Name: result.GetString(i)})
183+
enum, err := types.ParseEnumName(ft.GetElems(), result.GetString(i), ft.GetCollate())
184+
if err != nil {
185+
return errors.Errorf("Wrong enum value parsed during evaluation")
186+
}
187+
buf.AppendEnum(enum)
183188
}
184189
}
185190
output.SetCol(colIdx, buf)
@@ -191,7 +196,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
191196
if result.IsNull(i) {
192197
buf.AppendNull()
193198
} else {
194-
buf.AppendSet(types.Set{Value: 0, Name: result.GetString(i)})
199+
set, err := types.ParseSetName(ft.GetElems(), result.GetString(i), ft.GetCollate())
200+
if err != nil {
201+
return errors.Errorf("Wrong set value parsed during evaluation")
202+
}
203+
buf.AppendSet(set)
195204
}
196205
}
197206
output.SetCol(colIdx, buf)

pkg/util/codec/codec.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -360,14 +360,11 @@ func encodeHashChunkRowIdx(typeCtx types.Context, row chunk.Row, tp *types.Field
360360
b = unsafe.Slice((*byte)(unsafe.Pointer(&v)), sizeUint64)
361361
} else {
362362
flag = compactBytesFlag
363-
enumVal := row.GetEnum(idx)
364-
str := enumVal.Name
365-
if str == "" {
366-
enum, err := types.ParseEnumValue(tp.GetElems(), enumVal.Value)
367-
if err == nil {
368-
// str will be empty string if v out of definition of enum.
369-
str = enum.Name
370-
}
363+
v := row.GetEnum(idx).Value
364+
str := ""
365+
if enum, err := types.ParseEnumValue(tp.GetElems(), v); err == nil {
366+
// str will be empty string if v out of definition of enum.
367+
str = enum.Name
371368
}
372369
b = ConvertByCollation(hack.Slice(str), tp)
373370
}
@@ -579,14 +576,11 @@ func HashChunkSelected(typeCtx types.Context, h []hash.Hash64, chk *chunk.Chunk,
579576
b = unsafe.Slice((*byte)(unsafe.Pointer(&v)), sizeUint64)
580577
} else {
581578
buf[0] = compactBytesFlag
582-
enumVal := column.GetEnum(i)
583-
str := enumVal.Name
584-
if str == "" {
585-
enum, err := types.ParseEnumValue(tp.GetElems(), enumVal.Value)
586-
if err == nil {
587-
// str will be empty string if v out of definition of enum.
588-
str = enum.Name
589-
}
579+
v := column.GetEnum(i).Value
580+
str := ""
581+
if enum, err := types.ParseEnumValue(tp.GetElems(), v); err == nil {
582+
// str will be empty string if v out of definition of enum.
583+
str = enum.Name
590584
}
591585
b = ConvertByCollation(hack.Slice(str), tp)
592586
}

0 commit comments

Comments
 (0)