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

add TiDB parser for parsing DDL #2

Merged
merged 4 commits into from Aug 17, 2017
Merged

Conversation

goccy
Copy link
Collaborator

@goccy goccy commented Aug 10, 2017

vitess parser has not support fully parsing for DDL.
So use https://github.com/ruiaylin/sqlparser for parsing DDL.
Add directly dependency built package because ruiaylin/sqlparser must compile after downloaded.

support like the following query

CREATE TABLE sample (
  id bigint(20) unsigned NOT NULL,
  other_id bigint(20) unsigned NOT NULL,
  enum_column enum('a','b','c','d') DEFAULT NULL,
  int_column int(10) DEFAULT '0',
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

parsing results

&sqlparser.CreateTable{
  DDL: &sqlparser.DDL{
    Action: "create",
    Table:  sqlparser.TableName{
      Name: sqlparser.TableIdent{
        v: "",
      },
      Qualifier: sqlparser.TableIdent{
        v: "",
      },
    },
    NewName: sqlparser.TableName{
      Name: sqlparser.TableIdent{
        v: "sample",
      },
      Qualifier: sqlparser.TableIdent{
        v: "",
      },
    },
    IfExists: false,
  },
  Columns: []*sqlparser.ColumnDef{
    &sqlparser.ColumnDef{
      Name:  "id",
      Type:  "bigint",
      Elems: []string{},
    },
    &sqlparser.ColumnDef{
      Name:  "other_id",
      Type:  "bigint",
      Elems: []string{},
    },
    &sqlparser.ColumnDef{
      Name:  "enum_column",
      Type:  "enum",
      Elems: []string{
        "a",
        "b",
        "c",
        "d",
      },
    },
    &sqlparser.ColumnDef{
      Name:  "int_column",
      Type:  "int",
      Elems: []string{},
    },
  },
}

@goccy goccy changed the title Feature/add tidbparser add TiDB parser for parsing DDL Aug 10, 2017
@ktsujichan
Copy link
Contributor

LGTM:+1:

@ktsujichan ktsujichan merged commit 6591355 into develop Aug 17, 2017
@ktsujichan ktsujichan deleted the feature/add-tidbparser branch August 17, 2017 11:07
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.

None yet

2 participants