-
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: handle max_allowed_packet warnings for to_base64 function. #7266
Merged
Merged
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5bb5cf7
expression: handle max_allowed_packet warnings for to_base64 functions
sisterdong 33a10e3
Merge branch 'develop'
sisterdong ea06d28
Merge branch 'master' of https://github.com/pingcap/tidb
sisterdong 9e310ec
Merge branch 'master' of https://github.com/pingcap/tidb
sisterdong 8c54930
Merge branch 'master' of https://github.com/pingcap/tidb
sisterdong abc9329
Merge branch 'master' of https://github.com/pingcap/tidb
sisterdong 9700a53
use `need encode length` to decide whether the result of `ToBase64` e…
sisterdong 1bbf7f4
Merge branch 'master' of https://github.com/pingcap/tidb
sisterdong 0467a1f
remove get err check
sisterdong 7f158ac
check the exactly warning count and warning content in each test case
sisterdong 67ea3e2
Merge branch 'master' into master
supernan1994 78c3716
Merge branch 'master' into master
supernan1994 2c6dd39
Merge branch 'master' into master
supernan1994 67984ea
Merge branch 'master' into master
zz-jason 60f73b5
Merge branch 'master' into master
supernan1994 055c2af
Merge branch 'master' into master
zz-jason 857951c
Merge branch 'master' into master
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
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 |
---|---|---|
|
@@ -1879,6 +1879,75 @@ func (s *testEvaluatorSuite) TestToBase64(c *C) { | |
c.Assert(err, IsNil) | ||
} | ||
|
||
func (s *testEvaluatorSuite) TestToBase64Sig(c *C) { | ||
colTypes := []*types.FieldType{ | ||
{Tp: mysql.TypeVarchar}, | ||
} | ||
|
||
tests := []struct { | ||
args string | ||
expect string | ||
isNil bool | ||
maxAllowPacket uint64 | ||
}{ | ||
{"abc", "YWJj", false, 4}, | ||
{"abc", "", true, 3}, | ||
{ | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | ||
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0\nNTY3ODkrLw==", | ||
false, | ||
89, | ||
}, | ||
{ | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | ||
"", | ||
true, | ||
88, | ||
}, | ||
{ | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | ||
"QUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0\nNTY3ODkrL0FCQ0RFRkdISUpLTE1OT1BRUlNUVVZXWFlaYWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4\neXowMTIzNDU2Nzg5Ky9BQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWmFiY2RlZmdoaWprbG1ub3Bx\ncnN0dXZ3eHl6MDEyMzQ1Njc4OSsv", | ||
false, | ||
259, | ||
}, | ||
{ | ||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | ||
"", | ||
true, | ||
258, | ||
}, | ||
} | ||
|
||
args := []Expression{ | ||
&Column{Index: 0, RetType: colTypes[0]}, | ||
} | ||
|
||
warningCount := 0 | ||
|
||
for _, test := range tests { | ||
resultType := &types.FieldType{Tp: mysql.TypeVarchar, Flen: base64NeededEncodedLength(len(test.args))} | ||
base := baseBuiltinFunc{args: args, ctx: s.ctx, tp: resultType} | ||
toBase64 := &builtinToBase64Sig{base, test.maxAllowPacket} | ||
|
||
input := chunk.NewChunkWithCapacity(colTypes, 1) | ||
input.AppendString(0, test.args) | ||
res, isNull, err := toBase64.evalString(input.GetRow(0)) | ||
c.Assert(err, IsNil) | ||
if test.isNil { | ||
c.Assert(isNull, IsTrue) | ||
warningCount += 1 | ||
} else { | ||
c.Assert(isNull, IsFalse) | ||
} | ||
c.Assert(res, Equals, test.expect) | ||
} | ||
warnings := s.ctx.GetSessionVars().StmtCtx.GetWarnings() | ||
c.Assert(len(warnings), Equals, warningCount) | ||
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.
|
||
for _, warn := range warnings { | ||
c.Assert(terror.ErrorEqual(errWarnAllowedPacketOverflowed, warn.Err), IsTrue) | ||
} | ||
} | ||
|
||
func (s *testEvaluatorSuite) TestStringRight(c *C) { | ||
defer testleak.AfterTest(c)() | ||
fc := funcs[ast.Right] | ||
|
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.
warningCount
will add 1 whento_base64
result is nilThere 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.
can we reset the warning appended to
s.ctx.GetSessionVars().StmtCtx
and check the exactly warning count and warning content in each test case?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.
sure!
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.
👍