use of com.netflix.metacat.common.server.events.MetacatSaveMViewPartitionPostEvent 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;
}
Aggregations