Apache Pig教程之WordCount analysis概述
作者:本站整理 时间:2015-04-16
作为面向过程语言,Apache Pig可以借助Hadoop 和 MapReduce 平台快速查询大型半结构化数据集。今天小编就首先跟大家分享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';
<pre code_snippet_id="327646" snippet_file_name="blog_20140505_2_6349649" name="code" class="java">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.)})</pre><br>
<br>
<pre></pre>
<br>
相关文章
相关推荐
-
Premiere CS4汉化绿色版 v4.01
-
影子系统 8.5.5(系统保护工具)
-
DriverEasy V4.9.7.0官方中文版(驱动更新检测)
-
微PE工具箱官方安装版 V2.0
-
新毒霸WiFi V2.1.7941 绿色版
-
GlassPwn1.1b(系统补丁)官方下载
-
杨洋表情包官方版
-
WiFi共享大师 2.1.7.9(wifi热点创建工具)
-
Adobe Premiere Pro CC 2014中文绿色版 v8.1
-
路路通时刻表 V20151011绿色版(火车时刻表查询软件)
-
管家通进销存软件普及版 v9.4
-
3DField 4.2.1.0(三维模型信息提取)
-
瑞星路由卫士 V1.0.0.48官方版(路由器安全软件)
-
谷歌翻译器官方版
-
完美解码播放器官方版
-
新毒霸悟空开发版 SP10.0