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

expression: fix behavior for CASE WHEN (not_int) (#15309) #15359

Merged
merged 1 commit into from
Mar 14, 2020
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
19 changes: 11 additions & 8 deletions expression/builtin_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ func (c *caseWhenFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
}
// Set retType to BINARY(0) if all arguments are of type NULL.
if fieldTp.Tp == mysql.TypeNull {
fieldTp.Flen, fieldTp.Decimal = 0, -1
fieldTp.Flen, fieldTp.Decimal = 0, types.UnspecifiedLength
types.SetBinChsClnFlag(fieldTp)
}
argTps := make([]types.EvalType, 0, l)
for i := 0; i < l-1; i += 2 {
if args[i], err = wrapWithIsTrue(ctx, true, args[i]); err != nil {
return nil, err
}
argTps = append(argTps, types.ETInt, tp)
}
if l%2 == 1 {
Expand Down Expand Up @@ -221,7 +224,7 @@ func (b *builtinCaseWhenIntSig) Clone() builtinFunc {
}

// evalInt evals a builtinCaseWhenIntSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenIntSig) evalInt(row chunk.Row) (ret int64, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down Expand Up @@ -257,7 +260,7 @@ func (b *builtinCaseWhenRealSig) Clone() builtinFunc {
}

// evalReal evals a builtinCaseWhenRealSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenRealSig) evalReal(row chunk.Row) (ret float64, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down Expand Up @@ -293,7 +296,7 @@ func (b *builtinCaseWhenDecimalSig) Clone() builtinFunc {
}

// evalDecimal evals a builtinCaseWhenDecimalSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenDecimalSig) evalDecimal(row chunk.Row) (ret *types.MyDecimal, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down Expand Up @@ -329,7 +332,7 @@ func (b *builtinCaseWhenStringSig) Clone() builtinFunc {
}

// evalString evals a builtinCaseWhenStringSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenStringSig) evalString(row chunk.Row) (ret string, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down Expand Up @@ -365,7 +368,7 @@ func (b *builtinCaseWhenTimeSig) Clone() builtinFunc {
}

// evalTime evals a builtinCaseWhenTimeSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenTimeSig) evalTime(row chunk.Row) (ret types.Time, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down Expand Up @@ -401,7 +404,7 @@ func (b *builtinCaseWhenDurationSig) Clone() builtinFunc {
}

// evalDuration evals a builtinCaseWhenDurationSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenDurationSig) evalDuration(row chunk.Row) (ret types.Duration, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down Expand Up @@ -437,7 +440,7 @@ func (b *builtinCaseWhenJSONSig) Clone() builtinFunc {
}

// evalJSON evals a builtinCaseWhenJSONSig.
// See https://dev.mysql.com/doc/refman/5.7/en/case.html
// See https://dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html#operator_case
func (b *builtinCaseWhenJSONSig) evalJSON(row chunk.Row) (ret json.BinaryJSON, isNull bool, err error) {
var condition int64
args, l := b.getArgs(), len(b.getArgs())
Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (s *testEvaluatorSuite) TestCaseWhen(c *C) {
{[]interface{}{nil, 1, false, 2, 3}, 3},
{[]interface{}{1, jsonInt.GetMysqlJSON(), nil}, 3},
{[]interface{}{0, jsonInt.GetMysqlJSON(), nil}, nil},
{[]interface{}{0.1, 1, 2}, 1},
{[]interface{}{0.0, 1, 0.1, 2}, 2},
}
fc := funcs[ast.Case]
for _, t := range tbl {
Expand Down