`
cumtheima
  • 浏览: 253420 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

hive学习总结(1)—Hive几种数据导入方式

    博客分类:
  • Hive
阅读更多

1.从本地文件系统中导入数据到hive表

 

(1)数据准备(/home/sopdm/test.dat):

 

  1,wyp,25,13188888888

  2,test,30,13899999999

  3,zs,34,89931412

 

(2)首先创建表

use sopdm;

drop table if exists sopdm.wyp;

create table if not exists sopdm.wyp(id int,name string,age int,tel string)

row format delimited

fields terminated by ','

stored as textfile;

 

(3)从本地文件系统中导入数据到Hive

 

load data local inpath ‘/home/sopdm/test.dat’ into table sopdm.wyp;

 

(4)可以到wyp表的数据目录下查看,如下命令

 

dfs  -ls  /user/sopdm/hive/warehouse/sopdm.db/wyp;

 

2.从HDFS上导入数据到Hive表

 

(1)现在hdfs中创建一个input目录存放HDFS文件

hadoop fs -mkdir input;     hadoop fs -mkdir /user/sopdm/input;

 

(2)把本地文件上传到HDFS,并重命名为test_hdfs.dat

hadoop fs -put /home/sopdm/test.dat /user/sopdm/input/test_hdfs.dat;

 

(3)查看文件

dfs -cat /user/sopdm/input/test_hdfs.dat;

 

(4)将内容导入hive表中

 

--拷贝“本地数据“hive”使用:load data local…

--转移“HDFS”“hive”(必须同一个集群)使用:load data…

load data inpath ‘/user/sopdm/input/test_hdfs.dat’ into table sopdm.wyp;

 

3.从别的Hive表中导入数据到Hive表中

 

create table if not exists sopdm.wyp2(id int,name string,tel string)

row format delimited

fields terminated by ','

stored as textfile;

 

--overwrite是覆盖,into是追加

insert into table sopdm.wyp2

select id,name,tel from sopdm.wyp;

 

--多表插入

--高效方式-查询语句插入多个分区

from sopdm.wyp w

insert overwrite table sopdm.wyp2

    select w.id,w.name,w.tel where w.age=25

insert overwrite table sopdm.wyp2

    select w.id,w.name,w.tel where w.age=27;

 

4.创建Hive表的同时导入查询数据

 

create table sopdm.wyp3

       as select id,name,tel,age from sopdm.wyp where age=25;

 

5.使用sqoop从关系数据库导入数据到Hive

    这个放在sqoop总结中去讲解。

 

1
0
分享到:
评论
1 楼 cumtheima 2014-11-21  
多多提问交流哦!

相关推荐

Global site tag (gtag.js) - Google Analytics