Github user hvanhovell commented on a diff in the pull request:
https://github.com/apache/spark/pull/13676#discussion_r67636421
--- Diff:
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveInspectors.scala ---
@@ -479,8 +340,299 @@ private[hive] trait HiveInspectors {
}
/**
- * Builds specific unwrappers ahead of time according to object inspector
+ * Builds unwrappers ahead of time according to object inspector
* types to avoid pattern matching and branching costs per row.
+ *
+ * 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.
+ *
+ * @param objectInspector the ObjectInspector used to create an
unwrapper.
+ * @return A function that unwraps data objects.
+ * Use the overloaded HiveStructField version for in-place
updating of a MutableRow.
+ */
+ 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()
--- End diff --
Isn't it faster to call `poi.getWritableConstantValue.get()` outside of the
function? And use the result in the function? Or am I missing something here?
The same goes for all other constants.
---
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]