Skip to content

Commit

Permalink
[cdc] Fixed when the order of the same field differs, it is considere…
Browse files Browse the repository at this point in the history
…d a schema change. (apache#3314)
  • Loading branch information
chenxi0599 authored and sunxiaojian committed May 28, 2024
1 parent 47a90e0 commit 4c09a24
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,29 @@ public List<DataField> parseSchemaChange() {
.forEach(
dataField -> {
DataField previous = previousDataFields.get(dataField.name());
if (!Objects.equals(previous, dataField)) {
// When the order of the same field is different, its ID may also be
// different,
// so the comparison should not include the ID.
if (!dataFieldEqualsIgnoreId(previous, dataField)) {
previousDataFields.put(dataField.name(), dataField);
change.add(dataField);
}
});
return change;
}

private boolean dataFieldEqualsIgnoreId(DataField dataField1, DataField dataField2) {
if (dataField1 == dataField2) {
return true;
} else if (dataField1 != null && dataField2 != null) {
return Objects.equals(dataField1.name(), dataField2.name())
&& Objects.equals(dataField1.type(), dataField2.type())
&& Objects.equals(dataField1.description(), dataField2.description());
} else {
return false;
}
}

@Override
public List<CdcRecord> parseRecords() {
if (record.hasPayload()) {
Expand Down

0 comments on commit 4c09a24

Please sign in to comment.