【问题标题】:Pig - Unhandled internal error NoClassDefFoundExceptionPig - 未处理的内部错误 NoClassDefFoundException
【发布时间】:2013-06-16 04:16:24
【问题描述】:

我遇到了一个特定的过滤问题(在此描述:Pig - How to manipulate and compare dates?),所以正如我们告诉我的,我决定编写自己的过滤 UDF。代码如下:

import java.io.IOException;

import org.apache.pig.FilterFunc;
import org.apache.pig.data.Tuple;

import org.joda.time.*;
import org.joda.time.format.*;

public class DateCloseEnough extends FilterFunc {


int nbmois;

/*
 * @param nbMois: if the number of months between two dates is inferior to this variable, then we consider that these two dates are close
 */
public DateCloseEnough(String nbmois_) {
    nbmois = Integer.valueOf(nbmois_);
}

public Boolean exec(Tuple input) throws IOException {

    // We're getting the date
    String date1 = (String)input.get(0);

    // We convert it into date
    final DateTimeFormatter dtf = DateTimeFormat.forPattern("MM yyyy");
    LocalDate d1 = new LocalDate();
    d1 = LocalDate.parse(date1, dtf);
    d1 = d1.withDayOfMonth(1);

    // We're getting today's date
    DateTime today = new DateTime();
    int mois = today.getMonthOfYear();
    String real_mois;
    if(mois >= 1 && mois <= 9) real_mois = "0" + mois;
    else real_mois = "" + mois;

    LocalDate d2 = new LocalDate();
    d2 = LocalDate.parse(real_mois + " " + today.getYear(), dtf);
    d2 = d2.withDayOfMonth(1);

    // Number of months between these two dates
    String nb_months_between = "" + Months.monthsBetween(d1,d2);

    return (Integer.parseInt(nb_months_between) <= nbmois);

}



}

我从 Eclipse 中创建了这段代码的 Jar 文件。

我正在使用这些 piglatin 代码行过滤我的数据:

REGISTER Desktop/myUDFs.jar
DEFINE DateCloseEnough DateCloseEnough('12');

experiences1 = LOAD '/home/training/Desktop/BDD/experience.txt' USING PigStorage(',') AS (id_cv:int, id_experience:int, date_deb:chararray, date_fin:chararray, duree:int, contenu_experience:chararray);

experiences = FILTER experiences1 BY DateCloseEnough(date_fin);

我正在使用这个 linux 命令启动我的程序:

pig -x local "myScript.pig"

我得到这个错误:

2013-06-19 07:27:17,253 [main] INFO  org.apache.pig.Main - Logging error messages to: /home/training/pig_1371652037252.log
2013-06-19 07:27:17,933 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 2998: Unhandled internal error. org/joda/time/ReadablePartial Details at logfile: /home/training/pig_1371652037252.log

我检查了日志文件,我看到了这个:

Pig Stack Trace

ERROR 2998: Unhandled internal error. org/joda/time/ReadablePartial

java.lang.NoClassDefFoundError: org/joda/time/ReadablePartial
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at org.apache.pig.impl.PigContext.resolveClassName(PigContext.java:441)
at org.apache.pig.impl.PigContext.instantiateFuncFromSpec(PigContext.java:471)
at org.apache.pig.impl.PigContext.instantiateFuncFromAlias(PigContext.java:544)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.EvalFuncSpec(QueryParser.java:4834)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.PUnaryCond(QueryParser.java:1949)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.PAndCond(QueryParser.java:1790)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.POrCond(QueryParser.java:1734)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.PCond(QueryParser.java:1700)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.FilterClause(QueryParser.java:1548)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.BaseExpr(QueryParser.java:1276)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.Expr(QueryParser.java:893)
at org.apache.pig.impl.logicalLayer.parser.QueryParser.Parse(QueryParser.java:682)
at org.apache.pig.impl.logicalLayer.LogicalPlanBuilder.parse(LogicalPlanBuilder.java:63)
at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1031)
at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:981)
at org.apache.pig.PigServer.registerQuery(PigServer.java:383)
at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:717)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:273)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:166)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:142)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:89)
at org.apache.pig.Main.main(Main.java:320)
Caused by: java.lang.ClassNotFoundException: org.joda.time.ReadablePartial
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 24 more

我试图修改我的 PIG_CLASSPATH 变量,但我发现这个变量根本不存在(虽然其他一些猪脚本正在工作)。

你有解决问题的想法吗?

谢谢。

【问题讨论】:

  • @zsxwing 谢谢,但它不会改变任何东西。
  • 您使用register path_to_joda-time-2.2.jar添加了joda-time-2.2.jar?
  • @zsxwing 不,我将它包含在我的 java 代码中
  • 如何将它包含在您的 java 代码中?解压 joda-time-2.2.jar 以合并到您的 jar 中,或者只是将整个 joda-time-2.2.jar 放入您的 jar 中?后者不起作用,因为 Pig 不处理这种情况。

标签: java hadoop user-defined-functions apache-pig


【解决方案1】:

首先,您需要告诉 Pig 您正在使用哪个 jar。请参阅此答案:how to include external jar file using PIG配置构建路径在eclipse中添加是不够的。 Eclipse 不会帮助您生成正确的 jar。

其次,String nb_months_between = "" + Months.monthsBetween(d1,d2); 是错误的。您可以使用int nb_months_between = Months.monthsBetween(d1,d2).getMonths();。如果您阅读 Months.toString,它会返回 "P" + String.valueOf(getValue()) + "M";。所以你不能使用这个值并想把它转换成一个int。

【讨论】:

  • 很好用。不过有点精确:命令“pig -Dpig.additional.jars=/local/path/to/your.jar”对我不起作用,你必须使用“register /local/path/to/your.jar ;"在你的猪脚本中。谢谢。
  • 抱歉,-Dpig.additional.jars 不需要绝对路径。你能用-Dpig.additional.jars粘贴你用来运行你的脚本的命令吗?例如,pig -Dpig.additional.jars=abc.jar:efg.jar -f abc.pig
  • 我只是在执行“pig -Dpig.additional.jars=abc.jar:efg.jar”而不启动脚本。这就是为什么它不起作用
【解决方案2】:

你需要这个包:org/joda/time/ReadablePartial

可以在这里找到:jarfinder 下载joda-time-1.5.jar。添加到您的项目中,这应该可以解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    相关资源
    最近更新 更多