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

    https://github.com/apache/spark/pull/13676#discussion_r67281085
  
    --- Diff: 
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveInspectors.scala ---
    @@ -479,7 +354,287 @@ private[hive] trait HiveInspectors {
       }
     
       /**
    -   * Builds specific unwrappers ahead of time according to object inspector
    +   * Strictly follows the following order in unwrapping (constant OI has 
the higher priority):
    +   * Constant Null object inspector =>
    +   *   return null
    +   * Constant object inspector =>
    +   *   extract the value from constant object inspector
    +   * If object inspector prefers writable =>
    +   *   extract writable from `data` and then get the catalyst type from 
the writable
    +   * Extract the java object directly from the object inspector
    +   *
    +   * NOTICE: the complex data type requires recursive unwrapping.
    +   */
    +  def unwrapperFor(objectInspector: ObjectInspector): Any => Any =
    +    objectInspector match {
    +      case coi: ConstantObjectInspector if coi.getWritableConstantValue == 
null =>
    +        data: Any => null
    +      case poi: WritableConstantStringObjectInspector =>
    +        data: Any =>
    +          UTF8String.fromString(poi.getWritableConstantValue.toString)
    +      case poi: WritableConstantHiveVarcharObjectInspector =>
    +        data: Any =>
    +          
UTF8String.fromString(poi.getWritableConstantValue.getHiveVarchar.getValue)
    +      case poi: WritableConstantHiveCharObjectInspector =>
    +        data: Any =>
    +          
UTF8String.fromString(poi.getWritableConstantValue.getHiveChar.getValue)
    +      case poi: WritableConstantHiveDecimalObjectInspector =>
    +        data: Any =>
    +          HiveShim.toCatalystDecimal(
    +            PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector,
    +            poi.getWritableConstantValue.getHiveDecimal)
    +      case poi: WritableConstantTimestampObjectInspector =>
    +        data: Any => {
    +          val t = poi.getWritableConstantValue
    +          t.getSeconds * 1000000L + t.getNanos / 1000L
    +        }
    +      case poi: WritableConstantIntObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantDoubleObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantBooleanObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantLongObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantFloatObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantShortObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantByteObjectInspector =>
    +        data: Any =>
    +          poi.getWritableConstantValue.get()
    +      case poi: WritableConstantBinaryObjectInspector =>
    +        data: Any => {
    +          val writable = poi.getWritableConstantValue
    +          val temp = new Array[Byte](writable.getLength)
    +          System.arraycopy(writable.getBytes, 0, temp, 0, temp.length)
    +          temp
    +        }
    +      case poi: WritableConstantDateObjectInspector =>
    +        data: Any =>
    +          DateTimeUtils.fromJavaDate(poi.getWritableConstantValue.get())
    +      case mi: StandardConstantMapObjectInspector =>
    +        val keyUnwrapper = unwrapperFor(mi.getMapKeyObjectInspector)
    +        val valueUnwrapper = unwrapperFor(mi.getMapValueObjectInspector)
    +        data: Any => {
    +          // take the value from the map inspector object, rather than the 
input data
    +          val keyValues = mi.getWritableConstantValue.asScala.toSeq
    +          val keys = keyValues.map(kv => keyUnwrapper(kv._1)).toArray
    +          val values = keyValues.map(kv => valueUnwrapper(kv._2)).toArray
    +          ArrayBasedMapData(keys, values)
    +        }
    +      case li: StandardConstantListObjectInspector =>
    +        val unwrapper = unwrapperFor(li.getListElementObjectInspector)
    +        data: Any => {
    +          // take the value from the list inspector object, rather than 
the input data
    +          val values = li.getWritableConstantValue.asScala
    +            .map(unwrapper)
    +            .toArray
    +          new GenericArrayData(values)
    +        }
    +      case poi: VoidObjectInspector =>
    +        data: Any =>
    +          null // always be null for void object inspector
    +      case pi: PrimitiveObjectInspector => pi match {
    +        // We think HiveVarchar/HiveChar is also a String
    +        case hvoi: HiveVarcharObjectInspector if hvoi.preferWritable() =>
    +          data: Any => {
    +            if (data != null) {
    --- End diff --
    
    i think the problem there is it might hurt perf.



---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to