Github user arina-ielchiieva commented on a diff in the pull request:
https://github.com/apache/drill/pull/1085#discussion_r161208584
--- Diff: common/src/main/java/org/apache/drill/common/types/Types.java ---
@@ -728,4 +733,49 @@ public static boolean isLaterType(MajorType type) {
return type.getMinorType() == MinorType.LATE;
}
+ public static boolean isEquivalent(MajorType type1, MajorType type2) {
+
+ // Requires full type equality, including fields such as precision and
scale.
+ // But, unset fields are equivalent to 0. Can't use the
protobuf-provided
+ // isEquals() which treats set and unset fields as different.
+
+ if (type1.getMinorType() != type2.getMinorType() ||
+ type1.getMode() != type2.getMode() ||
+ type1.getScale() != type2.getScale() ||
+ type1.getPrecision() != type2.getPrecision()) {
+ return false;
+ }
+
+ // Subtypes are only for unions and are seldom used.
+
+ if (type1.getMinorType() != MinorType.UNION) {
+ return true;
+ }
+
+ List<MinorType> subtypes1 = type1.getSubTypeList();
+ List<MinorType> subtypes2 = type2.getSubTypeList();
+ if (subtypes1 == subtypes2) { // Only occurs if both are null
+ return true;
+ }
+ if (subtypes1 == null || subtypes2 == null) {
+ return false;
+ }
+ if (subtypes1.size() != subtypes2.size()) {
+ return false;
+ }
+
+ // Now it gets slow because subtype lists are not ordered.
+
+ List<MinorType> copy1 = new ArrayList<>();
+ List<MinorType> copy2 = new ArrayList<>();
+ copy1.addAll(subtypes1);
+ copy2.addAll(subtypes2);
+ Collections.sort(copy1);
+ Collections.sort(copy2);
+ return copy1.equals(copy2);
+ }
+
+ public static String typeKey(MinorType type) {
--- End diff --
Why we need this method? It looks like it is never used? If it's intended
for future use please add java doc then.
---