简体   繁体   English

hive 列名称更改而不会丢失分区 avro 表中的数据

[英]hive column name alter without loosing data in portitioned avro table

i have a avro hive table partitioned by date.我有一个按日期分区的 avro hive 表。

acct_no <string> acct_cd <int>  date <date>
acct01           01             2022-10-31
acct02           02             2022-10-31 
acct03           03             2022-10-31  

i want to rename acct_cd to account_code我想将 acct_cd 重命名为 account_code

i used command我用命令

alter table <table_name> change acct_cd account_code int;

it changed the table attribute but data lost:它更改了表属性但数据丢失:

acct_no <string> account_code <int>  date <date>
acct01         null                  2022-10-31
acct02         null                  2022-10-31 
acct03         null                  2022-10-31 

How to avoid losing data and change the column name?如何避免丢失数据和更改列名?

As per hive, hive , change a column name just changes hive metadata, underlying data/structure remains as is.根据hive、hivechange列名只会更改 hive 元数据,底层数据/结构保持原样。 Which means, you have to take care of the data after alter.这意味着,您必须在更改后处理数据。

You have two options -你有两个选择 -

  1. Create a backup table.创建备份表。 Drop original table.删除原始表。 Crete a new table with new column name and insert into the new table from backup table.使用新列名创建一个新表,并从备份表插入到新表中。
  2. Create a backup table.创建备份表。 Rename the column in original table.重命名原始表中的列。 Use insert overwrite table command to fillup original table from backup table.使用insert overwrite table命令从备份表中填充原始表。

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

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