从本地文件系统中导入数据到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;

从本地文件系统中导入数据到Hive表

load datalocalinpath ‘/home/sopdm/test.dat’ into table sopdm.wyp;

从HDFS上导入数据到Hive表

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

从别的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是追加

insertintotable 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

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

你可能感兴趣的:(从本地文件系统中导入数据到hive表)