【发布时间】:2016-12-02 15:50:09
【问题描述】:
我制作了一个简单的 UDF 来转换或从 spark 中 temptabl 中的时间字段中提取一些值。我注册了该函数,但是当我使用 sql 调用该函数时,它会引发 NullPointerException。以下是我的功能和执行过程。我正在使用齐柏林飞艇。奇怪的是,这昨天还在工作,但今天早上它停止工作了。
功能
def convert( time:String ) : String = {
val sdf = new java.text.SimpleDateFormat("HH:mm")
val time1 = sdf.parse(time)
return sdf.format(time1)
}
注册函数
sqlContext.udf.register("convert",convert _)
在没有 SQL 的情况下测试函数——这可行
convert(12:12:12) -> returns 12:12
在 Zeppelin 中使用 SQL 测试函数失败。
%sql
select convert(time) from temptable limit 10
temptable 的结构
root
|-- date: string (nullable = true)
|-- time: string (nullable = true)
|-- serverip: string (nullable = true)
|-- request: string (nullable = true)
|-- resource: string (nullable = true)
|-- protocol: integer (nullable = true)
|-- sourceip: string (nullable = true)
我得到的堆栈跟踪的一部分。
java.lang.NullPointerException
at org.apache.hadoop.hive.ql.exec.FunctionRegistry.getFunctionInfo(FunctionRegistry.java:643)
at org.apache.hadoop.hive.ql.exec.FunctionRegistry.getFunctionInfo(FunctionRegistry.java:652)
at org.apache.spark.sql.hive.HiveFunctionRegistry.lookupFunction(hiveUdfs.scala:54)
at org.apache.spark.sql.hive.HiveContext$$anon$3.org$apache$spark$sql$catalyst$analysis$OverrideFunctionRegistry$$super$lookupFunction(HiveContext.scala:376)
at org.apache.spark.sql.catalyst.analysis.OverrideFunctionRegistry$$anonfun$lookupFunction$2.apply(FunctionRegistry.scala:44)
at org.apache.spark.sql.catalyst.analysis.OverrideFunctionRegistry$$anonfun$lookupFunction$2.apply(FunctionRegistry.scala:44)
at scala.Option.getOrElse(Option.scala:120)
at org.apache.spark.sql.catalyst.analysis.OverrideFunctionRegistry$class.lookupFunction(FunctionRegistry.scala:44)
【问题讨论】:
标签: scala apache-spark apache-spark-sql apache-zeppelin