Repository: sentry Updated Branches: refs/heads/sentry-ha-redesign 0613eb62b -> 8aaa73de7
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) Project: http://git-wip-us.apache.org/repos/asf/sentry/repo Commit: http://git-wip-us.apache.org/repos/asf/sentry/commit/8aaa73de Tree: http://git-wip-us.apache.org/repos/asf/sentry/tree/8aaa73de Diff: http://git-wip-us.apache.org/repos/asf/sentry/diff/8aaa73de Branch: refs/heads/sentry-ha-redesign Commit: 8aaa73de7585eb1e28080eb48ae7c06906cedcff Parents: 0613eb6 Author: Alexander Kolbasov <ak...@cloudera.com> Authored: Mon Mar 13 16:21:37 2017 -0700 Committer: Alexander Kolbasov <ak...@cloudera.com> Committed: Mon Mar 13 18:29:48 2017 -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/8aaa73de/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/8aaa73de/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 5f6ad0f..d0139ad 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 @@ -121,6 +121,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 Partition 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/8aaa73de/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 98ec814..5cd69e1 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 */