Apache Hive File

Hive 文件存储格式主要包括以下几类:

  1. TEXTFILE
  2. SEQUENCEFILE
  3. RCFILE
  4. ORCFILE
    其中TEXTFILE为默认格式,建表时不指定默认为这个格式,导入数据时会直接把数据文件拷贝到hdfs上不进行处理;SEQUENCEFILE, RCFILE,ORCFILE格式得表不能直接从本地文件导入数据,数据要先导入到textfile格式得表中,然后再从表中用insert导入SequenceFile,RCFile,ORCFile表中
Hive环境
create table if not exists nsf_textfile
(
id string,chicun string,fbl string,qz string,hz string ,dc string,tag string ,phone string ,keywords string,xq string,type string, new_keyworlds string
) 
row format delimited fields terminated by '\t' stored as textfile;

load data local inpath '/home/cloudera/a2data/hive/file.txt' overwrite into table a2data.nsf_testfile;

**texffile:**默认格式,数据不做压缩,这样会导致磁盘空间占用大,数据解析资源大
可结合Gzip、Bzip2使用(系统自动检查,执行查询时自动解压), 但是使用这种方法, hive不会对数据进行切分,从而无法对数据进行并行操作

hive> set hive.exec.compress.output=true;
hive> set mapred.output.compress=true;
hive> set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec;
hive> set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec;
hive> inster overwrite table textfile_table select * from nsf_textfile;
~~

### SEQUENCEFILE
equenceFile是Hadoop API提供的一种二进制文件支持,其具有使用方便、可分割、可压缩的特点。

SequenceFile支持三种压缩选择:NONE,RECORD,BLOCK。Record压缩率低,一般建议使用BLOCK压缩。
~~~sql
create table if not exists seqfile_table(
id string,chicun string,fbl string,qz string,hz string ,dc string,tag string ,phone string ,keywords string,xq string,type string, new_keyworlds 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;  
set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec;  
SET mapred.output.compression.type=BLOCK;
insert overwrite table seqfile_table select * from textfile_table;  

RCFILE

RCFILE是一种行列存储相结合的存储方式。首先,其将数据按行分块,保证同一个record在一个块上,避免读一个记录需要读取多个block。其次,块数据列式存储,有利于数据压缩和快速的列存取。

create table if not exists rcfile_table(
id string,chicun string,fbl string,qz string,hz string ,dc string,tag string ,phone string ,keywords string,xq string,type string, new_keyworlds 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 textfile_table; 
ORCFILE

ORC File,它的全名是Optimized Row Columnar (ORC) file,其实就是对RCFile做了一些优化。这种文件格式可以提供一种高效的方法来存储Hive数据。它的设计目标是来克服Hive其他格式的缺陷。

运用ORC File可以提高Hive的读、写以及处理数据的性能。

和RCFile格式相比,ORC File格式有以下优点:

  1. 每个task只输出单个文件,这样可以减少NameNode的负载;

  2. 支持各种复杂的数据类型,比如: datetime, decimal, 以及一些复杂类型(struct, list, map, and union);

  3. 在文件中存储了一些轻量级的索引数据;

  4. 基于数据类型的块模式压缩:a、integer类型的列用行程长度编码(run-length encoding);b、String类型的列用字典编码(dictionary encoding);

  5. 用多个互相独立的RecordReaders并行读相同的文件;

  6. 无需扫描markers就可以分割文件;

  7. 绑定读写所需要的内存;

  8. metadata的存储是用 Protocol Buffers的,所以它支持添加和删除一些列。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值