阿帕奇猪,程序问题

时间:2014-11-18 10:30:04

标签: apache-pig

我是猪编程的新手,我只是尝试一个程序,如下所示输入

****Input:**gedit bomb**

sasi:where is the bomb
pras:bomb is with me
sasi:what is the bomb time
pras:it is set to nine.

****output:****

sasi:2
pras:1

每个名字(sasi,pras)出现“炸弹”字的次数。

**Code:**

**A = load 'bomb' USING PigStorage(':') as (name:chararray,word:chararray);
B = FOREACH A generate(flatten(word)) as words;
C = FILTER B by words == 'bomb';**
d = group C by A.name;

i am confused from step 'd' ,can anyone say how to acheive the above mentioned output like 
sasi:2
pras:1


Thanks in advance.

1 个答案:

答案 0 :(得分:1)

试试这个

A = load 'bomb' USING PigStorage(':') as (name:chararray,word:chararray);
B = GROUP A BY name;
C = FOREACH B{
                filterByBomb = FILTER A by word MATCHES '.*bomb.*';
                GENERATE group,COUNT(filterByBomb.word);
             }  
STORE C INTO 'output' USING PigStorage(':');

<强>输出:

pras:1
sasi:2