如何在 Apache Pig 中按第二个字符排序列表?

How can order a list by the second char in Apache Pig?

如何按第二个字符对列表进行排序?

例如这个列表:

apple
mango
orange

我要按第二个字母排序(字母顺序)

mango
apple
orange

谢谢!

从第一个字段的第二个字符生成第二个字段,然后按第二个字符排序field.Finally仅从有序关系中获取第一个字段。

A = LOAD 'test3.txt' USING PigStorage('\t') as (a1:chararray);
B = FOREACH A GENERATE a1,SUBSTRING(a1,1,2) as a2;
C = ORDER B BY a2;
D = FOREACH C GENERATE a1;
DUMP D;

输出

我的数据是

1,The Nightmare Before Christmas
2,The Mummy
3,Orphans of the Storm
4,The Object of Beauty

   A = LOAD '/home/abhijit/Downloads/movies.txt' USING PigStorage(',') as (a1:int,a2:chararray);
   B = FOREACH A GENERATE a2,SUBSTRING(a2,1,2) as a3;
   C = ORDER B BY a3;
   D = FOREACH C GENERATE a2;
   DUMP D;