Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15064#discussion_r79103035
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveInspectors.scala ---
    @@ -240,74 +240,173 @@ private[hive] trait HiveInspectors {
     
       /**
        * Wraps with Hive types based on object inspector.
    -   * TODO: Consolidate all hive OI/data interface code.
        */
       protected def wrapperFor(oi: ObjectInspector, dataType: DataType): Any 
=> Any = oi match {
    -    case _: JavaHiveVarcharObjectInspector =>
    +    case x: ConstantObjectInspector =>
           (o: Any) =>
    -        if (o != null) {
    -          val s = o.asInstanceOf[UTF8String].toString
    -          new HiveVarchar(s, s.length)
    -        } else {
    -          null
    +        x.getWritableConstantValue
    +    case x: PrimitiveObjectInspector => x match {
    +      // TODO we don't support the HiveVarcharObjectInspector yet.
    +      case _: StringObjectInspector if x.preferWritable() =>
    +        (o: Any) => getStringWritable(o)
    +      case _: StringObjectInspector =>
    +        (o: Any) => if (o != null) o.asInstanceOf[UTF8String].toString() 
else null
    +      case _: IntObjectInspector if x.preferWritable() =>
    +        (o: Any) => getIntWritable(o)
    +      case _: IntObjectInspector =>
    +        (o: Any) => if (o != null) o.asInstanceOf[java.lang.Integer] else 
null
    --- End diff --
    
    Let's add a helper method to abstract this null checking logic, e.g.
    ```
    def withNullSafe(f: Any => Any): Any => Any = {
      input => if (input == null) null else f(null)
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to