Search in sources :

Example 16 with PartitionDto

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

the class CatalogThriftHiveMetastore method get_partitions_by_filter.

/**
     * {@inheritDoc}
     */
@Override
public List<Partition> get_partitions_by_filter(final String dbName, final String tblName, final String filter, final short maxParts) throws TException {
    return requestWrapper("get_partitions_by_filter", new Object[] { dbName, tblName, filter, 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, filter, 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 17 with PartitionDto

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

the class HiveConvertersImpl method hiveToMetacatPartition.

/**
     * {@inheritDoc}
     */
@Override
public PartitionDto hiveToMetacatPartition(final TableDto tableDto, final Partition partition) {
    final QualifiedName tableName = tableDto.getName();
    final QualifiedName partitionName = QualifiedName.ofPartition(tableName.getCatalogName(), tableName.getDatabaseName(), tableName.getTableName(), getNameFromPartVals(tableDto, partition.getValues()));
    final PartitionDto result = new PartitionDto();
    String owner = "";
    if (tableDto.getSerde() != null) {
        owner = tableDto.getSerde().getOwner();
    }
    result.setSerde(toStorageDto(partition.getSd(), owner));
    result.setMetadata(partition.getParameters());
    final AuditDto auditDto = new AuditDto();
    auditDto.setCreatedDate(epochSecondsToDate(partition.getCreateTime()));
    auditDto.setLastModifiedDate(epochSecondsToDate(partition.getLastAccessTime()));
    result.setAudit(auditDto);
    result.setName(partitionName);
    return result;
}
Also used : AuditDto(com.netflix.metacat.common.dto.AuditDto) QualifiedName(com.netflix.metacat.common.QualifiedName) PartitionDto(com.netflix.metacat.common.dto.PartitionDto)

Example 18 with PartitionDto

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

the class HiveConvertersImpl method metacatToHivePartition.

/**
     * {@inheritDoc}
     */
@Override
public Partition metacatToHivePartition(final PartitionDto partitionDto, @Nullable final TableDto tableDto) {
    final Partition result = new Partition();
    final QualifiedName name = partitionDto.getName();
    final List<String> values = Lists.newArrayListWithCapacity(16);
    String databaseName = "";
    String tableName = "";
    if (name != null) {
        if (name.getPartitionName() != null) {
            for (String partialPartName : SLASH_SPLITTER.split(partitionDto.getName().getPartitionName())) {
                final List<String> nameValues = ImmutableList.copyOf(EQUAL_SPLITTER.split(partialPartName));
                if (nameValues.size() != 2) {
                    throw new IllegalStateException("Unrecognized partition name: " + partitionDto.getName());
                }
                final String value = nameValues.get(1);
                values.add(value);
            }
        }
        if (name.getDatabaseName() != null) {
            databaseName = name.getDatabaseName();
        }
        if (name.getTableName() != null) {
            tableName = name.getTableName();
        }
    }
    result.setValues(values);
    result.setDbName(databaseName);
    result.setTableName(tableName);
    Map<String, String> metadata = partitionDto.getMetadata();
    if (metadata == null) {
        metadata = Maps.newHashMap();
    }
    result.setParameters(metadata);
    result.setSd(fromStorageDto(partitionDto.getSerde()));
    final StorageDescriptor sd = result.getSd();
    if (tableDto != null) {
        if (sd.getSerdeInfo() != null && tableDto.getSerde() != null && Strings.isNullOrEmpty(sd.getSerdeInfo().getSerializationLib())) {
            sd.getSerdeInfo().setSerializationLib(tableDto.getSerde().getSerializationLib());
        }
        final List<FieldDto> fields = tableDto.getFields();
        if (fields == null) {
            sd.setCols(Collections.emptyList());
        } else {
            sd.setCols(fields.stream().filter(field -> !field.isPartition_key()).map(this::metacatToHiveField).collect(Collectors.toList()));
        }
    }
    final AuditDto auditDto = partitionDto.getAudit();
    if (auditDto != null) {
        if (auditDto.getCreatedDate() != null) {
            result.setCreateTime(dateToEpochSeconds(auditDto.getCreatedDate()));
        }
        if (auditDto.getLastModifiedDate() != null) {
            result.setLastAccessTime(dateToEpochSeconds(auditDto.getLastModifiedDate()));
        }
    }
    return result;
}
Also used : TableDto(com.netflix.metacat.common.dto.TableDto) MetaException(org.apache.hadoop.hive.metastore.api.MetaException) Date(java.util.Date) HashMap(java.util.HashMap) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) StorageDto(com.netflix.metacat.common.dto.StorageDto) SerDeInfo(org.apache.hadoop.hive.metastore.api.SerDeInfo) Partition(org.apache.hadoop.hive.metastore.api.Partition) Warehouse(org.apache.hadoop.hive.metastore.Warehouse) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) AuditDto(com.netflix.metacat.common.dto.AuditDto) Splitter(com.google.common.base.Splitter) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) Nullable(javax.annotation.Nullable) QualifiedName(com.netflix.metacat.common.QualifiedName) FieldDto(com.netflix.metacat.common.dto.FieldDto) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Table(org.apache.hadoop.hive.metastore.api.Table) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) List(java.util.List) PartitionDto(com.netflix.metacat.common.dto.PartitionDto) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Database(org.apache.hadoop.hive.metastore.api.Database) Collections(java.util.Collections) Partition(org.apache.hadoop.hive.metastore.api.Partition) AuditDto(com.netflix.metacat.common.dto.AuditDto) QualifiedName(com.netflix.metacat.common.QualifiedName) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) FieldDto(com.netflix.metacat.common.dto.FieldDto)

Example 19 with PartitionDto

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

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

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