use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MViewServiceImpl method savePartitions.
/**
* {@inheritDoc}
*/
@Override
public PartitionsSaveResponseDto savePartitions(final QualifiedName name, final PartitionsSaveRequestDto dto, final boolean merge) {
final 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, null, false, false, new GetPartitionsRequestDto(null, partitionNames, false, true));
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.QualifiedName in project metacat by Netflix.
the class MViewServiceImpl method updateAndReturn.
/**
* {@inheritDoc}
*/
@Override
public TableDto updateAndReturn(final QualifiedName name, final TableDto tableDto) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatUpdateMViewPreEvent(name, metacatRequestContext, this, tableDto));
final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
log.info("Updating view {}.", viewQName);
tableService.update(viewQName, tableDto);
final TableDto updatedDto = getOpt(name, GetTableServiceParameters.builder().includeInfo(true).includeDefinitionMetadata(false).includeDataMetadata(false).disableOnReadMetadataIntercetor(false).build()).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.postAsync(new MetacatUpdateMViewPostEvent(name, metacatRequestContext, this, updatedDto));
return updatedDto;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class MViewServiceImpl method deleteAndReturn.
/**
* {@inheritDoc}
*/
@Override
public TableDto deleteAndReturn(final QualifiedName name) {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.postSync(new MetacatDeleteMViewPreEvent(name, metacatRequestContext, this));
final QualifiedName viewQName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, createViewName(name));
log.info("Deleting view {}.", viewQName);
final TableDto deletedDto = tableService.deleteAndReturn(viewQName, true);
eventBus.postAsync(new MetacatDeleteMViewPostEvent(name, metacatRequestContext, this, deletedDto));
return deletedDto;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class TableServiceImpl method getQualifiedNames.
/**
* {@inheritDoc}
*/
@Override
public Map<String, List<QualifiedName>> getQualifiedNames(final List<String> uris, final boolean prefixSearch) {
final Map<String, List<QualifiedName>> result = Maps.newHashMap();
connectorManager.getTableServices().forEach(service -> {
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
try {
final Map<String, List<QualifiedName>> names = service.getTableNames(connectorRequestContext, uris, prefixSearch);
names.forEach((uri, qNames) -> {
final List<QualifiedName> existingNames = result.get(uri);
if (existingNames == null) {
result.put(uri, qNames);
} else {
existingNames.addAll(qNames);
}
});
} catch (final UnsupportedOperationException uoe) {
log.debug("Table service doesn't support getting table names by URI. Skipping");
}
});
return result;
}
use of com.netflix.metacat.common.QualifiedName in project metacat by Netflix.
the class TableServiceImpl method copy.
/**
* {@inheritDoc}
*/
@Override
public TableDto copy(final TableDto tableDto, 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;
}
Aggregations