-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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, executor: rewrite built-in func length using new expression evaluation architecture #3519
expression, executor: rewrite built-in func length using new expression evaluation architecture #3519
Changes from 3 commits
98f90f7
19f3dc4
0c4d342
bee6a0f
423427d
90df590
06f61d5
43bb81a
ebdcbd6
2173faa
11ddfee
8053d55
1f96f8a
d4bb118
a0bb54a
9c306e2
21ee83d
9a920b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,32 +132,30 @@ type lengthFunctionClass struct { | |
} | ||
|
||
func (c *lengthFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { | ||
sig := &builtinLengthSig{newBaseBuiltinFunc(args, ctx)} | ||
tp := types.NewFieldType(mysql.TypeLonglong) | ||
tp.Flen = 10 | ||
types.SetBinChsClnFlag(tp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider field length? |
||
sig := &builtinLengthSig{baseIntBuiltinFunc{newBaseBuiltinFuncWithTp(args, tp, ctx)}} | ||
return sig.setSelf(sig), errors.Trace(c.verifyArgs(args)) | ||
} | ||
|
||
type builtinLengthSig struct { | ||
baseBuiltinFunc | ||
baseIntBuiltinFunc | ||
} | ||
|
||
// eval evals a builtinLengthSig. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update this comments. |
||
// See https://dev.mysql.com/doc/refman/5.7/en/string-functions.html | ||
func (b *builtinLengthSig) eval(row []types.Datum) (d types.Datum, err error) { | ||
args, err := b.evalArgs(row) | ||
func (b *builtinLengthSig) evalInt(row []types.Datum) (int64, bool, error) { | ||
ctx, sc := b.ctx, b.ctx.GetSessionVars().StmtCtx | ||
arg0, err := WrapWithCastAsString(b.args[0], ctx) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not add cast here. |
||
if err != nil { | ||
return types.Datum{}, errors.Trace(err) | ||
return 0, false, errors.Trace(err) | ||
} | ||
switch args[0].Kind() { | ||
case types.KindNull: | ||
return d, nil | ||
default: | ||
s, err := args[0].ToString() | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
} | ||
d.SetInt64(int64(len(s))) | ||
return d, nil | ||
val, isNull, err := arg0.EvalString(row, sc) | ||
if isNull || err != nil { | ||
return 0, isNull, errors.Trace(err) | ||
} | ||
return int64(len([]byte(val))), false, nil | ||
} | ||
|
||
type asciiFunctionClass struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to
https://github.com/mysql/mysql-server/blob/5.7/sql/item_func.h#L1435