Hive TextFile、OrcFile存储格式以及相应压缩算法的测试

一、存储格式介绍

  1. TextFile
    ·存储格式:作为hive当中默认的存储格式
    ·存储方式:行式存储
    ·缺点:磁盘开销大,数据解析开销大。
    ·用处:可结合Gzip、Bzip2使用(系统自 动检查,执行查询时自动解压),但使用这种方式,压缩后的文件不支持split,Hive不会对数据进行切分,从而无法对数据进行并行操作。
  2. SequenceFile
    ·格式支持:SequenceFile是Hadoop API提供的一种二进制文件支持
    ·存储方式:行式存储
    ·优点:其具有使用方便、可分割、 可压缩的特点
    ·压缩选择:支持三种压缩选择:NONE,RECORD,BLOCK。
    其中,Record压缩率低,一般建议使用BLOCK压缩。 优势是文件和hadoop api中的MapFile是相互兼容的
  3. RCFile
    ·存储方式:数据按行分块,每块按列存储。
    ·优点:结合了行存储和列存储的所长。RCFile 保证同一行的数据位于同一节点,因此元组重构的开销很低; 其次,像列存储一样,RCFile 能够利用列维度的数据压缩,并且能跳过不必要的列读取
    ·具体介绍:
    RCFile的一个行组包括三个部分:
    第一部分是:行组头部的【同步标识】,主要用于分隔 hdfs 块中的两个连续行组
    第二部分是:行组的【元数据头部】,用于存储行组单元的信息,包括行组中的记录数、每个列的字节数、列中每 个域的字节数
    第三部分是:【表格数据段】,即实际的列存储数据。在该部分中,同一列的所有域顺序存储。 从图可以看出,首先存储了列 A 的所有域,然后存储列 B 的所有域等。

在这里插入图片描述

  1. ORCFile
    ·存储方式:数据按行分块 每块按照列存储。
    ·优点:压缩快、快速列存取。效率比rcfile高,是rcfile的改良版本。

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

二、案例实操
⚠️ 指定的路径要使用联邦路径头,要不报错。
在这里插入图片描述

  1. 建表语句准备
###方案1:存储格式为OrcFile、压缩算法:Snappy
create table if not exists default.dwm_lbs_fusion_anal_hour_001
(
    c_code string comment 'c编码',
    r_code string comment 'r编码',
    data_type string comment '类型:1、2、3',
    event_time string comment '时间',
    lon string comment '经度',
    lat string comment '纬度'
)
    comment '测试表3'
    partitioned by (day_id string comment '账期:天', hour_id string comment '账期:时', province_code string comment '省份编码')
    row format delimited fields terminated by ','
  stored AS orcfile 
location 'hdfs://Bservice03/domain/ns3/ml/tmp_lbs.db/lbs/tmp/dwm_lbs_fusion_anal_houre_003'
tblproperties("orc.compress"="SNAPPY");

###方案2:存储格式为OrcFile、压缩算法:none
create table if not exists default.dwm_lbs_fusion_anal_hour_002
(
    c_code string comment 'c编码',
    r_code string comment 'r编码',
    data_type string comment '类型:1、2、3',
    event_time string comment '时间',
    lon string comment '经度',
    lat string comment '纬度'
)
    comment '测试表3'
    partitioned by (day_id string comment '账期:天', hour_id string comment '账期:时', province_code string comment '省份编码')
    row format delimited fields terminated by ','
  stored AS orcfile 
location 'hdfs://Bservice03/domain/ns3/ml/tmp_lbs.db/lbs/tmp/dwm_lbs_fusion_anal_houre_002';

###方案3:存储格式为TextFile、压缩算法:Gzip
create table if not exists default.dwm_lbs_fusion_anal_hour_003
(
    c_code string comment 'c编码',
    r_code string comment 'r编码',
    data_type string comment '类型:1、2、3',
    event_time string comment '时间',
    lon string comment '经度',
    lat string comment '纬度'
)
    comment '测试表3'
    partitioned by (day_id string comment '账期:天', hour_id string comment '账期:时', province_code string comment '省份编码')
    row format delimited fields terminated by ','
  stored AS textfile 
location 'hdfs://Bservice03/domain/ns3/ml/tmp_lbs.db/lbs/tmp/dwm_lbs_fusion_anal_houre_001';
--设置压缩类型为Gzip压缩 
SET hive.exec.compress.output=true; 
SET mapred.output.compress=true; 
SET mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec; 

###方案4:存储格式为TextFile、压缩算法:none
create table if not exists default.dwm_lbs_fusion_anal_hour_004
(
    c_code string comment 'c编码',
    r_code string comment 'r编码',
    data_type string comment '类型:1、2、3',
    event_time string comment '时间',
    lon string comment '经度',
    lat string comment '纬度'
)
    comment '测试表3'
    partitioned by (day_id string comment '账期:天', hour_id string comment '账期:时', province_code string comment '省份编码')
    row format delimited fields terminated by ','
  stored AS textfile 
location 'hdfs://Bservice03/domain/ns3/ml/tmp_lbs.db/lbs/tmp/dwm_lbs_fusion_anal_houre_001';
  1. 动态插入数据
insert into dwm_lbs_fusion_anal_houre_001 partition (day_id,hour_id,province_code) select * from aaa;
insert into dwm_lbs_fusion_anal_houre_002 partition (day_id,hour_id,province_code) select * from aaa;
insert into dwm_lbs_fusion_anal_houre_003 partition (day_id,hour_id,province_code) select * from aaa;
insert into dwm_lbs_fusion_anal_houre_004 partition (day_id,hour_id,province_code) select * from aaa;
  1. 存储大小比较
  2. 查询效率比较
    在这里插入图片描述

三、初步结论
在这里插入图片描述

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值