diff --git a/lib/antlr/parse.go b/lib/antlr/parse.go index 7be6d367..6446f5c5 100644 --- a/lib/antlr/parse.go +++ b/lib/antlr/parse.go @@ -41,13 +41,7 @@ func Parse(sqlCmd string) ([]Event, error) { stream := antlr.NewCommonTokenStream(lexer, antlr.TokenDefaultChannel) // This will go through our custom visit function. If you are trying to print out the AST, split this function into [sqlStatements] and [parser] // Then have print [sqlStatements.ToStringTree(nil, parser)] - - parser := generated.NewMySqlParser(stream) - statements := parser.SqlStatements() - - fmt.Println("##", statements.ToStringTree(nil, parser)) - - return visit(statements) + return visit(generated.NewMySqlParser(stream).SqlStatements()) } func visit(tree antlr.Tree) ([]Event, error) { diff --git a/sources/mysql/streaming/ddl/ddl.go b/sources/mysql/streaming/ddl/ddl.go index 7687526f..bc7e7deb 100644 --- a/sources/mysql/streaming/ddl/ddl.go +++ b/sources/mysql/streaming/ddl/ddl.go @@ -90,6 +90,21 @@ func (s *SchemaAdapter) applyDDL(unixTs int64, result antlr.Event) error { s.adapters[result.GetTable()] = tblAdapter return nil + case antlr.RenameTableEvent: + tblAdapter, ok := s.adapters[castedResult.GetTable()] + if !ok { + return fmt.Errorf("table not found: %q", result.GetTable()) + } + + newTableAdapter, err := NewTableAdapter(s.dbName, s.tableCfgMap[castedResult.GetNewTableName()], tblAdapter.columns, unixTs, s.sqlMode) + if err != nil { + return err + } + + // Delete the old table adapter and create a new one + delete(s.adapters, result.GetTable()) + s.adapters[castedResult.GetNewTableName()] = newTableAdapter + return nil } tblAdapter, ok := s.adapters[result.GetTable()]