liyafan82 commented on a change in pull request #2224:
URL: https://github.com/apache/calcite/pull/2224#discussion_r508346994



##########
File path: core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
##########
@@ -2199,13 +2199,49 @@ public static boolean equal(
       RelDataType type2,
       Litmus litmus) {
     if (!areRowTypesEqual(type1, type2, false)) {
-      return litmus.fail("Type mismatch:\n{}:\n{}\n{}:\n{}",
+      return litmus.fail("Type mismatch:\n{}:\n{}\n{}:\n{}\ndifference:\n{}",
           desc1, type1.getFullTypeString(),
-          desc2, type2.getFullTypeString());
+          desc2, type2.getFullTypeString(),
+          getFullTypeDifferenceString(type1, type2));
     }
     return litmus.succeed();
   }
 
+  public static String getFullTypeDifferenceString(RelDataType source,
+      RelDataType target) {
+    if (source == target) {
+      return "";
+    }
+
+    if (source.getFieldCount() > target.getFieldCount()) {
+      return "Type mismatch: the target type has less fields than the source 
type";
+    } else if (source.getFieldCount() < target.getFieldCount()) {
+      return "Type mismatch: the target type has more fields than the source 
type";
+    }
+
+    final StringBuilder stringBuilder = new StringBuilder("Type mismatch: \n");
+    final List<RelDataTypeField> f1 = source.getFieldList();
+    final List<RelDataTypeField> f2 = target.getFieldList();
+    for (Pair<RelDataTypeField, RelDataTypeField> pair : Pair.zip(f1, f2)) {
+      final RelDataType type1 = pair.left.getType();
+      final RelDataType type2 = pair.right.getType();
+      // If one of the types is ANY comparison should succeed
+      if (type1.getSqlTypeName() == SqlTypeName.ANY
+          || type2.getSqlTypeName() == SqlTypeName.ANY) {
+        continue;
+      }
+      if (!type1.equals(type2)) {
+        stringBuilder.append(pair.left.getName());
+        stringBuilder.append(": ");
+        stringBuilder.append(type1.getFullTypeString());
+        stringBuilder.append(" -> ");
+        stringBuilder.append(type2.getFullTypeString());
+        stringBuilder.append("\n");
+      }
+    }
+    return stringBuilder.toString();

Review comment:
       If stringBuilder is not empty, we should add the prefix "Type mismatch"?




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

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


Reply via email to