-
hadoop是一個開源的大數據框架。
hadoop是一個分布式計算的解決方案。
hadoop=HDFS(分布式文件系統)+MapReduce(分布式計算)
hadoop核心:HDFS分布式文件系統是大數據技術的基礎。
MapReduce編程模型:分布式計算是大數據應用的解決方案。
查看全部 -
HDFS 數據塊存儲 主節點:NameNode 從節點:DataNode MapReduce:編程模型 分而治之:先Map,再Reduce查看全部
-
31421
查看全部 -
23131
查看全部 -
342432
查看全部 -
34243
查看全部 -
323223
查看全部 -
34234
查看全部 -
23231
查看全部 -
21312
查看全部 -
12312
查看全部 -
213121
查看全部 -
將MapReduce程序提交到Hadoop框架上
查看全部 -
map函數:
def?red_input(file): ????for?line?in?file: ????????yield?line.split() def?main(): ????data?=?red_input(sys.stdin) ????for?words?in?data: ????????for?word?in?words: ????????????print("%s%s%d"%(word,'\t',1))
reduce函數:
from?itertools?import?groupby from?operator?import?itemgetter def?read_mapper_output(file,sepatator='\t'): ????for?line?in?file: ????????yield?line.rstrip().split(sepatator,1) def?main(): ????data?=?read_mapper_output(sys.stdin) ????for?current_word,group?in?groupby(data,itemgetter(0)): ????????total_count?=?sum(int(count)?for?current_word,count?in?group) ????????print("%s%s%d"%?(current_word,'\t',total_count))
執行命令
如圖
查看全部 -
In [1]: l = ["a","bb","ccc"]? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
In [2]: l_count = list(map(len,l))? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
In [3]: l_count? ? ?
Out[3]: [1, 2, 3]
In [5]: from functools import reduce? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
In [6]: l_sum = reduce(lambda x,y:x+y,l_count)? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
In [7]: l_sum? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Out[7]: 6
查看全部
舉報