zhongyujiang commented on code in PR #5426:
URL: https://github.com/apache/iceberg/pull/5426#discussion_r952097640


##########
core/src/main/java/org/apache/iceberg/util/PropertyUtil.java:
##########
@@ -92,4 +102,42 @@ public static Map<String, String> propertiesWithPrefix(
         .filter(e -> e.getKey().startsWith(prefix))
         .collect(Collectors.toMap(e -> e.getKey().replaceFirst(prefix, ""), 
Map.Entry::getValue));
   }
+
+  public static Map<String, String> applySchemaChanges(
+      Map<String, String> properties,
+      List<String> deletedColumns,
+      Map<String, String> renamedColumns) {
+    if (!properties.keySet().stream()
+        .anyMatch(key -> 
COLUMN_PREFIX_PROPERTIES.stream().anyMatch(key::startsWith))) {
+      return properties;
+    } else {
+      Map<String, String> updatedProperties = Maps.newHashMap();
+      properties
+          .keySet()
+          .forEach(
+              key -> {
+                String prefix =
+                    COLUMN_PREFIX_PROPERTIES.stream()
+                        .filter(key::startsWith)
+                        .findFirst()
+                        .orElse(null);
+
+                if (prefix != null) {
+                  String columnAlias = key.replaceFirst(prefix, "");
+                  if (renamedColumns.get(columnAlias) != null) {
+                    // The name has changed.
+                    String newKey = prefix + renamedColumns.get(columnAlias);
+                    updatedProperties.put(newKey, properties.get(key));
+                  } else if (!deletedColumns.contains(columnAlias)) {
+                    // Copy over the original.
+                    updatedProperties.put(key, properties.get(key));
+                  }

Review Comment:
   Good catch!



##########
core/src/main/java/org/apache/iceberg/util/PropertyUtil.java:
##########
@@ -18,13 +18,23 @@
  */
 package org.apache.iceberg.util;
 
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.stream.Collectors;
+import org.apache.iceberg.TableProperties;
 import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
 import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
 
 public class PropertyUtil {
 
+  private static final Set<String> COLUMN_PREFIX_PROPERTIES =

Review Comment:
   Updated.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to