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: remove the usage of "TypeClass" in "builtin_string.go" #4573

Merged
merged 4 commits into from Sep 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 11 additions & 13 deletions expression/builtin_string.go
Expand Up @@ -1241,22 +1241,21 @@ func (c *hexFunctionClass) getFunction(ctx context.Context, args []Expression) (
return nil, errors.Trace(err)
}

switch t := args[0].GetTypeClass(); t {
case types.ClassString:
argTp := fieldTp2EvalTp(args[0].GetType())
switch argTp {
case tpString, tpDatetime, tpTimestamp, tpDuration, tpJSON:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a function like IsStringEvalTp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for now

bf := newBaseBuiltinFuncWithTp(args, ctx, tpString, tpString)
// Use UTF-8 as default
bf.tp.Flen = args[0].GetType().Flen * 3 * 2
sig := &builtinHexStrArgSig{baseStringBuiltinFunc{bf}}
return sig.setSelf(sig), nil

case types.ClassInt, types.ClassReal, types.ClassDecimal:
case tpInt, tpReal, tpDecimal:
bf := newBaseBuiltinFuncWithTp(args, ctx, tpString, tpInt)
bf.tp.Flen = args[0].GetType().Flen * 2
sig := &builtinHexIntArgSig{baseStringBuiltinFunc{bf}}
return sig.setSelf(sig), nil

default:
return nil, errors.Errorf("Hex invalid args, need int or string but get %T", t)
return nil, errors.Errorf("Hex invalid args, need int or string but get %T", args[0].GetType())
}
}

Expand Down Expand Up @@ -1302,17 +1301,16 @@ func (c *unhexFunctionClass) getFunction(ctx context.Context, args []Expression)
return nil, errors.Trace(err)
}
argType := args[0].GetType()
switch t := args[0].GetTypeClass(); t {
case types.ClassString:
argEvalTp := fieldTp2EvalTp(argType)
switch argEvalTp {
case tpString, tpDatetime, tpTimestamp, tpDuration, tpJSON:
// Use UTF-8 as default charset, so there're (Flen * 3 + 1) / 2 byte-pairs
retFlen = (argType.Flen*3 + 1) / 2

case types.ClassInt, types.ClassReal, types.ClassDecimal:
case tpInt, tpReal, tpDecimal:
// For number value, there're (Flen + 1) / 2 byte-pairs
retFlen = (argType.Flen + 1) / 2

default:
return nil, errors.Errorf("Unhex invalid args, need int or string but get %T", t)
return nil, errors.Errorf("Unhex invalid args, need int or string but get %s", argType)
}

bf := newBaseBuiltinFuncWithTp(args, ctx, tpString, tpString)
Expand Down Expand Up @@ -2173,7 +2171,7 @@ func (c *octFunctionClass) getFunction(ctx context.Context, args []Expression) (
return nil, errors.Trace(err)
}
var sig builtinFunc
if IsHybridType(args[0]) || args[0].GetTypeClass() == types.ClassInt {
if IsHybridType(args[0]) || fieldTp2EvalTp(args[0].GetType()) == tpInt {
bf := newBaseBuiltinFuncWithTp(args, ctx, tpString, tpInt)
bf.tp.Flen, bf.tp.Decimal = 64, types.UnspecifiedLength
sig = &builtinOctIntSig{baseStringBuiltinFunc{bf}}
Expand Down