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();
}
Aggregations