--建立数据表: 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