Search in sources :

Example 1 with PartitionedTableToTable

use of com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable in project airpal by airbnb.

the class UsersResource method getUserQueries.

@GET
@Path("queries")
public Response getUserQueries(@Auth AirpalUser user, @PathParam("id") String userId, @QueryParam("results") int numResults, @QueryParam("table") List<PartitionedTable> tables) {
    Iterable<Job> recentlyRun;
    int results = Optional.of(numResults).or(0);
    if (results <= 0) {
        results = 100;
    }
    if (tables.size() < 1) {
        recentlyRun = jobHistoryStore.getRecentlyRunForUser(userId, results);
    } else {
        recentlyRun = jobHistoryStore.getRecentlyRunForUser(userId, results, Iterables.transform(tables, new PartitionedTableToTable()));
    }
    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) PartitionedTableToTable(com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Column(com.facebook.presto.client.Column) ImmutableList(com.google.common.collect.ImmutableList) PartitionedTableToTable(com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable) Job(com.airbnb.airpal.api.Job) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

Job (com.airbnb.airpal.api.Job)1 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)1 PartitionedTableToTable (com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable)1 Table (com.airbnb.airpal.presto.Table)1 Column (com.facebook.presto.client.Column)1 ImmutableList (com.google.common.collect.ImmutableList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1