Search in sources :

Example 11 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto in project metacat by Netflix.

the class PartitionServiceImpl method list.

@Override
public List<PartitionDto> list(final QualifiedName name, final String filter, final List<String> partitionNames, final Sort sort, final Pageable pageable, final boolean includeUserDefinitionMetadata, final boolean includeUserDataMetadata, final boolean includePartitionDetails) {
    if (Strings.isNullOrEmpty(filter) && (pageable == null || !pageable.isPageable()) && (partitionNames == null || partitionNames.isEmpty()) && config.getQualifiedNamesToThrowErrorWhenNoFilterOnListPartitions().contains(name)) {
        throw new IllegalArgumentException(String.format("No filter or limit specified for table %s", name));
    }
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final ConnectorPartitionService service = connectorManager.getPartitionService(name.getCatalogName());
    final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto();
    requestDto.setFilter(filter);
    requestDto.setIncludePartitionDetails(includePartitionDetails);
    requestDto.setPartitionNames(partitionNames);
    final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
    final List<PartitionInfo> resultInfo = service.getPartitions(connectorContext, name, converterUtil.toPartitionListRequest(requestDto, pageable, sort));
    List<PartitionDto> result = Lists.newArrayList();
    if (resultInfo != null && !resultInfo.isEmpty()) {
        result = resultInfo.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
        final List<QualifiedName> names = Lists.newArrayList();
        final List<String> uris = Lists.newArrayList();
        result.forEach(partitionDto -> {
            names.add(partitionDto.getName());
            uris.add(partitionDto.getDataUri());
        });
        registry.gauge(this.partitionGetCountId.withTags(new HashMap<>(name.parts())), result.size());
        log.info("Got {} partitions for {} using filter: {} and partition names: {}", result.size(), name, filter, partitionNames);
        if (includeUserDefinitionMetadata || includeUserDataMetadata) {
            final List<ListenableFuture<Map<String, ObjectNode>>> futures = Lists.newArrayList();
            futures.add(threadServiceManager.getExecutor().submit(() -> includeUserDefinitionMetadata ? userMetadataService.getDefinitionMetadataMap(names) : Maps.newHashMap()));
            futures.add(threadServiceManager.getExecutor().submit(() -> includeUserDataMetadata ? userMetadataService.getDataMetadataMap(uris) : Maps.newHashMap()));
            try {
                final List<Map<String, ObjectNode>> metadataResults = Futures.successfulAsList(futures).get(1, TimeUnit.HOURS);
                final Map<String, ObjectNode> definitionMetadataMap = metadataResults.get(0);
                final Map<String, ObjectNode> dataMetadataMap = metadataResults.get(1);
                result.forEach(partitionDto -> userMetadataService.populateMetadata(partitionDto, definitionMetadataMap.get(partitionDto.getName().toString()), dataMetadataMap.get(partitionDto.getDataUri())));
            } catch (Exception e) {
                Throwables.propagate(e);
            }
        }
    }
    return result;
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HashMap(java.util.HashMap) QualifiedName(com.netflix.metacat.common.QualifiedName) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto in project metacat by Netflix.

the class PartitionServiceImpl method get.

@Override
public PartitionDto get(@Nonnull final QualifiedName name) {
    PartitionDto result = null;
    final QualifiedName tableName = QualifiedName.ofTable(name.getCatalogName(), name.getDatabaseName(), name.getTableName());
    final List<PartitionDto> dtos = list(tableName, null, Lists.newArrayList(name.getPartitionName()), null, null, true, true, true);
    if (!dtos.isEmpty()) {
        result = dtos.get(0);
    }
    return result;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) PartitionDto(com.netflix.metacat.common.dto.PartitionDto)

Example 13 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto in project metacat by Netflix.

the class MetacatServiceHelper method postPostUpdateEvent.

/**
     * Calls the right method of the event bus for the given qualified name.
     *
     * @param name                  name
     * @param metacatRequestContext context
     * @param oldDTo                dto
     * @param currentDto            dto
     */
public void postPostUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto oldDTo, final BaseDto currentDto) {
    if (name.isPartitionDefinition()) {
        final List<PartitionDto> dtos = Lists.newArrayList();
        if (currentDto != null) {
            dtos.add((PartitionDto) currentDto);
        }
        // This request neither added nor updated partitions
        final PartitionsSaveResponseDto partitionsSaveResponseDto = new PartitionsSaveResponseDto();
        this.eventBus.postAsync(new MetacatSaveTablePartitionPostEvent(name, metacatRequestContext, this, dtos, partitionsSaveResponseDto));
    } else if (name.isTableDefinition()) {
        final MetacatUpdateTablePostEvent event = new MetacatUpdateTablePostEvent(name, metacatRequestContext, this, (TableDto) oldDTo, (TableDto) currentDto);
        this.eventBus.postAsync(event);
    } else if (name.isDatabaseDefinition()) {
        this.eventBus.postAsync(new MetacatUpdateDatabasePostEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatUpdateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePostEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Example 14 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto in project metacat by Netflix.

the class MetacatElasticSearchEventHandlers method metacatSaveTablePartitionPostEventHandler.

/**
     * Subscriber.
     *
     * @param event event
     */
@EventListener
public void metacatSaveTablePartitionPostEventHandler(final MetacatSaveTablePartitionPostEvent event) {
    log.debug("Received SaveTablePartitionEvent {}", event);
    registry.counter(Metrics.CounterElasticSearchPartitionSave.name()).increment();
    final List<PartitionDto> partitionDtos = event.getPartitions();
    final MetacatRequestContext context = event.getRequestContext();
    final List<ElasticSearchDoc> docs = partitionDtos.stream().map(dto -> new ElasticSearchDoc(dto.getName().toString(), dto, context.getUserName(), false)).collect(Collectors.toList());
    es.save(ElasticSearchDoc.Type.partition.name(), docs);
}
Also used : MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) MetacatDeleteTablePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePostEvent) MetacatUpdateTablePostEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePostEvent) TableDto(com.netflix.metacat.common.dto.TableDto) MetacatRenameTablePostEvent(com.netflix.metacat.common.server.events.MetacatRenameTablePostEvent) EventListener(org.springframework.context.event.EventListener) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) MetacatDeleteDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatDeleteDatabasePostEvent) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MetacatJsonLocator(com.netflix.metacat.common.json.MetacatJsonLocator) MetacatCreateDatabasePostEvent(com.netflix.metacat.common.server.events.MetacatCreateDatabasePostEvent) Objects(java.util.Objects) MetacatCreateTablePostEvent(com.netflix.metacat.common.server.events.MetacatCreateTablePostEvent) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) Registry(com.netflix.spectator.api.Registry) MetacatSaveTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) Metrics(com.netflix.metacat.common.server.monitoring.Metrics) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) EventListener(org.springframework.context.event.EventListener)

Example 15 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto in project metacat by Netflix.

the class CatalogThriftHiveMetastore method getPartitionDtoByName.

private PartitionDto getPartitionDtoByName(final TableDto tableDto, final String partName) throws TException {
    final GetPartitionsRequestDto dto = new GetPartitionsRequestDto();
    dto.setIncludePartitionDetails(true);
    dto.setPartitionNames(ImmutableList.of(partName));
    final List<PartitionDto> partitionDtos = partV1.getPartitionsForRequest(catalogName, tableDto.getName().getDatabaseName(), tableDto.getName().getTableName(), null, null, null, null, false, dto);
    if (partitionDtos == null || partitionDtos.isEmpty()) {
        throw new NoSuchObjectException("Partition (" + partName + ") not found on " + tableDto.getName());
    } else if (partitionDtos.size() != 1) {
        // I don't think this is even possible
        throw new NoSuchObjectException("Partition (" + partName + ") matched extra on " + tableDto.getName());
    }
    return partitionDtos.get(0);
}
Also used : PartitionDto(com.netflix.metacat.common.dto.PartitionDto) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException)

Aggregations

PartitionDto (com.netflix.metacat.common.dto.PartitionDto)20 TableDto (com.netflix.metacat.common.dto.TableDto)11 QualifiedName (com.netflix.metacat.common.QualifiedName)6 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)6 Partition (org.apache.hadoop.hive.metastore.api.Partition)6 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)5 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Lists (com.google.common.collect.Lists)3 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)3 MetacatSaveTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Splitter (com.google.common.base.Splitter)2 Strings (com.google.common.base.Strings)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 AuditDto (com.netflix.metacat.common.dto.AuditDto)2 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)2 StorageDto (com.netflix.metacat.common.dto.StorageDto)2 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)2