hive的数据文件存储格式

版权声明:版权声明中 https://blog.csdn.net/lds_include/article/details/88786967

hive的数据文件存储格式

类型

  • texfile:默认的存储格式:普通的文本文件,数据不压缩,磁盘的开销比较大,分析开销大。
  • sequencefile:提供的一种二进制存储格式,可以切割,天生压缩。
  • rcfile:提供的是一种行列混合存储方式,该方式会把相近的行和列数据放在一块儿,存储比较耗时,查询效率高,也天生压缩。
  • orc:是rcfile的一种优化存储。
  • parquet:自定义输入输出格式。

具体描述

1、texfile普通文本文件(通常默认的就是这个格式)

  • 创建表

    create table if not exists one (
    	id int,
    	name string
    )
    row format delimited fileds terminated by'\t'
    storted as textfile
    ;
    
  • 加载数据
    load data local inpath ‘localpath’ into table one;

2、sequencefile二进制放式:hive提供的二进制序列文件存储,天生压缩。默认支持压缩、分割,使用便捷、写和查询较快。sequencefile和压缩属性可以搭配使用

  • 注意:sequeceFile不允许使用load方式加载数据。需要使用insert 方式插入。

  • 创建数据

    create table if not exists tow(
    id int,
    name string
    )
    row format delimited fields terminated by '\t'
    lines terminated by '\n'
    stored as sequencefile
    ;
    
  • 加载数据正确方式

    insert into table tow select * from one;
    
  • 说明:存储的文件不能直接用cat命令去查看文件。

3、rcfile行列混合存储方式:rcfile可以进行行列混合压缩,将附近的列和行的数据尽量保存到相同的块里面,该存储格式会提高查询效率,但是写数据较慢。该方式和gzcodeC压缩属性结合不是很好,(orf与这个效果一样只是,他的效率比rcfile高很多)

  • 可以配合使用的压缩算法

    set mapred.output.compression=true;
    set mapred.output.compression.codec=org.apache.hadoop.io.compress.GzipCodec;
    
  • 注意: rcfile不允许使用load方式加载数据。需要使用insert 方式插入。

  • 创建数据

    create table if not exists three(
    id int,
    name string
    )
    row format delimited fields terminated by '\t'
    lines terminated by '\n'
    stored as rcfile
    ;
    
  • 加载数据正确方式

    insert into table three select * from one;
    

4、parquet存储自定义:

  • 创建数据

    扫描二维码关注公众号,回复: 5672420 查看本文章
    ##hello,hive
    ##hello,world
    ##hello,hadoop
    
  • 自定义创建表

    create table if not exists four(
    	str string
    )  
    stored as  
    inputformat 'org.apache.hadoop.hive.contrib.fileformat.base64.Base64TextInputFormat'  
    outputformat 'org.apache.hadoop.hive.contrib.fileformat.base64.Base64TextOutputFormat'
    ;
    
  • 加载数据

    load data local inpath 'localpath' into table four;
    
  • 注意:通常是使用 defaultCodec + rcfile搭配效率最好。

猜你喜欢

转载自blog.csdn.net/lds_include/article/details/88786967