为了账号安全,请及时绑定邮箱和手机立即绑定

HIVE数据导入基础

标签:
Java

Hive的几种常见的数据导入方式

1- 从本地文件系统中导入数据到Hive表

hive> 
create table table01    
> (id int, name string,    
> age int, tel string)    
> ROW FORMAT DELIMITED    
> FIELDS TERMINATED BY '\t'    
> STORED AS TEXTFILE;
load data local inpath 'table01.txt' into table table01;


2- HDFS上导入数据到Hive表

从本地文件系统中将数据导入到Hive表的过程中,其实是先将数据临时复制到HDFS的一个目录下,

然后再将数据从那个临时目录下移动到对应的Hive表的数据目录里面.

load data inpath '/home/table01/add.txt' into table table01;

3- 从别的表中查询出相应的数据并导入到Hive表中

hive> 
create table test(    
> id int, name string    
> ,tel string)    
> partitioned by    
> (age int)    
> ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' STORED AS TEXTFILE;	

执行导入的操作

insert into table test   
 > partition (age='25')    
 > select id, name, tel    
 > from table01;	
 	
 insert overwrite table test    
 > PARTITION (age)    
 > select id, name, tel, age    
 > from table01;


4- 在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表中

create table test4    
> as    
> select id, name, tel    
> from table01;

5- 案例从txt格式导入到orc格式:

textfile格式的hive表  insert into到orc格式的hive表

1-分别创建textfile和orc表
create table t_txt
(id int, name string,age int,tel string)
ROW FORMAT DELIMITEDFIELDS TERMINATED BY '\t'STORED AS TEXTFILE;	
	
create table t_orc
(id int, name string,age int, tel string)
STORED AS orc;

2- 导入数据到textfile1	
ccc 18	159516169092	
lich	88	14567890976
load data local inpath '/home/hadoop/data/t_txt.txt' into table t_txt;

3- 导入到orc表
insert into table t_orc
select *from t_txt;	





点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
6396
获赞与收藏
157

关注作者,订阅最新文章

阅读免费教程

  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消