Search in sources :

Example 6 with GetPartitionsRequestDto

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

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

GetPartitionsRequestDto (com.netflix.metacat.common.dto.GetPartitionsRequestDto)7 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)5 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)5 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)5 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)4 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)3 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)3 HashMap (java.util.HashMap)3 HasMetadata (com.netflix.metacat.common.dto.HasMetadata)2 MetacatDeleteTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPostEvent)2 MetacatDeleteTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatDeleteTablePartitionPreEvent)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 QualifiedName (com.netflix.metacat.common.QualifiedName)1 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)1 PartitionsSaveResponseDto (com.netflix.metacat.common.dto.PartitionsSaveResponseDto)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 MetacatSaveTablePartitionPostEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPostEvent)1 MetacatSaveTablePartitionPreEvent (com.netflix.metacat.common.server.events.MetacatSaveTablePartitionPreEvent)1 Map (java.util.Map)1