语法错误,在“groupped”处或附近出现意外符号

dgenwo3n  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(504)

我有以下代码:

Input_File = load '/user/cloudera/teste' USING PigStorage (' ')
      as (ID:Int, 
          Descrip:Chararray,
          Date:Datetime);

groupped = group Input_File by (ID, Date);

ranked = foreach groupped {
        ranked = rank groupped by ID desc DENSE;
        generate flatten(ranked);
        }

STORE ranked into '/user/cloudera/teste1123';

我正在尝试在此数据集上创建排名列:

id  des date
1   A   01-01-2016
2   A   02-01-2016
2   C   03-01-2016
2   D   03-01-2016
3   A   01-01-2016

主要目标是:

rank    id  desc    date
1       1   A   01-01-2016
2       2   A   02-01-2016
3       2   C   03-01-2016
3       2   D   03-01-2016
4       3   A   01-01-2016

但当我运行代码时,会出现以下错误:

ERROR 1200: <line 5, column 14>  Syntax error, unexpected symbol at or near 'groupped'

Failed to parse: <line 5, column 14>  Syntax error, unexpected symbol at or near 'groupped'
    at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:241)
    at org.apache.pig.parser.QueryParserDriver.parse(QueryParserDriver.java:179)
    at org.apache.pig.PigServer$Graph.validateQuery(PigServer.java:1660)
    at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1633)
    at org.apache.pig.PigServer.registerQuery(PigServer.java:587)
    at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:1090)
    at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:501)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198)
    at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:173)
    at org.apache.pig.tools.grunt.Grunt.run(Grunt.java:69)
    at org.apache.pig.Main.run(Main.java:547)
    at org.apache.pig.Main.main(Main.java:158)
    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.run(RunJar.java:221)
    at org.apache.hadoop.util.RunJar.main(RunJar.java:136)

我做错了什么?
非常感谢!

holgip5t

holgip5t1#

不确定语法错误在哪里,但是这里是您正在寻找的解决方案。
注意:您必须将日期作为chararray加载

Input_File = load '/user/cloudera/teste' USING PigStorage(' ') as (ID:int, Descrip:chararray,Date:chararray);
ranked = rank Input_File by ID ASC,Date DENSE;
dump ranked;

输出

相关问题