1

我想按降序/升序计算字符出现的次数,而忽略特殊字符Apache Pig?任何人都可以为此提供解决方案吗?

我的输入文件如下所示:

adaek@482;awst%16
alf$951;adftu*15

期望的输出:

a : 5
d,t,f:2
e,k,w,l,u: 1
4

1 回答 1

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;
于 2013-08-19T11:31:21.607 回答