博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mark : Hive文件格式(表STORE AS 的四种类型)
阅读量:4217 次
发布时间:2019-05-26

本文共 3732 字,大约阅读时间需要 12 分钟。

hive文件存储格式包括以下几类:

1、TEXTFILE

2、SEQUENCEFILE

3、RCFILE

4、ORCFILE(0.11以后出现)

其中TEXTFILE为默认格式,建表时不指定默认为这个格式,导入数据时会直接把数据文件拷贝到hdfs上不进行处理;

SEQUENCEFILE,RCFILE,ORCFILE格式的表不能直接从本地文件导入数据,数据要先导入到textfile格式的表中, 然后再从表中用insert导入SequenceFile,RCFile,ORCFile表中。

前提创建环境:

hive 0.8

创建一张testfile_table表,格式为textfile。

create table if not exists testfile_table( site string, url  string, pv   bigint, label string) row format delimited fields terminated by '\t' stored as textfile;

load data local inpath '/app/weibo.txt' overwrite into table textfile_table;

一、TEXTFILE

默认格式,数据不做压缩,磁盘开销大,数据解析开销大。
可结合Gzip、Bzip2使用(系统自动检查,执行查询时自动解压),但使用这种方式,hive不会对数据进行切分,
从而无法对数据进行并行操作。
示例:

create table if not exists textfile_table(site string,url  string,pv   bigint,label string)row format delimitedfields 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;  set io.compression.codecs=org.apache.hadoop.io.compress.GzipCodec;  insert overwrite table textfile_table select * from textfile_table;

二、SEQUENCEFILE

SequenceFile是Hadoop API提供的一种二进制文件支持,其具有使用方便、可分割、可压缩的特点。
SequenceFile支持三种压缩选择:NONE,RECORD,BLOCK。Record压缩率低,一般建议使用BLOCK压缩。
示例:

create table if not exists seqfile_table(site string,url  string,pv   bigint,label string)row format delimitedfields 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。其次,块数据列式存储,有利于数据压缩和快速的列存取。
RCFILE文件示例:

create table if not exists rcfile_table(site string,url  string,pv   bigint,label string)row format delimitedfields 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()

五、再看TEXTFILE、SEQUENCEFILE、RCFILE三种文件的存储情况:

[hadoop@node3 ~]$ hadoop dfs -dus /user/hive/warehouse/*hdfs://node1:19000/user/hive/warehouse/hbase_table_1    0hdfs://node1:19000/user/hive/warehouse/hbase_table_2    0hdfs://node1:19000/user/hive/warehouse/orcfile_table    0hdfs://node1:19000/user/hive/warehouse/rcfile_table    102638073hdfs://node1:19000/user/hive/warehouse/seqfile_table   112497695hdfs://node1:19000/user/hive/warehouse/testfile_table  536799616hdfs://node1:19000/user/hive/warehouse/textfile_table  107308067[hadoop@node3 ~]$ hadoop dfs -ls /user/hive/warehouse/*/-rw-r--r--   2 hadoop supergroup   51328177 2014-03-20 00:42 /user/hive/warehouse/rcfile_table/000000_0-rw-r--r--   2 hadoop supergroup   51309896 2014-03-20 00:43 /user/hive/warehouse/rcfile_table/000001_0-rw-r--r--   2 hadoop supergroup   56263711 2014-03-20 01:20 /user/hive/warehouse/seqfile_table/000000_0-rw-r--r--   2 hadoop supergroup   56233984 2014-03-20 01:21 /user/hive/warehouse/seqfile_table/000001_0-rw-r--r--   2 hadoop supergroup  536799616 2014-03-19 23:15 /user/hive/warehouse/testfile_table/weibo.txt-rw-r--r--   2 hadoop supergroup   53659758 2014-03-19 23:24 /user/hive/warehouse/textfile_table/000000_0.gz-rw-r--r--   2 hadoop supergroup   53648309 2014-03-19 23:26 /user/hive/warehouse/textfile_table/000001_1.gz

总结:

相比TEXTFILE和SEQUENCEFILE,RCFILE由于列式存储方式,数据加载时性能消耗较大,但是具有较好的压缩比和查询响应。数据仓库的特点是一次写入、多次读取,因此,整体来看,RCFILE相比其余两种格式具有较明显的优势。

转载地址:http://wuvmi.baihongyu.com/

你可能感兴趣的文章
自动驾驶汽车传感器数字孪生建模(一)
查看>>
CUDA 学习(四)、线程
查看>>
CUDA 学习(五)、线程块
查看>>
CUDA 学习(八)、线程块调度
查看>>
CUDA 学习(九)、CUDA 内存
查看>>
CUDA 学习(十一)、共享内存
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十四章 生化尖兵
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十五章 超级马里奥64
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十六章 Raptor Safari
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十七章 游戏感的原理
查看>>
游戏感:虚拟感觉的游戏设计师指南——第十八章 我想做的游戏
查看>>
游戏设计的艺术:一本透镜的书——第十章 某些元素是游戏机制
查看>>
游戏设计的艺术:一本透镜的书——第十一章 游戏机制必须平衡
查看>>
游戏设计的艺术:一本透镜的书——第十二章 游戏机制支撑谜题
查看>>
游戏设计的艺术:一本透镜的书——第十三章 玩家通过界面玩游戏
查看>>
编写苹果游戏中心应用程序(翻译 1.3 为iOS应用程序设置游戏中心)
查看>>
编写苹果游戏中心应用程序(翻译 1.4 添加游戏工具包框架)
查看>>
编写苹果游戏中心应用程序(翻译 1.5 在游戏中心验证本地玩家)
查看>>
编写苹果游戏中心应用程序(翻译 1.6 获取本地玩家的信息)
查看>>
编写苹果游戏中心应用程序(翻译 1.7 在游戏中心添加朋友)
查看>>