create table score3 like score;
insert into table score3 partition(month ='201807') values ('001','002','100');
load data local 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;
常用于实际生产环境当中,将一张表拆开成两部分或者多部分
load data local inpath '/export/servers/hivedatas/score.csv' overwrite into table score partition(month='201806');
create table score_first( s_id string,c_id string) partitioned by (month string) row format delimited fields terminated by '\t' ;
create table score_second(c_id string,s_score int) partitioned by (month string) row format delimited fields terminated by '\t';
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;
将查询的结果保存到一张表当中去
create table score5 as select * from score;
1) 创建表,并指定在hdfs上的位置
create external table score6 (s_id string,c_id string,s_score int) row format delimited fields terminated by '\t' location '/myscore6';
2)上传数据到hdfs上
hdfs dfs -mkdir -p /myscore6
hdfs dfs -put score.csv /myscore6;
3)查询数据
select * from score6;
外部分区表和外部分桶表需要修复
create table techer2 like techer;
export table techer to '/export/techer';
import table techer2 from '/export/techer';
将hive表中的数据导出到其他任意目录,例如linux本地磁盘,例如hdfs,例如mysql等等
1) 将查询的结果导出到本地
insert overwrite local directory '/export/servers/exporthive' 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;
dfs -get /export/servers/exporthive/000000_0 /export/servers/exporthive/local.txt;
基本语法:(hive -f/-e 执行语句或者脚本 > file)
bin/hive -e "select * from myhive.score;" > /export/servers/exporthive/score.txt
export table score to '/export/exporthive/score';