第2节 hive基本操作:10、外部分区表综合练习

mac2022-06-30  75

外部分区表综合练习:

需求描述:现在有一个文件score.csv文件,存放在集群的这个目录下/export/servers/scoredatas/month=201806,这个文件每天都会生成,存放到对应的日期文件夹下面去,文件别人也需要公用,不能移动。需求,创建hive对应的表,并将数据加载到表中,进行数据统计分析,且删除表之后,数据不能删除

 

需求实现:

数据准备:

hdfs dfs -mkdir -p /scoredatas/month=201806

hdfs dfs -put score.csv /scoredatas/month=201806/

 

创建外部分区表,并指定文件数据存放目录

 

create external table score4(s_id string, c_id string,s_score int) partitioned by (month string) row format delimited fields terminated by '\t' location '/scoredatas';

 

 

进行表的修复,说白了就是建立我们表与我们数据文件之间的一个关系映射

msck  repair   table  score4;

 

修复成功之后即可看到数据已经全部加载到表当中去了

 

 

第二种实现方式,上传数据之后手动添加分区即可

数据准备:

hdfs dfs -mkdir -p /scoredatas/month=201806

hdfs dfs -put score.csv /scoredatas/month=201806

 

修改表,进行手动添加方式

alter table score4 add partition(month='201806');

转载于:https://www.cnblogs.com/mediocreWorld/p/11055758.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)