-
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
Merged
Merged
expression, executor: rewrite built-in func length using new expression evaluation architecture #3519
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
98f90f7
expression, executor: rewrite built-in func length using new expressi…
XuHuaiyu 19f3dc4
fix ci
XuHuaiyu 0c4d342
expression: set types of arguments when build built-in function signa…
XuHuaiyu bee6a0f
Merge branch 'master' of https://github.com/pingcap/tidb into xhy/wra…
XuHuaiyu 423427d
expression: wrap arguments when new built-in function
XuHuaiyu 90df590
set flen
XuHuaiyu 06f61d5
fix CI
XuHuaiyu 43bb81a
address comment
XuHuaiyu ebdcbd6
address comment
XuHuaiyu 2173faa
Merge branch 'master' of https://github.com/pingcap/tidb into xhy/wra…
XuHuaiyu 11ddfee
address comment
XuHuaiyu 8053d55
Merge branch 'master' of https://github.com/pingcap/tidb into xhy/length
XuHuaiyu 1f96f8a
Merge branch 'xhy/wrap-cast' of https://github.com/pingcap/tidb into …
XuHuaiyu d4bb118
address comment
XuHuaiyu a0bb54a
Merge branch 'master' of https://github.com/pingcap/tidb into xhy/length
XuHuaiyu 9c306e2
address comment
XuHuaiyu 21ee83d
Merge branch 'master' of https://github.com/pingcap/tidb into xhy/length
XuHuaiyu 9a920b5
address comment
XuHuaiyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,32 +132,29 @@ type lengthFunctionClass struct { | |
} | ||
|
||
func (c *lengthFunctionClass) getFunction(args []Expression, ctx context.Context) (builtinFunc, error) { | ||
sig := &builtinLengthSig{newBaseBuiltinFunc(args, ctx)} | ||
tp := types.NewFieldType(mysql.TypeLonglong) | ||
types.SetBinChsClnFlag(tp) | ||
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 { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider field length?