运行UDF的scala代码时出现java.lang.NoClassDefFoundError问题

时间:2018-02-13 12:09:01

标签: scala hive ide user-defined-functions

我正在尝试在scala中编写一个UDF,以便获得两个日期之间的所有月份。这就是我写的。

package com.company.datediff

import org.apache.hadoop.hive.ql.exec.UDF
import java.time._

class hive_udf extends UDF {
  def evaluate(date1: String, date2: String): String = {
     val s1 = LocalDate.parse(date1)
     val s2=  LocalDate.parse(date2)
     val p = Period.between(s1, s2)
     val l=p.getMonths()
     val min1= s1.getMonthValue()
     val max1= s2.getMonthValue()
     var arr1=""
     for (i <- min1 to max1){
         arr1=arr1.concat(","+ i)    
     }
     /*var i=min1
     while (i<= max1){
       arr1=arr1.concat(","+ i)
       }*/
     return arr1 
     }
}

在没有for循环的情况下运行此代码时,代码运行完全正常。在包含for循环后,我得到'java.lang.NoClassDefFoundError'

  

执行错误,返回代码-101   “org.apache.hadoop.hive.ql.exec.FunctionTask。阶/功能1'

PFB完整错误的详细信息:

java.lang.NoClassDefFoundError: scala/Function1
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.apache.hadoop.hive.ql.exec.Registry.registerToSessionRegistry(Registry.java:518)
        at org.apache.hadoop.hive.ql.exec.Registry.registerPermanentFunction(Registry.java:207)
        at org.apache.hadoop.hive.ql.exec.FunctionRegistry.registerPermanentFunction(FunctionRegistry.java:1536)
        at org.apache.hadoop.hive.ql.exec.FunctionTask.createPermanentFunction(FunctionTask.java:136)
        at org.apache.hadoop.hive.ql.exec.FunctionTask.execute(FunctionTask.java:75)
        at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:160)
        at org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:89)
        at org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:1748)
        at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:1494)
        at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1291)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1158)
        at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1148)
        at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:217)
        at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:169)
        at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:380)
        at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:740)
        at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:685)
        at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.hadoop.util.RunJar.run(RunJar.java:233)
        at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
Caused by: java.lang.ClassNotFoundException: scala.Function1
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 26 more
FAILED: Execution Error, return code -101 from org.apache.hadoop.hive.ql.exec.FunctionTask. scala/Function1

我对Java或Scala的接触有限。不知道我哪里错了。任何帮助表示赞赏。感谢

0 个答案:

没有答案