Search in sources :

Example 36 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class PolarisConnectorDatabaseService method list.

/**
 * {@inheritDoc}.
 */
@Override
public List<DatabaseInfo> list(final ConnectorRequestContext context, final QualifiedName name, @Nullable final QualifiedName prefix, @Nullable final Sort sort, @Nullable final Pageable pageable) {
    try {
        final PolarisDatabaseMapper mapper = new PolarisDatabaseMapper(name.getCatalogName());
        List<PolarisDatabaseEntity> dbs = polarisStoreService.getAllDatabases();
        if (prefix != null) {
            dbs = dbs.stream().filter(n -> QualifiedName.ofDatabase(name.getCatalogName(), n.getDbName()).startsWith(prefix)).collect(Collectors.toCollection(ArrayList::new));
        }
        if (sort != null) {
            ConnectorUtils.sort(dbs, sort, Comparator.comparing(p -> p.getDbName()));
        }
        return ConnectorUtils.paginate(dbs, pageable).stream().map(d -> mapper.toInfo(d)).collect(Collectors.toList());
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed databases list polaris prefix %s", prefix), exception);
    }
}
Also used : ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) Pageable(com.netflix.metacat.common.dto.Pageable) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) QualifiedName(com.netflix.metacat.common.QualifiedName) Collectors(java.util.stream.Collectors) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ArrayList(java.util.ArrayList) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) DatabaseInfo(com.netflix.metacat.common.server.connectors.model.DatabaseInfo) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) ConnectorContext(com.netflix.metacat.common.server.connectors.ConnectorContext) ConnectorUtils(com.netflix.metacat.common.server.connectors.ConnectorUtils) Comparator(java.util.Comparator) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) PolarisStoreService(com.netflix.metacat.connector.polaris.store.PolarisStoreService) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) Nullable(javax.annotation.Nullable) Sort(com.netflix.metacat.common.dto.Sort) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) ArrayList(java.util.ArrayList) PolarisDatabaseMapper(com.netflix.metacat.connector.polaris.mappers.PolarisDatabaseMapper) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 37 with ConnectorRequestContext

use of com.netflix.metacat.common.server.connectors.ConnectorRequestContext in project metacat by Netflix.

the class S3ConnectorPartitionService method savePartitions.

@Override
public PartitionsSaveResponse savePartitions(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName tableName, @Nonnull final PartitionsSaveRequest partitionsSaveRequest) {
    log.debug("Start: Save partitions for table {}", tableName);
    // Table
    final Table table = getTable(tableName);
    // New partition ids
    final List<String> addedPartitionIds = Lists.newArrayList();
    // Updated partition ids
    final List<String> existingPartitionIds = Lists.newArrayList();
    // 
    Map<String, Partition> existingPartitionMap = Maps.newHashMap();
    if (partitionsSaveRequest.getCheckIfExists()) {
        final List<String> partitionNames = partitionsSaveRequest.getPartitions().stream().map(partition -> {
            final String partitionName = partition.getName().getPartitionName();
            PartitionUtil.validatePartitionName(partitionName, infoConverter.partitionKeys(table));
            return partitionName;
        }).collect(Collectors.toList());
        existingPartitionMap = getPartitionsByNames(table.getId(), partitionNames);
    }
    // New partitions
    final List<Partition> s3Partitions = Lists.newArrayList();
    for (PartitionInfo partition : partitionsSaveRequest.getPartitions()) {
        final String partitionName = partition.getName().getPartitionName();
        final Partition s3Partition = existingPartitionMap.get(partitionName);
        if (s3Partition == null) {
            addedPartitionIds.add(partitionName);
            s3Partitions.add(infoConverter.toPartition(table, partition));
        } else {
            final String partitionUri = infoConverter.getUri(partition);
            final String s3PartitionUri = s3Partition.getUri();
            if (partitionUri != null && !partitionUri.equals(s3PartitionUri)) {
                s3Partition.setUri(partitionUri);
                existingPartitionIds.add(partitionName);
                s3Partitions.add(s3Partition);
            }
        }
    }
    final List<String> partitionIdsForDeletes = partitionsSaveRequest.getPartitionIdsForDeletes();
    if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
        partitionDao.deleteByNames(catalogName, tableName.getDatabaseName(), tableName.getTableName(), partitionIdsForDeletes);
    }
    partitionDao.save(s3Partitions);
    log.debug("End: Save partitions for table {}", tableName);
    return PartitionsSaveResponse.builder().added(addedPartitionIds).updated(existingPartitionIds).build();
}
Also used : TableDao(com.netflix.metacat.connector.s3.dao.TableDao) PartitionKeyParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionKeyParserEval) PartitionParamParserEval(com.netflix.metacat.common.server.partition.visitor.PartitionParamParserEval) Transactional(com.google.inject.persist.Transactional) Partition(com.netflix.metacat.connector.s3.model.Partition) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) Lists(com.google.common.collect.Lists) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo) Map(java.util.Map) PartitionParser(com.netflix.metacat.common.server.partition.parser.PartitionParser) Named(javax.inject.Named) PartitionUtil(com.netflix.metacat.common.server.partition.util.PartitionUtil) Nonnull(javax.annotation.Nonnull) ConnectorRequestContext(com.netflix.metacat.common.server.connectors.ConnectorRequestContext) PartitionDao(com.netflix.metacat.connector.s3.dao.PartitionDao) Nullable(javax.annotation.Nullable) Collection(java.util.Collection) Pageable(com.netflix.metacat.common.dto.Pageable) QualifiedName(com.netflix.metacat.common.QualifiedName) BaseInfo(com.netflix.metacat.common.server.connectors.model.BaseInfo) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) PartitionsSaveResponse(com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) TableInfo(com.netflix.metacat.common.server.connectors.model.TableInfo) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException) StringReader(java.io.StringReader) PartitionsSaveRequest(com.netflix.metacat.common.server.connectors.model.PartitionsSaveRequest) Table(com.netflix.metacat.connector.s3.model.Table) PartitionListRequest(com.netflix.metacat.common.server.connectors.model.PartitionListRequest) PartitionNotFoundException(com.netflix.metacat.common.server.connectors.exception.PartitionNotFoundException) Sort(com.netflix.metacat.common.dto.Sort) Partition(com.netflix.metacat.connector.s3.model.Partition) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) Table(com.netflix.metacat.connector.s3.model.Table) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo)

Aggregations

ConnectorRequestContext (com.netflix.metacat.common.server.connectors.ConnectorRequestContext)37 MetacatRequestContext (com.netflix.metacat.common.MetacatRequestContext)25 QualifiedName (com.netflix.metacat.common.QualifiedName)21 List (java.util.List)20 Lists (com.google.common.collect.Lists)15 Collectors (java.util.stream.Collectors)15 Pageable (com.netflix.metacat.common.dto.Pageable)14 Sort (com.netflix.metacat.common.dto.Sort)14 Nullable (javax.annotation.Nullable)14 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)13 Map (java.util.Map)12 Slf4j (lombok.extern.slf4j.Slf4j)12 Strings (com.google.common.base.Strings)10 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)10 Maps (com.google.common.collect.Maps)9 ConnectorContext (com.netflix.metacat.common.server.connectors.ConnectorContext)9 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)8 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)8 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)7 Throwables (com.google.common.base.Throwables)6