hive加载数据和导出数据

1.hive加载数据



1.1、load方式加载数据

两种:
1、load data local inpath "/home/hadoop/student.txt" into table student;
2、load data inpath "/appstudent/student.txt" into table student;
3、hadoop fs -put /home/hadoop/student.txt /user/hive/warehouse/myhive.db/student


1.2、insert方法加载数据

五种:
1、单个insert插入
insert into table (id, name , sex, age ,department) values (1,2,3,4,5),(1,2,3,4,5);
2、insert .... select ....
insert into table (id, name, sex, age, department) select id,name, sex,age, department from student;
3、多重插入
from student
insert into table ptn_student partition (department = 'CS') select * where department = 'CS'
insert into table ptn_student partition (department = 'IS') select * where department = 'IS'
4、分区插入
分两种:
1、静态分区插入
先添加分区:alter table ptn-student add partition (city="bj");
加载数据;load data local inpath "studnet.txt" into table pnt_student parition(city="bj");
2、动态分区
两个条件:
1、开启动态分区的开关
set hive.exec.dynamic.partition=true;
2、默认的动态分区的模式为严格模式
在严格模式下,进行动态分区插入要求至少要有一列静态分区,并且静态分区必须在前面
set hive.exec.dynamic.partition.mode = nonstrict;


动态分区插入的语句:
insert into table ptn_student partition(city) select id,name,sex,city from student;


注意:动态分区的字段必须是select的最后一个字段


2.insert方式导出数据

分两种:


1、导出到本地;
insert overwrite local direcotry "/home/hadoop/appstudent" select * from student;


2、导出到HDFS:
insert overwrite direcotry "/appstudent" select * from student;
insert overwrite direcotry "hdfs://hadoop02:9000/appstudent" select * from student;


3、hive表的数据进行备份:
export : 导出备份
import : 载入备份

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值