use of com.netflix.metacat.common.dto.PartitionsSaveRequestDto 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.PartitionsSaveRequestDto in project metacat by Netflix.
the class MViewServiceImpl method savePartitions.
@Override
public PartitionsSaveResponseDto savePartitions(@Nonnull final QualifiedName name, final PartitionsSaveRequestDto dto, final boolean merge) {
PartitionsSaveResponseDto result;
final List<PartitionDto> partitionDtos = dto.getPartitions();
if (partitionDtos == null || partitionDtos.isEmpty()) {
return new PartitionsSaveResponseDto();
}
final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
partitionDtos.forEach(partitionDto -> partitionDto.setName(QualifiedName.ofPartition(viewQName.getCatalogName(), viewQName.getDatabaseName(), viewQName.getTableName(), partitionDto.getName().getPartitionName())));
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatSaveMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
final List<String> partitionIdsForDeletes = dto.getPartitionIdsForDeletes();
if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
eventBus.postSync(new MetacatDeleteMViewPartitionPreEvent(name, metacatRequestContext, this, dto));
}
if (merge) {
final List<String> partitionNames = partitionDtos.stream().map(partitionDto -> partitionDto.getName().getPartitionName()).collect(Collectors.toList());
final List<PartitionDto> existingPartitions = partitionService.list(viewQName, null, partitionNames, null, null, false, false, false);
final Map<String, PartitionDto> existingPartitionsMap = existingPartitions.stream().collect(Collectors.toMap(partitionDto -> partitionDto.getName().getPartitionName(), Function.identity()));
final List<PartitionDto> mergedPartitions = partitionDtos.stream().map(partitionDto -> {
final String partitionName = partitionDto.getName().getPartitionName();
final PartitionDto existingPartition = existingPartitionsMap.get(partitionName);
return mergePartition(partitionDto, existingPartition);
}).collect(Collectors.toList());
dto.setPartitions(mergedPartitions);
result = partitionService.save(viewQName, dto);
} else {
result = partitionService.save(viewQName, dto);
}
eventBus.postAsync(new MetacatSaveMViewPartitionPostEvent(name, metacatRequestContext, this, dto.getPartitions()));
if (partitionIdsForDeletes != null && !partitionIdsForDeletes.isEmpty()) {
eventBus.postAsync(new MetacatDeleteMViewPartitionPostEvent(name, metacatRequestContext, this, partitionIdsForDeletes));
}
return result;
}
use of com.netflix.metacat.common.dto.PartitionsSaveRequestDto in project metacat by Netflix.
the class MetacatServiceHelper method postPreUpdateEvent.
/**
* Calls the right method of the event bus for the given qualified name.
*
* @param name name
* @param metacatRequestContext context
* @param dto dto
*/
public void postPreUpdateEvent(final QualifiedName name, final MetacatRequestContext metacatRequestContext, final BaseDto dto) {
if (name.isPartitionDefinition()) {
final PartitionsSaveRequestDto partitionsSaveRequestDto = new PartitionsSaveRequestDto();
if (dto != null) {
partitionsSaveRequestDto.setPartitions(ImmutableList.of((PartitionDto) dto));
}
this.eventBus.postSync(new MetacatSaveTablePartitionPreEvent(name, metacatRequestContext, this, partitionsSaveRequestDto));
} else if (name.isTableDefinition()) {
this.eventBus.postSync(new MetacatUpdateTablePreEvent(name, metacatRequestContext, this, (TableDto) dto, (TableDto) dto));
} else if (name.isDatabaseDefinition()) {
eventBus.postSync(new MetacatUpdateDatabasePreEvent(name, metacatRequestContext, this));
} else {
throw new IllegalArgumentException(String.format("Invalid name %s", name));
}
}
use of com.netflix.metacat.common.dto.PartitionsSaveRequestDto in project metacat by Netflix.
the class MViewServiceImpl method snapshotPartitions.
@Override
public void snapshotPartitions(@Nonnull final QualifiedName name, final String filter) {
final List<PartitionDto> partitionDtos = partitionService.list(name, filter, null, null, null, false, false, true);
if (partitionDtos != null && !partitionDtos.isEmpty()) {
log.info("Snapshot partitions({}) for view {}.", partitionDtos.size(), name);
final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
dto.setPartitions(partitionDtos);
savePartitions(name, dto, false);
}
}
use of com.netflix.metacat.common.dto.PartitionsSaveRequestDto in project metacat by Netflix.
the class PartitionServiceImpl method create.
@Override
public PartitionDto create(@Nonnull final QualifiedName name, @Nonnull final PartitionDto partitionDto) {
final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
dto.setCheckIfExists(false);
dto.setPartitions(Lists.newArrayList(partitionDto));
save(name, dto);
return partitionDto;
}
Aggregations