0
votes

So I had a shell script try to run a hive command to add a partition by passing it something like formatted_date=2016-01-01 and the hive sql do something like

alter table my_db.table add partition (create_dt = '${formatted_date}'
location '/user/.....'

what ended up happening was it created a partition named

create_dt=$%7Bformatted_date}

That's fine, I just want to drop this partition. But running a drop partition command like below doesn't actually drop the partition.

alter table my_db.table drop partition (create_dt = "create_dt=$%7Bcurrdate}")

I'm guessing this has something to do with the encoded URL chars. What's the best way to drop this partition?

edit:

I got lucky because my partitions were setup such that the malformed partition ended up being ordered as the first partition so I used a statement like this to drop it:

alter table my_db.table drop partition (create_dt < '2016-01-01');

where 2016-01-01 was the earliest partition and the one ordered after the malformed one.

Not an ideal solution and am still looking to see how to deal with encoded/control chars in a partition value.

1

1 Answers

0
votes

Looks like those are special characters that could be escaped out of using a regular expression. I would try below but unfortunately I can't test the code. Good luck!

alter table my_db.table drop partition (create_dt rlike '\\$\\%7Bcurrdate\\}')