5

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.

The storage format for the table in Parquet.

For e.g,

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

Result : NULL

Please let me know how to fix this issue?

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

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

Regards, Adarsh K S

Adarsh
  • 177
  • 1
  • 13

1 Answers1

-1

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 );
  • Above solution is not reasonable for partitioned tables, also replace columns will update the DDL but the extra column stays on for EXTERNAL tables. I'd caution against taking this approach, without understanding what is happening under the hood – Fremzy Jan 31 '23 at 00:05