--建立數據表: create table if not exists textfile_table( site string, url string, pv bigint, label string) row format delimited fields terminated by '\t' stored as textfile; --插入數據: set hive.exec.compress.output=true; --啓用壓縮格式 set mapred.output.compress=true; set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec; --指定輸出的壓縮格式爲Gzip set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec; insert overwrite table textfile_table select * from T_Name;
create table if not exists seqfile_table( site string, url string, pv bigint, label string) row format delimited fields terminated by '\t' stored as sequencefile; --插入數據操做: set hive.exec.compress.output=true; --啓用輸出壓縮格式 set mapred.output.compress=true; set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec; --指定輸出壓縮格式爲Gzip set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec; SET mapred.output.compression.type=BLOCK; --指定爲Block insert overwrite table seqfile_table select * from T_Name;
存儲方式:數據按行分組,每組內按列存儲,默認行組大小是4MB 算法
行列混合存儲的優勢:sql
RCFile的一個行組包括三個部分:apache
create table if not exists rcfile_table( site string, url string, pv bigint, label string) row format delimited fields terminated by '\t' stored as rcfile; --插入數據操做: set hive.exec.compress.output=true; set mapred.output.compress=true; set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec; set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec; insert overwrite table rcfile_table select * from T_Name;
運用ORC File能夠提升Hive的讀、寫以及處理數據的性能。
與RCFile格式相比,ORCFile有如下優勢:
(1)、每一個task只輸出單個文件,這樣能夠減小NameNode的負載
(2)、支持複雜的數據類型,如: datetime, decimal, 以及一些複雜類型(struct, list, map, and union)
(3)、在文件中存儲了一些輕量級的索引數據
(4)、基於數據類型的塊模式壓縮:integer類型列用行程長度編碼;String類型列用字典編碼;
(5)、用多個互相獨立的RecordReaders並行讀相同的文件
(6)、無需掃描markers就能夠分割文件
(7)、綁定讀寫所須要的內存
(8)、metadata的存儲是用 Protocol Buffers的,因此它支持添加和刪除一些列api
create table Addresses ( name string, street string, city string ) row format delimited fields terminated by '\t' stored as orc tblproperties ("orc.compress"="NONE");
create table myfile_table(str STRING) stored as inputformat 'org.apache.hadoop.hive.contrib.fileformat.base64.Base64TextInputFormat' outputformat 'org.apache.hadoop.hive.contrib.fileformat.base64.Base64TextOutputFormat';
實驗所用表爲15列,共約300多條非重複記錄,總記錄數20123648oop
格式 | 大小 | 可分割 | * | col5 | count(*) | max(c1) | max(c1) where c5='xxx' |
textfile | 1.3GB | 是 | 31s | 21s | 23s | 25s | 26s |
rc-none | 1.0GB | 是 | 31s | 20s | 22s | 25s | 23s |
rc-gzip | 1.6MB | 否 | 27s | 1s | 1s | 31s | 28s |
orc-none | 53.3MB | 是 | 20s | 1s | 1s | 21s | 22s |
orc-zlib | 645.2KB | 是 | 20s | 1s | 1s | 21s | 21s |
實驗所用表爲72列,皆爲非重複記錄,總記錄數爲7644851性能
格式 | 大小 | 可分割 | * | c5 | count(*) | max(c5) | max(c5) where c9='T'測試 |
c2,count(*) group by c2編碼 |
textfile | 3.3G | 是 | 27 | 10 | 12 | 12 | 7 | 28 |
seq-none | 3.46G | 是 | 25 | 7 | 12 | 12 | 16 | 8 |
seq-block | 0.91G | 是 | 47 | 16 | 10 | 10 | 10 | 10 |
orc-none | 1.7G | 是 | 37 | 5 | 5 | 5 | 5 | 8 |
orc-zlib | 0.66G | 是 | 37 | 6 | 8 | 5 | 5 | 8 |
數據倉庫的特色:一次寫入、屢次讀取、並行執行,所以,總體來看,ORCFile相比其餘格式具備較明顯的優點。url