use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class S3ConnectorTableService method update.
@Override
public void update(@Nonnull final ConnectorContext context, @Nonnull final TableInfo tableInfo) {
log.debug("Start: Update table {}", tableInfo.getName());
final QualifiedName tableName = tableInfo.getName();
final Table table = tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName());
if (table == null) {
throw new TableNotFoundException(tableName);
}
//we can update the fields, the uri, or the full serde
final Location newLocation = infoConverter.toLocation(tableInfo);
Location location = table.getLocation();
if (location == null) {
location = new Location();
location.setTable(table);
table.setLocation(location);
}
if (newLocation.getUri() != null) {
location.setUri(newLocation.getUri());
}
final Info newInfo = newLocation.getInfo();
if (newInfo != null) {
final Info info = location.getInfo();
if (info == null) {
location.setInfo(newInfo);
newInfo.setLocation(location);
} else {
if (newInfo.getInputFormat() != null) {
info.setInputFormat(newInfo.getInputFormat());
}
if (newInfo.getOutputFormat() != null) {
info.setOutputFormat(newInfo.getOutputFormat());
}
if (newInfo.getOwner() != null) {
info.setOwner(newInfo.getOwner());
}
if (newInfo.getSerializationLib() != null) {
info.setSerializationLib(newInfo.getSerializationLib());
}
if (newInfo.getParameters() != null && !newInfo.getParameters().isEmpty()) {
info.setParameters(newInfo.getParameters());
}
}
}
final Schema newSchema = newLocation.getSchema();
if (newSchema != null) {
final List<Field> newFields = newSchema.getFields();
if (newFields != null && !newFields.isEmpty()) {
final Schema schema = location.getSchema();
if (schema == null) {
location.setSchema(newSchema);
newSchema.setLocation(location);
} else {
final List<Field> fields = schema.getFields();
if (fields.isEmpty()) {
newFields.forEach(field -> {
field.setSchema(schema);
fields.add(field);
});
} else {
for (int i = 0; i < newFields.size(); i++) {
final Field newField = newFields.get(i);
newField.setPos(i);
newField.setSchema(schema);
if (newField.getType() == null) {
newField.setType(newField.getSourceType());
}
}
schema.setFields(null);
fieldDao.delete(fields);
tableDao.save(table, true);
schema.setFields(newFields);
}
}
}
}
log.debug("End: Update table {}", tableInfo.getName());
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class S3ConnectorTableService method delete.
@Override
public void delete(@Nonnull final ConnectorContext context, @Nonnull final QualifiedName name) {
log.debug("Start: Delete table {}", name);
final Table table = tableDao.getBySourceDatabaseTableName(catalogName, name.getDatabaseName(), name.getTableName());
if (table == null) {
throw new TableNotFoundException(name);
}
tableDao.delete(table);
log.debug("End: Delete table {}", name);
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class S3ConnectorTableService method rename.
@Override
public void rename(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName oldName, @Nonnull final QualifiedName newName) {
log.debug("Start: Rename table {} with {}", oldName, newName);
final Table oldTable = tableDao.getBySourceDatabaseTableName(catalogName, oldName.getDatabaseName(), oldName.getTableName());
if (oldTable == null) {
throw new TableNotFoundException(oldName);
}
final Table newTable = tableDao.getBySourceDatabaseTableName(catalogName, newName.getDatabaseName(), newName.getTableName());
if (newTable == null) {
oldTable.setName(newName.getTableName());
tableDao.save(oldTable);
} else {
throw new TableAlreadyExistsException(newName);
}
log.debug("End: Rename table {} with {}", oldName, newName);
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class PartitionServiceImpl method delete.
/**
* {@inheritDoc}
*/
@Override
public void delete(final QualifiedName name, final List<String> partitionIds) {
validateDeletes(name, partitionIds != null ? partitionIds.size() : 0);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
registry.distributionSummary(this.partitionDeleteDistSummary.withTags(name.parts())).record(partitionIds.size());
if (!tableService.exists(name)) {
throw new TableNotFoundException(name);
}
if (!partitionIds.isEmpty()) {
final PartitionsSaveRequestDto dto = new PartitionsSaveRequestDto();
dto.setPartitionIdsForDeletes(partitionIds);
eventBus.post(new MetacatDeleteTablePartitionPreEvent(name, metacatRequestContext, this, dto));
final ConnectorPartitionService service = connectorManager.getPartitionService(name);
// Get the partitions before calling delete
final GetPartitionsRequestDto requestDto = new GetPartitionsRequestDto(null, partitionIds, false, true);
final ConnectorRequestContext connectorRequestContext = converterUtil.toConnectorContext(metacatRequestContext);
final List<PartitionInfo> partitionInfos = service.getPartitions(connectorRequestContext, name, converterUtil.toPartitionListRequest(requestDto, null, null), this.getTableInfo(name));
List<HasMetadata> partitions = Lists.newArrayList();
List<PartitionDto> partitionDtos = Lists.newArrayList();
if (partitionInfos != null) {
partitionDtos = partitionInfos.stream().map(converterUtil::toPartitionDto).collect(Collectors.toList());
partitions = new ArrayList<>(partitions);
}
log.info("Deleting partitions with names {} for {}", partitionIds, name);
service.deletePartitions(connectorRequestContext, name, partitionIds, this.getTableInfo(name));
// delete metadata
log.info("Deleting user metadata for partitions with names {} for {}", partitionIds, name);
if (!partitions.isEmpty()) {
deleteMetadatas(metacatRequestContext.getUserName(), partitions);
}
eventBus.post(new MetacatDeleteTablePartitionPostEvent(name, metacatRequestContext, this, partitionDtos));
}
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class MViewServiceImpl method createAndSnapshotPartitions.
/**
* Creates the materialized view using the schema of the give table
* Assumes that the "franklinviews" database name already exists in the given catalog.
*/
@Override
public TableDto createAndSnapshotPartitions(final QualifiedName name, final boolean snapshot, @Nullable final String filter) {
final TableDto result;
// Get the table
log.info("Get the table {}", name);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
eventBus.post(new MetacatCreateMViewPreEvent(name, metacatRequestContext, this, snapshot, filter));
final Optional<TableDto> oTable = tableService.get(name, GetTableServiceParameters.builder().includeDataMetadata(false).includeDefinitionMetadata(false).disableOnReadMetadataIntercetor(// turn off for optimization
true).includeInfo(true).build());
if (oTable.isPresent()) {
final TableDto table = oTable.get();
final String viewName = createViewName(name);
final QualifiedName targetName = QualifiedName.ofTable(name.getCatalogName(), VIEW_DB_NAME, viewName);
// Get the view table if it exists
log.info("Check if the view table {} exists.", targetName);
Optional<TableDto> oViewTable = Optional.empty();
try {
// read the original view back
oViewTable = tableService.get(targetName, GetTableServiceParameters.builder().includeDataMetadata(false).includeDefinitionMetadata(false).disableOnReadMetadataIntercetor(false).includeInfo(true).build());
} catch (NotFoundException ignored) {
}
if (!oViewTable.isPresent()) {
log.info("Creating view {}.", targetName);
//
if (MetacatServiceHelper.isIcebergTable(table)) {
table.getFields().forEach(f -> f.setSource_type(null));
}
result = tableService.copy(table, targetName);
} else {
result = oViewTable.get();
}
if (snapshot) {
snapshotPartitions(name, filter);
}
eventBus.post(new MetacatCreateMViewPostEvent(name, metacatRequestContext, this, result, snapshot, filter));
} else {
throw new TableNotFoundException(name);
}
return result;
}
Aggregations