瞌睡中的葡萄虎

博客园 首页 新随笔 联系 订阅 管理

Hive常用的存储类型有:

1、TextFile: Hive默认的存储类型;文件大占用空间大,未压缩,查询慢;

2、Sequence File:将属于以<KEY,VALUE>的形式序列化到文件中;该类型的文件存储略大于TEXTFILE类型;

3、RCFile:面向列的文件格式。遵循“先按列划分再按行划分”的理念。在查询过程中,针对它并不关心的列时会在IO上跳过这些列;RCFile并没有性能优势,只是在存储上省了10%的空间,因为列的数据类型是一样的,更方便进行压缩;在读取所有列的情况下,RCFile的性能还没有SequenceFile高。

RCFile案例:

创建表:

create table emp_rcfile(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
row format delimited fields terminated by '\t' lines terminated by '\n' 
stored as rcfile;

加载表数据:

load data local inpath '/home/spark/software/data/emp.txt' overwrite into table emp_rcfile;

报错:
Failed with exception Wrong file format. Please check the file's format.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask

解决方法:在创建rcfile表的同时再创建一个textfile的临时表,将数据先导入到textfile表中

创建与rcfile表相同的textfile的表:

create table emp_rcfile_raw(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int
)
row format delimited fields terminated by '\t' lines terminated by '\n' 
stored as textfile;

导入原始数据到textfile的表:

load data local inpath '/home/spark/software/data/emp.txt' overwrite into table emp_rcfile_raw;

然后再将textfile表中的数据插入到rcfile表中:

insert into table emp_rcfile select * from emp_rcfile_raw;

查看hdfs文件

hadoop fs -ls /user/hive/warehouse/emp_rcfile 
/user/hive/warehouse/emp_rcfile/000000_0

 

posted on 2014-08-14 13:33  瞌睡中的葡萄虎  阅读(2803)  评论(0编辑  收藏  举报