淄博网站建设铭盛信息,项目建设计划书,百度竞价网站建设,2017网站建设方案Hive文件存储格式包括以下几类#xff1a; 1、TEXTFILE 2、SEQUENCEFILE 3、RCFILE 4、ORCFILE 其中TEXTFILE为默认格式#xff0c;建表时不指定默认为这个格式#xff0c;导入数据时会直接把数据文件拷贝到hdfs上不进行处理。 SEQUENCEFILE#xff0c;RCFILE#xff0c;O… Hive文件存储格式包括以下几类 1、TEXTFILE 2、SEQUENCEFILE 3、RCFILE 4、ORCFILE 其中TEXTFILE为默认格式建表时不指定默认为这个格式导入数据时会直接把数据文件拷贝到hdfs上不进行处理。 SEQUENCEFILERCFILEORCFILE格式的表不能直接从本地文件导入数据数据要先导入到textfile格式的表中 然后再从表中用insert导入SequenceFile,RCFile,ORCFile表中。 更多用法一定要去看官网啊 https://cwiki.apache.org/confluence/display/Hive/LanguageManualDDL 一、TEXTFILE 格式默认格式数据不做压缩磁盘开销大数据解析开销大。 可结合Gzip、Bzip2使用(系统自动检查执行查询时自动解压)但使用这种方式Hive不会对数据进行切分 从而无法对数据进行并行操作。 示例 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; 插入数据操作 Hive Hive.exec.compress.outputtrue;
Hive set mapred.output.compresstrue;
Hive set mapred.output.compression.codecorg.apache.hadoop.io.compress.GzipCodec;
Hive set io.compression.codecsorg.apache.hadoop.io.compress.GzipCodec;
Hive insert overwrite table textfile_table select * from textfile_table; 二、SEQUENCEFILE 格式 SequenceFile是Hadoop API提供的一种二进制文件支持其具有使用方便、可分割、可压缩的特点。 SequenceFile支持三种压缩选择NONERECORDBLOCK。Record压缩率低一般建议使用BLOCK压缩。 示例 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; 插入数据操作 Hive set Hive.exec.compress.outputtrue;
Hive set mapred.output.compresstrue;
Hive set mapred.output.compression.codecorg.apache.hadoop.io.compress.GzipCodec;
Hive set io.compression.codecsorg.apache.hadoop.io.compress.GzipCodec;
Hive SET mapred.output.compression.typeBLOCK;
Hive 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 delimited
fields terminated by \t
stored as rcfile; 插入数据操作 Hive set Hive.exec.compress.outputtrue;
Hive set mapred.output.compresstrue;
Hive set mapred.output.compression.codecorg.apache.hadoop.io.compress.GzipCodec;
Hive set io.compression.codecsorg.apache.hadoop.io.compress.GzipCodec;
Hive insert overwrite table rcfile_table select * from textfile_table; 四、ORCFILE() 以后补充 五、再看TEXTFILE、SEQUENCEFILE、RCFILE三种文件的存储情况 [hadoopmaster ~]$ hadoop dfs -dus /user/Hive/warehouse/* hdfs://master :9000/user/Hive/warehouse/hbase_table_1 0 hdfs://master :9000/user/Hive/warehouse/hbase_table_2 0 hdfs://master :9000/user/Hive/warehouse/orcfile_table 0 hdfs://master :9000/user/Hive/warehouse/rcfile_table 102638073 hdfs://master :9000/user/Hive/warehouse/seqfile_table 112497695 hdfs://master :9000/user/Hive/warehouse/testfile_table 536799616 hdfs://master :9000/user/Hive/warehouse/textfile_table 107308067 [hadoopsinglehadoop ~]$ 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和SEQUENCEFILERCFILE由于列式存储方式数据加载时性能消耗较大但是具有较好的压缩比和查询响应。 数据仓库的特点是一次写入、多次读取因此整体来看RCFILE相比其余两种格式具有较明显的优势。 以下本文转自于。http://blog.csdn.net/cnbird2008/article/details/9182869 Hive数据压缩 本文介绍Hadoop系统中Hive数据压缩方案的比较结果及具体压缩方法。 一、压缩方案比较 关于Hadoop HDFS文件的压缩格式选择我们通过多个真实的Track数据做测试得出结论如下 1. 系统的默认压缩编码方式 DefaultCodec 无论在压缩性能上还是压缩比上都优于GZIP 压缩编码。这一点与网上的一些观点不大一致网上不少人认为GZIP的压缩比要高一些估计和Cloudera的封装及我们Track的数据类型有关。 2. Hive文件的RCFile 的在压缩比压缩效率及查询效率上都优于SEQENCE FILE (包括RECORD, BLOCK 级别) 。 3. 所有压缩文件均可以正常解压为TEXT 文件但比原始文件略大可能是行列重组造成的。 关于压缩文件对于其他组件是适用性如下 1. Pig 不支持任何形式的压缩文件。 2. Impala 目前支持SequenceFile的压缩格式但还不支持RCFile的压缩格式。 综上所述 从压缩及查询的空间和时间性能上来说DefaultCodeC RCFile的压缩方式均为最优但使用该方式会使得Pig 和Impala 无法使用Impala的不兼容不确定是否是暂时的。 而DefaultCodeC SequenceFile 在压缩比查询性能上略差于RCFile (压缩比约 6:5), 但可以支持 Impala实时查询。 推荐方案 采用RCFile 方式压缩历史数据。FackBook全部hive表都用RCFile存数据。 二、局部压缩方法 只需要两步 1. 创建表时指定压缩方式默认不压缩以下为示例 create external table track_hist( id bigint, url string, referer string, keyword string, type int, gu_idstring, …/*此处省略中间部分字段*/ …, string,ext_field10 string) partitioned by (ds string) stored as RCFile location /data/share/track_histk ; 2. 插入数据是设定立即压缩 SET hive.exec.compress.outputtrue; insert overwrite table track_histpartition(ds2013-01-01) select id,url, …/*此处省略中间部分字段*/ …, ext_field10 fromtrackinfo where ds2013-01-01; 三、全局方式修改属性文件 在hive-site.xml中设置 property namehive.default.fileformat/name valueRCFile/value descriptionDefault file format for CREATE TABLE statement.Options are TextFile and SequenceFile. Users can explicitly say CREAT E TABLE ... STORED ASlt;TEXTFILE|SEQUENCEFILEgt; to override/description /property property namehive.exec.compress.output/name valuetrue/value description This controls whether the final outputs of a query(to a local/hdfs file or a hive table) is compressed. The compres sion codec and other options are determinedfrom hadoop config variables mapred.output.compress* /description 四、注意事项 1、Map阶段输出不进行压缩 2、对输出文本进行处理时不压缩 本文转自大数据躺过的坑博客园博客原文链接http://www.cnblogs.com/zlslch/p/6103760.html如需转载请自行联系原作者