Search in sources :

Example 6 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class DatabaseServiceImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public DatabaseDto get(final QualifiedName name, final GetDatabaseServiceParameters getDatabaseServiceParameters) {
    validate(name);
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final MetacatCatalogConfig config = connectorManager.getCatalogConfig(name);
    final ConnectorDatabaseService service = connectorManager.getDatabaseService(name);
    final ConnectorTableService tableService = connectorManager.getTableService(name);
    final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
    final DatabaseDto dto = converterUtil.toDatabaseDto(service.get(connectorRequestContext, name));
    dto.setType(config.getType());
    if (getDatabaseServiceParameters.isIncludeTableNames()) {
        final List<QualifiedName> tableNames = tableService.listNames(connectorRequestContext, name, null, null, null);
        List<QualifiedName> viewNames = Collections.emptyList();
        if (config.isIncludeViewsWithTables()) {
            // TODO JdbcMetadata returns ImmutableList.of() for views.  We should change it to fetch views.
            try {
                viewNames = service.listViewNames(connectorRequestContext, name);
            } catch (UnsupportedOperationException ignored) {
            }
        }
        // Check to see if schema exists
        if (tableNames.isEmpty() && viewNames.isEmpty() && !exists(name)) {
            throw new DatabaseNotFoundException(name);
        }
        dto.setTables(Stream.concat(tableNames.stream(), viewNames.stream()).map(QualifiedName::getTableName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.toList()));
    }
    if (getDatabaseServiceParameters.isIncludeUserMetadata()) {
        log.info("Populate user metadata for schema {}", name);
        userMetadataService.populateMetadata(dto, getDatabaseServiceParameters.isDisableOnReadMetadataIntercetor());
    }
    return dto;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) MetacatCatalogConfig(com.netflix.metacat.common.server.spi.MetacatCatalogConfig) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 7 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class PartitionServiceImpl method getPartitionUris.

/**
 * {@inheritDoc}
 */
@Override
public List<String> getPartitionUris(final QualifiedName name, @Nullable final Sort sort, @Nullable final Pageable pageable, @Nullable final GetPartitionsRequestDto getPartitionsRequestDto) {
    List<String> result = Lists.newArrayList();
    if (tableService.exists(name)) {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final ConnectorPartitionService service = connectorManager.getPartitionService(name);
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        try {
            result = service.getPartitionUris(connectorRequestContext, name, converterUtil.toPartitionListRequest(getPartitionsRequestDto, pageable, sort));
        } catch (final UnsupportedOperationException uoe) {
            log.info("Catalog {} doesn't support getPartitionUris. Ignoring.", name.getCatalogName());
        }
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 8 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class PartitionServiceImpl method count.

/**
 * {@inheritDoc}
 */
@Override
public Integer count(final QualifiedName name) {
    Integer result = 0;
    if (tableService.exists(name)) {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final ConnectorPartitionService service = connectorManager.getPartitionService(name);
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        result = service.getPartitionCount(connectorRequestContext, name);
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 9 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class PartitionServiceImpl method getPartitionKeys.

/**
 * {@inheritDoc}
 */
@Override
public List<String> getPartitionKeys(final QualifiedName name, @Nullable final Sort sort, @Nullable final Pageable pageable, @Nullable final GetPartitionsRequestDto getPartitionsRequestDto) {
    List<String> result = Lists.newArrayList();
    if (tableService.exists(name)) {
        final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
        final ConnectorPartitionService service = connectorManager.getPartitionService(name);
        final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
        try {
            result = service.getPartitionKeys(connectorRequestContext, name, converterUtil.toPartitionListRequest(getPartitionsRequestDto, pageable, sort));
        } catch (final UnsupportedOperationException uoe) {
            log.debug("Catalog {} doesn't support getPartitionKeys. Ignoring.", name.getCatalogName());
        }
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Example 10 with ConnectorRequestContext

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;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) QualifiedName(com.netflix.metacat.common.QualifiedName) List(java.util.List) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext)

Aggregations

ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)29 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)20 QualifiedName (com.netflix.metacat.common.QualifiedName)15 List (java.util.List)13 Lists (com.google.common.collect.Lists)11 Pageable (com.netflix.metacat.common.dto.Pageable)10 Sort (com.netflix.metacat.common.dto.Sort)10 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)10 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)10 Map (java.util.Map)10 Nullable (javax.annotation.Nullable)10 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)9 Collectors (java.util.stream.Collectors)9 Strings (com.google.common.base.Strings)8 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)8 PartitionListRequest (com.netflix.metacat.common.server.connectors.model.PartitionListRequest)8 Maps (com.google.common.collect.Maps)7 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 TableDto (com.netflix.metacat.common.dto.TableDto)6