voonhous commented on code in PR #17599:
URL: https://github.com/apache/hudi/pull/17599#discussion_r2651572665


##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaComparatorForSchemaEvolution.java:
##########
@@ -0,0 +1,371 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.common.schema;
+
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Defines equality comparison rules for HoodieSchema schemas for schema 
evolution purposes.
+ *
+ * <p>This class provides schema comparison logic that focuses only on 
attributes that affect
+ * data readers/writers, ignoring metadata like documentation, namespace, and 
aliases which
+ * don't impact schema evolution compatibility.</p>
+ *
+ * <h2>Common Rules Across All Types</h2>
+ * Included in equality check:
+ * <ul>
+ *   <li>Name/identifier</li>
+ *   <li>Type including primitive type, complex type (see below), and logical 
type</li>
+ * </ul>
+ * Excluded from equality check:
+ * <ul>
+ *   <li>Namespace</li>
+ *   <li>Documentation</li>
+ *   <li>Aliases</li>
+ *   <li>Custom properties</li>
+ * </ul>
+ *
+ * <h2>Type-Specific Rules</h2>
+ *
+ * <h3>Record</h3>
+ * Included:
+ * <ul>
+ *   <li>Field names</li>
+ *   <li>Field types</li>
+ *   <li>Field order attribute</li>
+ *   <li>Default values</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Field documentation</li>
+ *   <li>Field aliases</li>
+ * </ul>
+ *
+ * <h3>Enum</h3>
+ * Included:
+ * <ul>
+ *   <li>Name</li>
+ *   <li>Symbol order</li>
+ *   <li>Symbol value</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Custom properties</li>
+ * </ul>
+ *
+ * <h3>Array</h3>
+ * Included:
+ * <ul>
+ *   <li>Items schema</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Documentation</li>
+ *   <li>Custom properties</li>
+ * </ul>
+ *
+ * <h3>Map</h3>
+ * Included:
+ * <ul>
+ *   <li>Values schema</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Documentation</li>
+ *   <li>Custom properties</li>
+ * </ul>
+ *
+ * <h3>Fixed</h3>
+ * Included:
+ * <ul>
+ *   <li>Size</li>
+ *   <li>Name</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Namespace</li>
+ *   <li>Aliases</li>
+ * </ul>
+ *
+ * <h3>Union</h3>
+ * Included:
+ * <ul>
+ *   <li>Member types</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Member order</li>
+ * </ul>
+ *
+ * <h3>Logical Types</h3>
+ * Included:
+ * <ul>
+ *   <li>Logical type name (via schema subclass)</li>
+ *   <li>Underlying primitive type</li>
+ *   <li>Decimal precision/scale (if applicable)</li>
+ *   <li>Timestamp/Time precision (if applicable)</li>
+ * </ul>
+ * Excluded:
+ * <ul>
+ *   <li>Documentation</li>
+ *   <li>Custom properties</li>
+ * </ul>
+ */
+public class HoodieSchemaComparatorForSchemaEvolution {
+
+  protected HoodieSchemaComparatorForSchemaEvolution() {
+  }
+
+  private static final HoodieSchemaComparatorForSchemaEvolution VALIDATOR = 
new HoodieSchemaComparatorForSchemaEvolution();
+
+  public static boolean schemaEquals(HoodieSchema s1, HoodieSchema s2) {
+    return VALIDATOR.schemaEqualsInternal(s1, s2);
+  }
+
+  protected boolean schemaEqualsInternal(HoodieSchema s1, HoodieSchema s2) {
+    if (s1 == s2) {
+      return true;
+    }
+    if (s1 == null || s2 == null) {
+      return false;
+    }
+    if (s1.getType() != s2.getType()) {
+      return false;
+    }
+
+    switch (s1.getType()) {
+      case RECORD:
+        return recordSchemaEquals(s1, s2);
+      case ENUM:
+        return enumSchemaEquals(s1, s2);
+      case ARRAY:
+        return arraySchemaEquals(s1, s2);
+      case MAP:
+        return mapSchemaEquals(s1, s2);
+      case FIXED:
+        return fixedSchemaEquals(s1, s2);
+      case UNION:
+        return unionSchemaEquals(s1, s2);
+      case STRING:
+      case BYTES:
+      case INT:
+      case LONG:
+      case FLOAT:
+      case DOUBLE:
+      case BOOLEAN:
+      case NULL:
+        return primitiveSchemaEquals(s1, s2);
+      case DECIMAL:
+        return decimalSchemaEquals(s1, s2);
+      case TIME:
+        return timeSchemaEquals(s1, s2);
+      case TIMESTAMP:
+        return timestampSchemaEquals(s1, s2);
+      case DATE:
+      case UUID:
+        return logicalTypeSchemaEquals(s1, s2);

Review Comment:
   Done.



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