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 ConnectorRequestContext 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 ConnectorRequestContext 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 get.
@Override
public TableInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
final Table table = tableDao.getBySourceDatabaseTableName(catalogName, name.getDatabaseName(), name.getTableName());
if (table == null) {
throw new TableNotFoundException(name);
}
log.debug("Get table {}", name);
return infoConverter.toTableInfo(name, table);
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class PolarisConnectorTableService method get.
/**
* {@inheritDoc}.
*/
@Override
public TableInfo get(final ConnectorRequestContext requestContext, final QualifiedName name) {
try {
final PolarisTableEntity polarisTableEntity = polarisStoreService.getTable(name.getDatabaseName(), name.getTableName()).orElseThrow(() -> new TableNotFoundException(name));
final TableInfo info = polarisTableMapper.toInfo(polarisTableEntity);
final String tableLoc = HiveTableUtil.getIcebergTableMetadataLocation(info);
return getIcebergTable(name, tableLoc, info, requestContext.isIncludeMetadata(), connectorContext.getConfig().isIcebergCacheEnabled());
} catch (TableNotFoundException | IllegalArgumentException exception) {
log.error(String.format("Not found exception for polaris table %s", name), exception);
throw exception;
} catch (ConnectorException connectorException) {
log.error("Encountered connector exception for polaris table {}. {}", name, connectorException);
throw connectorException;
} catch (Exception exception) {
final String msg = String.format("Failed getting polaris table %s", name);
log.error(msg, exception);
throw exception;
}
}
use of com.netflix.metacat.common.server.connectors.exception.TableNotFoundException in project metacat by Netflix.
the class PolarisConnectorTableService method rename.
/**
* {@inheritDoc}.
*/
@Override
public void rename(final ConnectorRequestContext context, final QualifiedName oldName, final QualifiedName newName) {
// check exists then rename in non-transactional optimistic manner
if (exists(context, newName)) {
throw new TableAlreadyExistsException(newName);
}
try {
final PolarisTableEntity table = polarisStoreService.getTable(oldName.getDatabaseName(), oldName.getTableName()).orElseThrow(() -> new TableNotFoundException(oldName));
polarisStoreService.saveTable(table.toBuilder().tblName(newName.getTableName()).build());
} catch (TableNotFoundException exception) {
log.error(String.format("Not found exception for polaris table %s", oldName), exception);
throw exception;
} catch (DataIntegrityViolationException exception) {
throw new InvalidMetaException(oldName, exception);
} catch (Exception exception) {
final String msg = String.format("Failed renaming polaris table %s", oldName);
log.error(msg, exception);
throw new ConnectorException(msg, exception);
}
}
Aggregations