hive add partition statement ignores leading zero

2019-08-15 13:08发布

问题:

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.



标签: hadoop hive yarn