Hive数据导入方式

来源:互联网 发布:网络与新媒体专业方向 编辑:程序博客网 时间:2024/05/29 18:11

一、创建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 test001
    partition (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;


原创粉丝点击