hive建外部表时location修改问题

 

一、有一次外部表的时候,忘记设置location

create external table test.ads_education_course_feature_dm
(
	course_id string comment '课程id',
	course_name string comment '课程name',
	detail_browser_times string comment '详情页浏览次数',
	exposure_convert_borwser_rate string comment '曝光转化率',
	pay_flow_7day string comment '七日流水',
	complete_course_rate string comment '完课率',
	learn_times string comment '学习次数',
	learn_users string comment '学习用户数'
) comment '课程特征'
partitioned by (pt_d string comment '天分区')
row format delimited fields terminated by '\001'
stored as orc --注意未设置location

外部表结构

有一个临时 tmp_educenter_course_feature_dm(内部,测试需要)
create table test.tmp_educenter_course_feature_dm
(
    course_id string comment '课程id',
    course_name string comment '课程name',
    detail_browser_times string comment '详情页浏览次数',
    exposure_convert_borwser_rate string comment '曝光转化率',
    pay_flow_7day string comment '七日流水',
    complete_course_rate string comment '完课率',
    learn_times string comment '学习次数',
    learn_users string comment '学习用户数'
) comment '课程特征'
partitioned by (pt_d string comment '天分区')
row format delimited fields terminated by '\001'
stored as orc

插入测试数据

load data local inpath '/root/test.txt' into table test.tmp_educenter_course_feature_dm partition (pt_d='20201031');

二、直接关联其他的数据再插入到ads_education_course_feature_dm中

insert overwrite table test.ads_education_course_feature_dm partition(pt_d='20201031')
select 
    course_id,  --course_id
    course_name, --'课程name',
    detail_browser_times, --'详情页浏览次数',
    exposure_convert_borwser_rate, --'曝光转化率',
    pay_flow_7day, --'七日流水',
    complete_course_rate, --'完课率',
    learn_times, --'学习次数',
    learn_users   --'学习用户数'
from test.tmp_educenter_course_feature_dm
where pt_d='20201031'

查看外部表的分区

show partitions test.ads_education_course_feature_dm;

查看外部表路径下的分区文件

hdfs dfs -ls  hdfs://node01:8020/user/hive/warehouse/test.db/ads_education_course_feature_dm

三、直接修改外部表location

alter table test.ads_education_course_feature_dm set location '/myhive/ads/ads_education_course_feature_dm'

四、再次插入执行数据插入

insert overwrite table test.ads_education_course_feature_dm partition(pt_d='20201031')
select 
    course_id,  --course_id
    course_name, --'课程name',
    detail_browser_times, --'详情页浏览次数',
    exposure_convert_borwser_rate, --'曝光转化率',
    pay_flow_7day, --'七日流水',
    complete_course_rate, --'完课率',
    learn_times, --'学习次数',
    learn_users   --'学习用户数'
from test.tmp_educenter_course_feature_dm
where pt_d='20201031'

五、查看修改后的location下的分区文件,发现并没有分区20201031的文件,覆盖的文件还是写到了原来的location地址

六、对于已经存在分区文件的外部表,如果要修改location,记得对已经存在的分区单独设置location,再进行数据的insert overwrite 的时候就会在新location路径下创文件

alter table test.ads_education_course_feature_dm set location '/myhive/ads/ads_education_course_feature_dm';

alter table test.ads_education_course_feature_dm partition(pt_d='20201031') set location '/myhive/ads/ads_education_course_feature_dm'; 
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值