Java的HadoopFileInputFormat實現(xiàn)類有哪些

這篇文章主要講解了“Java的Hadoop FileInputFormat實現(xiàn)類有哪些”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Java的Hadoop FileInputFormat實現(xiàn)類有哪些”吧!

創(chuàng)新互聯(lián)建站憑借專業(yè)的設(shè)計團(tuán)隊扎實的技術(shù)支持、優(yōu)質(zhì)高效的服務(wù)意識和豐厚的資源優(yōu)勢,提供專業(yè)的網(wǎng)站策劃、網(wǎng)站建設(shè)、成都做網(wǎng)站、網(wǎng)站優(yōu)化、軟件開發(fā)、網(wǎng)站改版等服務(wù),在成都十載的網(wǎng)站建設(shè)設(shè)計經(jīng)驗,為成都上1000+中小型企業(yè)策劃設(shè)計了網(wǎng)站。

思考

在運行MapReduce程序時,輸入的文件格式有很多,比如:基于行的日志文件、二進(jìn)制格式文件、數(shù)據(jù)庫表等。那么,針對不同的數(shù)據(jù)類型,MapReduce是怎么讀取這些數(shù)據(jù)的呢?

FileInputFormat常見的接口實現(xiàn)類包括:TextInputFormat,KeyValueTextInputFormat,NLineInputFormat,CombineTextInputFormat和自定義InputFormat等。

1.TextInputFormat

TextInputFormat是默認(rèn)的FileInputFormat實現(xiàn)類。按行讀取每條記錄。鍵是存儲該行在整個文件中的起始字節(jié)偏移量, LongWritable類型。值是這行的內(nèi)容,不包括任何行終止符(換行符和回車符),Text類型。

以下是一個示例,比如,一個分片包含了如下4條文本記錄。

Rich learning formIntelligent learning engineLearning more convenientFrom the real demand for more close to the enterprise

每條記錄表示為以下鍵/值對:

(0,Rich learning form)(19,Intelligent learning engine)(47,Learning more convenient)(72,From the real demand for more close to the enterprise)

2.KeyValueTextInputFormat

每一行均為一條記錄,被分隔符分割為key,value??梢酝ㄟ^在驅(qū)動類中設(shè)置conf.set(KeyValueLineRecordReader.KEY_VALUE_SEPERATOR, "\t");來設(shè)定分隔符。默認(rèn)分隔符是tab(\t)。

以下是一個示例,輸入是一個包含4條記錄的分片。其中——>表示一個(水平方向的)制表符。

line1 ——>Rich learning formline2 ——>Intelligent learning engineline3 ——>Learning more convenientline4 ——>From the real demand for more close to the enterprise

每條記錄表示為以下鍵/值對:

(line1,Rich learning form)(line2,Intelligent learning engine)(line3,Learning more convenient)(line4,From the real demand for more close to the enterprise)

注意:此時的鍵是每行排在制表符之前的Text序列。

 3.NLineInputFormat

如果使用NlineInputFormat,代表每個map進(jìn)程處理的InputSplit不再按Block塊去劃分,而是按NlineInputFormat指定的行數(shù)N來劃分。即輸入文件的總行數(shù)/N=切片數(shù),如果不整除,切片數(shù)=商+1。

以下是一個示例,仍然以上面的4行輸入為例。

Rich learning formIntelligent learning engineLearning more convenientFrom the real demand for more close to the enterprise

例如,如果N是2,則每個輸入分片包含兩行。開啟2個MapTask。

(0,Rich learning form)(19,Intelligent learning engine)

另一個 mapper 則收到后兩行:

(47,Learning more convenient)(72,From the real demand for more close to the enterprise)

這里的鍵和值與TextInputFormat生成的一樣。

感謝各位的閱讀,以上就是“Java的Hadoop FileInputFormat實現(xiàn)類有哪些”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Java的Hadoop FileInputFormat實現(xiàn)類有哪些這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

文章題目:Java的HadoopFileInputFormat實現(xiàn)類有哪些
文章起源:http://muchs.cn/article14/jiodge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、網(wǎng)站建設(shè)域名注冊、網(wǎng)站設(shè)計公司、商城網(wǎng)站移動網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作