Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Dec 19, 2024
1 parent c8b9228 commit 845f342
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/antlr/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions sources/mysql/streaming/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down

0 comments on commit 845f342

Please sign in to comment.