difin commented on code in PR #6120:
URL: https://github.com/apache/hive/pull/6120#discussion_r2440781036


##########
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HiveSchemaUtil.java:
##########
@@ -178,13 +188,55 @@ public static SchemaDifference 
getSchemaDiff(Collection<FieldSchema> minuendColl
     }
 
     if (bothDirections) {
-      SchemaDifference otherWay = getSchemaDiff(subtrahendCollection, 
minuendCollection, false);
+      SchemaDifference otherWay = getSchemaDiff(subtrahendCollection, 
minuendCollection, null, defaultValues, false);
       otherWay.getMissingFromSecond().forEach(difference::addMissingFromFirst);
     }
 
+    if (schema != null) {
+      for (Types.NestedField field : schema.columns()) {
+        if (!isRemovedField(field, difference.getMissingFromFirst())) {
+          getDefaultValDiff(field, defaultValues, difference);
+        }
+      }
+    }
+
     return difference;
   }
 
+  private static boolean isRemovedField(Types.NestedField field, 
List<FieldSchema> missingFields) {
+    for (FieldSchema fieldSchema : missingFields) {
+      if (fieldSchema.getName().equalsIgnoreCase(field.name())) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  private static void getDefaultValDiff(Types.NestedField field, Map<String, 
String> defaultValues,
+      SchemaDifference difference) {
+
+    String defaultStr = defaultValues.get(field.name());
+
+    // Skip if no default at all
+    if (defaultStr == null && field.writeDefault() == null) {
+      return;
+    }
+
+    if (field.type().isPrimitiveType()) {
+      Object expectedDefault = HiveSchemaUtil.getDefaultValue(defaultStr, 
field.type());
+      if (!Objects.equals(expectedDefault, field.writeDefault())) {
+        difference.addDefaultChanged(field, expectedDefault);
+      }
+    } else if (field.type().isStructType()) {
+      Map<String, String> structDefaults = getDefaultValuesMap(defaultStr);
+
+      for (Types.NestedField nested : field.type().asStructType().fields()) {
+        getDefaultValDiff(nested, structDefaults, difference);
+      }
+    }
+  }

Review Comment:
   Can you please add a comment to explain what this method does?



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