2014-10-31 74 views
1

當我嘗試在Pig查詢下運行時,使用SORT命令時出現錯誤。如果我省略SORT轉換,那麼查詢就能夠執行。Apache Pig錯誤 - 無法跟蹤

grunt> month1 = LOAD 'hdfs://localhost.localdomain:8020/user/cloudera/data/big1/climate_month1.txt' USING PigStorage(','); 

grunt> month2 = LOAD 'hdfs://localhost.localdomain:8020/user/cloudera/data/big1/climate_month2.txt' USING PigStorage(','); 

grunt> month3 = LOAD 'hdfs://localhost.localdomain:8020/user/cloudera/data/big1/climate_month3.txt' USING PigStorage(','); 

grunt> month4 = LOAD 'hdfs://localhost.localdomain:8020/user/cloudera/data/big1/climate_month4.txt' USING PigStorage(','); 

grunt> month5 = LOAD 'hdfs://localhost.localdomain:8020/user/cloudera/data/big1/climate_month5.txt' USING PigStorage(','); 

grunt> months = UNION month1, month2, month3, month4, month5; 

grunt> clearWeather = FILTER months BY skyCondition == 'CLR'; 

grunt> shapedWeather = FOREACH clearWeather GENERATE date, SUBSTRING(date,0,4) as YEAR, SUBSTRING(date,4,6) as MONTH, SUBSTRING(date,6,8) as DAY, skyCondition, dryTemp; 

grunt> groupedByMonthDay = GROUP shapedWeather BY (MONTH, DAY) PARALLEL 10; 

grunt> aggedResults = FOREACH groupedByMonthDay GENERATE group as MonthDay, AVG(shapedWeather.dryTemp) AS AVERAGETEMP, MIN(shapedWeather.dryTemp) AS MINIMUMTEMP, MAX(shapedWeather.dryTemp) AS MAXIMUMTEMP, COUNT(shapedWeather.dryTemp) AS COUNTTEMP PARALLEL 10; 

grunt> sortedResult = SORT aggedResults BY $1 DESC; 

2014-10-31 10:22:44,664 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 11, column 0> Syntax error, unexpected symbol at or near 'sortedResult' 
Details at logfile: /home/cloudera/pig_1414775884282.log 

和錯誤文件說: /home/cloudera/pig_1414775884282.log 誰能給我這個解決方案。

Pig Stack Trace 
    --------------- 
    ERROR 1200: <line 11, column 0> Syntax error, unexpected symbol at or near 'sortedResult' 

    Failed to parse: <line 11, column 0> Syntax error, unexpected symbol at or near 'sortedResult' 
     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.validateQuery(PigServer.java:1572) 
     at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1545) 
     at org.apache.pig.PigServer.registerQuery(PigServer.java:518) 
     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.run(Grunt.java:69) 
     at org.apache.pig.Main.run(Main.java:538) 
     at org.apache.pig.Main.main(Main.java:157) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.apache.hadoop.util.RunJar.main(RunJar.java:208) 

回答

2

Pig中沒有SORT命令。嘗試ORDER命令

sortedResult = ORDER aggedResults BY $1 DESC; 
+0

感謝Siva,現在我得到了解決方案。 – Green 2014-10-31 18:06:18