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;
}
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);
}
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;
}
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);
}
}
}
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;
}
Aggregations