Search in sources :

Example 1 with PartitionDto

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

the class CatalogThriftHiveMetastore method get_partitions_by_names.

/**
     * {@inheritDoc}
     */
@Override
public List<Partition> get_partitions_by_names(final String dbName, final String tblName, final List<String> names) throws TException {
    return requestWrapper("get_partitions_by_names", new Object[] { dbName, tblName, names }, () -> {
        final String databaseName = normalizeIdentifier(dbName);
        final String tableName = normalizeIdentifier(tblName);
        final TableDto tableDto = v1.getTable(catalogName, databaseName, tableName, true, false, false);
        final GetPartitionsRequestDto dto = new GetPartitionsRequestDto();
        dto.setIncludePartitionDetails(true);
        dto.setPartitionNames(names);
        final List<PartitionDto> metacatPartitions = partV1.getPartitionsForRequest(catalogName, databaseName, tableName, null, null, null, null, false, dto);
        final List<Partition> result = Lists.newArrayListWithCapacity(metacatPartitions.size());
        for (PartitionDto partition : metacatPartitions) {
            result.add(hiveConverters.metacatToHivePartition(partition, tableDto));
        }
        return result;
    });
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) GetPartitionsRequestDto(com.netflix.metacat.common.dto.GetPartitionsRequestDto) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 2 with PartitionDto

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

the class CatalogThriftHiveMetastore method get_partitions_ps.

/**
     * {@inheritDoc}
     */
@Override
public List<Partition> get_partitions_ps(final String dbName, final String tblName, final List<String> partVals, final short maxParts) throws TException {
    return requestWrapper("get_partitions_ps", new Object[] { dbName, tblName, partVals, maxParts }, () -> {
        final String databaseName = normalizeIdentifier(dbName);
        final String tableName = normalizeIdentifier(tblName);
        final TableDto tableDto = v1.getTable(catalogName, databaseName, tableName, true, false, false);
        final String partFilter = partition_values_to_partition_filter(tableDto, partVals);
        final Integer maxValues = maxParts > 0 ? Short.toUnsignedInt(maxParts) : null;
        final List<PartitionDto> metacatPartitions = partV1.getPartitions(catalogName, dbName, tblName, partFilter, null, null, null, maxValues, false);
        final List<Partition> result = Lists.newArrayListWithCapacity(metacatPartitions.size());
        for (PartitionDto partition : metacatPartitions) {
            result.add(hiveConverters.metacatToHivePartition(partition, tableDto));
        }
        return result;
    });
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 3 with PartitionDto

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

the class CatalogThriftHiveMetastore method get_partitions.

/**
     * {@inheritDoc}
     */
@Override
public List<Partition> get_partitions(final String dbName, final String tblName, final short maxParts) throws TException {
    return requestWrapper("get_partitions", new Object[] { dbName, tblName, maxParts }, () -> {
        final String databaseName = normalizeIdentifier(dbName);
        final String tableName = normalizeIdentifier(tblName);
        final TableDto tableDto = v1.getTable(catalogName, databaseName, tableName, true, false, false);
        final Integer maxValues = maxParts > 0 ? Short.toUnsignedInt(maxParts) : null;
        final List<PartitionDto> metacatPartitions = partV1.getPartitions(catalogName, dbName, tblName, null, null, null, null, maxValues, false);
        final List<Partition> result = Lists.newArrayListWithCapacity(metacatPartitions.size());
        for (PartitionDto partition : metacatPartitions) {
            result.add(hiveConverters.metacatToHivePartition(partition, tableDto));
        }
        return result;
    });
}
Also used : Partition(org.apache.hadoop.hive.metastore.api.Partition) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) TableDto(com.netflix.metacat.common.dto.TableDto)

Example 4 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto 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 5 with PartitionDto

use of com.netflix.metacat.common.dto.PartitionDto 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)

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