大数据高频面试题之Hive表数据的加载与导出
Hive表数据加载1)直接向分区表中插入数据insert into table score3 partition(month =‘201807’) values (‘001’,‘002’,‘100’);2)通过查询插入数据先通过load加载创建一个表(linux) load data local inpath ‘/export/servers/hivedatas/score.csv’ overwr
Hive表数据加载
1)直接向分区表中插入数据
insert into table score3 partition(month =‘201807’) values (‘001’,‘002’,‘100’);
2)通过查询插入数据
先通过load加载创建一个表
(linux) load data local inpath ‘/export/servers/hivedatas/score.csv’ overwrite into table score partition(month=‘201806’);
(HDFS) load data inpath ‘/export/servers/hivedatas/score.csv’ overwrite into table score
partition(month=‘201806’);
通过查询方式加载数据
create table score4 like score;
insert overwrite table score4 partition(month = ‘201806’) select s_id,c_id,s_score from score;
关键字overwrite必须要有
3)多插入模式
from score
insert overwrite table score_first partition(month=‘201806’) select s_id,c_id
insert overwrite table score_second partition(month = ‘201806’) select c_id,s_score;
4)查询语句中创建表并加载数据(as select)
create table score5 as select * from score;
5)创建表时通过location指定加载数据路径
create external table score6 (s_id string,c_id string,s_score int) row format delimited fields terminated by ‘\t’ location ‘/myscore6’;
Hive表数据的导出
1)将查询的结果导出到本地
insert overwrite local directory ‘/export/servers/exporthive/a’ select * from score;
2)将查询的结果格式化导出到本地
insert overwrite local directory ‘/export/servers/exporthive’ row format delimited fields terminated by ‘\t’ collection items terminated by ‘#’ select * from student;
3)将查询的结果导出到HDFS上(没有local)
insert overwrite directory ‘/export/servers/exporthive’ row format delimited fields terminated by ‘\t’ collection items terminated by ‘#’ select * from score;
4)Hadoop命令导出到本地
dfs -get /export/servers/exporthive/000000_0 /export/servers/exporthive/local.txt;
5)hive shell 命令导出
bin/hive -e “select * from yhive.score;” > /export/servers/exporthive/score.txt
6)export导出到HDFS上(全表导出)
export table score to ‘/export/exporthive/score’;

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)