栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Pig 分析训练

Pig 分析训练

一、准备数据

在HDFS文件系统创建一个input目录,并从本地上传任意一个文件到目录中,为后面的Pig单词统计准备数据:

hdfs dfs -mkdir /input
hdfs dfs -ls /

我们就任意分析一个数据,比如Hadoop下的README.txt文件,将它上传至HDFS

cd /usr/cstor/hadoop


cat README.txt

hdfs dfs -put README.txt /input

hdfs dfs -ls /input

 二、启动 Grunt shell

cd /root/soft/pig
pig -x local 

读取并转换数据

a = load 'hdfs://master:8020/pig/README.txt' as (line: chararray) ;   按行读取HDFS文件

b = foreach a generate flatten(TOKENIZE(line,'t ,.'))as word;        将每行单词用tab、逗号,句号以及空格分隔单词

dump b ;

 

 c = group b by word ;       按单词分组,将相同的单词归并到一起
dump c ;

 d = foreach c generate group, COUNT(b)  as count ;     统计每个单词的个数
dump d ;

e = order d by count desc ;   将统计出的次数来排序(降序)
dump e ;

 

 ok,分析完成,出现最多的是the 出现了8次。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/748310.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号