You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/03/23 03:07:10 UTC

arrow git commit: ARROW-454: pojo.Field doesn't implement hashCode()

Repository: arrow
Updated Branches:
  refs/heads/master 2406d4eed -> bf2acf6cb


ARROW-454: pojo.Field doesn't implement hashCode()

Author: Julien Le Dem <ju...@dremio.com>

Closes #423 from julienledem/field_hashcode and squashes the following commits:

192a689 [Julien Le Dem] ARROW-454: pojo.Field doesn't implement hashCode()


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/bf2acf6c
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/bf2acf6c
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/bf2acf6c

Branch: refs/heads/master
Commit: bf2acf6cb22b8d2bf6d0fb98a6117e78e92b81fe
Parents: 2406d4e
Author: Julien Le Dem <ju...@dremio.com>
Authored: Wed Mar 22 23:07:05 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Wed Mar 22 23:07:05 2017 -0400

----------------------------------------------------------------------
 .../src/main/codegen/templates/ArrowType.java   |  2 +-
 .../apache/arrow/vector/types/pojo/Field.java   | 29 +++++++++++---------
 .../arrow/vector/types/pojo/TestSchema.java     | 22 +++++++++++++++
 3 files changed, 39 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/bf2acf6c/java/vector/src/main/codegen/templates/ArrowType.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/codegen/templates/ArrowType.java b/java/vector/src/main/codegen/templates/ArrowType.java
index 85ea389..91cbe98 100644
--- a/java/vector/src/main/codegen/templates/ArrowType.java
+++ b/java/vector/src/main/codegen/templates/ArrowType.java
@@ -164,7 +164,7 @@ public abstract class ArrowType {
 
     @Override
     public int hashCode() {
-      return Objects.hash(<#list type.fields as field>${field.name}<#if field_has_next>, </#if></#list>);
+      return java.util.Arrays.deepHashCode(new Object[] {<#list type.fields as field>${field.name}<#if field_has_next>, </#if></#list>});
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/arrow/blob/bf2acf6c/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java
----------------------------------------------------------------------
diff --git a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java
index bbbd559..c310b90 100644
--- a/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java
+++ b/java/vector/src/main/java/org/apache/arrow/vector/types/pojo/Field.java
@@ -24,14 +24,6 @@ import static org.apache.arrow.vector.types.pojo.ArrowType.getTypeForField;
 import java.util.List;
 import java.util.Objects;
 
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableList;
-import com.google.flatbuffers.FlatBufferBuilder;
-
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.vector.FieldVector;
 import org.apache.arrow.vector.schema.TypeLayout;
@@ -40,6 +32,14 @@ import org.apache.arrow.vector.types.Types;
 import org.apache.arrow.vector.types.Types.MinorType;
 import org.apache.arrow.vector.types.pojo.ArrowType.Int;
 
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import com.google.flatbuffers.FlatBufferBuilder;
+
 public class Field {
   private final String name;
   private final boolean nullable;
@@ -177,18 +177,21 @@ public class Field {
   }
 
   @Override
+  public int hashCode() {
+    return Objects.hash(name, nullable, type, dictionary, children);
+  }
+
+  @Override
   public boolean equals(Object obj) {
     if (!(obj instanceof Field)) {
       return false;
     }
     Field that = (Field) obj;
     return Objects.equals(this.name, that.name) &&
-            Objects.equals(this.nullable, that.nullable) &&
-            Objects.equals(this.type, that.type) &&
+           Objects.equals(this.nullable, that.nullable) &&
+           Objects.equals(this.type, that.type) &&
            Objects.equals(this.dictionary, that.dictionary) &&
-            (Objects.equals(this.children, that.children) ||
-                    (this.children == null || this.children.size() == 0) &&
-                    (that.children == null || that.children.size() == 0));
+           Objects.equals(this.children, that.children);
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/arrow/blob/bf2acf6c/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
----------------------------------------------------------------------
diff --git a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
index 5b74c54..a7d1cce 100644
--- a/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
+++ b/java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestSchema.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
+import java.util.List;
 
 import org.apache.arrow.vector.types.FloatingPointPrecision;
 import org.apache.arrow.vector.types.IntervalUnit;
@@ -125,6 +126,27 @@ public class TestSchema {
     Schema actual = Schema.fromJSON(json);
     assertEquals(schema.toJson(), actual.toJson());
     assertEquals(schema, actual);
+    validateFieldsHashcode(schema.getFields(), actual.getFields());
+    assertEquals(schema.hashCode(), actual.hashCode());
+  }
+
+  private void validateFieldsHashcode(List<Field> schemaFields, List<Field> actualFields) {
+    assertEquals(schemaFields.size(), actualFields.size());
+    if (schemaFields.size() == 0) {
+      return;
+    }
+    for (int i = 0; i < schemaFields.size(); i++) {
+      Field schemaField = schemaFields.get(i);
+      Field actualField = actualFields.get(i);
+      validateFieldsHashcode(schemaField.getChildren(), actualField.getChildren());
+      validateHashCode(schemaField.getType(), actualField.getType());
+      validateHashCode(schemaField, actualField);
+    }
+  }
+
+  private void validateHashCode(Object o1, Object o2) {
+    assertEquals(o1, o2);
+    assertEquals(o1 + " == " + o2, o1.hashCode(), o2.hashCode());
   }
 
   private void contains(Schema schema, String... s) throws IOException {