Pig中使用的一些实例语法

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安装与配置教程

Pig 安装部署及MapReduce模式下测试

Pig安装及本地模式测试,体验

Pig的安装配置与基本使用

Hadoop Pig进阶语法

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/4749acdd0c888984b0b9bbf5e4fb396b.html