Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id E0C02200C4E for ; Thu, 23 Mar 2017 04:07:12 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DF55C160B91; Thu, 23 Mar 2017 03:07:12 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2FCAD160B86 for ; Thu, 23 Mar 2017 04:07:12 +0100 (CET) Received: (qmail 78124 invoked by uid 500); 23 Mar 2017 03:07:11 -0000 Mailing-List: contact commits-help@arrow.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@arrow.apache.org Delivered-To: mailing list commits@arrow.apache.org Received: (qmail 78115 invoked by uid 99); 23 Mar 2017 03:07:11 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Mar 2017 03:07:11 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id D5173DFE34; Thu, 23 Mar 2017 03:07:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: wesm@apache.org To: commits@arrow.apache.org Message-Id: <72dbf879e94e49feb4c18ec8c40c1e6b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: arrow git commit: ARROW-454: pojo.Field doesn't implement hashCode() Date: Thu, 23 Mar 2017 03:07:10 +0000 (UTC) archived-at: Thu, 23 Mar 2017 03:07:13 -0000 Repository: arrow Updated Branches: refs/heads/master 2406d4eed -> bf2acf6cb ARROW-454: pojo.Field doesn't implement hashCode() Author: Julien Le Dem 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 Authored: Wed Mar 22 23:07:05 2017 -0400 Committer: Wes McKinney 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>, ); + return java.util.Arrays.deepHashCode(new Object[] {<#list type.fields as field>${field.name}<#if field_has_next>, }); } @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 schemaFields, List 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 {