Example usage for com.amazonaws.services.glue.model GetTablesRequest GetTablesRequest

List of usage examples for com.amazonaws.services.glue.model GetTablesRequest GetTablesRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.glue.model GetTablesRequest GetTablesRequest.

Prototype

GetTablesRequest

Source Link

Usage

From source file:com.facebook.presto.hive.metastore.glue.GlueHiveMetastore.java

License:Apache License

@Override
public Optional<List<String>> getAllTables(String databaseName) {
    try {/*from   w ww.ja va2  s  .c o  m*/
        List<String> tableNames = new ArrayList<>();
        String nextToken = null;

        do {
            GetTablesResult result = glueClient
                    .getTables(new GetTablesRequest().withDatabaseName(databaseName).withNextToken(nextToken));
            result.getTableList().forEach(table -> tableNames.add(table.getName()));
            nextToken = result.getNextToken();
        } while (nextToken != null);

        return Optional.of(tableNames);
    } catch (EntityNotFoundException e) {
        // database does not exist
        return Optional.empty();
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}

From source file:com.facebook.presto.hive.metastore.glue.GlueHiveMetastore.java

License:Apache License

@Override
public Optional<List<String>> getAllViews(String databaseName) {
    try {/*from w  ww  .j a  v a2  s. c o m*/
        List<String> views = new ArrayList<>();
        String nextToken = null;

        do {
            GetTablesResult result = glueClient
                    .getTables(new GetTablesRequest().withDatabaseName(databaseName).withNextToken(nextToken));
            result.getTableList().stream().filter(table -> VIRTUAL_VIEW.name().equals(table.getTableType()))
                    .forEach(table -> views.add(table.getName()));
            nextToken = result.getNextToken();
        } while (nextToken != null);

        return Optional.of(views);
    } catch (EntityNotFoundException e) {
        // database does not exist
        return Optional.empty();
    } catch (AmazonServiceException e) {
        throw new PrestoException(HIVE_METASTORE_ERROR, e);
    }
}