Github user parthchandra commented on a diff in the pull request:
https://github.com/apache/drill/pull/914#discussion_r149765040
--- Diff:
exec/vector/src/main/java/org/apache/drill/exec/record/MaterializedField.java
---
@@ -168,6 +174,58 @@ public boolean equals(Object obj) {
Objects.equals(this.type, other.type);
}
+ public boolean isEquivalent(MaterializedField other) {
+ if (! name.equalsIgnoreCase(other.name)) {
+ return false;
+ }
+
+ // 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(), that treats set and unset fields as different.
+
+ if (type.getMinorType() != other.type.getMinorType()) {
+ return false;
+ }
+ if (type.getMode() != other.type.getMode()) {
+ return false;
+ }
+ if (type.getScale() != other.type.getScale()) {
+ return false;
+ }
+ if (type.getPrecision() != other.type.getPrecision()) {
+ return false;
+ }
+
+ // Compare children -- but only for maps, not the internal children
+ // for Varchar, repeated or nullable types.
+
+ if (type.getMinorType() != MinorType.MAP) {
+ return true;
+ }
+
+ if (children == null || other.children == null) {
+ return children == other.children;
+ }
+ if (children.size() != other.children.size()) {
+ return false;
+ }
+
+ // Maps are name-based, not position. But, for our
+ // purposes, we insist on identical ordering.
+
+ Iterator<MaterializedField> thisIter = children.iterator();
+ Iterator<MaterializedField> otherIter = other.children.iterator();
+ while (thisIter.hasNext()) {
--- End diff --
isEquivalent requires identical ordering which is a stronger requirement
than the guarantee that the children list is providing. Could we use contains()
to find the child and then apply isEquivalent recursively?
---