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: panic in test mode if builtin function's PbCode unspecified #13334

Merged
merged 7 commits into from
Nov 12, 2019
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
12 changes: 12 additions & 0 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,19 @@ func (c *greatestFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
switch tp {
case types.ETInt:
sig = &builtinGreatestIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_GreatestInt)
case types.ETReal:
sig = &builtinGreatestRealSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_GreatestReal)
case types.ETDecimal:
sig = &builtinGreatestDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_GreatestDecimal)
case types.ETString:
sig = &builtinGreatestStringSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_GreatestString)
case types.ETDatetime:
sig = &builtinGreatestTimeSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_GreatestTime)
}
return sig, nil
}
Expand Down Expand Up @@ -631,14 +636,19 @@ func (c *leastFunctionClass) getFunction(ctx sessionctx.Context, args []Expressi
switch tp {
case types.ETInt:
sig = &builtinLeastIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LeastInt)
case types.ETReal:
sig = &builtinLeastRealSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LeastReal)
case types.ETDecimal:
sig = &builtinLeastDecimalSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LeastDecimal)
case types.ETString:
sig = &builtinLeastStringSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LeastString)
case types.ETDatetime:
sig = &builtinLeastTimeSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LeastTime)
}
return sig, nil
}
Expand Down Expand Up @@ -838,8 +848,10 @@ func (c *intervalFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
var sig builtinFunc
if allInt {
sig = &builtinIntervalIntSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IntervalInt)
} else {
sig = &builtinIntervalRealSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_IntervalReal)
}
return sig, nil
}
Expand Down
26 changes: 22 additions & 4 deletions expression/builtin_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/encrypt"
"github.com/pingcap/tipb/go-tipb"
)

var (
Expand Down Expand Up @@ -126,9 +127,13 @@ func (c *aesDecryptFunctionClass) getFunction(ctx sessionctx.Context, args []Exp
if len(args) != 3 {
return nil, ErrIncorrectParameterCount.GenWithStackByArgs("aes_decrypt")
}
return &builtinAesDecryptIVSig{bf, mode}, nil
sig := &builtinAesDecryptIVSig{bf, mode}
sig.setPbCode(tipb.ScalarFuncSig_AesDecryptIV)
return sig, nil
}
return &builtinAesDecryptSig{bf, mode}, nil
sig := &builtinAesDecryptSig{bf, mode}
sig.setPbCode(tipb.ScalarFuncSig_AesDecrypt)
return sig, nil
}

type builtinAesDecryptSig struct {
Expand Down Expand Up @@ -253,9 +258,13 @@ func (c *aesEncryptFunctionClass) getFunction(ctx sessionctx.Context, args []Exp
if len(args) != 3 {
return nil, ErrIncorrectParameterCount.GenWithStackByArgs("aes_encrypt")
}
return &builtinAesEncryptIVSig{bf, mode}, nil
sig := &builtinAesEncryptIVSig{bf, mode}
sig.setPbCode(tipb.ScalarFuncSig_AesEncryptIV)
return sig, nil
}
return &builtinAesEncryptSig{bf, mode}, nil
sig := &builtinAesEncryptSig{bf, mode}
sig.setPbCode(tipb.ScalarFuncSig_AesEncrypt)
return sig, nil
}

type builtinAesEncryptSig struct {
Expand Down Expand Up @@ -368,6 +377,7 @@ func (c *decodeFunctionClass) getFunction(ctx sessionctx.Context, args []Express

bf.tp.Flen = args[0].GetType().Flen
sig := &builtinDecodeSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Decode)
return sig, nil
}

Expand Down Expand Up @@ -427,6 +437,7 @@ func (c *encodeFunctionClass) getFunction(ctx sessionctx.Context, args []Express

bf.tp.Flen = args[0].GetType().Flen
sig := &builtinEncodeSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Encode)
return sig, nil
}

Expand Down Expand Up @@ -484,6 +495,7 @@ func (c *passwordFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETString)
bf.tp.Flen = mysql.PWDHashLen + 1
sig := &builtinPasswordSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Password)
return sig, nil
}

Expand Down Expand Up @@ -571,6 +583,7 @@ func (c *md5FunctionClass) getFunction(ctx sessionctx.Context, args []Expression
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETString)
bf.tp.Flen = 32
sig := &builtinMD5Sig{bf}
sig.setPbCode(tipb.ScalarFuncSig_MD5)
return sig, nil
}

Expand Down Expand Up @@ -607,6 +620,7 @@ func (c *sha1FunctionClass) getFunction(ctx sessionctx.Context, args []Expressio
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETString)
bf.tp.Flen = 40
sig := &builtinSHA1Sig{bf}
sig.setPbCode(tipb.ScalarFuncSig_SHA1)
return sig, nil
}

Expand Down Expand Up @@ -647,6 +661,7 @@ func (c *sha2FunctionClass) getFunction(ctx sessionctx.Context, args []Expressio
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETString, types.ETString, types.ETInt)
bf.tp.Flen = 128 // sha512
sig := &builtinSHA2Sig{bf}
sig.setPbCode(tipb.ScalarFuncSig_SHA2)
return sig, nil
}

Expand Down Expand Up @@ -747,6 +762,7 @@ func (c *compressFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
bf.tp.Flen = compressBound
types.SetBinChsClnFlag(bf.tp)
sig := &builtinCompressSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Compress)
return sig, nil
}

Expand Down Expand Up @@ -809,6 +825,7 @@ func (c *uncompressFunctionClass) getFunction(ctx sessionctx.Context, args []Exp
bf.tp.Flen = mysql.MaxBlobWidth
types.SetBinChsClnFlag(bf.tp)
sig := &builtinUncompressSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_Uncompress)
return sig, nil
}

Expand Down Expand Up @@ -862,6 +879,7 @@ func (c *uncompressedLengthFunctionClass) getFunction(ctx sessionctx.Context, ar
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETInt, types.ETString)
bf.tp.Flen = 10
sig := &builtinUncompressedLengthSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_UncompressedLength)
return sig, nil
}

Expand Down
4 changes: 4 additions & 0 deletions expression/builtin_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/plancodec"
"github.com/pingcap/tidb/util/printer"
"github.com/pingcap/tipb/go-tipb"
)

var (
Expand Down Expand Up @@ -302,8 +303,10 @@ func (c *lastInsertIDFunctionClass) getFunction(ctx sessionctx.Context, args []E

if len(args) == 1 {
sig = &builtinLastInsertIDWithIDSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LastInsertIDWithID)
} else {
sig = &builtinLastInsertIDSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_LastInsertID)
}
return sig, err
}
Expand Down Expand Up @@ -579,6 +582,7 @@ func (c *rowCountFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
}
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETInt)
sig = &builtinRowCountSig{bf}
sig.setPbCode(tipb.ScalarFuncSig_RowCount)
return sig, nil
}

Expand Down
2 changes: 2 additions & 0 deletions expression/builtin_like.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ func (c *regexpFunctionClass) getFunction(ctx sessionctx.Context, args []Express
var sig builtinFunc
if types.IsBinaryStr(args[0].GetType()) || types.IsBinaryStr(args[1].GetType()) {
sig = newBuiltinRegexpBinarySig(bf)
sig.setPbCode(tipb.ScalarFuncSig_RegexpBinarySig)
} else {
sig = newBuiltinRegexpSig(bf)
sig.setPbCode(tipb.ScalarFuncSig_RegexpSig)
}
return sig, nil
}
Expand Down
Loading