# Configuring a `DM` Task: `Binlog` Event Filter

+ `Binlog` event filter is a more fine-grained filtering rule than the block and allow lists filtering rule
+ Define a global filter rule set by using **`filters`** in the task configuration file
  + **`schema-pattern:`** The pattern of the data source schema name, wildcard characters `(*?)` are supported
  + **`table-pattern:`**The pattern of the data source table name, wildcard characters `(*?)` are supported
  + **`events:`** The event types to be filtered out in schemas or tables that match the `schema-pattern` or the `table-pattern`
  + **`sql-pattern:`** Regular expressions used to match specified `DDL` `SQL` statements
  + **`action:`** Whether to migrate (`Do`) or ignore (`Ignore`) the `binlog` that matches the filtering rule
+ Reference the block and allow list rules in the data source configuration to filter tables to be migrated
```
~!@# Global Binlog Event Filter@!~
filters:  
 ~!@filter-rule-1@!~:
    schema-pattern: "test_*"
    table-pattern: "t_*" 
    events: ["truncate table", "drop table"]   
    sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
    action: Ignore                             
 filter-rule-2:
    schema-pattern: "test"
    events: ["all dml"]
    action: Do
```
```
~!@# Reference the Binlog Event Filter@!~
mysql-instances:
  - source-id: ~!@"mysql-replica-01"@!~
    block-allow-list:  "bw-rule-1"
    filter-rules: ~!@["filter-rule-1"]@!~
```
```
```
-------------------------------------------------------------
The `Binlog` event filter is a more granular filter rule than the allow and deny list of migration tables. It is possible to specify that only certain types of binlogs are migrated or filtered out for certain schemas/tables, such as `INSERT` and `TRUNCATE TABLE.`

Skip this configuration if you do not need to filter specific `binlog` events of certain schemas or tables.

If multiple rules are matched on the same table, the rules will be applied sequentially, and the priority of the deny list is higher than the allow list. That is, if both the `Ignore` and `Do` rules are applied to a table, then `Ignore` takes effect.

Starting with `TiDB Data Migration v2.0.2`, the `Binlog` event filter can also be configured in the upstream database configuration file.

Parameter explanation:
- `schema-pattern/table-pattern:` `Binlog` events or `DDL SQL` statements for matched tables.
- `events:` binlog events array.

Filter `SQL` statements not supported by `TiDB`, such as `PROCEDURE` statements that are not supported by `TiDB`:

```
filters:
  filter-procedure-rule:
    schema-pattern: "test_*"
    table-pattern: "t_*"
    sql-pattern: ["^DROP\\s+PROCEDURE", "^CREATE\\s+PROCEDURE"]
    action: Ignore
```


You can set `schema-pattern` to `*` to make a global filter rule. `Global filter` rules must be set as strict as possible to avoid filtering out data that needs to be migrated.

For example, you can set the following rules to filter out `PARTITION` statements:

```
filters:
  filter-partition-rule:
    schema-pattern: "*"
    sql-pattern: ["ALTER\\s+TABLE[\\s\\S]*ADD\\s+PARTITION", "ALTER\\s+TABLE[\\s\\S]*DROP\\s+PARTITION"]
    action: Ignore
```