github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/pkg/binlog-filter/util.go (about) 1 // Copyright 2018 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package filter 15 16 import ( 17 "strings" 18 19 "github.com/pingcap/errors" 20 "github.com/pingcap/tidb/pkg/parser/ast" 21 ) 22 23 // AstToDDLEvent returns filter.DDLEvent 24 func AstToDDLEvent(node ast.StmtNode) EventType { 25 switch n := node.(type) { 26 case *ast.CreateDatabaseStmt: 27 return CreateDatabase 28 case *ast.DropDatabaseStmt: 29 return DropDatabase 30 case *ast.CreateTableStmt: 31 return CreateTable 32 case *ast.DropTableStmt: 33 if n.IsView { 34 return DropView 35 } 36 return DropTable 37 case *ast.TruncateTableStmt: 38 return TruncateTable 39 case *ast.RenameTableStmt: 40 return RenameTable 41 case *ast.CreateIndexStmt: 42 return CreateIndex 43 case *ast.DropIndexStmt: 44 return DropIndex 45 case *ast.AlterTableStmt: 46 return AlterTable 47 case *ast.CreateViewStmt: 48 return CreateView 49 case *ast.AlterDatabaseStmt: 50 return AlterDatabase 51 } 52 53 return NullEvent 54 } 55 56 // toEventType converts event type string to EventType and check if it is valid. 57 func toEventType(es string) (EventType, error) { 58 event := EventType(strings.ToLower(es)) 59 switch event { 60 case AllEvent, 61 AllDDL, 62 AllDML, 63 NullEvent, 64 NoneEvent, 65 NoneDDL, 66 NoneDML, 67 InsertEvent, 68 UpdateEvent, 69 DeleteEvent, 70 CreateDatabase, 71 DropDatabase, 72 AlterDatabase, 73 CreateTable, 74 DropTable, 75 TruncateTable, 76 RenameTable, 77 CreateIndex, 78 DropIndex, 79 CreateView, 80 DropView, 81 AlterTable, 82 AddTablePartition, 83 DropTablePartition, 84 TruncateTablePartition, 85 86 IncompatibleDDLChanges, 87 ValueRangeDecrease, 88 PrecisionDecrease, 89 ModifyColumn, 90 RenameColumn, 91 RenameIndex, 92 DropColumn, 93 DropPrimaryKey, 94 DropUniqueKey, 95 ModifyDefaultValue, 96 ModifyConstraint, 97 ModifyColumnsOrder, 98 ModifyCharset, 99 ModifyCollation, 100 RemoveAutoIncrement, 101 ModifyStorageEngine, 102 ReorganizePartition, 103 RebuildPartition, 104 CoalescePartition, 105 SplitPartition, 106 ExchangePartition, 107 108 ModifySchemaCharsetAndCollate, 109 ModifyTableCharsetAndCollate, 110 ModifyTableComment, 111 RecoverTable, 112 AlterTablePartitioning, 113 RemovePartitioning, 114 AddColumn, 115 SetDefaultValue, 116 RebaseAutoID, 117 AddPrimaryKey, 118 AlterIndexVisibility, 119 AlterTTLInfo, 120 AlterTTLRemove, 121 MultiSchemaChange: 122 return event, nil 123 case CreateSchema: // alias of CreateDatabase 124 return CreateDatabase, nil 125 case DropSchema: // alias of DropDatabase 126 return DropDatabase, nil 127 case AlterSchema: 128 return AlterDatabase, nil 129 default: 130 return NullEvent, errors.NotValidf("event type %s", es) 131 } 132 }