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 support for createIndexStmt and dropIndexStmt #844

Merged
merged 3 commits into from
Jan 18, 2024

Conversation

deadspacewii
Copy link
Contributor

fix create index indexName on tableName and drop index on DDL statment

@deadspacewii
Copy link
Contributor Author

This PR addresses the changes requested in #843

@dveeden
Copy link
Collaborator

dveeden commented Jan 17, 2024

Would it be possible to add some tests?

@deadspacewii
Copy link
Contributor Author

Would it be possible to add some tests?
it's hard to repeat this situation, but i can show you:

type MyEventHandler struct {
canal.DummyEventHandler
}

func (h *MyEventHandler) OnDDL(header *replication.EventHeader, nextPos mysql.Position, queryEvent *replication.QueryEvent) error {
fmt.Println("query: ", string(queryEvent.Query))
fmt.Println("schame: ", len(string(queryEvent.Schema)))
fmt.Println("type: ", header.EventType)
return nil
}

cfg := canal.NewDefaultConfig()
c, err := canal.NewCanal(cfg)
if err != nil {
log.Fatal(err)
}

c.SetEventHandler(&MyEventHandler{})
c.Run()

i use this code to get ddl sql,but when i use alter table test add index index_name (id), this queryevent can be fetch by canal, but if i use create index index_name on test (id),
canal can't get the queryevent and return. i see the source code, find sync.parseStmt method do not match *ast.DropIndexStmt and *ast.CreateIndexStmt(because the parse of
tidb config the create index and drop index as *ast.CreateIndexStmt and *ast.DropIndexStmt). finally, it cause nothing to output when i use create index and drop index

@deadspacewii
Copy link
Contributor Author

Would it be possible to add some tests?
I have create three tests,you can see and run

Copy link
Collaborator

@lance6716 lance6716 left a comment

Choose a reason for hiding this comment

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

thanks for your PR. please check my comment and apply it for the DROP INDEX test cases

canal/canal_test.go Outdated Show resolved Hide resolved
for _, node := range nodes {
rdb := node.db
rtable := node.table
if (len(rdb) != 0 && rdb != db) || rtable != baseTable {
Copy link
Collaborator

Choose a reason for hiding this comment

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

and here, you can use require.Equal(t, db, rdb) and require.Equal(t, baseTable, rtable)

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 have apply require package to test

@lance6716 lance6716 merged commit b390029 into go-mysql-org:master Jan 18, 2024
13 checks passed
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.

3 participants