hive add partition statement ignores leading zero

前提是你 提交于 2019-12-11 12:06:26

问题


I've folder on hdfs
/user/test/year=2016/month=04/dt=25/000000_0

Need to add this above partition path to a test table.

command :

ALTER TABLE test ADD IF NOT EXISTS PARTITION (year=2016,month=04,dt=25)

But this add partition command is ignoring the leading zero in the month partition and creates an extra folder inside 2016 as month=4. /user/test/year=2016/month=04/ /user/test/year=2016/month=4/ and table will be pointed to /user/test/year=2016/month=4/ this path which doesn't contain any data.

I've checked the logs which says WARN org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer - Partition Spec month=04 has been changed to month=4

Please let me know if anyone faced this kind of issue and how to avoid this?

Hive version is : 1.2.1000


回答1:


You are using integer type for partitions. If you need leading zeros than use string partitions and quotes: ALTER TABLE test ADD IF NOT EXISTS PARTITION (year='2016',month='04',dt='25')




回答2:


You can use MSCK REPAIR TABLE test if partition folders already created. It will scan all directories and create new partitions. For more details visit Hive Language Manual. Or you should use STRING for partition columns instead of INT.



来源:https://stackoverflow.com/questions/38017321/hive-add-partition-statement-ignores-leading-zero

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