Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-2540] [SQL] Add HiveDecimal & HiveVarchar support in unwrapping data #1436

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion sql/hive/src/main/scala/org/apache/spark/sql/hive/hiveUdfs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package org.apache.spark.sql.hive

import scala.collection.mutable.ArrayBuffer

import org.apache.hadoop.hive.common.`type`.HiveDecimal
import org.apache.hadoop.hive.common.`type`.{HiveDecimal, HiveVarchar}
import org.apache.hadoop.hive.ql.exec.UDF
import org.apache.hadoop.hive.ql.exec.{FunctionInfo, FunctionRegistry}
import org.apache.hadoop.hive.ql.udf.{UDFType => HiveUDFType}
Expand Down Expand Up @@ -280,6 +280,16 @@ private[hive] case class HiveGenericUdf(name: String, children: Seq[Expression])
private[hive] trait HiveInspectors {

def unwrapData(data: Any, oi: ObjectInspector): Any = oi match {
case hvoi: HiveVarcharObjectInspector => if (data == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be a better way to write this:

    case hvoi: HiveVarcharObjectInspector =>
      if (data == null) null else hvoi.getPrimitiveJavaObject(data).getValue
    case hdoi: HiveDecimalObjectInspector =>
      if (data == null) null else BigDecimal(hdoi.getPrimitiveJavaObject(data).bigDecimalValue())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, cool. :)

null
} else {
hvoi.getPrimitiveJavaObject(data).getValue
}
case hdoi: HiveDecimalObjectInspector => if (data == null) {
null
} else {
BigDecimal(hdoi.getPrimitiveJavaObject(data).bigDecimalValue())
}
case pi: PrimitiveObjectInspector => pi.getPrimitiveJavaObject(data)
case li: ListObjectInspector =>
Option(li.getList(data))
Expand Down