问题
Let's say I have set_of_values :
a, k
a, l
a, m
b, x
b, y
b, z
If I use
a = RANK set_of_values;
I get:
1, a, k
2, a, l
3, a, m
4, b, x
5, b, y
6, b, z
What I would like to achieve is RANK, but inside the group.
First :
a = group set_of_values by first_value;
(a,{(a,k),(a,l),(a,m)})
(b,{(b,x),(b,y),(b,z)})
And what should I do now to get:
(a,{(1,a,k),(2,a,l),(3,a,m)})
(b,{(1,b,x),(2,b,y),(3,b,z)})
EDIT (added RANK inside foreach)
b = foreach a { c = RANK $1; generate c; }
I get:
2014-03-05 09:55:05,601 [main] ERROR org.apache.pig.tools.grunt.Grunt - ERROR 1200: <line 5, column 20> Syntax error, unexpected symbol at or near 'RANK'
Details at logfile: /export/home/pig/pig_1394009645035.log
Log file:
ERROR 1200: <line 5, column 20> Syntax error, unexpected symbol at or near 'RANK'
Failed to parse: <line 5, column 20> Syntax error, unexpected symbol at or near 'RANK'
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:1571)
at org.apache.pig.PigServer$Graph.registerQuery(PigServer.java:1544)
at org.apache.pig.PigServer.registerQuery(PigServer.java:516)
at org.apache.pig.tools.grunt.GruntParser.processPig(GruntParser.java:988)
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:160)
回答1:
This might be too late for a reply, but I found someone posted this on stack overflow only: Usage of Apache Pig rank function
P.S: He is using DataFu UDF: Enumerate , and it worked for me.
来源:https://stackoverflow.com/questions/22151364/rank-inside-the-bag