Search in sources :

Example 1 with StorageDto

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

the class HiveConvertersImpl method metacatToHiveTable.

/**
     * {@inheritDoc}
     */
@Override
public Table metacatToHiveTable(final TableDto dto) {
    final Table table = new Table();
    String tableName = "";
    String databaseName = "";
    final QualifiedName name = dto.getName();
    if (name != null) {
        tableName = name.getTableName();
        databaseName = name.getDatabaseName();
    }
    table.setTableName(tableName);
    table.setDbName(databaseName);
    final StorageDto storageDto = dto.getSerde();
    String owner = "";
    if (storageDto != null && storageDto.getOwner() != null) {
        owner = storageDto.getOwner();
    }
    table.setOwner(owner);
    final AuditDto auditDto = dto.getAudit();
    if (auditDto != null && auditDto.getCreatedDate() != null) {
        table.setCreateTime(dateToEpochSeconds(auditDto.getCreatedDate()));
    }
    Map<String, String> params = new HashMap<>();
    if (dto.getMetadata() != null) {
        params = dto.getMetadata();
    }
    table.setParameters(params);
    // TODO get this
    table.setTableType("EXTERNAL_TABLE");
    table.setSd(fromStorageDto(storageDto));
    final StorageDescriptor sd = table.getSd();
    final List<FieldDto> fields = dto.getFields();
    if (fields == null) {
        table.setPartitionKeys(Collections.emptyList());
        sd.setCols(Collections.emptyList());
    } else {
        final List<FieldSchema> nonPartitionFields = Lists.newArrayListWithCapacity(fields.size());
        final List<FieldSchema> partitionFields = Lists.newArrayListWithCapacity(fields.size());
        for (FieldDto fieldDto : fields) {
            final FieldSchema f = metacatToHiveField(fieldDto);
            if (fieldDto.isPartition_key()) {
                partitionFields.add(f);
            } else {
                nonPartitionFields.add(f);
            }
        }
        table.setPartitionKeys(partitionFields);
        sd.setCols(nonPartitionFields);
    }
    return table;
}
Also used : Table(org.apache.hadoop.hive.metastore.api.Table) AuditDto(com.netflix.metacat.common.dto.AuditDto) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QualifiedName(com.netflix.metacat.common.QualifiedName) FieldSchema(org.apache.hadoop.hive.metastore.api.FieldSchema) StorageDescriptor(org.apache.hadoop.hive.metastore.api.StorageDescriptor) StorageDto(com.netflix.metacat.common.dto.StorageDto) FieldDto(com.netflix.metacat.common.dto.FieldDto)

Example 2 with StorageDto

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

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

the class TableServiceImpl method copy.

@Override
public TableDto copy(@Nonnull final TableDto tableDto, @Nonnull final QualifiedName targetName) {
    final QualifiedName databaseName = QualifiedName.ofDatabase(targetName.getCatalogName(), targetName.getDatabaseName());
    if (!databaseService.exists(databaseName)) {
        final DatabaseDto databaseDto = new DatabaseDto();
        databaseDto.setName(databaseName);
        databaseService.create(databaseName, databaseDto);
    }
    final TableDto targetTableDto = new TableDto();
    targetTableDto.setName(targetName);
    targetTableDto.setFields(tableDto.getFields());
    targetTableDto.setPartition_keys(tableDto.getPartition_keys());
    final StorageDto storageDto = tableDto.getSerde();
    if (storageDto != null) {
        final StorageDto targetStorageDto = new StorageDto();
        targetStorageDto.setInputFormat(storageDto.getInputFormat());
        targetStorageDto.setOwner(storageDto.getOwner());
        targetStorageDto.setOutputFormat(storageDto.getOutputFormat());
        targetStorageDto.setParameters(storageDto.getParameters());
        targetStorageDto.setUri(storageDto.getUri());
        targetStorageDto.setSerializationLib(storageDto.getSerializationLib());
        targetTableDto.setSerde(targetStorageDto);
    }
    create(targetName, targetTableDto);
    return targetTableDto;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseDto(com.netflix.metacat.common.dto.DatabaseDto) TableDto(com.netflix.metacat.common.dto.TableDto) StorageDto(com.netflix.metacat.common.dto.StorageDto)

Example 4 with StorageDto

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

the class TableServiceImpl method setOwnerIfNull.

private void setOwnerIfNull(final TableDto tableDto, final String user) {
    if (!Strings.isNullOrEmpty(user)) {
        StorageDto serde = tableDto.getSerde();
        if (serde == null) {
            serde = new StorageDto();
            tableDto.setSerde(serde);
        }
        if (Strings.isNullOrEmpty(serde.getOwner())) {
            serde.setOwner(user);
        }
    }
}
Also used : StorageDto(com.netflix.metacat.common.dto.StorageDto)

Example 5 with StorageDto

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

the class MViewServiceImpl method mergePartition.

private PartitionDto mergePartition(final PartitionDto partitionDto, final PartitionDto existingPartition) {
    if (existingPartition != null) {
        final StorageDto existingSerde = existingPartition.getSerde();
        if (existingSerde != null) {
            StorageDto serde = partitionDto.getSerde();
            if (serde == null) {
                serde = new StorageDto();
                partitionDto.setSerde(serde);
            }
            if (serde.getUri() == null || serde.getUri().equals(existingSerde.getUri())) {
                serde.setUri(existingSerde.getUri());
                if (serde.getInputFormat() == null) {
                    serde.setInputFormat(existingSerde.getInputFormat());
                }
                if (serde.getOutputFormat() == null) {
                    serde.setOutputFormat(existingSerde.getOutputFormat());
                }
                if (serde.getSerializationLib() == null) {
                    serde.setSerializationLib(existingSerde.getSerializationLib());
                }
            }
        }
    }
    return partitionDto;
}
Also used : StorageDto(com.netflix.metacat.common.dto.StorageDto)

Aggregations

StorageDto (com.netflix.metacat.common.dto.StorageDto)6 QualifiedName (com.netflix.metacat.common.QualifiedName)2 AuditDto (com.netflix.metacat.common.dto.AuditDto)1 DatabaseDto (com.netflix.metacat.common.dto.DatabaseDto)1 FieldDto (com.netflix.metacat.common.dto.FieldDto)1 PartitionDto (com.netflix.metacat.common.dto.PartitionDto)1 PartitionsSaveRequestDto (com.netflix.metacat.common.dto.PartitionsSaveRequestDto)1 TableDto (com.netflix.metacat.common.dto.TableDto)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)1 SerDeInfo (org.apache.hadoop.hive.metastore.api.SerDeInfo)1 StorageDescriptor (org.apache.hadoop.hive.metastore.api.StorageDescriptor)1 Table (org.apache.hadoop.hive.metastore.api.Table)1