You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "hejiay (via GitHub)" <gi...@apache.org> on 2023/05/25 11:47:24 UTC

[GitHub] [inlong] hejiay opened a new pull request, #8095: [INLONG-7959][SORT]Dynamic schema evolution support delete,update column when multiple sink to iceberg table

hejiay opened a new pull request, #8095:
URL: https://github.com/apache/inlong/pull/8095

   ### Prepare a Pull Request
   *(Change the title refer to the following example)*
   
   - Title Example: [INLONG-XYZ][Component] Title of the pull request
   
   *(The following *XYZ* should be replaced by the actual [GitHub Issue](https://github.com/apache/inlong/issues) number)*
   
   - Fixes [#7959](https://github.com/apache/inlong/issues/7959)
   
   ### Motivation
   
   *support delete,update column when multiple sink to iceberg table*
   
   ### Modifications
   
   *Describe the modifications you've done.*
   
   ### Verifying this change
   
   *(Please pick either of the following options)*
   
   - [ ] This change added tests and can be verified as follows:
   
     *(example:)*
     - *Added integration tests for end-to-end deployment with large payloads (10MB)*
     - *Extended integration test for recovery after broker failure*
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a follow-up issue for adding the documentation
   


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208411380


##########
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()) {

Review Comment:
   because it can not distinguished (add + delete) or modify, example first [a, b, c] -> delete c [a, b] -> add d [a, b, d], it not suppoted to judge. I will support later use information extracted from DDL.



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208414903


##########
inlong-sort/sort-flink/base/src/main/java/org/apache/inlong/sort/base/sink/TableChange.java:
##########
@@ -177,9 +177,80 @@ public String toString() {
 
     final class DeleteColumn implements ColumnChange {
 
+        private final String[] fieldsNames;
+
+        public DeleteColumn(String[] fieldsNames) {
+            Preconditions.checkArgument(fieldsNames.length > 0, "Invalid filed name: at least one is required");
+            this.fieldsNames = fieldsNames;
+        }
+
         @Override
         public String[] fieldNames() {
-            return new String[0];
+            return fieldsNames;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (!(o instanceof DeleteColumn)) {
+                return false;
+            }
+            DeleteColumn that = (DeleteColumn) o;
+            return Arrays.equals(fieldsNames, that.fieldsNames);
+        }
+
+        @Override
+        public int hashCode() {
+            return Arrays.hashCode(fieldsNames);
+        }
+
+        @Override
+        public String toString() {
+            return String.format("DELETE COLUMNS `%s`", fieldsNames[fieldsNames.length - 1]);
+        }
+    }
+
+    final class UpdateColumn implements ColumnChange {
+
+        private final String[] fieldsNames;
+        private final LogicalType dataType;
+        private final boolean isNullable;
+        private final String comment;
+
+        public UpdateColumn(String[] fieldsNames, LogicalType dataType, boolean isNullable, String comment) {
+            Preconditions.checkArgument(fieldsNames.length > 0, "Invalid filed name: at least one is required");

Review Comment:
   it can not distinguished (add + delete) or modify, example first [a, b, c] -> delete c [a, b] -> add d [a, b, d], it is judged as unknown change, and I will judeg it by using information extracted from DDL in next version. 
   
   



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] lordcheng10 commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "lordcheng10 (via GitHub)" <gi...@apache.org>.
lordcheng10 commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1209051456


##########
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()) {

Review Comment:
   I got it, thanks for clarifying



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] lordcheng10 commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "lordcheng10 (via GitHub)" <gi...@apache.org>.
lordcheng10 commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208768400


##########
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()) {

Review Comment:
   > example first [a, b, c] -> delete c [a, b] -> add d [a, b, d]
   
   If two messages are received one after another: (a1,b1,c1)->(a1,b1,d1), through the diff schema, you can get an add(d) and delete(c), so after executing add and delete , becomes [a, b, d] ?
   



##########
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()) {

Review Comment:
   > example first [a, b, c] -> delete c [a, b] -> add d [a, b, d]
   @hejiay 
   If two messages are received one after another: (a1,b1,c1)->(a1,b1,d1), through the diff schema, you can get an add(d) and delete(c), so after executing add and delete , becomes [a, b, d] ?
   



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] lordcheng10 commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "lordcheng10 (via GitHub)" <gi...@apache.org>.
lordcheng10 commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208768400


##########
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()) {

Review Comment:
   > example first [a, b, c] -> delete c [a, b] -> add d [a, b, d]
   @hejiay 
   
   If two messages are received one after another: (a1,b1,c1)->(a1,b1,d1), through the diff schema, you can get an add(d) and delete(c), so after executing add and delete , becomes [a, b, d] ?
   



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay closed pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay closed pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg
URL: https://github.com/apache/inlong/pull/8095


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208411858


##########
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:
   sorry, changing the field position is currently not supported,because I haven't considered it yet
   
   
   
   



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] EMsnap commented on pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "EMsnap (via GitHub)" <gi...@apache.org>.
EMsnap commented on PR #8095:
URL: https://github.com/apache/inlong/pull/8095#issuecomment-1564115153

   > > How to tell if a schema change is (DeleteColumn + addColumn) or Modify column ?
   > > Such two operations are different in iceberg and may cause data loss is we can not operate correctly
   > 
   > Maybe just diff two different schema can not distinguish `add` + `delete` vs `modify`
   
   Yes indeed


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] thexiay commented on pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "thexiay (via GitHub)" <gi...@apache.org>.
thexiay commented on PR #8095:
URL: https://github.com/apache/inlong/pull/8095#issuecomment-1564111842

   > How to tell if a schema change is (DeleteColumn + addColumn) or Modify column ?
   > 
   > Such two operations are different in iceberg and may cause data loss is we can not operate correctly
   
   Maybe just diff two different schema can not distinguish `add` + `delete`  vs `modify`


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1209087824


##########
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:
   thanks,i got it



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on PR #8095:
URL: https://github.com/apache/inlong/pull/8095#issuecomment-1563737733

   @dockerzhang  please check again


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208799987


##########
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()) {

Review Comment:
   of course not,for iceberg, each field has a unique id. Even if it is deleted, the field still exists, but the content of the field will be hidden when querying.if modify, only one modify step [a, b, c] -> [a, b, d],The field[d] id has not changed.if add and delete, the filed d has a new unique id. So first add and then delete cannot be confused with modify.
   



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] thexiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "thexiay (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] EMsnap commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "EMsnap (via GitHub)" <gi...@apache.org>.
EMsnap commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1206465777


##########
inlong-sort/sort-flink/base/src/main/java/org/apache/inlong/sort/base/sink/TableChange.java:
##########
@@ -177,9 +177,80 @@ public String toString() {
 
     final class DeleteColumn implements ColumnChange {
 
+        private final String[] fieldsNames;
+
+        public DeleteColumn(String[] fieldsNames) {
+            Preconditions.checkArgument(fieldsNames.length > 0, "Invalid filed name: at least one is required");
+            this.fieldsNames = fieldsNames;
+        }
+
         @Override
         public String[] fieldNames() {
-            return new String[0];
+            return fieldsNames;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (!(o instanceof DeleteColumn)) {
+                return false;
+            }
+            DeleteColumn that = (DeleteColumn) o;
+            return Arrays.equals(fieldsNames, that.fieldsNames);
+        }
+
+        @Override
+        public int hashCode() {
+            return Arrays.hashCode(fieldsNames);
+        }
+
+        @Override
+        public String toString() {
+            return String.format("DELETE COLUMNS `%s`", fieldsNames[fieldsNames.length - 1]);
+        }
+    }
+
+    final class UpdateColumn implements ColumnChange {
+
+        private final String[] fieldsNames;
+        private final LogicalType dataType;
+        private final boolean isNullable;
+        private final String comment;
+
+        public UpdateColumn(String[] fieldsNames, LogicalType dataType, boolean isNullable, String comment) {
+            Preconditions.checkArgument(fieldsNames.length > 0, "Invalid filed name: at least one is required");

Review Comment:
   at least one field



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] gong commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "gong (via GitHub)" <gi...@apache.org>.
gong commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208796949


##########
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/SchemaChangeUtils.java:
##########
@@ -42,7 +44,7 @@ public class SchemaChangeUtils {
 
     /**
      * Compare two schemas and get the schema changes that happened in them.
-     * TODO: currently only support add column
+     * TODO: currently only support add column,delete column and update column(column type change)

Review Comment:
   `update column` include too many situation. Maybe differentiation of fine grains is better, not use `update column`



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1208800947


##########
inlong-sort/sort-flink/sort-flink-v1.13/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/multiple/SchemaChangeUtils.java:
##########
@@ -42,7 +44,7 @@ public class SchemaChangeUtils {
 
     /**
      * Compare two schemas and get the schema changes that happened in them.
-     * TODO: currently only support add column
+     * TODO: currently only support add column,delete column and update column(column type change)

Review Comment:
   Thanks for the correction



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] hejiay commented on pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "hejiay (via GitHub)" <gi...@apache.org>.
hejiay commented on PR #8095:
URL: https://github.com/apache/inlong/pull/8095#issuecomment-1566892860

   I accidentally deleted the original PR by mistake, so I resubmitted it. The new PR https://github.com/apache/inlong/pull/8120


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] lordcheng10 commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "lordcheng10 (via GitHub)" <gi...@apache.org>.
lordcheng10 commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1206488258


##########
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()) {

Review Comment:
   Why can't there be both deleted columns and new columns?



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang commented on pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang commented on PR #8095:
URL: https://github.com/apache/inlong/pull/8095#issuecomment-1566773880

   @hejiay if all comments are confirmed, please click `resolve`, and I found there are some conflicts, please fix them, thanks.


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] dockerzhang commented on pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "dockerzhang (via GitHub)" <gi...@apache.org>.
dockerzhang commented on PR #8095:
URL: https://github.com/apache/inlong/pull/8095#issuecomment-1563727579

   @hejiay thanks for your contribution, there is a file missing the license header, you could execute `mvn spotless:apply` to fix it.


-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] EMsnap commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "EMsnap (via GitHub)" <gi...@apache.org>.
EMsnap commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1206464428


##########
inlong-sort/sort-flink/base/src/main/java/org/apache/inlong/sort/base/sink/TableChange.java:
##########
@@ -177,9 +177,80 @@ public String toString() {
 
     final class DeleteColumn implements ColumnChange {
 
+        private final String[] fieldsNames;

Review Comment:
   fieldNames  would be better ?



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [inlong] thexiay commented on a diff in pull request #8095: [INLONG-7959][Sort] Dynamic schema evolution support delete and update columns when sink to Iceberg

Posted by "thexiay (via GitHub)" <gi...@apache.org>.
thexiay commented on code in PR #8095:
URL: https://github.com/apache/inlong/pull/8095#discussion_r1206502423


##########
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:
   What if column reorder?
   [a,b,c] -> [a,c,b]
   I don't see any solution int this algorithm.



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org