use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.
the class CatalogServiceImpl method get.
/**
* {@inheritDoc}
*/
@Nonnull
@Override
public CatalogDto get(final QualifiedName name) {
final Set<MetacatCatalogConfig> configs = connectorManager.getCatalogConfigs(name.getCatalogName());
final CatalogDto result = new CatalogDto();
result.setName(name);
final ConnectorRequestContext context = converterUtil.toConnectorContext(MetacatContextManager.getContext());
final List<String> databases = Lists.newArrayList();
configs.forEach(config -> {
QualifiedName qName = name;
if (config.getSchemaWhitelist().isEmpty()) {
result.setType(config.getType());
} else {
qName = QualifiedName.ofDatabase(name.getCatalogName(), config.getSchemaWhitelist().get(0));
}
databases.addAll(connectorManager.getDatabaseService(qName).listNames(context, name, null, null, null).stream().map(QualifiedName::getDatabaseName).filter(s -> config.getSchemaBlacklist().isEmpty() || !config.getSchemaBlacklist().contains(s)).filter(s -> config.getSchemaWhitelist().isEmpty() || config.getSchemaWhitelist().contains(s)).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
});
result.setDatabases(databases);
userMetadataService.populateMetadata(result, false);
return result;
}
use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.
the class TableServiceImpl method getQualifiedNames.
/**
* {@inheritDoc}
*/
@Override
public Map<String, List<QualifiedName>> getQualifiedNames(final List<String> uris, final boolean prefixSearch) {
final Map<String, List<QualifiedName>> result = Maps.newHashMap();
connectorManager.getTableServices().forEach(service -> {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
try {
final Map<String, List<QualifiedName>> names = service.getTableNames(connectorRequestContext, uris, prefixSearch);
names.forEach((uri, qNames) -> {
final List<QualifiedName> existingNames = result.get(uri);
if (existingNames == null) {
result.put(uri, qNames);
} else {
existingNames.addAll(qNames);
}
});
} catch (final UnsupportedOperationException uoe) {
log.debug("Table service doesn't support getting table names by URI. Skipping");
}
});
return result;
}
use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.
the class TableServiceImpl method exists.
/**
* {@inheritDoc}
*/
@Override
public boolean exists(final QualifiedName name) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorTableService service = connectorManager.getTableService(name);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
return service.exists(connectorRequestContext, name);
}
use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.
the class HiveConnectorTableService method getTableNames.
@Override
public List<QualifiedName> getTableNames(final ConnectorRequestContext context, final QualifiedName name, final String filter, @Nullable final Integer limit) {
try {
if (name.isDatabaseDefinition()) {
return metacatHiveClient.getTableNames(name.getDatabaseName(), filter, limit == null ? -1 : limit).stream().map(n -> QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), n)).collect(Collectors.toList());
} else {
int limitSize = limit == null || limit < 0 ? Integer.MAX_VALUE : limit;
final List<String> databaseNames = metacatHiveClient.getAllDatabases();
final List<QualifiedName> result = Lists.newArrayList();
for (int i = 0; i < databaseNames.size() && limitSize > 0; i++) {
final String databaseName = databaseNames.get(i);
final List<String> tableNames = metacatHiveClient.getTableNames(databaseName, filter, limitSize);
limitSize = limitSize - tableNames.size();
result.addAll(tableNames.stream().map(n -> QualifiedName.ofTable(name.getCatalogName(), databaseName, n)).collect(Collectors.toList()));
}
return result;
}
} catch (TException e) {
final String message = String.format("Failed getting the table names for database %s", name);
log.error(message);
throw new ConnectorException(message);
}
}
use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.
the class HiveConnectorTableService method list.
/**
* {@inheritDoc}.
*/
@Override
public List<TableInfo> list(final ConnectorRequestContext requestContext, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
try {
final List<TableInfo> tableInfos = Lists.newArrayList();
for (String tableName : metacatHiveClient.getAllTables(name.getDatabaseName())) {
final QualifiedName qualifiedName = QualifiedName.ofDatabase(name.getCatalogName(), tableName);
if (prefix != null && !qualifiedName.toString().startsWith(prefix.toString())) {
continue;
}
final Table table = metacatHiveClient.getTableByName(name.getDatabaseName(), tableName);
tableInfos.add(hiveMetacatConverters.toTableInfo(name, table));
}
// supporting sort by name only
if (sort != null) {
ConnectorUtils.sort(tableInfos, sort, Comparator.comparing(p -> p.getName().getTableName()));
}
return ConnectorUtils.paginate(tableInfos, pageable);
} catch (MetaException exception) {
throw new DatabaseNotFoundException(name, exception);
} catch (TException exception) {
throw new ConnectorException(String.format("Failed list hive table %s", name), exception);
}
}
Aggregations