You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sentry.apache.org by sr...@apache.org on 2016/10/11 16:47:14 UTC

sentry git commit: SENTRY-1459: Alter view with HMS Client fails with "java.lang.IllegalArgumentException: Can not create a Path from a null string" (Ankur Gupta, Reviewed by: Sravya Tirukkovalur)

Repository: sentry
Updated Branches:
  refs/heads/master e77ec8a6e -> 1e6ea0ea2


SENTRY-1459: Alter view with HMS Client fails with "java.lang.IllegalArgumentException: Can not create a Path from a null string" (Ankur Gupta, Reviewed by: Sravya Tirukkovalur)

Change-Id: I1761eb3b33e115de6cba17100d9af85bc0cb2b80


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

Branch: refs/heads/master
Commit: 1e6ea0ea2b8a1294d28990c35be95bcbe064f463
Parents: e77ec8a
Author: Sravya Tirukkovalur <sr...@apache.org>
Authored: Tue Oct 11 09:45:38 2016 -0700
Committer: Sravya Tirukkovalur <sr...@apache.org>
Committed: Tue Oct 11 09:45:38 2016 -0700

----------------------------------------------------------------------
 .../metastore/MetastoreAuthzBindingBase.java    | 19 ++++++++++-------
 ...actMetastoreTestWithStaticConfiguration.java |  9 ++++++++
 .../e2e/metastore/TestMetastoreEndToEnd.java    | 22 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sentry/blob/1e6ea0ea/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/metastore/MetastoreAuthzBindingBase.java
----------------------------------------------------------------------
diff --git a/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/metastore/MetastoreAuthzBindingBase.java b/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/metastore/MetastoreAuthzBindingBase.java
index fb7d246..3e2a9ea 100644
--- a/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/metastore/MetastoreAuthzBindingBase.java
+++ b/sentry-binding/sentry-binding-hive-common/src/main/java/org/apache/sentry/binding/metastore/MetastoreAuthzBindingBase.java
@@ -273,17 +273,21 @@ public abstract class MetastoreAuthzBindingBase extends MetaStorePreEventListene
         .getDbName(), context.getOldTable().getTableName());
 
     // if the operation requires location change, then add URI privilege check
-    String oldLocationUri;
-    String newLocationUri;
+    String oldLocationUri = null;
+    String newLocationUri = null;
     try {
-      oldLocationUri = PathUtils.parseDFSURI(warehouseDir,
-          getSdLocation(context.getOldTable().getSd()));
-      newLocationUri = PathUtils.parseDFSURI(warehouseDir,
-          getSdLocation(context.getNewTable().getSd()));
+      if (!StringUtils.isEmpty(context.getOldTable().getSd().getLocation())) {
+        oldLocationUri = PathUtils.parseDFSURI(warehouseDir,
+            getSdLocation(context.getOldTable().getSd()));
+      }
+      if (!StringUtils.isEmpty(context.getNewTable().getSd().getLocation())) {
+        newLocationUri = PathUtils.parseDFSURI(warehouseDir,
+            getSdLocation(context.getNewTable().getSd()));
+      }
     } catch (URISyntaxException e) {
       throw new MetaException(e.getMessage());
     }
-    if (oldLocationUri.compareTo(newLocationUri) != 0) {
+    if (!StringUtils.equals(oldLocationUri, newLocationUri)) {
       outputBuilder.addUriToOutput(getAuthServer(), newLocationUri,
           warehouseDir);
       operation = HiveOperation.ALTERTABLE_LOCATION;
@@ -291,7 +295,6 @@ public abstract class MetastoreAuthzBindingBase extends MetaStorePreEventListene
     authorizeMetastoreAccess(
         operation,
         inputBuilder.build(), outputBuilder.build());
-
   }
 
   private void authorizeAddPartition(PreAddPartitionEvent context)

http://git-wip-us.apache.org/repos/asf/sentry/blob/1e6ea0ea/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
index 9f35991..80ca5b5 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/AbstractMetastoreTestWithStaticConfiguration.java
@@ -101,6 +101,15 @@ public abstract class AbstractMetastoreTestWithStaticConfiguration extends
     return client.getTable(dbName, tabName);
   }
 
+  public Table createMetastoreView(HiveMetaStoreClient client, String dbName,
+      String tabName, List<FieldSchema> cols) throws Exception {
+
+    Table tbl = makeMetastoreTableObject(client, dbName, tabName, cols);
+    tbl.setTableType("VIRTUAL_VIEW");
+    client.createTable(tbl);
+    return tbl;
+  }
+
   public void addPartition(HiveMetaStoreClient client, String dbName,
       String tblName, List<String> ptnVals, Table tbl) throws Exception {
     Partition part = makeMetastorePartitionObject(dbName, tblName, ptnVals, tbl);

http://git-wip-us.apache.org/repos/asf/sentry/blob/1e6ea0ea/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
----------------------------------------------------------------------
diff --git a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
index c0f5fe8..59a4693 100644
--- a/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
+++ b/sentry-tests/sentry-tests-hive/src/test/java/org/apache/sentry/tests/e2e/metastore/TestMetastoreEndToEnd.java
@@ -276,6 +276,28 @@ public class TestMetastoreEndToEnd extends
   }
 
   /**
+   * Verify alter view privileges
+   * @throws Exception
+   */
+  @Test
+  public void testAlterViewPrivileges() throws Exception {
+    HiveMetaStoreClient client = context.getMetaStoreClient(ADMIN1);
+    createMetastoreView(client, dbName, tabName1,
+        Lists.newArrayList(new FieldSchema("col1", "int", "")));
+    client.close();
+
+    // verify group1 users with DDL privileges can alter tables in db_1
+    client = context.getMetaStoreClient(USER1_1);
+    Table metaView2 = client.getTable(dbName, tabName1);
+    metaView2.getSd().setCols(
+        Lists.newArrayList(new FieldSchema("col2", "double", "")));
+    client.alter_table(dbName, tabName1, metaView2);
+    Table metaView3 = client.getTable(dbName, tabName1);
+    assertEquals(metaView2.getSd().getCols(), metaView3.getSd().getCols());
+    client.close();
+  }
+
+  /**
    * Verify add partition privileges
    * @throws Exception
    */