Pig 知识盲点

1. Word Count 例子

inputfile   =  load 'file'  as (line);

内容:

{line: bytearray}

(Look at the stars, )
(Look how they shine for you, )
(And everything you do, )
(Yeah they were all yellow,)


wordsLine =  foreach inputfile   generate flatten(TOKENIZE(line))  aseachWord;

内容:

 {eachWord: chararray}

(Look)
(at)
(the)
(stars)
(Look)
(how)
(they)
(shine)
(for)
(you)
(And)
(everything)
(you)
(do)
(Yeah)
(they)
(were)
(all)
(yellow)


groupedWords = group wordsLine by eachWord;

内容:

{group: chararray,wordsLine: {(eachWord: chararray)}}

(at,{(at)})
(do,{(do)})
(And,{(And)})
(all,{(all)})
(for,{(for)})
(how,{(how)})
(the,{(the)})
(you,{(you),(you)})
(Look,{(Look),(Look)})

(Yeah,{(Yeah)})
(they,{(they),(they)})
(were,{(were)})
(shine,{(shine)})
(stars,{(stars)})
(yellow,{(yellow)})
(everything,{(everything)})


wordcount = foreach  groupedWords  generate  group, COUNT(wordsLine) as cnt

 {group: chararray, cnt:long}

(at,1)
(do,1)
(And,1)
(all,1)
(for,1)
(how,1)
(the,1)
(you,2)
(Look,2)
(Yeah,1)
(they,2)
(were,1)
(shine,1)
(stars,1)
(yellow,1)
(everything,1)




2.Pig 返回码

0: 成功;1:失败,可重试;2:失败;3:部分失败......其余是各种异常。


3. 复杂数据类型(很少用)

map:    

tuple: 定长有序    

bag: 无序   


4. NULL值

null  对任何运算符都抵消:

x+null = null

null==1 ? 1: 0 ,  返回值为null 


5.加载和存储 

加载函数:

PigStoreage(',') :HDFS路径

HBaseStoreage():HBase表

TextLoader: HDFS路径, 每行作为一个tuple


存储函数

PigStoreage(',') :HDFS路径

HBaseStoreage():HBase表

TextLoader: HDFS路径, 每行作为一个tuple


6.大小写敏感:
关键字不敏感: load == LOAD 
变量敏感:tablea != tableA
自定义函数敏感: count != COUNT

7.Parallel

可触发reduce的操作:group、order、distinct、join、cogroup、cross

后面可使用parallel 指定 并行数目


8. 注册UDF

使用命令register,或者属性 -Dudf.import.list, 或-Dpig.additional.jars


9. Java静态函数

实际是使用反射来运行


10. flattern

操作bag,一行变多行


11.  replicated Join

map side join


12. skew join

先抽样,确定键的分布,重写partitioner,从而均衡各个reducer的负载


13. merge join

已经排好序,比默认的高效


14. cogroup

对多个输入进行group,如 : C =  cogroup A by id, B by id.

相当于join的前一半


15. stream

执行perl、python等脚本


16.  直接运行mapreduce

使用mapreduce命令执行


17.  有向无环图 DAG


18. 分割器 Partitioner

可注册自定义jar包


19. 宏

使用define关键字


20. 嵌套Pig 脚本

使用import关键字


21. 执行计划 exlain

用于调试


22. illustrate

用于调试


23. Pig 统计信息

在日志或者终端输出


24. PigUnit

集成到JUnit


25.  与 Python 交互


26. 评估函数

求值函数,继承org.apache.pig.EvalFunc<V>, 实现 ecec(Tuple input)

也可以用Python书写


27. 过滤函数

继承org.apache.pig.FilterFunc


28. 加载函数


29. 存储函数


30. Piggybank

内置常用聚合函数、数学函数、字符串处理函数。

特别的,有正则表达式匹配函数:REGEX_EXTRACT、REGEX_EXTRACT_ALL

统计函数:相关系数COR、协方差COV等等。








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值