Skip to content

Commit

Permalink
expression_filter(dm): fix append update filter for non-update item (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Jan 18, 2023
1 parent 2cbcba3 commit 4432cb5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions dm/syncer/expr_filter_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (g *ExprFilterGroup) GetUpdateExprs(table *filter.Table, ti *model.TableInf

if _, ok := g.hasUpdateFilter[tableID]; ok {
for _, c := range g.configs[tableID] {
if c.UpdateOldValueExpr == "" && c.UpdateNewValueExpr == "" {
continue
}
if c.UpdateOldValueExpr != "" {
expr, err := getSimpleExprOfTable(g.tidbCtx, c.UpdateOldValueExpr, ti, g.logCtx.L())
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions dm/syncer/expr_filter_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,13 @@ create table t (
for i, c := range cases {
t.Logf("case #%d", i)
g := NewExprFilterGroup(tcontext.Background(), sessCtx, []*config.ExpressionFilter{c})
oldExprs, newExprs, err := g.GetUpdateExprs(table, tableInfo)
require.NoError(t, err)
oldExprs, newExprs, err2 := g.GetUpdateExprs(table, tableInfo)
require.NoError(t, err2)
require.Equal(t, len(oldExprs), len(newExprs))
}
g := NewExprFilterGroup(tcontext.Background(), sessCtx, cases)
oldExprs, newExprs, err := g.GetUpdateExprs(table, tableInfo)
require.NoError(t, err)
require.Equal(t, len(oldExprs), len(newExprs))
require.Len(t, oldExprs, 3)
}
6 changes: 6 additions & 0 deletions dm/tests/expression_filter/conf/dm-task2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mysql-instances:
black-white-list: "instance"
expression-filters:
- "even_c"
- "always_false"
- "future_date"
- "pythagorean"
- "update_old_lt_100"
Expand All @@ -26,6 +27,11 @@ expression-filter:
schema: "expr_filter"
table: "t2"
insert-value-expr: "c % 2 = 0"
always_false:
schema: "expr_filter"
table: "t2"
update-old-value-expr: "1 = 0"
update-new-value-expr: "1 = 0"
future_date:
schema: "expr_filter"
table: "t3"
Expand Down
3 changes: 2 additions & 1 deletion dm/tests/expression_filter/data/db1.increment2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ alter table t2 drop column c;
insert into t2 (id, should_skip) values (5, 0), (6, 0);
-- test filter become valid again, and the checking column is a generated column
alter table t2 add column c int as (id + 1);
insert into t2 (id, should_skip, d) values (7, 1, 100), (8, 0, 200);
insert into t2 (id, should_skip, d) values (7, 1, 100), (8, 0, 200), (10, 2, 300);
update t2 set should_skip = 0 where id = 10;

-- test a new created table
create table t3 (id int primary key,
Expand Down
6 changes: 4 additions & 2 deletions dm/tests/expression_filter/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ function complex_behaviour() {
"\"result\": true" 2 \
"\"synced\": true" 1

run_sql_tidb "select count(1) from expr_filter.t2"
check_contains "count(1): 5"
run_sql_tidb "select count(0) from expr_filter.t2"
check_contains "count(0): 6"
run_sql_tidb "select count(1) from expr_filter.t2 where should_skip = 0"
check_contains "count(1): 6"
run_sql_tidb "select count(2) from expr_filter.t2 where should_skip = 1"
check_contains "count(2): 0"

Expand Down

0 comments on commit 4432cb5

Please sign in to comment.