




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、8. 在 Eclipse 中運行“Word Count” MapReduce 程序(1)在 Eclipse 中創(chuàng)建 “WordCount” MapReduce 項目點擊File菜單,選擇 New - Project:選擇Map/Reduce Project,點擊 Next:填寫 Project name為 MyWordCount,點擊 Finish 創(chuàng)建項目。MyWordCount 項目,選擇 New - Class:在 Name 處填寫 WordCountTest。將如下 WordCountTest 的代碼到該 WordCountTest.java 中。import java.io.IOEx
2、ception; import java.util.Iterator;import java.util.StringTokenizer;import.apache.hadoop.conf.Configuration; import.apache.hadoop.fs.Path;import.apache.hadoop.io.Writable; import.apache.hadoop.io.Text;import.apache.hadoop.mapreduce.Job; import.apache.hadoop.mapreduce.Mapper; import.apache.hadoop.map
3、reduce.Reducer;import.apache.hadoop.mapreduce.lib.input.FileInputFormat;importimport.apache.hadoop.mapreduce.lib.output.FileOutputFormat;.apache.hadoop.util.GenericOptionsParser;public class WordCountTest public WordCountTest() public sic void main(String args) throws Exception Configuration conf =
4、new Configuration();String otherArgs = (new GenericOptionsParser(conf, args).getRemainingArgs(); if(otherArgs.length 2) System.err.prln(Usage: wordcount . ); System.exit(2);Job job = Job.getInstance(conf, word count test); job.setJarByClass(WordCountTest.class); job.setMapperClass(WordCountTest.Toke
5、nizerMapper.class);binerClass(WordCountTest.SumReducer.class); job.setReducerClass(WordCountTest.SumReducer.class); job.setOutputKeyClass(Text.class);job.setOutputValueClass(Writable.class);for(i = 0; i otherArgs.length - 1; +i) FileInputFormat.addInputPath(job, neth(otherArgsi);FileOutputFormat.set
6、OutputPath(job, neth(otherArgsotherArgs.length - 1);System.exit(pletion(true)?0:1);public sic classSumReducer extends Reducer privateWritable result = newWritable();publicSumReducer() public void reduce(Text key, Iterable values, Reducer.Context context) throws IOException,sum = 0;erruptedException
7、Writable val;for(Iterator itr = values.iterator(); itr.hasNext(); sum += val.get() val = (Writable)itr.next();(2)將 Hadoop 配置文件添加到“WordCount” MapReduce 項目將 perties中:到 WordCount 項目下的 src 文件夾(/workspace/WordCount/src)og4j 用于程序的輸出,需要 perties 這個配置文件,如果沒有該文件到項目中,運行程序后在 Console 面板中會出現(xiàn)警告提示
8、:log4j:WARNNoappenderscouldbefoundforlogger雖然不影響程序的正確運行的,但程序運行時無法看到任何提示消息(只能看到出錯信息)。完成后,務(wù)必WordCount 選擇 refresh 進行刷新(不會自動刷新,需要手動刷新),可以看到文件結(jié)構(gòu)如下所示:(.apache.hadoop.metrics2.lib.MutableMetricsFactory).log4j:WARN Please initialize the log4j system properly.log4j:WARN Seefor more info.hfutmaster $ cp /hado
9、op-2.5.2/etc/hadoop/perties /workspace/MyWordCount/srcthis.result.set(sum); context.write(key, this.result);public sic class TokenizerMapper extends Mapper private sic finalWritable one = newWritable(1);private Text word = new Text();public TokenizerMapper() publicvoidmap(Objectkey,Textvalu
10、e,Mapper.Context context) throws IOException,erruptedException StringTokenizer itr = new StringTokenizer(value.toString();while(itr.hasMoreTokens() this.word.set(itr.nextToken(); context.write(this.word, one);(3)通過 Eclipse 運行“MyWordCount” MapReduce 項目點擊中的 Run 圖標,或者Project Explorer 中的 WordCountTest.java,選擇Run As - Run on Hadoop,就可以運行 MapReduce 程序了。不過由于沒有指定參數(shù),運行時會提示 “Usage: wordcount”,需要通過 Eclipse 設(shè)定一下運行參數(shù)。剛創(chuàng)建的 WordCount.java,選擇 Run As - Run Configurations,在此處可以設(shè)置運行時的相關(guān)參數(shù)( 如果 Java Application 下面沒有 WordCount, 那么需要先雙擊 JavaApplication )。 切 換 到“ Arguments ”, 在Program arguments 處填寫
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 墩、臺身和蓋梁工程現(xiàn)場質(zhì)量檢驗報告單(五)
- 智能交通管理平臺開發(fā)協(xié)議
- 辦公用品采購預(yù)算與實際使用對比表格
- 專業(yè)資料出版合作協(xié)議
- 水利水電工程施工承包協(xié)議
- 企業(yè)品牌授權(quán)使用協(xié)議書
- 小學(xué)生體育運動啟蒙故事讀后感
- 太陽能光伏系統(tǒng)安裝維護合同
- 2024-2025學(xué)年高二數(shù)學(xué)湘教版選擇性必修第二冊教學(xué)課件 第2章-2.4空間向量在立體幾何中的應(yīng)用-2.4.3 向量與夾角
- 水系統(tǒng)基礎(chǔ)知識培訓(xùn)課件
- 思想道德與法治教案第四章:明確價值要求踐行價值準則
- 寧騷版《公共政策學(xué)》課后答案
- 氧氣安全標簽
- 不經(jīng)歷風(fēng)雨怎么見彩虹》教學(xué)設(shè)計
- 二年級有余數(shù)的除法口算題1000道
- (綜合治理)修復(fù)工程指南(試行) - 貴州省重金屬污染防治與土壤修復(fù)網(wǎng)
- 員工就餐簽到表
- A-level項目介紹(課堂PPT)
- 航海計算軟件---ETA計算器
- 光伏電站運維手冊
- 半導(dǎo)體及集成電路領(lǐng)域的撰寫及常見問題
評論
0/150
提交評論