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等等。
轉載于:https://www.cnblogs.com/leeeee/p/7276132.html
總結
- 上一篇: 组合数(DFS)
- 下一篇: delphi使用 第三方控件