Skip to content

Commit

Permalink
sync_diff: support json compare (#674)
Browse files Browse the repository at this point in the history
close #606
  • Loading branch information
xiongjiwei authored Sep 21, 2022
1 parent 79986ad commit af5f0ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sync_diff_inspector/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (df *Diff) consume(ctx context.Context, rangeInfo *splitter.RangeInfo) bool
if err != nil {
df.report.SetTableMeetError(schema, table, err)
}
isEqual = isEqual && isDataEqual
isEqual = isDataEqual
}
dml.node.State = state
id := rangeInfo.ChunkRange.Index
Expand Down
18 changes: 18 additions & 0 deletions sync_diff_inspector/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ package utils
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"math"
"reflect"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -533,6 +535,22 @@ func CompareData(map1, map2 map[string]*dbutil.ColumnData, orderKeyCols, columns
if math.Abs(num1-num2) <= 1e-6 {
continue
}
} else if column.FieldType.GetType() == mysql.TypeJSON {
if (str1 == str2) || (data1.IsNull == data2.IsNull) {
continue
}
var v1, v2 any
err := json.Unmarshal(data1.Data, &v1)
if err != nil {
return false, 0, errors.Errorf("unmarshal json %s failed, error %v", str1, err)
}
err = json.Unmarshal(data2.Data, &v2)
if err != nil {
return false, 0, errors.Errorf("unmarshal json %s failed, error %v", str2, err)
}
if reflect.DeepEqual(v1, v2) {
continue
}
} else {
if (str1 == str2) && (data1.IsNull == data2.IsNull) {
continue
Expand Down

0 comments on commit af5f0ab

Please sign in to comment.