[pig] pig 基础使用

1.pig运行模式html

本地模式: pig -x local  linux

 直接访问本地磁盘apache

集群模式: pig  或者 pig -x mapreduce编程

2.pig latin 交互grunt

帮助信息 helpspa

上传本地文件到hdfs中命令行

查看内容 cat 3d

 加载数据code

grunt> A = load '/pig/input/a.data' using PigStorage('\t');  --加载文件,并用冒号’\t‘将数据分离为多个字段
grunt> B = foreach A generate $0 as id; --将每一次迭代的第一个元祖数据做为id
grunt> dump B; 在命令行输出结果

 执行成功,以下展现:htm

 计算结果

 3. 小试牛刀

1)、加载学生信息

student = load '/pig/input/student.data' using PigStorage(',') as (id:long,name:chararray,class:int,state:int);

2)过滤 符合条件的数据

filterStudent= filter student by state==1;

3)展现每一个班的学生

groupStudentByClass= group student by class parallel 2;

dump groupStudentByClass;

4)统计每一个班的人数

groupclass= foreach groupStudentByClass generate $0 as sid,COUNT($1) as total;

dump groupclass;

5)join

studentTeacher = join student by class,teacher by clazz;

dump studentTeacher;

参考资料:

https://www.ibm.com/developerworks/cn/linux/l-apachepigdataquery/

http://pig.apache.org/docs/r0.16.0/start.html

Apache Pig的一些基础概念及用法总结

<pig编程指南>

相关文章
相关标签/搜索