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

parser, ast: add ColumnOptionCollate for all column types #260

Merged
merged 5 commits into from
Apr 4, 2019

Conversation

bb7133
Copy link
Member

@bb7133 bb7133 commented Mar 25, 2019

What problem does this PR solve?

In MySQL CREATE TABLE syntax, column collation is part of the column option, so the following statements are valid(although meaningless):

create table t(a decimal collate utf8_bin)
create table t(a decimal collate utf8_bin collate utf8_general_ci)

This PR makes those statements acceptable

What is changed and how it works?

Column "COLLATE" definitions are moved from 'StringType' to 'ColumnOption'

Check List

Tests

  • Unit test

Code changes

  • Has interface methods change

Side effects

  • Increased code complexity

Related changes

  • None

parser.y Outdated
$$ = &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType), Options: $3.([]*ast.ColumnOption)}
def := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType)}
opts := make([]*ast.ColumnOption, 0)
for _, opt := range $3.([]*ast.ColumnOption) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this logic to CreateTable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

@bb7133 bb7133 force-pushed the bb7133/parser_collate branch from 4b60e72 to 4990418 Compare March 28, 2019 09:27
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -416,6 +418,12 @@ func (n *ColumnOption) Restore(ctx *RestoreCtx) error {
if err := n.Refer.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing ColumnOption ReferenceDef")
}
case ColumnOptionCollate:
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add test in TestDDL for testing restore.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed, PTAL!

@bb7133 bb7133 force-pushed the bb7133/parser_collate branch from 37794c8 to f5a0676 Compare April 2, 2019 02:30
Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala
Copy link
Contributor

zimulala commented Apr 2, 2019

Please fix the conflict.

@bb7133 bb7133 force-pushed the bb7133/parser_collate branch from f5a0676 to 09b4eea Compare April 2, 2019 06:13
@bb7133
Copy link
Member Author

bb7133 commented Apr 2, 2019

Updated, thanks @zimulala

@bb7133 bb7133 added status/LGT2 LGT2 and removed status/LGT1 LGT1 labels Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants