mayankkunwar commented on code in PR #5269:
URL: https://github.com/apache/hive/pull/5269#discussion_r1619883119


##########
ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/HiveMetaStoreAuthorizer.java:
##########
@@ -213,15 +214,46 @@ public final List<String> filterCatalogs(List<String> 
catalogs) throws MetaExcep
 
   @Override
   @Deprecated
-  public List<TableMeta> filterTableMetas(String catName, String 
dbName,List<TableMeta> tableMetas)
+  public List<TableMeta> filterTableMetas(String catName, String dbName, 
List<TableMeta> tableMetas)
       throws MetaException {
-    return filterTableMetas(tableMetas);
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("==> HiveMetaStoreAuthorizer.filterTableMetas()");
+    }
+    List<String> tableNames = new ArrayList<>();
+    List<TableMeta> filteredTableMetas = new ArrayList<>();
+    if (tableMetas != null) {
+      for (TableMeta tableMeta : tableMetas) {
+        tableNames.add(tableMeta.getTableName());
+      }
+      TableFilterContext     tableFilterContext     = new 
TableFilterContext(dbName, tableNames);
+      HiveMetaStoreAuthzInfo hiveMetaStoreAuthzInfo = 
tableFilterContext.getAuthzContext();
+      final List<String>  filteredTableNames = 
filterTableNames(hiveMetaStoreAuthzInfo, dbName, tableNames);
+      if (CollectionUtils.isEmpty(filteredTableNames)) {
+        filteredTableMetas = Collections.emptyList();
+        if (LOG.isInfoEnabled()) {
+          LOG.info("<== HiveMetaStoreAuthorizer.filterTableMetas() : returning 
empty set");
+        }
+      } else {
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("<== HiveMetaStoreAuthorizer.filterTableMetas() : " + 
filteredTableNames);
+        }
+        filteredTableMetas = tableMetas.stream().filter(tblMeta -> 
filteredTableNames.stream()
+            .anyMatch(tblName -> 
tblName.equals(tblMeta.getTableName()))).collect(Collectors.toList());
+      }
+    }
+    return filteredTableMetas;
   }
 
   @Override
   public final List<TableMeta> filterTableMetas(List<TableMeta> tableMetas)
       throws MetaException {
-    return tableMetas;
+    String catName = null;
+    String dbName = null;
+    if (tableMetas != null) {

Review Comment:
   If "tableMetas" is empty, can it throw ArrayOutOfBound exception?



##########
ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/HiveMetaStoreAuthorizer.java:
##########
@@ -213,15 +214,46 @@ public final List<String> filterCatalogs(List<String> 
catalogs) throws MetaExcep
 
   @Override
   @Deprecated
-  public List<TableMeta> filterTableMetas(String catName, String 
dbName,List<TableMeta> tableMetas)
+  public List<TableMeta> filterTableMetas(String catName, String dbName, 
List<TableMeta> tableMetas)
       throws MetaException {
-    return filterTableMetas(tableMetas);
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("==> HiveMetaStoreAuthorizer.filterTableMetas()");
+    }
+    List<String> tableNames = new ArrayList<>();
+    List<TableMeta> filteredTableMetas = new ArrayList<>();
+    if (tableMetas != null) {
+      for (TableMeta tableMeta : tableMetas) {
+        tableNames.add(tableMeta.getTableName());
+      }
+      TableFilterContext     tableFilterContext     = new 
TableFilterContext(dbName, tableNames);
+      HiveMetaStoreAuthzInfo hiveMetaStoreAuthzInfo = 
tableFilterContext.getAuthzContext();
+      final List<String>  filteredTableNames = 
filterTableNames(hiveMetaStoreAuthzInfo, dbName, tableNames);
+      if (CollectionUtils.isEmpty(filteredTableNames)) {
+        filteredTableMetas = Collections.emptyList();
+        if (LOG.isInfoEnabled()) {
+          LOG.info("<== HiveMetaStoreAuthorizer.filterTableMetas() : returning 
empty set");
+        }
+      } else {
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("<== HiveMetaStoreAuthorizer.filterTableMetas() : " + 
filteredTableNames);
+        }
+        filteredTableMetas = tableMetas.stream().filter(tblMeta -> 
filteredTableNames.stream()
+            .anyMatch(tblName -> 
tblName.equals(tblMeta.getTableName()))).collect(Collectors.toList());
+      }
+    }
+    return filteredTableMetas;
   }
 
   @Override
   public final List<TableMeta> filterTableMetas(List<TableMeta> tableMetas)
       throws MetaException {
-    return tableMetas;
+    String catName = null;
+    String dbName = null;
+    if (tableMetas != null) {
+      catName = tableMetas.get(0).getCatName();
+      dbName = tableMetas.get(0).getDbName();

Review Comment:
   I am not sure about this, but will the "tableMetas" have only single DbName? 
Can't it have, multiple DbNames?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to