Search in sources :

Example 1 with Partition

use of com.netflix.metacat.connector.s3.model.Partition in project metacat by Netflix.

the class S3ConnectorPartitionService method update.

@Override
public void update(@Nonnull final ConnectorContext context, @Nonnull final PartitionInfo partitionInfo) {
    final QualifiedName name = partitionInfo.getName();
    log.debug("Start: Update partition {}", name);
    final QualifiedName tableName = QualifiedName.ofTable(catalogName, name.getDatabaseName(), name.getTableName());
    // Table
    final Table table = getTable(tableName);
    final List<Partition> partitions = partitionDao.getPartitions(table.getId(), Lists.newArrayList(name.getPartitionName()), null, null, null, null);
    if (partitions.isEmpty()) {
        throw new PartitionNotFoundException(tableName, name.getPartitionName());
    }
    partitionDao.save(infoConverter.fromPartitionInfo(partitionInfo));
    log.debug("End: Update partition {}", name);
}
Also used : Partition(com.netflix.metacat.connector.s3.model.Partition) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) PartitionNotFoundException(com.netflix.metacat.common.server.connectors.exception.PartitionNotFoundException) Table(com.netflix.metacat.connector.s3.model.Table) QualifiedName(com.netflix.metacat.common.QualifiedName)

Example 2 with Partition

use of com.netflix.metacat.connector.s3.model.Partition in project metacat by Netflix.

the class S3ConnectorInfoConverter method fromPartitionInfo.

/**
 * Converts from partition info to s3 partition object.
 * @param partitionInfo partition info
 * @return s3 partition
 */
Partition fromPartitionInfo(final PartitionInfo partitionInfo) {
    final Partition result = new Partition();
    result.setName(partitionInfo.getName().getPartitionName());
    result.setUri(partitionInfo.getSerde().getUri());
    final AuditInfo auditInfo = partitionInfo.getAudit();
    if (auditInfo != null) {
        result.setCreatedDate(auditInfo.getCreatedDate());
        result.setLastUpdatedDate(auditInfo.getLastModifiedDate());
    }
    return result;
}
Also used : Partition(com.netflix.metacat.connector.s3.model.Partition) AuditInfo(com.netflix.metacat.common.server.connectors.model.AuditInfo)

Example 3 with Partition

use of com.netflix.metacat.connector.s3.model.Partition in project metacat by Netflix.

the class S3ConnectorInfoConverter method partitionKeys.

/**
 * Gets the partition keys for the given table.
 * @param table table info
 * @return list of keys
 */
public List<String> partitionKeys(final Table table) {
    List<String> result = Lists.newArrayList();
    if (table.getLocation() != null) {
        final Schema schema = table.getLocation().getSchema();
        if (schema != null) {
            final List<Field> fields = schema.getFields();
            result = fields.stream().filter(Field::isPartitionKey).map(Field::getName).collect(Collectors.toList());
        }
    }
    return result;
}
Also used : Field(com.netflix.metacat.connector.s3.model.Field) Schema(com.netflix.metacat.connector.s3.model.Schema)

Example 4 with Partition

use of com.netflix.metacat.connector.s3.model.Partition in project metacat by Netflix.

the class S3ConnectorPartitionService method create.

@Override
public void create(@Nonnull final ConnectorRequestContext context, @Nonnull final PartitionInfo partitionInfo) {
    final QualifiedName name = partitionInfo.getName();
    log.debug("Start: Create partition {}", name);
    final QualifiedName tableName = QualifiedName.ofTable(catalogName, name.getDatabaseName(), name.getTableName());
    // Table
    final Table table = getTable(tableName);
    final List<Partition> partitions = partitionDao.getPartitions(table.getId(), Lists.newArrayList(name.getPartitionName()), null, null, null, null);
    if (!partitions.isEmpty()) {
        throw new PartitionAlreadyExistsException(tableName, name.getPartitionName());
    }
    partitionDao.save(infoConverter.toPartition(table, partitionInfo));
    log.debug("End: Create partition {}", name);
}
Also used : 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) QualifiedName(com.netflix.metacat.common.QualifiedName) PartitionAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException)

Example 5 with Partition

use of com.netflix.metacat.connector.s3.model.Partition in project metacat by Netflix.

the class S3ConnectorPartitionService method _getConnectorPartitions.

@SuppressWarnings("checkstyle:methodname")
private List<PartitionInfo> _getConnectorPartitions(final QualifiedName tableName, final String filterExpression, final List<String> partitionIds, final Sort sort, final Pageable pageable, final boolean includePartitionDetails) {
    // batch exists
    final boolean isBatched = !Strings.isNullOrEmpty(filterExpression) && filterExpression.contains(FIELD_BATCHID);
    // Support for dateCreated
    final boolean hasDateCreated = !Strings.isNullOrEmpty(filterExpression) && filterExpression.contains(FIELD_DATE_CREATED);
    String dateCreatedSqlCriteria = null;
    if (hasDateCreated) {
        dateCreatedSqlCriteria = getDateCreatedSqlCriteria(filterExpression);
    }
    // Table
    final Table table = getTable(tableName);
    final Collection<String> singlePartitionExprs = getSinglePartitionExprs(filterExpression);
    final List<Partition> partitions = partitionDao.getPartitions(table.getId(), partitionIds, singlePartitionExprs, dateCreatedSqlCriteria, sort, Strings.isNullOrEmpty(filterExpression) ? pageable : null);
    final FilterPartition filter = new FilterPartition();
    List<PartitionInfo> result = partitions.stream().filter(partition -> {
        Map<String, String> values = null;
        if (hasDateCreated) {
            values = Maps.newHashMap();
            values.put(FIELD_DATE_CREATED, (partition.getCreatedDate().getTime() / 1000) + "");
        }
        return Strings.isNullOrEmpty(filterExpression) || filter.evaluatePartitionExpression(filterExpression, partition.getName(), partition.getUri(), isBatched, values);
    }).map(partition -> infoConverter.toPartitionInfo(tableName, table, partition)).collect(Collectors.toList());
    // 
    if (pageable != null && pageable.isPageable() && !Strings.isNullOrEmpty(filterExpression)) {
        int limit = pageable.getOffset() + pageable.getLimit();
        if (result.size() < limit) {
            limit = result.size();
        }
        if (pageable.getOffset() > limit) {
            result = Lists.newArrayList();
        } else {
            result = result.subList(pageable.getOffset(), limit);
        }
    }
    return result;
}
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) 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) FilterPartition(com.netflix.metacat.common.server.partition.util.FilterPartition) PartitionInfo(com.netflix.metacat.common.server.connectors.model.PartitionInfo)

Aggregations

Partition (com.netflix.metacat.connector.s3.model.Partition)11 QualifiedName (com.netflix.metacat.common.QualifiedName)9 FilterPartition (com.netflix.metacat.common.server.partition.util.FilterPartition)9 Table (com.netflix.metacat.connector.s3.model.Table)9 PartitionNotFoundException (com.netflix.metacat.common.server.connectors.exception.PartitionNotFoundException)7 PartitionAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.PartitionAlreadyExistsException)5 Strings (com.google.common.base.Strings)3 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Transactional (com.google.inject.persist.Transactional)3 Pageable (com.netflix.metacat.common.dto.Pageable)3 Sort (com.netflix.metacat.common.dto.Sort)3 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)3 TableNotFoundException (com.netflix.metacat.common.server.connectors.exception.TableNotFoundException)3 BaseInfo (com.netflix.metacat.common.server.connectors.model.BaseInfo)3 PartitionInfo (com.netflix.metacat.common.server.connectors.model.PartitionInfo)3 PartitionListRequest (com.netflix.metacat.common.server.connectors.model.PartitionListRequest)3 PartitionsSaveRequest (com.netflix.metacat.common.server.connectors.model.PartitionsSaveRequest)3 PartitionsSaveResponse (com.netflix.metacat.common.server.connectors.model.PartitionsSaveResponse)3 PartitionParser (com.netflix.metacat.common.server.partition.parser.PartitionParser)3