一、创建Hive表
create table test001(id int, name string)
partitioned by(age int) //分区
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE;
建成表结构如下:
二、从本地导数据到Hive表
load data local inpath '/user/test001.txt' into table test001 partition (age=20) ;
三、从HDFS导数据到Hive表
load data inpath '/user/haha/test001.txt' into table test001 partition (age=20) ;
四、从别的表中查询出相应的数据并导入到Hive表中
1.静态分区插入
insert into table test001partition (age='20')
select id, name
from test002;
2.动态分区插入
insert into table test001
partition (age)
select id, name,age
from test002;
3.多表插入
from test003
insert into table test001
partition(age)
select id, name, age
insert into table test002
select id, name
where age>20;