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



##########
File path: core/src/main/java/org/apache/calcite/plan/RelOptUtil.java
##########
@@ -2199,13 +2199,57 @@ 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 "";
+    }
+
+    final int sourceFieldCount = source.getFieldCount();
+    final int targetFieldCount = target.getFieldCount();
+    if (sourceFieldCount != targetFieldCount) {
+      return "Type mismatch: the field size of source and target are not 
equal, "
+          + "the source type has " + sourceFieldCount + " fields, "
+          + "while the target type has " + targetFieldCount + " fields";

Review comment:
       The message does not help developers.
   
   Here's a long-standing issue for JUnit4 which was finally fixed in 4.13
   
https://github.com/junit-team/junit4/blob/HEAD/doc/ReleaseNotes4.13.md#pull-request-1300-show-contents-of-actual-array-when-array-lengths-differ
   
   > Previously, when comparing two arrays which differ in length, 
assertArrayEquals() would only report that they differ in length. Now, it does 
the usual array comparison even when arrays differ in length, producing a 
failure message which combines the difference in length and the first 
difference in content. Where the content is another array, it is described by 
its type and length
   
   That is why "source has 5 fields, target has 4 fields" is not really much 
better than "something is different", and it indeed is way worse than the 
previous error which produced full type dump. At least, there was a possibility 
to manually inspect and compare types, and now it is lost.




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