简体   繁体   English

Hive alter table change列名称为重命名的列提供“NULL”

[英]Hive alter table change column name gives 'NULL' to the renamed column

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. 但是在名称更改后,新列只给了我'NULL'值。

The storage format for the table in Parquet. Parquet中表格的存储格式。

For eg, 例如,

'user' is a column in 'Test' table of string data type. 'user'是字符串数据类型的'Test'表中的一列。 Inserted a sample record with value as 'John'. 插入一个样本记录,其值为“John”。

Select user from Test;

Result : John 结果:约翰

I have renamed 'user' to 'user_name' without changing any data type. 我已将'user'重命名为'user_name'而不更改任何数据类型。

ALTER TABLE Test CHANGE user user_name String;

Select user_name from Test;

Result : NULL 结果:NULL

Please let me know how to fix this issue? 请让我知道如何解决这个问题?

Whether MSCK Repair table command be of any use in this case? 在这种情况下,MSCK Repair table命令是否有用?

Do I need to reload this table again to fix this issue? 我是否需要再次重新加载此表以解决此问题?

Regards, Adarsh KS 此致,Adarsh KS

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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM