码迷,mamicode.com
首页 > 其他好文 > 详细

pig中使用的一些实例语法

时间:2014-10-31 19:07:07      阅读:272      评论:0      收藏:0      [点我收藏+]

标签: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中使用的一些实例语法

标签:pig

原文地址:http://blog.csdn.net/longshenlmj/article/details/40658911

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!