Hive常用的存储类型有:
1、TextFile: Hive默认的存储类型;文件大占用空间大,未压缩,查询慢;
2、Sequence File:
3、RCFile:facebook开发的一个集行存储和列存储的优点于一身,压缩比更高,读取列更快,它在mr环境中大规模数据处理中扮演着重要的角色;是一种行列存储相结合的存储方式,首先它将数据按行分块,保证同一个record在一个块中,避免读取一个记录需要读取多个record;一般情况下,hive表推荐使用RCFile;
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
Hive基础之Hive的存储类型
时间: 2024-10-04 18:40:19