hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject [26/50] [abbrv] hive git commit: HIVE-11580: ThriftUnionObjectInspector#toString throws NPE (Jimmy, reviewed by Chao)
Date Tue, 25 Aug 2015 21:28:56 GMT
HIVE-11580: ThriftUnionObjectInspector#toString throws NPE (Jimmy, reviewed by Chao)


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

Branch: refs/heads/llap
Commit: 6433c3b0b8e305c8dddc6ea2fe94cfcd5062e40d
Parents: 5edbf31
Author: Jimmy Xiang <jxiang@cloudera.com>
Authored: Fri Aug 14 15:48:23 2015 -0700
Committer: Jimmy Xiang <jxiang@cloudera.com>
Committed: Tue Aug 18 08:49:21 2015 -0700

----------------------------------------------------------------------
 .../ThriftUnionObjectInspector.java             | 26 ++++++++++----------
 .../TestThriftObjectInspectors.java             | 10 ++++++--
 2 files changed, 21 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/6433c3b0/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftUnionObjectInspector.java
----------------------------------------------------------------------
diff --git a/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftUnionObjectInspector.java
b/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftUnionObjectInspector.java
index 17add28..600abbb 100644
--- a/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftUnionObjectInspector.java
+++ b/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ThriftUnionObjectInspector.java
@@ -18,18 +18,18 @@
 
 package org.apache.hadoop.hive.serde2.objectinspector;
 
-import com.google.common.primitives.UnsignedBytes;
-import org.apache.hadoop.util.ReflectionUtils;
-import org.apache.thrift.TFieldIdEnum;
-import org.apache.thrift.TUnion;
-import org.apache.thrift.meta_data.FieldMetaData;
-
 import java.lang.reflect.Field;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.thrift.TFieldIdEnum;
+import org.apache.thrift.TUnion;
+import org.apache.thrift.meta_data.FieldMetaData;
+
+import com.google.common.primitives.UnsignedBytes;
+
 /**
  * Always use the ObjectInspectorFactory to create new ObjectInspector objects,
  * instead of directly creating an instance of this class.
@@ -37,7 +37,8 @@ import java.util.Map;
 public class ThriftUnionObjectInspector extends ReflectionStructObjectInspector implements
UnionObjectInspector {
 
   private static final String FIELD_METADATA_MAP = "metaDataMap";
-  private  List<ObjectInspector> ois;
+  private List<ObjectInspector> ois;
+  private List<StandardStructObjectInspector.MyField> fields;
 
   @Override
   public boolean shouldIgnoreField(String name) {
@@ -88,10 +89,14 @@ public class ThriftUnionObjectInspector extends ReflectionStructObjectInspector
 
     try {
       final Map<? extends TFieldIdEnum, FieldMetaData> fieldMap = (Map<? extends
TFieldIdEnum, FieldMetaData>) fieldMetaData.get(null);
+      fields = new ArrayList<StandardStructObjectInspector.MyField>(fieldMap.size());
       this.ois = new ArrayList<ObjectInspector>();
       for(Map.Entry<? extends TFieldIdEnum, FieldMetaData> metadata : fieldMap.entrySet())
{
-        final Type fieldType = ThriftObjectInspectorUtils.getFieldType(objectClass, metadata.getValue().fieldName);
+        int fieldId = metadata.getKey().getThriftFieldId();
+        String fieldName = metadata.getValue().fieldName;
+        final Type fieldType = ThriftObjectInspectorUtils.getFieldType(objectClass, fieldName);
         final ObjectInspector reflectionObjectInspector = ObjectInspectorFactory.getReflectionObjectInspector(fieldType,
options);
+        fields.add(new StandardStructObjectInspector.MyField(fieldId, fieldName, reflectionObjectInspector));
         this.ois.add(reflectionObjectInspector);
       }
     } catch (IllegalAccessException e) {
@@ -112,10 +117,5 @@ public class ThriftUnionObjectInspector extends ReflectionStructObjectInspector
   public String getTypeName() {
     return ObjectInspectorUtils.getStandardUnionTypeName(this);
   }
-
-  @Override
-  public Object create() {
-    return ReflectionUtils.newInstance(objectClass, null);
-  }
 }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/6433c3b0/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java
----------------------------------------------------------------------
diff --git a/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java
b/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java
index 968cd22..85f2bd6 100644
--- a/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java
+++ b/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestThriftObjectInspectors.java
@@ -23,14 +23,15 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
-import junit.framework.TestCase;
-
 import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category;
 import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
 import org.apache.hadoop.hive.serde2.thrift.test.Complex;
 import org.apache.hadoop.hive.serde2.thrift.test.IntString;
+import org.apache.hadoop.hive.serde2.thrift.test.PropValueUnion;
 import org.apache.hadoop.hive.serde2.thrift.test.SetIntString;
 
+import junit.framework.TestCase;
+
 /**
  * TestThriftObjectInspectors.
  *
@@ -60,6 +61,11 @@ public class TestThriftObjectInspectors extends TestCase {
         assertNull(soi.getStructFieldData(null, fields.get(i)));
       }
 
+      ObjectInspector oi = ObjectInspectorFactory
+          .getReflectionObjectInspector(PropValueUnion.class,
+          ObjectInspectorFactory.ObjectInspectorOptions.THRIFT);
+      assertNotNull(oi.toString());
+
       // real object
       Complex c = new Complex();
       c.setAint(1);


Mime
View raw message