Search in sources :

Example 1 with PartitionsSaveRequestDto

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

the class CatalogThriftHiveMetastore method appendPartitionsCore.

private void appendPartitionsCore(final String dbName, final String tblName, final String partName) throws TException {
    final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
    final PartitionDto partitionDto = new PartitionDto();
    partitionDto.setName(QualifiedName.ofPartition(catalogName, dbName, tblName, partName));
    partitionDto.setSerde(new StorageDto());
    partitionsSaveRequestDto.setPartitions(Lists.newArrayList(partitionDto));
    partV1.savePartitions(catalogName, dbName, tblName, partitionsSaveRequestDto);
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) StorageDto(com.netflix.metacat.common.dto.StorageDto)

Example 2 with PartitionsSaveRequestDto

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

the class MViewServiceImpl method savePartitions.

@Override
public PartitionsSaveResponseDto savePartitions(@Nonnull final QualifiedName name, final PartitionsSaveRequestDto dto, final boolean merge) {
    PartitionsSaveResponseDto result;
    final List<PartitionDto> partitionDtos = dto.getPartitions();
    if (partitionDtos == null || partitionDtos.isEmpty()) {
        return new PartitionsSaveResponseDto();
    }
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    partitionDtos.forEach(partitionDto -> partitionDto.setName(QualifiedName.ofPartition(viewQName.getCatalogName(), viewQName.getDatabaseName(), viewQName.getTableName(), partitionDto.getName().getPartitionName())));
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    eventBus.postSync(new MetacatSaveMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
    final List<String> partitionIdsForDeletes = dto.getPartitionIdsForDeletes();
    if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
        eventBus.postSync(new MetacatDeleteMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
    }
    if (merge) {
        final List<String> partitionNames = partitionDtos.stream().map(partitionDto -> partitionDto.getName().getPartitionName()).collect(Collectors.toList());
        final List<PartitionDto> existingPartitions = partitionService.list(viewQName, null, partitionNames, null, null, false, false, false);
        final Map<String, PartitionDto> existingPartitionsMap = existingPartitions.stream().collect(Collectors.toMap(partitionDto -> partitionDto.getName().getPartitionName(), Function.identity()));
        final List<PartitionDto> mergedPartitions = partitionDtos.stream().map(partitionDto -> {
            final String partitionName = partitionDto.getName().getPartitionName();
            final PartitionDto existingPartition = existingPartitionsMap.get(partitionName);
            return mergePartition(partitionDto, existingPartition);
        }).collect(Collectors.toList());
        dto.setPartitions(mergedPartitions);
        result = partitionService.save(viewQName, dto);
    } else {
        result = partitionService.save(viewQName, dto);
    }
    eventBus.postAsync(new MetacatSaveMViewPartitionPostEvent(name, metacatRequestContext, this, dto.getPartitions()));
    if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
        eventBus.postAsync(new MetacatDeleteMViewPartitionPostEvent(name, metacatRequestContext, this, partitionIdsForDeletes));
    }
    return result;
}
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) MetacatDeleteMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent) QualifiedName(com.netflix.metacat.common.QualifiedName) MetacatSaveMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPreEvent) MetacatDeleteMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) MetacatSaveMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPostEvent) PartitionsSaveResponseDto(com.netflix.metacat.common.dto.PartitionsSaveResponseDto)

Example 3 with PartitionsSaveRequestDto

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

the class MetacatServiceHelper method postPreUpdateEvent.

/**
     * Calls the right method of the event bus for the given qualified name.
     *
     * @param name                  name
     * @param metacatRequestContext context
     * @param dto                   dto
     */
public void postPreUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto dto) {
    if (name.isPartitionDefinition()) {
        final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
        if (dto != null) {
            partitionsSaveRequestDto.setPartitions(ImmutableList.of((PartitionDto) dto));
        }
        this.eventBus.postSync(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, partitionsSaveRequestDto));
    } else if (name.isTableDefinition()) {
        this.eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, (TableDto) dto, (TableDto) dto));
    } else if (name.isDatabaseDefinition()) {
        eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
    } else {
        throw new IllegalArgumentException(String.format("Invalid name %s", name));
    }
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatUpdateDatabasePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateDatabasePreEvent) MetacatSaveTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) MetacatUpdateTablePreEvent(com.netflix.metacat.common.server.events.MetacatUpdateTablePreEvent)

Example 4 with PartitionsSaveRequestDto

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

the class MViewServiceImpl method snapshotPartitions.

@Override
public void snapshotPartitions(@Nonnull final QualifiedName name, final String filter) {
    final List<PartitionDto> partitionDtos = partitionService.list(name, filter, null, null, null, false, false, true);
    if (partitionDtos != null && !partitionDtos.isEmpty()) {
        log.info("Snapshot partitions({}) for view {}.", partitionDtos.size(), name);
        final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
        dto.setPartitions(partitionDtos);
        savePartitions(name, dto, false);
    }
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) PartitionDto(com.netflix.metacat.common.dto.PartitionDto)

Example 5 with PartitionsSaveRequestDto

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

the class PartitionServiceImpl method create.

@Override
public PartitionDto create(@Nonnull final QualifiedName name, @Nonnull final PartitionDto partitionDto) {
    final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
    dto.setCheckIfExists(false);
    dto.setPartitions(Lists.newArrayList(partitionDto));
    save(name, dto);
    return partitionDto;
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto)

Aggregations

PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)10 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)6 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)3 TableDto (com.netflix.metacat.common.dto.TableDto)3 QualifiedName (com.netflix.metacat.common.QualifiedName)2 StorageDto (com.netflix.metacat.common.dto.StorageDto)2 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)2 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)2 MetacatDeleteMViewPartitionPostEvent (com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent)2 MetacatDeleteMViewPartitionPreEvent (com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MoreObjects (com.google.common.base.MoreObjects)1 Lists (com.google.common.collect.Lists)1 NameDateDto (com.netflix.metacat.common.NameDateDto)1 GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)1 HasMetadata (com.netflix.metacat.common.dto.HasMetadata)1 Pageable (com.netflix.metacat.common.dto.Pageable)1 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)1 Sort (com.netflix.metacat.common.dto.Sort)1 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)1