我想按降序/升序计算一个字符的出现次数,而忽略Apache Pig
中的特殊字符?任何人都可以为此提供解决方案吗?
我的输入文件如下:
adaek@482;awst%16
alf$951;adftu*15
期望的输出:
a : 5
d,t,f:2
e,k,w,l,u: 1
答案 0 :(得分:1)
你需要一个UDF StringToCharArray,它将一个字符串分成一个字符包(包裹toCharArray()并返回包),然后执行以下操作:
a = load ... as (inp : chararray);
b = foreach a generate flatten(StringToCharArray(inp)) as singlechar;
c = group b by singlechar;
d = foreach c generate c.group as singlechar, COUNT_STAR(b) as total;
e = group d by total;
f = foreach e generate d as chargroup, e.group as total;
dump f;