Hive数据加载,hive加载
Hive数据加载,hive加载
内表数据加载
创建表时加载
create table newtable as select col1,col2 from oldtable
hive> create table testNew as select name,addr from testtable;
hive> select * from testNew;
OK
liguodong cd
aobama lsj
liguodong cd
aobama lsj
创建表时指定数据位置
create table tablename location '/**/**'
create table if not exists testNew2(
name string comment 'name value',
addr string comment 'addr value'
)
row format delimited fields terminated by '\t'
lines terminated by '\n'
stored as textfile
location '/liguodong/hivedata'
;
本地数据加载
load data local inpath 'localpath' [overwrite] into table tablename
追加
hive> load data local inpath '/liguodong/hivedata/datatest' into table testNew2;
覆盖
load data local inpath '/liguodong/hivedata/datatest' overwrite into table testNew2;
加载hdfs数据
load data inpath 'hdfspath' [overwrite] into table tablename
注:这个操作是移动数据,而不是复制数据。
load data inpath '/liguodong/datatest' into table testNew2;
load data inpath '/liguodong/datatest' overwrite into table testNew2;
使用Hadoop命令拷贝数据到指定位置(hive的shell中执行和Linux的shell执行)
由查询语句加载数据
insert [overwrite | into] table tablename
select col1,col2 from table where ...
from table
insert [overwrite | into ]table tablename
select col1,col2
where ...
注意:字段对应不同于一些关系型数据库。
外表数据加载
创建表时指定数据位置
create external table tablename() location ''
查询插入,同内表
使用Hadoop命令拷贝数据到指定位置(hive的shell中执行和Linux的Shell执行)
版权声明:本文为博主原创文章,未经博主允许不得转载。
评论暂时关闭