-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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: rewrite builtin function: EXPORT_SET #4434
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2bc4b99
expression: rewrite builtin function: EXPORT_SET
zz-jason b98d3a6
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason 9fda41a
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason 16c8e2f
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason c2ec01b
address comment:
zz-jason b446483
Merge branch 'master' of https://github.com/pingcap/tidb into zz-jaso…
zz-jason cbdaa65
address comment
zz-jason 3535d86
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason 5776769
Merge branch 'master' of https://github.com/pingcap/tidb into zz-jaso…
zz-jason 38cbffe
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason 0086a05
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason 4f08a30
address comment
zz-jason 5e4666c
address comment
zz-jason 01e745f
Merge branch 'master' into zz-jason/expression/string/export_set
zz-jason 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2372,62 +2372,62 @@ func (c *exportSetFunctionClass) getFunction(ctx context.Context, args []Express | |
if err := c.verifyArgs(args); err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
sig := &builtinExportSetSig{newBaseBuiltinFunc(args, ctx)} | ||
argTps := make([]evalTp, 0, 5) | ||
argTps = append(argTps, tpInt, tpString, tpString) | ||
if len(args) > 3 { | ||
argTps = append(argTps, tpString) | ||
} | ||
if len(args) > 4 { | ||
argTps = append(argTps, tpInt) | ||
} | ||
bf := newBaseBuiltinFuncWithTp(args, ctx, tpString, argTps...) | ||
bf.tp.Flen = mysql.MaxBlobWidth | ||
sig := &builtinExportSetSig{baseStringBuiltinFunc{bf}} | ||
return sig.setSelf(sig), nil | ||
} | ||
|
||
type builtinExportSetSig struct { | ||
baseBuiltinFunc | ||
baseStringBuiltinFunc | ||
} | ||
|
||
// eval evals a builtinExportSetSig. | ||
// evalString evals EXPORT_SET(bits,on,off[,separator[,number_of_bits]]). | ||
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 comments. |
||
// See https://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_export-set | ||
func (b *builtinExportSetSig) eval(row []types.Datum) (d types.Datum, err error) { | ||
args, err := b.evalArgs(row) | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
func (b *builtinExportSetSig) evalString(row []types.Datum) (string, bool, error) { | ||
sc := b.ctx.GetSessionVars().StmtCtx | ||
bits, isNull, err := b.args[0].EvalInt(row, sc) | ||
if isNull || err != nil { | ||
return "", true, errors.Trace(err) | ||
} | ||
var ( | ||
bits uint64 | ||
on string | ||
off string | ||
separator = "," | ||
numberOfBits = 64 | ||
) | ||
switch len(args) { | ||
case 5: | ||
var arg int64 | ||
arg, err = args[4].ToInt64(b.ctx.GetSessionVars().StmtCtx) | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
} | ||
if arg >= 0 && arg < 64 { | ||
numberOfBits = int(arg) | ||
} | ||
fallthrough | ||
case 4: | ||
separator, err = args[3].ToString() | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
} | ||
fallthrough | ||
case 3: | ||
arg, err := args[0].ToInt64(b.ctx.GetSessionVars().StmtCtx) | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
|
||
on, isNull, err := b.args[1].EvalString(row, sc) | ||
if isNull || err != nil { | ||
return "", true, errors.Trace(err) | ||
} | ||
|
||
off, isNull, err := b.args[2].EvalString(row, sc) | ||
if isNull || err != nil { | ||
return "", true, errors.Trace(err) | ||
} | ||
|
||
separator, numberOfBits := ",", int64(64) | ||
if len(b.args) > 3 { | ||
separator, isNull, err = b.args[3].EvalString(row, sc) | ||
if isNull || err != nil { | ||
return "", true, errors.Trace(err) | ||
} | ||
bits = uint64(arg) | ||
on, err = args[1].ToString() | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
} | ||
if len(b.args) > 4 { | ||
numberOfBits, isNull, err = b.args[4].EvalInt(row, sc) | ||
if isNull || err != nil { | ||
return "", true, errors.Trace(err) | ||
} | ||
off, err = args[2].ToString() | ||
if err != nil { | ||
return d, errors.Trace(err) | ||
if numberOfBits < 0 || numberOfBits > 64 { | ||
numberOfBits = 64 | ||
} | ||
} | ||
var result string | ||
for i := 0; i < numberOfBits; i++ { | ||
|
||
result := "" | ||
for i := int64(0); i < numberOfBits; i++ { | ||
if bits&1 > 0 { | ||
result += on | ||
} else { | ||
|
@@ -2438,8 +2438,7 @@ func (b *builtinExportSetSig) eval(row []types.Datum) (d types.Datum, err error) | |
result += separator | ||
} | ||
} | ||
d.SetString(result) | ||
return d, nil | ||
return result, false, nil | ||
} | ||
|
||
type formatFunctionClass 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.
split it into 3 sigs.