Repository: sentry
Updated Branches:
  refs/heads/master 4d9665f60 -> 13010b0b6


SENTRY-2299: NPE In Sentry HDFS Sync Plugin (Na Li, reviewed by Sergio Pena, 
Kalyan Kumar Kalvagadda, Arjun Mishra)


Project: http://git-wip-us.apache.org/repos/asf/sentry/repo
Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/13010b0b
Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/13010b0b
Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/13010b0b

Branch: refs/heads/master
Commit: 13010b0b600c4f2e7a7ea7f0ec8dcae87632950a
Parents: 4d9665f
Author: lina.li <[email protected]>
Authored: Fri Jul 13 15:10:52 2018 -0500
Committer: lina.li <[email protected]>
Committed: Fri Jul 13 15:10:52 2018 -0500

----------------------------------------------------------------------
 .../java/org/apache/sentry/hdfs/HMSPaths.java   |  8 +++++-
 .../org/apache/sentry/hdfs/TestHMSPaths.java    | 28 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/13010b0b/sentry-hdfs/sentry-hdfs-common/src/main/java/org/apache/sentry/hdfs/HMSPaths.java
----------------------------------------------------------------------
diff --git 
a/sentry-hdfs/sentry-hdfs-common/src/main/java/org/apache/sentry/hdfs/HMSPaths.java
 
b/sentry-hdfs/sentry-hdfs-common/src/main/java/org/apache/sentry/hdfs/HMSPaths.java
index 3919d60..97a04d9 100644
--- 
a/sentry-hdfs/sentry-hdfs-common/src/main/java/org/apache/sentry/hdfs/HMSPaths.java
+++ 
b/sentry-hdfs/sentry-hdfs-common/src/main/java/org/apache/sentry/hdfs/HMSPaths.java
@@ -878,7 +878,13 @@ public class HMSPaths implements AuthzPaths {
     if (!oldPathElements.equals(newPathElements)) {
       Entry oldEntry = root.find(oldPathElements.toArray(new String[0]), 
false);
       Entry newParent = root.createParent(newPathElements);
-      oldEntry.moveTo(newParent, newPathElements.get(newPathElements.size() - 
1));
+
+      if (oldEntry == null) {
+        LOG.warn(String.format("%s Moving old paths for renameAuthzObject({%s, 
%s} -> {%s, %s}) is skipped. Cannot find entry for old name",
+            this, oldName, assemblePaths(oldPathElems), newName, 
assemblePaths(newPathElems)));
+      } else {
+        oldEntry.moveTo(newParent, newPathElements.get(newPathElements.size() 
- 1));
+      }
     }
 
     // Re-write authObj from oldName to newName.

http://git-wip-us.apache.org/repos/asf/sentry/blob/13010b0b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestHMSPaths.java
----------------------------------------------------------------------
diff --git 
a/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestHMSPaths.java
 
b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestHMSPaths.java
index 20ed97c..fe2aa90 100644
--- 
a/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestHMSPaths.java
+++ 
b/sentry-hdfs/sentry-hdfs-common/src/test/java/org/apache/sentry/hdfs/TestHMSPaths.java
@@ -396,6 +396,34 @@ public class TestHMSPaths {
   }
 
   @Test
+  public void testRenameExternalTableDiffPaths() {
+    String[] prefixes = {"/user/hive/warehouse"};
+    HMSPaths paths = new HMSPaths(prefixes);
+    //Create old table and partition locations
+    String table1Path = "/user/external/warehouse/db1.db/table1";
+    String partition1Path = "/user/external/warehouse/db1.db/table1/part1";
+    paths.addAuthzObject("db1.table1",
+        HMSPaths.getPathsElements(Arrays.asList(table1Path, partition1Path)));
+
+    //Create new table location
+    String table2Path = "/user/external/warehouse/db2.db/table2";
+    paths.renameAuthzObject("db1.table1", 
HMSPaths.getPathsElements(Arrays.asList(table1Path)),
+        "db2.table2", HMSPaths.getPathsElements(Arrays.asList(table2Path)));
+
+    //Assert that old path is not associated with a table
+    Assert.assertEquals(null, 
paths.findAuthzObject(HMSPaths.getPathElements(table1Path)));
+    Assert.assertEquals(null, 
paths.findAuthzObject(HMSPaths.getPathElements(partition1Path)));
+
+    //Assert that new path is not associated with new table because no entry 
is created for external path
+    Assert.assertEquals(null, 
paths.findAuthzObject(HMSPaths.getPathElements(table2Path)));
+
+    //Assert that old path is not moved under new table
+    String partition2Path = "/user/external/warehouse/db2.db/table2/part1";
+    Assert.assertEquals(null,
+        paths.findAuthzObject(HMSPaths.getPathElements(partition2Path)));
+  }
+
+  @Test
   public void testRenameSamePaths() {
     String[] prefixes = {"/user/hive/warehouse"};
     HMSPaths paths = new HMSPaths(prefixes);

Reply via email to