hadoop中各種輸入輸出格式

2021-06-23 05:02:29 字數 1288 閱讀 4505

hadoop中的map reduce框架依賴inputformat提供資料,依賴outputformat輸出資料,每乙個map reduce程式都離不開它們。hadoop提供了一系列inputformat和outputformat方便開發,本文介紹幾種常用的:

textinputformat

作為預設的檔案輸入格式,用於讀取純文字檔案,檔案被分為一系列以lf或者cr結束的行,key是每一行的位置偏移量,是longwritable型別的,value是每一行的內容,為text型別。

keyvaluetextinputformat

同樣用於讀取檔案,如果行被分隔符(預設是tab)分割為兩部分,第一部分為key,剩下的部分為value;如果沒有分隔符,整行作為 key,value為空。

sequencefileinputformat

用於讀取sequence file。 sequence file是hadoop用於儲存資料自定義格式的binary檔案。它有兩個子類:sequencefileasbinaryinputformat,將 key和value以byteswritable的型別讀出;sequencefileastextinputformat,將key和value以text型別讀出。

sequencefileinputfilter

根據filter從sequence檔案中取得部分滿足條件的資料,通過 setfilterclass指定filter,內建了三種 filter,regexfilter取key值滿足指定的正規表示式的記錄;percentfilter通過指定引數f,取記錄行數%f==0的記錄;md5filter通過指定引數f,取md5(key)%f==0的記錄。

nlineinputformat

0.18.x新加入,可以將檔案以行為單位進行split,比如檔案的每一行對應乙個map。得到的key是每一行的位置偏移量(longwritable型別),value是每一行的內容,text型別。

compositeinputformat,用於多個資料來源的join。

textoutputformat,輸出到純文字檔案,格式為 key + " " + value。

nulloutputformat,hadoop中的/dev/null,將輸出送進黑洞。

sequencefileoutputformat, 輸出到sequence file格式檔案。

multiplesequencefileoutputformat, multipletextoutputformat,根據key將記錄輸出到不同的檔案。

dbinputformat和dboutputformat,從db讀取,輸出到db。

c 輸入輸出格式控制

使用這些格式需要宣告包含 long flags const 返回當前的格式標誌。long flays long newflag 設定格式標誌為newflag,返回舊的格式標誌。long setf long bits 設定指定的格式標誌位,返回舊的格式標誌。long setf long bits,lo...

python的輸入輸出格式

1.輸入格式 1 直接輸入 raw input 提示詞 2 將輸入的值賦值給passwd passwd raw input 請輸入你的密碼 3 將輸入的值轉換型別賦值給price price float raw input 水果的單價 2.輸出格式 1 print 格式化字串 變數1 print 你...

ACM常用輸入輸出格式

因為acm新人對於acm題目中處理輸入輸出存在一些疑惑,於是在這裡記錄幾種常用的輸入輸出方法。int n scanf d n while n c int a while scanf d a eof c int a while cin a c int n while scanf d n n 0 c i...