Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIVE-28286: Add filtering support for get_table_metas (Naveen Gangam) #5269

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* HiveMetaStoreAuthorizer : Do authorization checks on MetaStore Events in MetaStorePreEventListener
Expand Down Expand Up @@ -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)
nrg4878 marked this conversation as resolved.
Show resolved Hide resolved
throws MetaException {
return filterTableMetas(tableMetas);
if (LOG.isDebugEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to check LOG.isDebugEnabled(), since LOG.debug will only output, when debug level logging is enabled.

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)) {
dengzhhu653 marked this conversation as resolved.
Show resolved Hide resolved
filteredTableMetas = Collections.emptyList();
if (LOG.isInfoEnabled()) {
nrg4878 marked this conversation as resolved.
Show resolved Hide resolved
LOG.info("<== HiveMetaStoreAuthorizer.filterTableMetas() : returning empty set");
}
} else {
if (LOG.isDebugEnabled()) {
nrg4878 marked this conversation as resolved.
Show resolved Hide resolved
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

catName = tableMetas.get(0).getCatName();
dbName = tableMetas.get(0).getDbName();
dengzhhu653 marked this conversation as resolved.
Show resolved Hide resolved
}
return filterTableMetas(catName, dbName, tableMetas);
}

@Override
Expand Down
Loading