apachepig:按字母顺序对chararray/string列排序

z8dt9xmd  于 2021-06-21  发布在  Pig
关注(0)|答案(1)|浏览(384)

如果我有如下表格:
编号:intname:chararray
如何在pig中按字母顺序排列“name”列?
“order table by name asc”是否符合要求?还是按字符串长度排序?

mnemlml8

mnemlml81#

默认情况下,order by will根据字符串长度以asc形式提供输出。您可以从这个示例中进行检查

input.txt  
1 ZZ  
2 III
3 II
4 JJJJ
5 Z
6 IIIIII
7 FFF
8 IIII
9 JJ
10 AAA

PigScript:
A = LOAD 'input.txt' using PigStorage(' ') AS (id:int,name:chararray);
B = ORDER A BY name;
DUMP B;

Output:
(10,AAA)
(7,FFF)
(3,II)
(2,III)
(8,IIII)
(6,IIIIII)
(9,JJ)
(4,JJJJ)
(5,Z)
(1,ZZ)

相关问题