Is it possible to change the metadata of a column that is on a partitioned table in Hive?

橙三吉。 提交于 2019-12-02 13:19:57

问题


This is an extension of a previous question I asked: Is it possible to change partition metadata in HIVE?

We are exploring the idea of changing the metadata on the table as opposed to performing a CAST operation on the data in SELECT statements. Changing the metadata in the MySQL metastore is easy enough. But, is it possible to have that metadata change applied to a column that is on a partitioned table (they are daily)? Note: the column itself is not the partitioning column. It is a simple ID field that is being changed from STRING to BIGINT.

Otherwise, we might be stuck with current and future data being of type BIGINT while the historical is STRING.

Question: Is it possible to change partition meta data in Hive? If yes, how?

Note: I am asking this as a separate question as the original answer appears to be for a column on a partitioned table that is also the partitioning column. So, I do not want to muddy the waters.

Update:

I ran the ALTER TABLE .. CHANGE COLUMN ... CASCADE command, but I get the following error:

Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Not allowed to alter schema of Avro stored table having external schema. Consider removing avro.schema.literal or avro.schema.url from table properties.

The metadata is stored in a separate avro file. I can confirm that the updated metadata is in the avro file, but not in the individual partition file.

Note: The table is stored as EXTERNAL.


回答1:


You can easily change column type:

Use alter table in Hive, change type to STRING, etc:

alter table table_name change column col_name col_name string cascade; --change to string

See documentation.

ALTER TABLE CHANGE COLUMN with CASCADE command changes the columns of a table's metadata, and cascades the same change to all the partition metadata.

Alternatively you can recreate table like in this answer: https://stackoverflow.com/a/58299056/2700344



来源:https://stackoverflow.com/questions/58333567/is-it-possible-to-change-the-metadata-of-a-column-that-is-on-a-partitioned-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!