private Optional<List<String>> loadAllTables(String databaseName) throws Exception { Callable<List<String>> getAllTables = stats .getGetAllTables() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { return client.getAllTables(databaseName); } }); Callable<Void> getDatabase = stats .getGetDatabase() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { client.getDatabase(databaseName); return null; } }); try { return retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run( "getAllTables", () -> { List<String> tables = getAllTables.call(); if (tables.isEmpty()) { // Check to see if the database exists getDatabase.call(); } return Optional.of(tables); }); } catch (NoSuchObjectException e) { return Optional.empty(); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }
private Optional<Database> loadDatabase(String databaseName) throws Exception { try { return retry() .stopOn(NoSuchObjectException.class) .stopOnIllegalExceptions() .run( "getDatabase", stats .getGetDatabase() .wrap( () -> { try (HiveMetastoreClient client = clientProvider.createMetastoreClient()) { return Optional.of(client.getDatabase(databaseName)); } })); } catch (NoSuchObjectException e) { return Optional.empty(); } catch (TException e) { throw new PrestoException(HIVE_METASTORE_ERROR, e); } }