08hive数据导入

一.向表中装载数据(Load)

1、语法
	load data local inpath '/root/hivedata/stu.txt' 
		[overwrite] into table student [partition(partcoll=vall,……)];			
			load data:表示加载数据
			local:表示从本地加载数据到hive表,否则从HDFS加载数据到hive表
			inpath:表示加载数据的路径
			overwrite:表示覆盖表中已有数据
			into :表示加载到哪张表,表示追加
			student:表示具体的表
			partition:表示上传到指定分区
2、实操过程
0.1创建一张表
	create table student(id string,name string) 
		row format delimited fields terminated by '\t';
0.2加载本地文件到hive
	load data local inpath '/root/hivedata/student.txt' into table default.student; === 这个加载是cp复制
0.3上传文件到HDFS
	hdfs dfs -put /root/hivedata/student.txt /datas/; 
0.4加载HDFS上的数据到hive
	load data inpath '/datas/student.txt' into table default.student; === 这个加载是移动

二.通过查询语句向表中插入数据(Insert)

1、创建一张分区表
create table student(id int,name string) partitioned by (month string)
	row format delimited fields terminated by '\t';
2、原始插入数据
insert into table student partition(month='202001') values(1,'haohao');
3、基本模式插入
insert overwrite table student partition (month='202001') select id,name from student where month='202002')
4、多插入模式
from student 
insert overwrite table student partition(month='201908')
select id,name
insert overwrite table student partition(month='201909')
select id,name

三.查询语句创建表并加载数据(As Select)

create table if not exists student_one as select id,name from student;

四.创建表时通过Location指定加载数据路径

1、创建表,并指定hdfs上的位置
create table if not exists school(id int,name string)
	row format delimited fields terminated by '\t'
	location '/user/root/hive/school';
2、上传数据到hdfs上
dfs -put /root/hivedata/stu.txt  /user/hive/warehouse/school;
3、查询数据
select * from school;
4、实例
dfs -mkdir -p /user/hao;
dfs -put /root/hivedata/student.txt /user/hao/;
create table student4 like student location '/user/hao/';
select * from student4;

五.Import数据到指定hive表中

import table school partition(month='201909') from 
	  '/user/hive/warehouse/export/school';
 注意:先用export导出后,再将数据导入。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hao难懂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值