Github user sitalkedia commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15064#discussion_r79239277
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveInspectors.scala ---
    @@ -238,102 +238,166 @@ private[hive] trait HiveInspectors {
         case c => throw new AnalysisException(s"Unsupported java type $c")
       }
     
    +  private def withNullSafe(f: Any => Any): Any => Any = {
    +    input => if (input == null) null else f(input)
    +  }
    +
       /**
        * 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 =>
    -      (o: Any) =>
    -        if (o != null) {
    -          val s = o.asInstanceOf[UTF8String].toString
    -          new HiveVarchar(s, s.length)
    -        } else {
    -          null
    -        }
    -
    -    case _: JavaHiveCharObjectInspector =>
    -      (o: Any) =>
    -        if (o != null) {
    -          val s = o.asInstanceOf[UTF8String].toString
    -          new HiveChar(s, s.length)
    -        } else {
    -          null
    -        }
    -
    -    case _: JavaHiveDecimalObjectInspector =>
    -      (o: Any) =>
    -        if (o != null) {
    -          HiveDecimal.create(o.asInstanceOf[Decimal].toJavaBigDecimal)
    -        } else {
    -          null
    -        }
    -
    -    case _: JavaDateObjectInspector =>
    -      (o: Any) =>
    -        if (o != null) {
    -          DateTimeUtils.toJavaDate(o.asInstanceOf[Int])
    -        } else {
    -          null
    -        }
    -
    -    case _: JavaTimestampObjectInspector =>
    +    case x: ConstantObjectInspector =>
           (o: Any) =>
    -        if (o != null) {
    -          DateTimeUtils.toJavaTimestamp(o.asInstanceOf[Long])
    -        } else {
    -          null
    -        }
    +        x.getWritableConstantValue
    +    case x: PrimitiveObjectInspector => x match {
    +      // TODO we don't support the HiveVarcharObjectInspector yet.
    +      case _: StringObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getStringWritable(o))
    +      case _: StringObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[UTF8String].toString())
    +      case _: IntObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getIntWritable(o))
    +      case _: IntObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Integer])
    +      case _: BooleanObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getBooleanWritable(o))
    +      case _: BooleanObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Boolean])
    +      case _: FloatObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getFloatWritable(o))
    +      case _: FloatObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Float])
    +      case _: DoubleObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getDoubleWritable(o))
    +      case _: DoubleObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Double])
    +      case _: LongObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getLongWritable(o))
    +      case _: LongObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Long])
    +      case _: ShortObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getShortWritable(o))
    +      case _: ShortObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Short])
    +      case _: ByteObjectInspector if x.preferWritable() =>
    +        withNullSafe(o => getByteWritable(o))
    +      case _: ByteObjectInspector =>
    +        withNullSafe(o => o.asInstanceOf[java.lang.Byte])
    +      case _: JavaHiveVarcharObjectInspector =>
    +        withNullSafe(
    --- End diff --
    
    Fixed, thanks.


---
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