Hive几种数据导入方式
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
1.從本地文件系統(tǒng)中導入數(shù)據(jù)到hive表
(1)數(shù)據(jù)準備(/home/sopdm/test.dat):
1,wyp,25,13188888888 2,test,30,13899999999 3,zs,34,89931412
(2)首先創(chuàng)建表 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)從本地文件系統(tǒng)中導入數(shù)據(jù)到Hive表
load data local inpath ‘/home/sopdm/test.dat’ into table sopdm.wyp;
(4)可以到wyp表的數(shù)據(jù)目錄下查看,如下命令
dfs -ls /user/sopdm/hive/warehouse/sopdm.db/wyp;
2.從HDFS上導入數(shù)據(jù)到Hive表
(1)現(xiàn)在hdfs中創(chuàng)建一個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)將內(nèi)容導入hive表中
--拷貝“本地數(shù)據(jù)”到“hive”使用:load data local… --轉(zhuǎn)移“HDFS”到“hive”(必須同一個集群)使用:load data… load data inpath ‘/user/sopdm/input/test_hdfs.dat’ into table sopdm.wyp;
3.從別的Hive表中導入數(shù)據(jù)到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;
--多表插入 --高效方式-查詢語句插入多個分區(qū) 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.創(chuàng)建Hive表的同時導入查詢數(shù)據(jù)
create table sopdm.wyp3 as select id,name,tel,age from sopdm.wyp where age=25;
5.使用sqoop從關(guān)系數(shù)據(jù)庫導入數(shù)據(jù)到Hive表 這個放在sqoop總結(jié)中去講解。
轉(zhuǎn)載于:https://my.oschina.net/u/2381604/blog/799451
總結(jié)
以上是生活随笔為你收集整理的Hive几种数据导入方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HTML5性能优化需要注意的几个问题
- 下一篇: java中的泛型的使用与理解