共计 1733 个字符,预计需要花费 5 分钟才能阅读完成。
pig 中使用的一些实例语法
1:加载名用正则表达式:
LOAD ‘/user/wizad/data/wizad/raw/2014-0{6,7-0,7-1,7-2,7-3,8}*/3_1/adwords*’
2:filter 的几种简单用法:
按值过滤
FILTER clickDate_all BY log_type==’2′;
FILTER mapping_table BY mapping_ad_network_id==’3′ AND mapping_type==’5′;
test =FILTER allRow BY (ad_id==’14997′ OR ad_id==’14998′ OR ad_id==’14999′) AND log_type==2;
test=FILTER allRow BY (INDEXOF(ad_id,’14997′)==0 OR INDEXOF(ad_id,’14998′)==0 OR INDEXOF(ad_id,’14999′)==0) AND log_type==2;
配合 size 函数
FILTER count_imei BY (SIZE(cimei)>14 AND SIZE(cimei)<17);
正则表达式
FILTER cimei2 BY NOT cimei MATCHES ‘^[0-9]*$’;
FILTER cmac2 BY cmac MATCHES ‘/[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}:[A-F\d]{2}/’;
3:排序
ORDER province_count BY $2 DESC;
4:CONCAT 函数的使用。可用于生成独立的一列,如 count 了的一个数,前面加一列名称
FOREACH origin_cleaned_data GENERATE CONCAT(‘<-_’,’->’) AS cou,guid,log_type;
read_social_14 =FOREACH metadata_social_14 GENERATE CONCAT(’14’,’==’),guid_social;
all_id =FOREACH allRow GENERATE id,CONCAT(‘_’,’-‘) as cc;
5:值替换:过滤空值,改成取值为 unknown。
origin_historical = FOREACH origin_cleaned_data GENERATE wizad_ad_id,guid,log_type,
((province_region_id == ”) ? ‘unknown’ : province_region_id)
6: 切分成不同子集,按值:
SPLIT geelyTuiGuang INTO Android IF os_id==1,ios IF os_id==2;
SPLIT ios INTO ios6 IF (INDEXOF(os_version,’7′)!=0),ios7 IF INDEXOF(os_version,’7′)==0;
7:replace 函数替换值
FOREACH ios6 GENERATE imei,mac_address as cmac,REPLACE(idfa,’null’,”);
8:en_guid =STREAM duimei THROUGH `awk -F”,” ‘{if($3 == “null”) print $1″,”$2″,”; else print $0}’`;
Pig 的安装与测试 http://www.linuxidc.com/Linux/2014-07/104039.htm
Pig 安装与配置教程 http://www.linuxidc.com/Linux/2013-04/82785.htm
Pig 安装部署及 MapReduce 模式下测试 http://www.linuxidc.com/Linux/2013-04/82786.htm
Pig 安装及本地模式测试, 体验 http://www.linuxidc.com/Linux/2013-04/82783.htm
Pig 的安装配置与基本使用 http://www.linuxidc.com/Linux/2013-02/79928.htm
Hadoop Pig 进阶语法 http://www.linuxidc.com/Linux/2013-02/79462.htm