jfsii commented on code in PR #5269:
URL: https://github.com/apache/hive/pull/5269#discussion_r1621005898
##########
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)) {
Review Comment:
Do you need the if/else?
It could be re-written as (since filteredTableMetas is initialized empty):
```
if (CollectionUtils.isNotEmpty(filteredTableNames)) {
filteredTableMetas = tableMetas.stream().filter(tblMeta ->
filteredTableNames.stream()
.anyMatch(tblName ->
tblName.equals(tblMeta.getTableName()))).collect(Collectors.toList());
}
```
Actually I think you can even remove the check for empty too if you wanted:
```
filteredTableMetas = tableMetas.stream().filter(tblMeta ->
filteredTableNames.stream()
.anyMatch(tblName ->
tblName.equals(tblMeta.getTableName()))).collect(Collectors.toList());
```
which might do a bit more work than needed (if there are no
filteredTableNames, I assume collect(Collectors.toList()) would return an empty
list.
Now that I think about it the streaming line will be N^2 if nothing is
filtered, it might be a bit better to convert fileteredTableNames to a set, so
you can simply do an existence check in the filter portion rather than another
stream.
##########
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)
Review Comment:
It is a deprecated method from the interface MetaStoreFilterHook, it has to
be implemented. As for the usage of it, I would say removing the parameter
would be outside of the scope of this review (looking around the codebase, most
people pass null to the method, so I'm going to guess it is not really used
anywhere but fixing it should be a different PR).
--
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]