在apache pig

时间:2016-12-09 01:33:44

标签: apache-pig

我正在尝试学习Apache Pig。如果这是一个蹩脚的问题,我很抱歉。

我有三列sitenameupcountdowncount

当我使用describe res时,我得到:res: {sitename: chararray,upcount: int,downcount: int}

我要做的是通过upcount查找upcount/(upcount+downcount)的网站站点百分比 我无法弄清楚如何实现它。我试过以下:

res_sum = foreach res generate sitename, upcount+downcount;

但它出现了以下错误:

Pig Stack Trace
---------------
ERROR 1066: Unable to open iterator for alias res_sum

org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias res_sum
    at org.apache.pig.PigServer.openIterator(PigServer.java:935)
    at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:754)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:376)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:230)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:205)
    at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:66)
    at org.apache.pig.Main.run(Main.java:565)
    at org.apache.pig.Main.main(Main.java:177)
    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:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.io.IOException: Job terminated with anomalous status FAILED
    at org.apache.pig.PigServer.openIterator(PigServer.java:927)
    ... 13 more
================================================================================

1 个答案:

答案 0 :(得分:1)

尝试

res_sum = foreach res generate sitename, (upcount + downcount) as ud_sum;

如果不起作用 - 显示整个脚本