hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xu...@apache.org
Subject [25/43] hive git commit: HIVE-11288: Avro SerDe InstanceCache returns incorrect schema (Greg via Xuefu)
Date Fri, 31 Jul 2015 00:43:25 GMT
HIVE-11288: Avro SerDe InstanceCache returns incorrect schema (Greg via Xuefu)


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

Branch: refs/heads/spark
Commit: d2ee3543474b15d04bb3be3cdf0ad987338418a1
Parents: 65396f0
Author: xzhang <xzhang@xzdt>
Authored: Tue Jul 28 11:39:37 2015 -0700
Committer: xzhang <xzhang@xzdt>
Committed: Tue Jul 28 11:40:38 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hive/serde2/avro/InstanceCache.java  |  9 +++--
 .../hive/serde2/avro/TestInstanceCache.java     | 40 +++++++++++++-------
 2 files changed, 32 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/d2ee3543/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
----------------------------------------------------------------------
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java b/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
index 0b10d99..c7289cb 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/avro/InstanceCache.java
@@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import java.util.HashMap;
+import java.util.Map;
 import java.util.Set;
 
 /**
@@ -33,7 +34,7 @@ import java.util.Set;
  */
 public abstract class InstanceCache<SeedObject, Instance> {
   private static final Log LOG = LogFactory.getLog(InstanceCache.class);
-  HashMap<Integer, Instance> cache = new HashMap<Integer, Instance>();
+  Map<SeedObject, Instance> cache = new HashMap<SeedObject, Instance>();
   
   public InstanceCache() {}
 
@@ -53,15 +54,15 @@ public abstract class InstanceCache<SeedObject, Instance> {
       Set<SeedObject> seenSchemas) throws AvroSerdeException {
     if(LOG.isDebugEnabled()) LOG.debug("Checking for hv: " + hv.toString());
 
-    if(cache.containsKey(hv.hashCode())) {
+    if(cache.containsKey(hv)) {
       if(LOG.isDebugEnabled()) LOG.debug("Returning cache result.");
-      return cache.get(hv.hashCode());
+      return cache.get(hv);
     }
 
     if(LOG.isDebugEnabled()) LOG.debug("Creating new instance and storing in cache");
 
     Instance instance = makeInstance(hv, seenSchemas);
-    cache.put(hv.hashCode(), instance);
+    cache.put(hv, instance);
     return instance;
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/d2ee3543/serde/src/test/org/apache/hadoop/hive/serde2/avro/TestInstanceCache.java
----------------------------------------------------------------------
diff --git a/serde/src/test/org/apache/hadoop/hive/serde2/avro/TestInstanceCache.java b/serde/src/test/org/apache/hadoop/hive/serde2/avro/TestInstanceCache.java
index 814e8e4..cb7c6ed 100644
--- a/serde/src/test/org/apache/hadoop/hive/serde2/avro/TestInstanceCache.java
+++ b/serde/src/test/org/apache/hadoop/hive/serde2/avro/TestInstanceCache.java
@@ -24,9 +24,23 @@ import static org.junit.Assert.assertSame;
 
 public class TestInstanceCache {
   private static class Foo {
+
+    private int value = 42;
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) return true;
+      if (o == null || getClass() != o.getClass()) return false;
+
+      Foo foo = (Foo) o;
+
+      return value == foo.value;
+
+    }
+
     @Override
     public int hashCode() {
-      return 42;
+      return value;
     }
   }
 
@@ -41,12 +55,12 @@ public class TestInstanceCache {
   @Test
   public void instanceCachesOnlyCreateOneInstance() throws AvroSerdeException {
     InstanceCache<Foo, Wrapper<Foo>> ic = new InstanceCache<Foo, Wrapper<Foo>>()
{
-                                           @Override
-                                           protected Wrapper makeInstance(Foo hv,
-                                               Set<Foo> seenSchemas) {
-                                             return new Wrapper(hv);
-                                           }
-                                          };
+      @Override
+      protected Wrapper makeInstance(Foo hv,
+                                     Set<Foo> seenSchemas) {
+        return new Wrapper(hv);
+      }
+    };
     Foo f1 = new Foo();
 
     Wrapper fc = ic.retrieve(f1, null);
@@ -62,12 +76,12 @@ public class TestInstanceCache {
   @Test
   public void instanceCacheReturnsCorrectInstances() throws AvroSerdeException {
     InstanceCache<String, Wrapper<String>> ic = new InstanceCache<String,
Wrapper<String>>() {
-                                   @Override
-                                   protected Wrapper<String> makeInstance(
-                                       String hv, Set<String> seenSchemas) {
-                                     return new Wrapper<String>(hv);
-                                   }
-                                 };
+      @Override
+      protected Wrapper<String> makeInstance(
+          String hv, Set<String> seenSchemas) {
+        return new Wrapper<String>(hv);
+      }
+    };
 
     Wrapper<String> one = ic.retrieve("one", null);
     Wrapper<String> two = ic.retrieve("two", null);


Mime
View raw message