Hive alter table更改列名称将"NULL"赋予重命名的列 [英] Hive alter table change column name gives 'NULL' to the renamed column

查看:977
本文介绍了Hive alter table更改列名称将"NULL"赋予重命名的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将表中的现有列重命名为新列.但是,在更改名称后,新列仅给了我'NULL'值.

I had tried to rename an existing column in a table to a new one. But after the name change, the new column is giving me only 'NULL' value.

Parquet中表的存储格式.

The storage format for the table in Parquet.

例如

用户"是字符串数据类型的测试"表中的一列.插入了一个示例记录,其值为'John'.

'user' is a column in 'Test' table of string data type. Inserted a sample record with value as 'John'.

Select user from Test;

结果:约翰

Result : John

我已将用户"重命名为用户名",而未更改任何数据类型.

I have renamed 'user' to 'user_name' without changing any data type.

ALTER TABLE Test CHANGE user user_name String;

Select user_name from Test;

结果:NULL

Result : NULL

请让我知道如何解决此问题?

Please let me know how to fix this issue?

在这种情况下,MSCK修复表命令是否有用?

Whether MSCK Repair table command be of any use in this case?

我是否需要重新加载此表以解决此问题?

Do I need to reload this table again to fix this issue?

关于, Adarsh K S

Regards, Adarsh K S

推荐答案

您可以做的是添加新字段,执行一次插入覆盖,然后删除旧字段. 像这样:

What you can do is add the new field, execute one insert overwrite and then delete the old field. Something like this:

ALTER TABLE temp.Test ADD COLUMNS (user_new string) CASCADE;

insert overwrite table temp.Test
select 
      user_a,
      a,
      b,
      c,
      user_a as user_new
from temp.test;

ALTER TABLE temp.test  REPLACE COLUMNS(user_new string, a string, b string, c string );

这篇关于Hive alter table更改列名称将"NULL"赋予重命名的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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