pig—WordCount analysis

 grunt> cat /opt/dataset/input.txt
	keyword1 keyword2
	keyword2 keyword4
	keyword3 keyword1
	keyword4 keyword4
 A = LOAD '/opt/dataset/input.txt' using PigStorage('\n')  as (line:chararray);
 B = foreach A generate TOKENIZE((chararray)$0);
 C = foreach B generate flatten($0) as word;
 D = group C by word;
 E = foreach D generate COUNT(C), group;
 dump B;
({(keyword1),(keyword2)})
({(keyword2),(keyword4)})
({(keyword3),(keyword1)})
({(keyword4),(keyword4)})
 dump C;
(keyword1)
(keyword2)
(keyword2)
(keyword4)
(keyword3)
(keyword1)
(keyword4)
(keyword4)
 dump D;
(keyword1,{(keyword1),(keyword1)})
(keyword2,{(keyword2),(keyword2)})
(keyword3,{(keyword3)})
(keyword4,{(keyword4),(keyword4),(keyword4)})
 dump E;
(2,keyword1)
(2,keyword2)
(1,keyword3)
(3,keyword4)
 store E into './wordcount';
TOKENIZE
Splits a string and outputs a bag of words.

Syntax
TOKENIZE(expression)       

Terms
expression

An expression with data type chararray.

Usage
Use the TOKENIZE function to split a string of words (all words in a single tuple) into a bag of words (each word in a single tuple). The following characters are considered to be word separators: space, double quote("), coma(,) parenthesis(()), star(*).

Example
In this example the strings in each row are split.

A  = LOAD 'data' AS (f1:chararray);

DUMP A;
(Here is the first string.)
(Here is the second string.)
(Here is the third string.)

X = FOREACH A GENERATE TOKENIZE(f1);

DUMP X;
({(Here),(is),(the),(first),(string.)})
({(Here),(is),(the),(second),(string.)})
({(Here),(is),(the),(third),(string.)})




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值