Hive带分区列的表更改列类型之坑

常见的一个场景是Hive里面一个带分区的表,原来是int类型的字段,后来发现数据超过了int的最大值,要改成bigint。或者是

bigint要改string或decimal。无论如何,对于带分区的表,要改列类型,有一个坑:

如果使用alter table t change column oldcol newcol bigint,即把int类型的oldcol改为bigint类型的newcol

这个时候,去读数据,应该还是NULL的。

这是因为每个分区Hive还会存一份元数据,于是两种解决方案:

一个是alter table t change column oldcol newcol bigint cascade

一个是alter table t change column oldcol newcol bigint, alter table t partition(...) change column oldcol newcol bigint

参考https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-AlterColumn

 

posted @ 2015-09-09 18:06  upo  阅读(5551)  评论(0)    收藏  举报