thexiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1209008166


##########
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/SchemaChangeUtils.java:
##########
@@ -51,49 +53,81 @@ public class SchemaChangeUtils {
     static List<TableChange> diffSchema(Schema oldSchema, Schema newSchema) {
         List<String> oldFields = 
oldSchema.columns().stream().map(NestedField::name).collect(Collectors.toList());
         List<String> newFields = 
newSchema.columns().stream().map(NestedField::name).collect(Collectors.toList());
-        int oi = 0;
-        int ni = 0;
+        Set<String> oldFieldSet = new HashSet<>(oldFields);
+        Set<String> newFieldSet = new HashSet<>(newFields);
+
+        Set<String> intersectColSet = Sets.intersection(oldFieldSet, 
newFieldSet);
+        Set<String> colsToDelete = Sets.difference(oldFieldSet, newFieldSet);
+        Set<String> colsToAdd = Sets.difference(newFieldSet, oldFieldSet);
+
         List<TableChange> tableChanges = new ArrayList<>();
-        while (ni < newFields.size()) {
-            if (oi < oldFields.size() && 
oldFields.get(oi).equals(newFields.get(ni))) {
-                oi++;
-                ni++;
-            } else {
-                NestedField newField = newSchema.findField(newFields.get(ni));
+
+        // step0: Unknown change
+        if (!colsToDelete.isEmpty() && !colsToAdd.isEmpty()) {
+            tableChanges.add(new UnknownColumnChange(
+                    String.format(" old schema: [%s] and new schema: [%s], it 
is unknown column change",
+                            oldSchema.toString(), newSchema.toString())));
+            return tableChanges;
+        }
+
+        // step1: judge whether update column(only column type change and doc 
change)
+        for (String colName : intersectColSet) {

Review Comment:
   ok, if you don't handle reorder case.At least you should identified it and 
marked it as unsupported



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to