如何在Hive中重命名分区值? [英] How to rename partition value in Hive?

查看:739
本文介绍了如何在Hive中重命名分区值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个配置单元表"videotracking_playevent",它使用以下分区格式(所有字符串):source/createyear/createmonth/createday.示例:source = home/createyear = 2016/createmonth = 9/createday = 1

I have a hive table 'videotracking_playevent' which uses the following partition format (all strings): source/createyear/createmonth/createday. Example: source=home/createyear=2016/createmonth=9/createday=1

我正在尝试更新createmonth和createday的分区值,以始终使用两位数代替.示例:source = home/createyear = 2016/createmonth = 09/createday = 01

I'm trying to update the partition values of createmonth and createday to consistently use double digits instead. Example: source=home/createyear=2016/createmonth=09/createday=01

我尝试执行以下查询:

ALTER TABLE videotracking_playevent PARTITION (
source='home', 
createyear='2015', 
createmonth='11', 
createday='1'
) RENAME TO PARTITION (
source='home', 
createyear='2015', 
createmonth='11', 
createday='01'
);

但是,它从hive返回以下非描述性错误:执行错误,从org.apache.hadoop.hive.ql.exec.DDLTask返回代码1.空

However that returns the following, non-descriptive error from hive: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. null

我已经确认该分区存在,并且我认为我使用的是正确的语法.我的蜂巢版本是Hive 1.1.0有什么想法我可能做错了吗?

I've confirmed that this partition exists, and I think I'm using the correct syntax. My hive version is Hive 1.1.0 Any ideas what I might be doing wrong?

推荐答案

旧版本的Hive带有重命名分区的问题.对于您的情况,这也可能是一个问题.请参阅此链接详细信息.

There was an issue with old version of Hive with renaming partition. This might be an issue for your case too. Please see this link for detail.

如果使用的是较旧版本的Hive,则在执行重命名分区命令之前,需要设置以下两个属性.

You need to set below two property before executing the rename partition command if you are using Older version of Hive.

set fs.hdfs.impl.disable.cache=false; 
set fs.file.impl.disable.cache=false; 

现在通过设置此属性来运行查询.

Now run the query by setting this property.

hive> set fs.hdfs.impl.disable.cache=false;
hive> set  fs.file.impl.disable.cache=false;
hive> ALTER TABLE partition_test PARTITION (year='2016',day='1') RENAME TO PARTITION (year='2016',day='01');
OK
Time taken: 0.28 seconds
hive> show partitions partition_test;
OK
year=2016/day=01
Time taken: 0.091 seconds, Fetched: 1 row(s)
hive>

此问题已在Hive最新版本中修复.在我的情况下,Hive版本为1.2.1,并且无需设置该属性即可工作.请参见下面的示例.

This issue is fixed in Hive latest version. In my case Hive version is 1.2.1 and it works, without setting that property. Please see the example below.

创建分区表.

hive> create table partition_test(
    > name string,
    > age int)
    > partitioned by (year string, day string);
OK
Time taken: 5.35 seconds
hive> 

现在添加分区并检查新添加的分区.

Now add the partition and check the newly added partition.

hive> alter table partition_test ADD PARTITION (year='2016', day='1');
OK
Time taken: 0.137 seconds
hive>


hive> show partitions partition_test;
OK
year=2016/day=1
Time taken: 0.169 seconds, Fetched: 1 row(s)
hive>

使用 RENAME TO PARTITION 命令重命名分区并进行检查.

Rename the partition using RENAME TO PARTITION command and check it.

hive> ALTER TABLE partition_test PARTITION (year='2016',day='1') RENAME TO PARTITION (year='2016',day='01');
OK
Time taken: 0.28 seconds
hive> show partitions partition_test;
OK
year=2016/day=01
Time taken: 0.091 seconds, Fetched: 1 row(s)
hive>

希望它对您有帮助.

这篇关于如何在Hive中重命名分区值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆