MCPcopy Create free account
hub / github.com/actiontech/dtle / loadMapping

Method loadMapping

driver/mysql/binlog/binlog_reader.go:835–945  ·  view source on GitHub ↗
(sql, currentSchema string, schemasRenameMap map[string]string,
	oldSchemaNameToTablesRenameMap map[string]map[string]string, stmt ast.StmtNode,
	columnMap []string)

Source from the content-addressed store, hash-verified

833}
834
835func (b *BinlogReader) loadMapping(sql, currentSchema string, schemasRenameMap map[string]string,
836 oldSchemaNameToTablesRenameMap map[string]map[string]string, stmt ast.StmtNode,
837 columnMap []string) (string, error) {
838
839 logMapping := func(oldName, newName, mappingType string) {
840 msg := fmt.Sprintf("ddl %s mapping", mappingType)
841 b.logger.Debug(msg, "from", oldName, "to", newName)
842 }
843
844 // will do nothing if `table` is nil
845 renameAstTableFn := func(table *ast.TableName) {
846 if table == nil {
847 return
848 }
849 table.Schema = model.NewCIStr(g.StringElse(table.Schema.String(), currentSchema))
850 newSchemaName := schemasRenameMap[table.Schema.String()]
851 tableNameMap := oldSchemaNameToTablesRenameMap[table.Schema.String()]
852 newTableName := tableNameMap[table.Name.String()]
853
854 if newSchemaName != "" {
855 logMapping(table.Schema.String(), newSchemaName, "schema")
856 table.Schema = model.NewCIStr(newSchemaName)
857 }
858
859 if newTableName != "" {
860 logMapping(table.Name.String(), newTableName, "table")
861 table.Name = model.NewCIStr(newTableName)
862 }
863
864 }
865
866 renameTableFn := func(schemaName string, oldTableName *string) {
867 tableNameMap := oldSchemaNameToTablesRenameMap[schemaName]
868 newTableName := tableNameMap[*oldTableName]
869 if newTableName != "" {
870 logMapping(*oldTableName, newTableName, "table")
871 *oldTableName = newTableName
872 }
873 }
874
875 renameSchemaFn := func(oldSchema *string) {
876 newSchemaName := schemasRenameMap[*oldSchema]
877 if newSchemaName != "" {
878 logMapping(*oldSchema, newSchemaName, "schema")
879 *oldSchema = newSchemaName
880 }
881 }
882
883 switch v := stmt.(type) {
884 case *ast.DropTableStmt:
885 for _, table := range v.Tables {
886 renameAstTableFn(table)
887 }
888 case *ast.RenameTableStmt:
889 for _, tt := range v.TableToTables {
890 renameAstTableFn(tt.OldTable)
891 renameAstTableFn(tt.NewTable)
892 }

Callers 1

handleQueryEventMethod · 0.95

Calls 3

StringElseFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected