天天看点

Hive(31):将txt数据导入ORC格式表一、实现功能二、实例三、参考

一、实现功能

将txt或者csv数据加载到orc格式的hive中,因为不能直接创建orc类型数据,而直接将txt(csv)数据load进入orc表,会报错。所以,需要创建一个textfile格式中间表。

二、实例

1.创建textfile临时表:

create table if not exists people_orc_txt(
  name string,
  gender string
)
row format delimited
 fields terminated by ','
 stored as textfile;
 
           

 2.创建ORC表:

drop table people_orc;
create table if not exists people_orc(
  name string,
  gender string
)
row format delimited
 fields terminated by ','
 STORED AS ORC;
           

3.创建测试数据  

vi /opt/data/people.txt
zhangs,male
lisi,male
wangwu,male
           

4.将测试数据导入临时普通表:

load data local inpath '/opt/data/people.txt' into table people_orc_txt;
           

5.将临时普通表的数据插入到ORC表:

insert into table people_orc select * from people_orc_txt;
           

三、参考

1.Difference between 'Stored as InputFormat, OutputFormat' and 'Stored as' in Hive

2.Loading Data from a .txt file to Table Stored as ORC in Hive