Search in sources :

Example 1 with NameDateDto

use of com.netflix.metacat.common.NameDateDto in project metacat by Netflix.

the class MViewServiceImpl method list.

@Override
public List<NameDateDto> list(@Nonnull final QualifiedName name) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final QualifiedName viewDbName = QualifiedName.ofDatabase(name.getCatalogName(), VIEW_DB_NAME);
    final ConnectorTableService service = connectorManager.getTableService(name.getCatalogName());
    List<QualifiedName> tableNames = Lists.newArrayList();
    try {
        final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
        tableNames = service.listNames(connectorContext, viewDbName, null, null, null);
    } catch (Exception ignored) {
    // ignore. Return an empty list if database 'franklinviews' does not exist
    }
    if (!name.isDatabaseDefinition() && name.isCatalogDefinition()) {
        return tableNames.stream().map(viewName -> {
            final NameDateDto dto = new NameDateDto();
            dto.setName(viewName);
            return dto;
        }).collect(Collectors.toList());
    } else {
        final String prefix = String.format("%s_%s_", name.getDatabaseName(), MoreObjects.firstNonNull(name.getTableName(), ""));
        return tableNames.stream().filter(qualifiedTableName -> qualifiedTableName.getTableName().startsWith(prefix)).map(qualifiedTableName -> {
            final NameDateDto dto = new NameDateDto();
            dto.setName(QualifiedName.ofView(qualifiedTableName.getCatalogName(), name.getDatabaseName(), name.getTableName(), qualifiedTableName.getTableName().substring(prefix.length())));
            return dto;
        }).collect(Collectors.toList());
    }
}
Also used : MViewService(com.netflix.metacat.main.services.MViewService) MetacatCreateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPreEvent) UserMetadataService(com.netflix.metacat.common.server.usermetadata.UserMetadataService) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatDeleteMViewPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPreEvent) MetacatEventBus(com.netflix.metacat.common.server.events.MetacatEventBus) MetacatSaveMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPreEvent) ConverterUtil(com.netflix.metacat.common.server.converter.ConverterUtil) MetacatContextManager(com.netflix.metacat.common.server.util.MetacatContextManager) MetacatDeleteMViewPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPostEvent) PartitionService(com.netflix.metacat.main.services.PartitionService) MetacatUpdateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPostEvent) StorageDto(com.netflix.metacat.common.dto.StorageDto) Function(java.util.function.Function) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) Lists(com.google.common.collect.Lists) TableService(com.netflix.metacat.main.services.TableService) Map(java.util.Map) MetacatCreateMViewPostEvent(com.netflix.metacat.common.server.events.MetacatCreateMViewPostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatDeleteMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) Nonnull(javax.annotation.Nonnull) MetacatDeleteMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent) NameDateDto(com.netflix.metacat.common.NameDateDto) MetacatUpdateMViewPreEvent(com.netflix.metacat.common.server.events.MetacatUpdateMViewPreEvent) Pageable(com.netflix.metacat.common.dto.Pageable) MoreObjects(com.google.common.base.MoreObjects) MetacatSaveMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPostEvent) QualifiedName(com.netflix.metacat.common.QualifiedName) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Optional(java.util.Optional) ConnectorManager(com.netflix.metacat.main.manager.ConnectorManager) Sort(com.netflix.metacat.common.dto.Sort) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) NameDateDto(com.netflix.metacat.common.NameDateDto) NotFoundException(com.netflix.metacat.common.server.connectors.exception.NotFoundException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MoreObjects (com.google.common.base.MoreObjects)1 Lists (com.google.common.collect.Lists)1 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)1 NameDateDto (com.netflix.metacat.common.NameDateDto)1 QualifiedName (com.netflix.metacat.common.QualifiedName)1 Pageable (com.netflix.metacat.common.dto.Pageable)1 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)1 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)1 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)1 Sort (com.netflix.metacat.common.dto.Sort)1 StorageDto (com.netflix.metacat.common.dto.StorageDto)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 NotFoundException (com.netflix.metacat.common.server.connectors.exception.NotFoundException)1 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)1 ConverterUtil (com.netflix.metacat.common.server.converter.ConverterUtil)1 MetacatCreateMViewPostEvent (com.netflix.metacat.common.server.events.MetacatCreateMViewPostEvent)1 MetacatCreateMViewPreEvent (com.netflix.metacat.common.server.events.MetacatCreateMViewPreEvent)1