Search in sources :

Example 6 with Column

use of com.facebook.presto.client.Column in project presto by prestodb.

the class PrestoResultSet method getColumns.

private static List<Column> getColumns(StatementClient client, Consumer<QueryStats> progressCallback) throws SQLException {
    while (client.isValid()) {
        QueryResults results = client.current();
        progressCallback.accept(QueryStats.create(results.getId(), results.getStats()));
        List<Column> columns = results.getColumns();
        if (columns != null) {
            return columns;
        }
        client.advance();
    }
    QueryResults results = client.finalResults();
    if (!client.isFailed()) {
        throw new SQLException(format("Query has no columns (#%s)", results.getId()));
    }
    throw resultsException(results);
}
Also used : Column(com.facebook.presto.client.Column) SQLException(java.sql.SQLException) QueryResults(com.facebook.presto.client.QueryResults)

Example 7 with Column

use of com.facebook.presto.client.Column in project airpal by airbnb.

the class QueryResource method getHistory.

@GET
@Path("history")
@Produces(MediaType.APPLICATION_JSON)
public Response getHistory(@Auth AirpalUser user, @QueryParam("table") List<Table> tables) {
    Iterable<Job> recentlyRun;
    if (tables.size() < 1) {
        recentlyRun = jobHistoryStore.getRecentlyRun(200);
    } else {
        Table[] tablesArray = tables.toArray(new Table[tables.size()]);
        Table[] restTables = Arrays.copyOfRange(tablesArray, 1, tablesArray.length);
        recentlyRun = jobHistoryStore.getRecentlyRun(200, tablesArray[0], restTables);
    }
    ImmutableList.Builder<Job> filtered = ImmutableList.builder();
    for (Job job : recentlyRun) {
        if (job.getTablesUsed().isEmpty() && (job.getState() == JobState.FAILED)) {
            filtered.add(job);
            continue;
        }
        for (Table table : job.getTablesUsed()) {
            if (AuthorizationUtil.isAuthorizedRead(user, table)) {
                filtered.add(new Job(job.getUser(), job.getQuery(), job.getUuid(), job.getOutput(), job.getQueryStats(), job.getState(), Collections.<Column>emptyList(), Collections.<Table>emptySet(), job.getQueryStartedDateTime(), job.getError(), job.getQueryFinishedDateTime()));
            }
        }
    }
    List<Job> sortedResult = Ordering.natural().nullsLast().onResultOf(JOB_ORDERING).reverse().immutableSortedCopy(filtered.build());
    return Response.ok(sortedResult).build();
}
Also used : Table(com.airbnb.airpal.presto.Table) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Column(com.facebook.presto.client.Column) ImmutableList(com.google.common.collect.ImmutableList) Job(com.airbnb.airpal.api.Job) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Column (com.facebook.presto.client.Column)7 ImmutableList (com.google.common.collect.ImmutableList)6 Job (com.airbnb.airpal.api.Job)3 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)3 Table (com.airbnb.airpal.presto.Table)3 QueryResults (com.facebook.presto.client.QueryResults)3 GET (javax.ws.rs.GET)3 QueryClient (com.airbnb.airpal.core.execution.QueryClient)2 QueryRunner (com.airbnb.airpal.presto.QueryRunner)2 HiveColumn (com.airbnb.airpal.presto.hive.HiveColumn)2 StatementClient (com.facebook.presto.client.StatementClient)2 List (java.util.List)2 Nullable (javax.annotation.Nullable)2 Path (javax.ws.rs.Path)2 PartitionedTableToTable (com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable)1 HivePartition (com.airbnb.airpal.presto.hive.HivePartition)1 ClientTypeSignature (com.facebook.presto.client.ClientTypeSignature)1 SQLException (java.sql.SQLException)1 Map (java.util.Map)1 Produces (javax.ws.rs.Produces)1