You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by yc...@apache.org on 2020/10/05 23:45:45 UTC
[hive] branch master updated: Show tables in database with owner
policy (#1380)
This is an automated email from the ASF dual-hosted git repository.
ychena pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 595d2f3 Show tables in database with owner policy (#1380)
595d2f3 is described below
commit 595d2f3fdfc5b61ea9916690714e3111cab45cd8
Author: saihemanth-cloudera <68...@users.noreply.github.com>
AuthorDate: Mon Oct 5 16:45:24 2020 -0700
Show tables in database with owner policy (#1380)
* Show tables in database with owner policy
* Trigger ptests
* HIVE-23969: Show tables in database with owner policy
* Trigger ptests again
* Trigger ptests again
---
.../plugin/TestHiveAuthorizerCheckInvocation.java | 17 +++++++++++++++++
.../metastore/filtercontext/TableFilterContext.java | 3 +--
.../org/apache/hadoop/hive/metastore/HiveMetaStore.java | 11 +++++++++--
3 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
index d046822..506bb7c 100644
--- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
+++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/authorization/plugin/TestHiveAuthorizerCheckInvocation.java
@@ -619,6 +619,23 @@ public class TestHiveAuthorizerCheckInvocation {
assertEquals("table name", inDbTableName.toLowerCase(), dbObj.getObjectName());
}
+ @Test
+ public void showTablesInDB() throws Exception{
+ final String tableName1 = "table1";
+ driver.run("create table " + dbName+"."+tableName1 + "(eid int, yoj int)");
+ final String tableName2 = "table2";
+ driver.run("create table " + dbName+"."+tableName2 + "(eid int, ecode int)");
+ reset(mockedAuthorizer);
+
+ int status = driver.compile("show tables in "+dbName, true);
+ assertEquals(0, status);
+ Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> io = getHivePrivilegeObjectInputs();
+ List<HivePrivilegeObject> inputs = io.getLeft();
+ HivePrivilegeObject dbObj = inputs.get(0);
+ assertEquals("input type", HivePrivilegeObjectType.DATABASE, dbObj.getType());
+ assertTrue(dbObj.getOwnerName() != null);
+ }
+
private void checkSingleTableInput(List<HivePrivilegeObject> inputs) {
assertEquals("number of inputs", 1, inputs.size());
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/filtercontext/TableFilterContext.java b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/filtercontext/TableFilterContext.java
index b140200..2b6814b 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/filtercontext/TableFilterContext.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/filtercontext/TableFilterContext.java
@@ -69,8 +69,7 @@ public class TableFilterContext extends HiveMetaStoreAuthorizableEvent {
HivePrivilegeObjectType type = HivePrivilegeObjectType.TABLE_OR_VIEW;
HivePrivObjectActionType objectActionType = HivePrivilegeObject.HivePrivObjectActionType.OTHER;
HivePrivilegeObject hivePrivilegeObject =
- new HivePrivilegeObject(type, table.getDbName(), table.getTableName(), null, null, objectActionType, null,
- null);
+ new HivePrivilegeObject(type, table.getDbName(), table.getTableName(), null, null, objectActionType, null, null, table.getOwner(), table.getOwnerType());
ret.add(hivePrivilegeObject);
}
} else {
diff --git a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index 8645994..d00dcd9 100644
--- a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -5841,8 +5841,15 @@ public class HiveMetaStore extends ThriftHiveMetastore {
String[] parsedDbName = parseDbName(dbname, conf);
try {
ret = getMS().getTables(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], pattern);
- ret = FilterUtils.filterTableNamesIfEnabled(isServerFilterEnabled, filterHook,
- parsedDbName[CAT_NAME], parsedDbName[DB_NAME], ret);
+ if(ret != null && !ret.isEmpty()) {
+ List<Table> tableInfo = new ArrayList<>();
+ tableInfo = getMS().getTableObjectsByName(parsedDbName[CAT_NAME], parsedDbName[DB_NAME], ret);
+ tableInfo = FilterUtils.filterTablesIfEnabled(isServerFilterEnabled, filterHook, tableInfo);// tableInfo object has the owner information of the table which is being passed to FilterUtils.
+ ret = new ArrayList<>();
+ for (Table tbl : tableInfo) {
+ ret.add(tbl.getTableName());
+ }
+ }
} catch (MetaException e) {
ex = e;
throw e;