天天看點

Hadoop中基于檔案的資料格式(1)SequenceFile1 概述2 壓縮類型3 特點4 代碼

1 sequencefile是hadoop為例存儲二進制的<k,v>而設計的一種平面檔案。

2 sequencefile的key和value是writable或者writable子類。

3 sequencefile的存儲不按照key排序,内部類writer提供了append方法。

4 sequencefile作為一個容器,可以将小檔案打包到sequencefile,高效對小檔案進行存儲和處理。

根據compressiontype的不同,有如下壓縮類型

none:不壓縮。每個記錄有key長度、value長度、key、value組成,長度字段分别為4位元組。

record: 記錄壓縮。結構與none非常類似,用定義在頭部的編碼器壓縮value,key不壓縮。

block:塊壓縮。一次壓縮多條記錄,當記錄位元組數達到一個門檻值則天際到塊,io.seqfile.compress.blocksize控制。格式為:記錄數,鍵長度,鍵,值長度,值。

分别對應writer:

writer : uncompressed records

recordcompresswriter : record-compressed files, only compress values

blockcompresswriter : block-compressed files, both keys & values are collected in 'blocks' separately and compressed. the size of the 'block' is configurable

優點

1 支援基于record和block的壓縮

2 支援splittable,能夠為mapreduce作為輸入分片

3 修改簡單,隻需要按照業務邏輯修改,不要考慮具體存儲格式

缺點

合并後的檔案不易檢視。hadoop fs -cat看不到,hadoop fs -text可以看到。

繼續閱讀