FAQ
Repository: hive
Updated Branches:
   refs/heads/master 5edbf31a7 -> 6433c3b0b


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/master
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);

Search Discussions

  • Jxiang at Aug 18, 2015 at 4:21 pm
    Repository: hive
    Updated Branches:
       refs/heads/branch-1 95fdf09c4 -> beb8e34a8


    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/beb8e34a
    Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/beb8e34a
    Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/beb8e34a

    Branch: refs/heads/branch-1
    Commit: beb8e34a855f37784c07b6ff079d5df77037805f
    Parents: 95fdf09
    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 09:13:26 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/beb8e34a/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/beb8e34a/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);

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedAug 18, '15 at 4:11p
activeAug 18, '15 at 4:21p
posts2
users1
websitehive.apache.org

1 user in discussion

Jxiang: 2 posts

People

Translate

site design / logo © 2021 Grokbase