Search in sources :

Example 6 with PartitionsSaveRequestDto

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

the class PartitionServiceImpl method update.

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

Example 7 with PartitionsSaveRequestDto

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

the class PartitionServiceImpl method delete.

@Override
public void delete(final QualifiedName name, final List<String> partitionIds) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    registry.gauge(this.partitionDeletedCountId.withTags(new HashMap<>(name.parts())), partitionIds.size());
    if (!tableService.exists(name)) {
        throw new TableNotFoundException(name);
    }
    if (!partitionIds.isEmpty()) {
        final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
        dto.setPartitionIdsForDeletes(partitionIds);
        eventBus.postSync(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
        final ConnectorPartitionService service = connectorManager.getPartitionService(name.getCatalogName());
        // Get the partitions before calling delete
        final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto();
        requestDto.setIncludePartitionDetails(false);
        requestDto.setPartitionNames(partitionIds);
        final ConnectorContext connectorContext = converterUtil.toConnectorContext(metacatRequestContext);
        final List<PartitionInfo> partitionInfos = service.getPartitions(connectorContext, name, converterUtil.toPartitionListRequest(requestDto, null, null));
        List<HasMetadata> partitions = Lists.newArrayList();
        if (partitionInfos != null) {
            partitions = partitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
        }
        log.info("Deleting partitions with names {} for {}", partitionIds, name);
        service.deletePartitions(connectorContext, name, partitionIds);
        // delete metadata
        log.info("Deleting user metadata for partitions with names {} for {}", partitionIds, name);
        if (!partitions.isEmpty()) {
            deleteMetadatas(metacatRequestContext.getUserName(), partitions);
        }
        eventBus.postAsync(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, partitionIds));
    }
}
Also used : MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) HasMetadata(com.netflix.metacat.common.dto.HasMetadata) HashMap(java.util.HashMap) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) MetacatDeleteTablePartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent) MetacatDeleteTablePartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent) PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo)

Example 8 with PartitionsSaveRequestDto

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

the class MViewServiceImpl method deletePartitions.

@Override
public void deletePartitions(@Nonnull final QualifiedName name, final List<String> partitionIds) {
    final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
    final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
    dto.setPartitionIdsForDeletes(partitionIds);
    eventBus.postSync(new MetacatDeleteMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
    final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
    partitionService.delete(viewQName, partitionIds);
    eventBus.postAsync(new MetacatDeleteMViewPartitionPostEvent(name, metacatRequestContext, this, partitionIds));
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) MetacatRequestContext(com.netflix.metacat.common.MetacatRequestContext) MetacatDeleteMViewPartitionPreEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPreEvent) MetacatDeleteMViewPartitionPostEvent(com.netflix.metacat.common.server.events.MetacatDeleteMViewPartitionPostEvent) QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 9 with PartitionsSaveRequestDto

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

the class CatalogThriftHiveMetastore method rename_partition.

/**
     * {@inheritDoc}
     */
@Override
public void rename_partition(final String dbName, final String tblName, final List<String> partVals, final Partition newPart) throws TException {
    requestWrapper("rename_partition", new Object[] { dbName, tblName, partVals }, () -> {
        final TableDto tableDto = getTableDto(dbName, tblName);
        final String partName = hiveConverters.getNameFromPartVals(tableDto, partVals);
        final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
        final PartitionDto partitionDto = hiveConverters.hiveToMetacatPartition(tableDto, newPart);
        partitionsSaveRequestDto.setPartitions(Lists.newArrayList(partitionDto));
        partitionsSaveRequestDto.setPartitionIdsForDeletes(Lists.newArrayList(partName));
        partV1.savePartitions(catalogName, dbName, tblName, partitionsSaveRequestDto);
        return null;
    });
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 10 with PartitionsSaveRequestDto

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

the class CatalogThriftHiveMetastore method addPartitionsCore.

private List<Partition> addPartitionsCore(final String dbName, final String tblName, final List<Partition> parts, final boolean ifNotExists) throws TException {
    log.debug("Ignoring {} since metacat save partitions will do an update if it already exists", ifNotExists);
    final TableDto tableDto = v1.getTable(catalogName, dbName, tblName, true, false, false);
    if (tableDto.getPartition_keys() == null || tableDto.getPartition_keys().isEmpty()) {
        throw new MetaException("Unable to add partition to unpartitioned table: " + tableDto.getName());
    }
    final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
    final List<PartitionDto> converted = Lists.newArrayListWithCapacity(parts.size());
    for (Partition partition : parts) {
        converted.add(hiveConverters.hiveToMetacatPartition(tableDto, partition));
    }
    partitionsSaveRequestDto.setPartitions(converted);
    partV1.savePartitions(catalogName, dbName, tblName, partitionsSaveRequestDto);
    return parts;
}
Also used : PartitionsSaveRequestDto(com.netflix.metacat.common.dto.PartitionsSaveRequestDto) Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto) MetaException(org.apache.hadoop.hive.metastore.api.MetaException)

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