以下是我运行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替换为STORE,则相同的代码可以正常工作而不会出现错误。
可以请我解释一下发生了什么吗?
谢谢
拉维
最佳答案
如果发生转储,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());
之后的代码,因为您已经打印了转储文件。