[Hive_add_9] Hive 的存储格式


0. 说明

  Hive 的存储格式 | textfile | sequencefile | rcfile | orc | parquet |


1. Hive的存储格式

  1.1 textfile

  行式存储 

  1.2 sequencefile

  二进制的k-v对,行式存储

  配置块压缩

  SET hive.exec.compress.output=true;
  
SET io.seqfile.compression.type=BLOCK;


  1.3 rcfile

  列式存储

  先将数据进行横切(4M),成为行组,行组内又纵向切割分为多个字段

  1.4 orc

  列式存储

  比 rc 文件更大的块(256M),优化磁盘的线性读取,通过指定的编码器确定数据类型并优化压缩
  还存储了基本统计数据,比如 min,max,sum,count。。。

  1.5 parquet

  列式存储

  适用范围更广(在 Hadoop 生态系统中)
  适用于嵌套文件格式


2. 测试 

  2.0 前期配置

  设置 Hive自动使用本地模式

SET hive.exec.mode.local.auto=true;

  输入文件大小低于此值会进入本地模式

SET hive.exec.mode.local.auto.inputbytes.max=500000000;

  输入文件个数低于此值会进入本地模式

SET hive.exec.mode.local.auto.input.files.max=5;

  设置seqFile使用块压缩

SET hive.exec.compress.output=true;
SET io.seqfile.compression.type=BLOCK;

  2.1 建表

create table user_seq(id int, name string, pass string, email string, nickname string) stored as SEQUENCEFILE;

create table user_rc(id int, name string, pass string, email string, nickname string) stored as rcfile;

create table user_orc2(id int, name string, pass string, email string, nickname string) stored as orc tblproperties("orc.compress"="ZLIB");

create table user_parquet2(id int, name string, pass string, email string, nickname string) stored as parquet tblproperties("parquet.compression"="GZIP");    

  2.2 插入数据

  导入大文件

load data local inpath '/home/centos/files/user_nopar.txt' into table user_nopar;

  插入数据

insert into user_seq select * from user_nopar;

insert into user_rc select * from user_nopar;

insert into user_orc2 select * from user_nopar;

insert into user_parquet2 select * from user_nopar;

  2.3 性能比较

  1. 比较生成文件大小
  text:45 MB
  seq:78.18 MB 性能差
  rc:114.84 KB
  orc:33.36 KB    //默认有压缩:ZLIB
  parquet:3.21 MB   //默认无压缩:NO ===GZIP==> 21.71 KB

  性能比较
  select count(*) from user_nopar;   //6.69
  select count(*) from user_seq;   //20.999 性能差
  select count(*) from user_rc;   //8.131
  select count(*) from user_orc2;   //6.84
  select count(*) from user_parquet2;   //2.56  √


原文地址:https://www.cnblogs.com/share23/p/10260168.html