apache pig,程序问题

n3schb8v  于 2021-06-25  发布在  Pig
关注(0)|答案(1)|浏览(247)

我是新来的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

它是每个名字出现“bomb”的次数(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.
ohtdti5x

ohtdti5x1#

像这样试试

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

相关问题