Repository: hive Updated Branches: refs/heads/master 3e8ae68eb -> afd0d9ffc
HIVE-17472: Drop-partition for multi-level partition fails, if data does not exist. (Chris Drome, reviewed by Mithun Radhakrishnan) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/afd0d9ff Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/afd0d9ff Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/afd0d9ff Branch: refs/heads/master Commit: afd0d9ffc4d8bc39effbb9f7324fcafa7518b141 Parents: 3e8ae68 Author: Mithun RK <mit...@apache.org> Authored: Tue Sep 12 11:45:57 2017 -0700 Committer: Mithun RK <mit...@apache.org> Committed: Thu Sep 21 11:06:01 2017 -0700 ---------------------------------------------------------------------- .../hadoop/hive/metastore/HiveMetaStore.java | 6 +- .../clientpositive/drop_deleted_partitions.q | 18 +++++ .../drop_deleted_partitions.q.out | 74 ++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/afd0d9ff/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java ---------------------------------------------------------------------- diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index b863d48..c5140e5 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -3589,8 +3589,10 @@ public class HiveMetaStore extends ThriftHiveMetastore { } private void deleteParentRecursive(Path parent, int depth, boolean mustPurge) throws IOException, MetaException { - if (depth > 0 && parent != null && wh.isWritable(parent) && wh.isEmpty(parent)) { - wh.deleteDir(parent, true, mustPurge); + if (depth > 0 && parent != null && wh.isWritable(parent)) { + if (wh.isDir(parent) && wh.isEmpty(parent)) { + wh.deleteDir(parent, true, mustPurge); + } deleteParentRecursive(parent.getParent(), depth - 1, mustPurge); } } http://git-wip-us.apache.org/repos/asf/hive/blob/afd0d9ff/ql/src/test/queries/clientpositive/drop_deleted_partitions.q ---------------------------------------------------------------------- diff --git a/ql/src/test/queries/clientpositive/drop_deleted_partitions.q b/ql/src/test/queries/clientpositive/drop_deleted_partitions.q new file mode 100644 index 0000000..a758b1b --- /dev/null +++ b/ql/src/test/queries/clientpositive/drop_deleted_partitions.q @@ -0,0 +1,18 @@ +create database dmp; + +create table dmp.mp (a string) partitioned by (b string, c string) location '/tmp/dmp_mp'; + +alter table dmp.mp add partition (b='1', c='1'); + +show partitions dmp.mp; + +dfs -rm -R /tmp/dmp_mp/b=1; + +explain extended alter table dmp.mp drop partition (b='1'); +alter table dmp.mp drop partition (b='1'); + +show partitions dmp.mp; + +drop table dmp.mp; + +drop database dmp; http://git-wip-us.apache.org/repos/asf/hive/blob/afd0d9ff/ql/src/test/results/clientpositive/drop_deleted_partitions.q.out ---------------------------------------------------------------------- diff --git a/ql/src/test/results/clientpositive/drop_deleted_partitions.q.out b/ql/src/test/results/clientpositive/drop_deleted_partitions.q.out new file mode 100644 index 0000000..e543158 --- /dev/null +++ b/ql/src/test/results/clientpositive/drop_deleted_partitions.q.out @@ -0,0 +1,74 @@ +PREHOOK: query: create database dmp +PREHOOK: type: CREATEDATABASE +PREHOOK: Output: database:dmp +POSTHOOK: query: create database dmp +POSTHOOK: type: CREATEDATABASE +POSTHOOK: Output: database:dmp +#### A masked pattern was here #### +PREHOOK: type: CREATETABLE +#### A masked pattern was here #### +PREHOOK: Output: database:dmp +PREHOOK: Output: dmp@mp +#### A masked pattern was here #### +POSTHOOK: type: CREATETABLE +#### A masked pattern was here #### +POSTHOOK: Output: database:dmp +POSTHOOK: Output: dmp@mp +PREHOOK: query: alter table dmp.mp add partition (b='1', c='1') +PREHOOK: type: ALTERTABLE_ADDPARTS +PREHOOK: Output: dmp@mp +POSTHOOK: query: alter table dmp.mp add partition (b='1', c='1') +POSTHOOK: type: ALTERTABLE_ADDPARTS +POSTHOOK: Output: dmp@mp +POSTHOOK: Output: dmp@mp@b=1/c=1 +PREHOOK: query: show partitions dmp.mp +PREHOOK: type: SHOWPARTITIONS +PREHOOK: Input: dmp@mp +POSTHOOK: query: show partitions dmp.mp +POSTHOOK: type: SHOWPARTITIONS +POSTHOOK: Input: dmp@mp +b=1/c=1 +#### A masked pattern was here #### +PREHOOK: query: explain extended alter table dmp.mp drop partition (b='1') +PREHOOK: type: ALTERTABLE_DROPPARTS +POSTHOOK: query: explain extended alter table dmp.mp drop partition (b='1') +POSTHOOK: type: ALTERTABLE_DROPPARTS +STAGE DEPENDENCIES: + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-0 + Drop Table Operator: + Drop Table + table: dmp.mp + +PREHOOK: query: alter table dmp.mp drop partition (b='1') +PREHOOK: type: ALTERTABLE_DROPPARTS +PREHOOK: Input: dmp@mp +PREHOOK: Output: dmp@mp@b=1/c=1 +POSTHOOK: query: alter table dmp.mp drop partition (b='1') +POSTHOOK: type: ALTERTABLE_DROPPARTS +POSTHOOK: Input: dmp@mp +POSTHOOK: Output: dmp@mp@b=1/c=1 +PREHOOK: query: show partitions dmp.mp +PREHOOK: type: SHOWPARTITIONS +PREHOOK: Input: dmp@mp +POSTHOOK: query: show partitions dmp.mp +POSTHOOK: type: SHOWPARTITIONS +POSTHOOK: Input: dmp@mp +PREHOOK: query: drop table dmp.mp +PREHOOK: type: DROPTABLE +PREHOOK: Input: dmp@mp +PREHOOK: Output: dmp@mp +POSTHOOK: query: drop table dmp.mp +POSTHOOK: type: DROPTABLE +POSTHOOK: Input: dmp@mp +POSTHOOK: Output: dmp@mp +PREHOOK: query: drop database dmp +PREHOOK: type: DROPDATABASE +PREHOOK: Input: database:dmp +PREHOOK: Output: database:dmp +POSTHOOK: query: drop database dmp +POSTHOOK: type: DROPDATABASE +POSTHOOK: Input: database:dmp +POSTHOOK: Output: database:dmp