use of io.trino.spi.StandardErrorCode.SCHEMA_NOT_EMPTY in project trino by trinodb.
the class TrinoHiveCatalog method dropNamespace.
@Override
public void dropNamespace(ConnectorSession session, String namespace) {
// basic sanity check to provide a better error message
if (!listTables(session, Optional.of(namespace)).isEmpty() || !listViews(session, Optional.of(namespace)).isEmpty()) {
throw new TrinoException(SCHEMA_NOT_EMPTY, "Schema not empty: " + namespace);
}
Optional<Path> location = metastore.getDatabase(namespace).orElseThrow(() -> new SchemaNotFoundException(namespace)).getLocation().map(Path::new);
// If we see files in the schema location, don't delete it.
// If we see no files, request deletion.
// If we fail to check the schema location, behave according to fallback.
boolean deleteData = location.map(path -> {
HdfsContext context = new HdfsContext(session);
try (FileSystem fs = hdfsEnvironment.getFileSystem(context, path)) {
return !fs.listLocatedStatus(path).hasNext();
} catch (IOException e) {
log.warn(e, "Could not check schema directory '%s'", path);
return deleteSchemaLocationsFallback;
}
}).orElse(deleteSchemaLocationsFallback);
metastore.dropDatabase(namespace, deleteData);
}
Aggregations