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

cmd, expression, parser: support GBK for builtin function char() #29543

Merged
merged 9 commits into from
Nov 12, 2021

Conversation

Defined2014
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #29461

Problem Summary: support GBK for builtin function char()

What is changed and how it works?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 8, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AilinKid
  • zimulala

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 8, 2021
@Defined2014
Copy link
Contributor Author

/cc @xiongjiwei @zimulala @tangenta @wjhuang2016
PTAL

parser/charset/encoding.go Outdated Show resolved Hide resolved
parser/charset/encoding.go Outdated Show resolved Hide resolved
result.AppendString(tempString)
dBytes := b.convertToBytes(bigints)

resultBytes, err := charset.NewEncoding(b.tp.Charset).Decode(nil, dBytes)
Copy link
Member

Choose a reason for hiding this comment

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

dest in the Decode should not be nil. We should create a buffer before the loop to avoid to allocate memory in the transform.

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 8, 2021

Choose a reason for hiding this comment

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

Done. @hawkingrei

@ti-chi-bot
Copy link
Member

@hawkingrei: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

// Decode convert bytes from a specific charset to utf-8 charset.
func (e *Encoding) Decode(dest, src []byte) ([]byte, error) {
if !e.enabled() {
if e.name == "utf-8" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use encodingLegacy instead of utf-8?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think utf-8 is better. encodingLegacy may change someday, and validUTF8 is only design for utf8.

// Decode convert bytes from a specific charset to utf-8 charset.
func (e *Encoding) Decode(dest, src []byte) ([]byte, error) {
if !e.enabled() {
if e.name == "utf-8" {
return e.validUTF8(src)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to check utf8 here?

Copy link
Contributor

@zimulala zimulala Nov 10, 2021

Choose a reason for hiding this comment

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

I got it. But it seems that only char using this check? Has this check been done elsewhere?

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 10, 2021

Choose a reason for hiding this comment

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

If we have some invalid utf8 characters in store, add this check could find them. After add this, the behavior between utf8 and gbk will be same. @zimulala

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I mean we already do check on the parser layer, and we'll do it repeatedly when we call it.

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 11, 2021

Choose a reason for hiding this comment

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

Create a new issue to follow the invlid UTF8 character in buitin func #29685. And delete the UTF8 check in this PR. @zimulala

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 11, 2021
// TODO: Uncomment it when issue #29685 be closed
// {"65", -1, 67.5, "utf8", nil, 1}, // with utf8, return nil
// {"a", -1, 67.5, "utf8", nil, 2}, // with utf8, return nil
// TODO: Uncomment it when gbk be added into charsetInfos
Copy link
Contributor

@zimulala zimulala Nov 12, 2021

Choose a reason for hiding this comment

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

What is the charsetInfos here?
If it is the session variable, we can try ctx.GetSessionVars().SetSystemVar(variable.CharacterSetConnection, v.charset).

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 12, 2021

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it.

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 12, 2021
@zimulala
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 43aadbf

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 12, 2021
@ti-chi-bot
Copy link
Member

@Defined2014: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support GBK for builtin function char
5 participants