tsreaper commented on code in PR #912:
URL: https://github.com/apache/incubator-paimon/pull/912#discussion_r1168107395


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/sink/cdc/NewDataFieldListProcessFunction.java:
##########
@@ -21,44 +21,95 @@
 import org.apache.paimon.schema.SchemaChange;
 import org.apache.paimon.schema.SchemaManager;
 import org.apache.paimon.schema.TableSchema;
+import org.apache.paimon.types.DataField;
 import org.apache.paimon.types.DataType;
 import org.apache.paimon.types.DataTypeChecks;
 import org.apache.paimon.types.DataTypeRoot;
+import org.apache.paimon.types.RowType;
 import org.apache.paimon.utils.Preconditions;
 
 import org.apache.flink.streaming.api.functions.ProcessFunction;
 import org.apache.flink.util.Collector;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 /**
- * A {@link ProcessFunction} to handle {@link SchemaChange}.
+ * A {@link ProcessFunction} to handle schema changes. New schema is 
represented by a list of {@link
+ * DataField}s.
  *
  * <p>NOTE: To avoid concurrent schema changes, the parallelism of this {@link 
ProcessFunction} must
  * be 1.
  */
-public class SchemaChangeProcessFunction extends ProcessFunction<SchemaChange, 
Void> {
+public class NewDataFieldListProcessFunction extends 
ProcessFunction<List<DataField>, Void> {
 
-    private static final Logger LOG = 
LoggerFactory.getLogger(SchemaChangeProcessFunction.class);
+    private static final Logger LOG =
+            LoggerFactory.getLogger(NewDataFieldListProcessFunction.class);
 
     private final SchemaManager schemaManager;
 
-    public SchemaChangeProcessFunction(SchemaManager schemaManager) {
+    public NewDataFieldListProcessFunction(SchemaManager schemaManager) {
         this.schemaManager = schemaManager;
     }
 
     @Override
     public void processElement(
-            SchemaChange schemaChange, Context context, Collector<Void> 
collector)
+            List<DataField> newDataFieldList, Context context, Collector<Void> 
collector)
             throws Exception {
+        for (SchemaChange schemaChange : 
extractSchemaChanges(newDataFieldList)) {
+            applySchemaChange(schemaChange);
+        }
+    }
+
+    private List<SchemaChange> extractSchemaChanges(List<DataField> 
newDataFieldList) {
+        RowType oldRowType = schemaManager.latest().get().logicalRowType();
+        Map<String, DataField> oldFields = new HashMap<>();
+        for (DataField oldField : oldRowType.getFields()) {
+            oldFields.put(oldField.name(), oldField);
+        }
+
+        List<SchemaChange> result = new ArrayList<>();
+        for (DataField newField : newDataFieldList) {
+            if (oldFields.containsKey(newField.name())) {
+                DataField oldField = oldFields.get(newField.name());

Review Comment:
   No need. Let's make it a utility method when we actually need to reuse 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: [email protected]

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

Reply via email to