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: implement Restore for IndexColName #91

Merged
merged 20 commits into from
Dec 24, 2018
Merged
8 changes: 7 additions & 1 deletion ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ type IndexColName struct {

// Restore implements Node interface.
func (n *IndexColName) Restore(ctx *RestoreCtx) error {
return errors.New("Not implemented")
if err := n.Column.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing IndexColName")
}
if n.Length > 0 {
ctx.WritePlainf("(%d)",n.Length)
}
return nil
}

// Accept implements Node Accept interface.
Expand Down
11 changes: 11 additions & 0 deletions ast/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ func (ts *testDDLSuite) TestDDLVisitorCover(c *C) {
}
}

func (ts *testDDLSuite) TestDDLIndexColNameRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"world", "`world`"},
{"world(2)", "`world`(2)"},
}
extractNodeFunc := func(node Node) Node {
return node.(*CreateIndexStmt).IndexColNames[0]
}
RunNodeRestoreTest(c, testCases, "CREATE INDEX idx ON t (%s) USING HASH", extractNodeFunc)
}

func (ts *testDDLSuite) TestDDLIndexOption(c *C) {
testCases := []NodeRestoreTestCase{
{"key_block_size=16", "KEY_BLOCK_SIZE=16"},
Expand Down