[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編程指南>

相關文章
相關標籤/搜索