Skip to content

Commit

Permalink
use another way to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros committed Nov 30, 2023
1 parent 771411f commit 8c356b3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
13 changes: 11 additions & 2 deletions pkg/expression/chunk_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package expression

import (
"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/sessionctx"
Expand Down Expand Up @@ -179,7 +180,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
if result.IsNull(i) {
buf.AppendNull()
} else {
buf.AppendEnum(types.Enum{Value: 0, Name: result.GetString(i)})
enum, err := types.ParseEnumName(ft.GetElems(), result.GetString(i), ft.GetCollate())
if err != nil {
return errors.Errorf("Wrong enum value parsed during evaluation")
}
buf.AppendEnum(enum)
}
}
output.SetCol(colIdx, buf)
Expand All @@ -191,7 +196,11 @@ func evalOneVec(ctx sessionctx.Context, expr Expression, input *chunk.Chunk, out
if result.IsNull(i) {
buf.AppendNull()
} else {
buf.AppendSet(types.Set{Value: 0, Name: result.GetString(i)})
set, err := types.ParseSetName(ft.GetElems(), result.GetString(i), ft.GetCollate())
if err != nil {
return errors.Errorf("Wrong set value parsed during evaluation")
}
buf.AppendSet(set)
}
}
output.SetCol(colIdx, buf)
Expand Down
26 changes: 10 additions & 16 deletions pkg/util/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,11 @@ func encodeHashChunkRowIdx(typeCtx types.Context, row chunk.Row, tp *types.Field
b = unsafe.Slice((*byte)(unsafe.Pointer(&v)), sizeUint64)
} else {
flag = compactBytesFlag
enumVal := row.GetEnum(idx)
str := enumVal.Name
if str == "" {
enum, err := types.ParseEnumValue(tp.GetElems(), enumVal.Value)
if err == nil {
// str will be empty string if v out of definition of enum.
str = enum.Name
}
v := row.GetEnum(idx).Value
str := ""
if enum, err := types.ParseEnumValue(tp.GetElems(), v); err == nil {
// str will be empty string if v out of definition of enum.
str = enum.Name
}
b = ConvertByCollation(hack.Slice(str), tp)
}
Expand Down Expand Up @@ -579,14 +576,11 @@ func HashChunkSelected(typeCtx types.Context, h []hash.Hash64, chk *chunk.Chunk,
b = unsafe.Slice((*byte)(unsafe.Pointer(&v)), sizeUint64)
} else {
buf[0] = compactBytesFlag
enumVal := column.GetEnum(i)
str := enumVal.Name
if str == "" {
enum, err := types.ParseEnumValue(tp.GetElems(), enumVal.Value)
if err == nil {
// str will be empty string if v out of definition of enum.
str = enum.Name
}
v := column.GetEnum(i).Value
str := ""
if enum, err := types.ParseEnumValue(tp.GetElems(), v); err == nil {
// str will be empty string if v out of definition of enum.
str = enum.Name
}
b = ConvertByCollation(hack.Slice(str), tp)
}
Expand Down

0 comments on commit 8c356b3

Please sign in to comment.