7. 讓專業的來
• Explaining Big Data
– 全盤簡介<8:32>
• What is Big Data and how does it work?
– 大數據之應用 < 1:33>
• TED : Kenneth Cukier: Big data is better data
– 大數據讓我們看見 新、精準、不同 <15:55>
• 《遠見》319期 - 看見未來5分鐘
– 影片與文字 報導 <2:25>
• 20150831中天新聞 大數據無所不在! 價格、促銷、分析數據預測消費
– 案例說明 <2:29>
• 淺談台灣巨量資料產業發展現況
– jazz wang’s slide on slide share
7
22. 分散式運算架構
• 分散式運算架構 (分散式系統) = 分散式檔案系統 +
分散式運算
• 一台機器無法處理,就用多台機器同時處理
– 分散式系統
– 易於橫向擴充,scale-out
CPU
Memory
disk
CPU
Memory
disk
CPU
Memory
disk
CPU
Memory
disk
CPU
Memory
disk
CPU
Memory
disk
一個便當吃不飽,可
以吃二個
70. 用pig 整形後
70
A1 北 劉 12.5
LOAD
LOAD
FILTER
JOIN
GROUP
FOREACH
STORE
(nm, dp, id)
(nm, dp, id)
(id, dt, hr)
(nm, dp, id, id, dt, hr)
(group, {(nm, dp, id, id, dt, hr)})
(group, …., AVG(hr))
(dp,group, nm, hr)
Logical PlanPig Latin
A = LOAD 'file1.txt' using PigStorage(',') AS (nm, dp, id) ;
B = LOAD ‘file2.txt' using PigStorage(',') AS (id, dt, hr) ;
C = FILTER B by hr > 8;
D = JOIN C BY id, A BY id;
E = GROUP D BY A::id;
F = FOREACH E GENERATE group, $1.dp,$1.nm,
AVG($1.hr);
STORE F INTO '/tmp/pig_output/';
nm dp Id Id dt hr
劉 北 A1 A1 7/7 13
李 中 B1 A1 7/8 12
王 中 B2 A1 7/9 4
Tips : 關鍵字大小寫有差;先用小量資料於
pig –x local 模式驗證;每行先配合dump or
illustrate看是否正確
73. Hive 架構提供了..
• 介面
– CLI
– WebUI
– API
• JDBC and ODBC
• Thrift Server (hiveserver)
– 使遠端Client可用 API 執
行 HiveQL
• Metastore
– DB, table, partition…
73
figure Source : http://blog.cloudera.com/blog/2013/07/how-hiveserver2-brings-security-and-concurrency-to-apache-hive
74. 現在換 蜂 也會的程式設計
74
$ hive
hive> create table A(x int, y int, z int)
hive> load data local inpath ‘file1 ’ into table A;
hive> select * from A where y>10000
hive> insert table B select *
from A where y>10000
figure Source : http://hortonworks.com/blog/stinger-phase-2-the-journey-to-100x-faster-hive/
75. 用 Hive 整形後
75
A1 北 劉 12.5
HiveQL
> create table A (nm String, dp String, id String)
> create table B (id String, dt Date, hr int)
> create table final (dp String, id String , nm String, avg float)
> load data inpath ‘file1’ into table A;
> load data inpath ‘file2’ into table B;
> Insert table final select a.id, collect_set(a.dp), collect_set(a.nm), avg(b.hr)
from a,b where b.hr > 8 and b.id = a.id group by a.id;
nm dp Id id dt hr
劉 北 A1 A1 7/7 13
李 中 B1 A1 7/8 12
王 中 B2 A1 7/9 4
Tips : create table & load
data 建議用 tool 匯入資料
較不會錯
76. Hive和SQL 比較
Hive RDMS
查詢語法 HQL SQL
儲存體 HDFS
Raw Device or
Local FS
運算方法 MapReduce Excutor
延遲 非常高 低
處理數據規模 大 小
修改資料 NO YES
索引
Index, Bigmap
index…
複雜健全的索
引機制
76
Source : http://sishuok.com/forum/blogPost/list/6220.html
77. Pig vs Hive
77
Hive Pig
SQL-LIKE 語法 PigLatin
Yes/明確型 Schemas/
Types
Yes /隱含型
Yes Partitions No
Thrift Server No
Yes Web
Interface
No
Yes(limited) JDBC/ODBC No
No Hdsf 操作 Yes
Hive更適合於數
據倉庫的任務,
用於靜態的結構
及需要經常分析
的工作
Pig賦予開發人員
在Big Data中,具
備更多的靈活性,
並允許開發簡潔腳
本
Source : http://f.dataguru.cn/thread-33553-1-1.html
104. Java programming
104
╚ Mapper / Realcase
public class WordCountMapper
extends Mapper< Object, Text , Text, IntWritable>{
public void map(Object key, Text value, Context context )
throws IOException, InterruptedException {
StringTokenizer itr = new StringTokenizer(value.toString());
IntWritable one = new IntWritable(1);
while (itr.hasMoreTokens()) {
Text word = new Text(itr.nextToken())
context.write(word, one);
}
}
}
106. Java programming
╚ Reducer / Realcase
106
public class WordCountReducer
extends Reducer< Text, IntWritable , Text , IntWritable > {
public void reduce( Text key, Iterable< IntWritable > values, Context context)
throws IOException, InterruptedException {
int sum = 0;
IntWritable result = new IntWritable();
for (IntWritable val : values) { sum += val.get();
}
result.set(sum);
context.write(key, result);
}
}