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

Fix: Vitess show character set where #5710

Merged
merged 12 commits into from
Feb 6, 2020

Conversation

Ronihe
Copy link
Contributor

@Ronihe Ronihe commented Jan 14, 2020

closes #5584

right now the show character set are hardcoded to be filtered with where statement.
since we don't really want to expand the results or forward the query to an underlying mysql because vitess only supports these 2 charsets.
Ideally there should be a where modular to do the function.

go/vt/vtgate/executor.go Outdated Show resolved Hide resolved
go/vt/vtgate/executor.go Outdated Show resolved Hide resolved
go/vt/vtgate/executor.go Outdated Show resolved Hide resolved
@Ronihe Ronihe marked this pull request as ready for review January 17, 2020 20:47
@Ronihe Ronihe requested a review from sougou as a code owner January 17, 2020 20:47
@Ronihe Ronihe requested review from systay and deepthi January 17, 2020 20:47
@deepthi
Copy link
Member

deepthi commented Jan 17, 2020

executor_test is failing:

##[error]    executor_test.go:833: show charset like '%foo':
        &{Fields:[name:"Charset" type:VARCHAR charset:33 flags:1  name:"Description" type:VARCHAR charset:33 flags:1  name:"Default collation" type:VARCHAR charset:33 flags:1  name:"Maxlen" type:INT32 ] RowsAffected:0 InsertID:0 Rows:[] Extras:<nil>}, want
        &{Fields:[name:"Charset" type:VARCHAR charset:33 flags:1  name:"Description" type:VARCHAR charset:33 flags:1  name:"Default collation" type:VARCHAR charset:33 flags:1  name:"Maxlen" type:INT32 ] RowsAffected:2 InsertID:0 Rows:[[VARCHAR("utf8") VARCHAR("UTF-8 Unicode") VARCHAR("utf8_general_ci") INT32(3)] [VARCHAR("utf8mb4") VARCHAR("UTF-8 Unicode") VARCHAR("utf8mb4_general_ci") INT32(4)]] Extras:<nil>}
##[error]    executor_test.go:833: show character set like '%foo':
        &{Fields:[name:"Charset" type:VARCHAR charset:33 flags:1  name:"Description" type:VARCHAR charset:33 flags:1  name:"Default collation" type:VARCHAR charset:33 flags:1  name:"Maxlen" type:INT32 ] RowsAffected:0 InsertID:0 Rows:[] Extras:<nil>}, want
        &{Fields:[name:"Charset" type:VARCHAR charset:33 flags:1  name:"Description" type:VARCHAR charset:33 flags:1  name:"Default collation" type:VARCHAR charset:33 flags:1  name:"Maxlen" type:INT32 ] RowsAffected:2 InsertID:0 Rows:[[VARCHAR("utf8") VARCHAR("UTF-8 Unicode") VARCHAR("utf8_general_ci") INT32(3)] [VARCHAR("utf8mb4") VARCHAR("UTF-8 Unicode") VARCHAR("utf8mb4_general_ci") INT32(4)]] Extras:<nil>}

I suggest changing the expected output for these cases and adding new cases to test with like 'utf8%' (if we want to support that).

deepthi
deepthi previously approved these changes Jan 30, 2020
Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

LGTM

@deepthi
Copy link
Member

deepthi commented Jan 30, 2020

@Ronihe can you rebase or merge and resolve conflicts?

row1 = append(row1, sqltypes.NewInt32(4))
rows = append(rows, row0, row1)

charsets := []string{"utf8", "utf8mb4"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you are using "magic" strings that are repeated in line 1580 of this file. I think it'd be better to use consts of strings, or even an enum.

rightString := string(sqlVal.Val)

switch cmpExp.Operator {
case "=":
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is full of magic strings, even before your changes. But we can improve the situation. Here I would suggest that you use the same string that the parser uses, which is sqlparser.EqualStr. That way it's easy to find usages of this symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@systay do you mean create a file in sqlparser just for all the magic string/ words?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just replace = with sqlparser.EqualStr

filteredColName = colName
}
}
case "like":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above, but with sqlparser.LikeStr

}
for _, query := range []string{"show charset like 'utf8'", "show character set like 'utf8'", "show charset where charset = 'utf8'", "show character set where charset = 'utf8'"} {
qr, err := executor.Execute(context.Background(), "TestExecute", session, query, nil)
if err != nil {
Copy link
Collaborator

@systay systay Jan 31, 2020

Choose a reason for hiding this comment

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

There's a few of them in the new code, and it's probably because most of this file is doing it.
For new code, I think it's way better to write require.NoError(t, err).

@deepthi deepthi dismissed their stale review January 31, 2020 19:34

I'll let @systay approve once his comments have been addressed

@systay systay merged commit a2dd7a0 into vitessio:master Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vitess wrong results: show character set where
4 participants