Pig Script在0.12.0上工作,但在0.11.1上不工作



我已经编写了这个pig脚本,它在0.12.0版本上运行得很好,但在0.11.1版本上无法运行我无法确定真正缺少的是什么。

data = LOAD '<file_name>' USING PigStorage(',') AS 
(Year,Month:int,DayofMonth,DayOfWeek,DepTime,CRSDepTime,ArrTime,CRSArrTime,UniqueCarrier,
    FlightNum,TailNum,ActualElapsedTime,CRSElapsedTime,AirTime,ArrDelay:int,DepDelay,Origin,
    Dest,Distance,TaxiIn,TaxiOut,Cancelled,CancellationCode,Diverted,CarrierDelay,
    WeatherDelay,NASDelay,SecurityDelay,LateAircraftDelay);
A = FILTER data BY (ArrDelay > 0);
X = GROUP A BY (Dest, Year, 
        (
            Case
                when Month>2 AND Month<6 THEN 'SPRING'
                when Month>5 AND Month<9 THEN 'SUMMER'
                when Month>8 AND Month<12 THEN 'FALL'
                when Month==12 OR (Month<3 AND Month>0) THEN 'WINTER'
            END
        )
    );
Y = FOREACH X GENERATE group.Dest, group.Year, group.$2, SUM(A.ArrDelay);
STORE Y INTO 'myoutput';

以下是运行脚本时出现的异常。

Pig Stack Trace
---------------
ERROR 1200: <file DelayBySeasonPerYear.pig, line 7, column 16>  Syntax error, unexpected symbol at or near 'Dest'
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1000: Error during parsing. <file DelayBySeasonPerYear.pig, line 7, column 16>  Syntax error, unexpected symbol at or near 'Dest'
    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1607)
    at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1546)
    at org.apache.pig.PigServer.registerQuery(PigServer.java:516)
    at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:991)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:412)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:194)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:170)
    at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
    at org.apache.pig.Main.run(Main.java:604)
    at org.apache.pig.Main.main(Main.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:160)
Caused by: Failed to parse: <file DelayBySeasonPerYear.pig, line 7, column 16>  Syntax error, unexpected symbol at or near 'Dest'
    at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:235)
    at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:177)
    at org.apache.pig.PigServer$Graph.parseQuery(PigServer.java:1599)
    ... 14 more

CASE最近才在0.12版本中实现。它在0.11中不可用。

参见:

  • https://issues.apache.org/jira/browse/PIG-3268(注意修复版本0.12)
  • http://hortonworks.com/blog/announcing-apache-pig-0-12/(关于0.12中的新功能的博客文章,其中之一是CASE

建议的解决方案:

编写一个UDF,该UDF接受Month值,然后返回一个带有写出的季节的chararray。然后,在FILTER之后的FOREACH语句中使用这个UDF。

...
A = FILTER data BY (ArrDelay > 0);
A = FOREACH A GENERATE MySeasonUDF(Month) as Season, Dest, Year, ArrDelay;
X = GROUP A BY (Dest, Year, Season);
...

相关内容

  • 没有找到相关文章

最新更新