dump不适用于pigrunner

时间:2013-04-28 06:48:28

标签: java hadoop apache-pig

以下是我的代码,它运行pigrunner和pigstats:

    String[] args = {"abc.pig"};
    PigStats stats = PigRunner.run(args,null);

    System.out.println("Stats : " + stats.getReturnCode());

    OutputStats os = stats.result("B");

    Iterator<Tuple> it = os.iterator();

    while(it.hasNext()){
        Tuple t = it.next();
        System.out.println(t.getAll());
    }

abc.pig的内容

A = load 'Courses' using PigStorage(' ');
B = foreach A generate $0 as id;
dump B;

我得到了正确的输出,但后面是带有根本原因的异常Stacktrace

org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: hdfs://localhost:54310/tmp/temp-221133443/tmp1478461116
  at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.listStatus(FileInputFormat.java:235)
  at org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigFileInputFormat.listStatus(PigFileInputFormat.java:37)
  at org.apache.hadoop.mapreduce.lib.input.FileInputFormat.getSplits(FileInputFormat.java:252)
  at org.apache.pig.impl.io.ReadToEndLoader.init(ReadToEndLoader.java:154)
  at org.apache.pig.impl.io.ReadToEndLoader.<init>(ReadToEndLoader.java:116)
  at org.apache.pig.tools.pigstats.OutputStats.iterator(OutputStats.java:148)
  at org.apache.jsp.result_jsp._jspService(result_jsp.java:86)
  at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
  at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
  at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
  at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
  at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
  at java.lang.Thread.run(Thread.java:662)

现在,如果我用存储替换DUMP,相同的代码可以正常运行。

有些人可以解释一下发生了什么吗?

由于 拉维

1 个答案:

答案 0 :(得分:3)

如果转储Pig将输出存储在临时位置,例如:hdfs:// localhost / tmp / temp797130848 / tmp1101984728 (在你的工作的config.xml中查看pig.map.output.dirs

PigRunner.run()在进程的某个时刻调用GruntParser.processDump(String alias),迭代结果元组并将它们打印到控制台:

Iterator<Tuple> result = mPigServer.openIterator(alias);
while (result.hasNext())
{
  Tuple t = result.next();
  System.out.println(TupleFormat.format(t));
}

在此之后,但在返回之前,它还会调用FileLocalizer.deleteTempFiles()删除此临时目录。

现在您想要返回别名 B 的结果。 OutputStats的迭代器尝试再次打开临时文件以循环遍历元组PigRunner.run()之前执行过。 但问题是这个文件不再存在,因此你得到了例外。

所以我建议您删除System.out.println("Stats : " + stats.getReturnCode());之后的代码,因为您已经打印了转储。