讀書筆記 MapReduce詞頻統計

2021-09-24 02:49:20 字數 921 閱讀 2119

詞頻統計作為mapreduce入門的乙個基礎演算法,相當與各種語言的「hello world」程式。下面簡單說一下mapreduce的演算法實現。

private intwritable one = new intwritable(1);

private text word = new text();

private string patter = "[^a-za-z0-9]";

@override

protected void map(object key, text value, context context) throws ioexception, interruptedexception

}} hello world! line one.

hello world! line two.

則第一次map獲取到的value為:

hello world! line one.

key為0。之後在map中通過迴圈,將單詞乙個個提取出來,通過context.write()方法輸出為如的鍵值對輸出。此時輸出的結果為:

,,,reducer**:

public class wordreducer extends reducer

result.set(sum);

context.write(key,result);

}}

reducer將相同的key(並非一定相同,可以通過制定不同的演算法使不同的值)分配到同乙個reducer上。此時可以通過取出value的值進行相加,獲得該單詞的頻率。最後通過context.write函式將結果輸出為文字。

main方法:

public class wordcounttest 

catch (exception e)

}}

MapReduce設計模式學習 讀書筆記

thinkgamer部落格 概要設計模式更接近簡單的mr應用,因為基於鍵將資料分組是mr范型的核心功能,所有的鍵將被分組匯入reducer中 本章涉及的概要模式有數值概要 numerical summarization 倒排索引 inverted index 計數器計數 counting with ...

MapReduce程式設計 統計詞頻

map keyin 輸入的key型別 valuein 輸入的value型別 keyout 輸出的key型別 valueout 輸出的value型別 public class extends reducer keyin reduce段輸入key型別,即map輸出的key型別 valuein reduc...

mysql運維 讀書筆記 Mysql 讀書筆記

mysql儲存時間有兩種型別 datetime和timestamp。分別說一下兩者的區別。datetime,以8位元組儲存時間,理論上可以從0000年儲存到9999年。並且沒有時區的概念,它儲存的就是乙個時間點的概念。timestamp和datetime最主要的不同就是,它是以4個位元組儲存,由19...