use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueriesResource method getQueries.
@GET
public Response getQueries(@Auth AirpalUser user, @QueryParam("results") int numResults, @QueryParam("table") List<PartitionedTable> tables) {
Iterable<Job> recentlyRun;
int results = Optional.of(numResults).or(200);
if (tables.size() < 1) {
recentlyRun = jobHistoryStore.getRecentlyRun(results);
} else {
recentlyRun = jobHistoryStore.getRecentlyRun(results, Iterables.transform(tables, new PartitionedTable.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();
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class ExecutionClient method jobFinished.
protected void jobFinished(Job job) {
job.setQueryFinished(new DateTime());
activeJobsStore.jobFinished(job);
historyStore.addRun(job);
for (Table t : job.getTablesUsed()) {
usageStore.markUsage(t);
}
if (job.getOutput() instanceof HiveTablePersistentOutput && job.getOutput().getLocation() != null) {
String[] parts = job.getOutput().getLocation().toString().split("\\.");
if (parts.length == 2) {
Map<String, List<String>> cache = schemaCache.getSchemaMap("hive");
List<String> tables = cache.get(parts[0]);
tables.add(parts[1]);
}
}
eventBus.post(new JobFinishedEvent(job));
executionMap.remove(job.getUuid());
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueryExecutionAuthorizerTest method testTableReferencesCreateView.
@Test
public void testTableReferencesCreateView() throws Exception {
Set<Table> tablesUsed = tablesUsedByQuery(TEST_CREATE_VIEW, defaultConnector, defaultSchema);
Set<Table> tablesExpected = ImmutableSet.of(new Table(defaultConnector, defaultSchema, "users"), new Table(defaultConnector, "the_gibson", "users_pii"));
assertEquals(tablesExpected, tablesUsed);
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueryExecutionAuthorizerTest method testTableReferencesCreateTable.
@Test
public void testTableReferencesCreateTable() throws Exception {
Set<Table> tablesUsed = tablesUsedByQuery(TEST_CREATE_TABLE, defaultConnector, defaultSchema);
Set<Table> tablesExpected = ImmutableSet.of(new Table(defaultConnector, defaultSchema, "users"), new Table(defaultConnector, "the_gibson", "users_pii"));
assertEquals(tablesExpected, tablesUsed);
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueryExecutionAuthorizerTest method testTableReferencesSelectWith.
@Test
public void testTableReferencesSelectWith() throws Exception {
Set<Table> tablesUsed = tablesUsedByQuery(TEST_ACCESS_WITH, defaultConnector, defaultSchema);
Set<Table> tablesExpected = ImmutableSet.of(new Table(defaultConnector, defaultSchema, "users"), new Table(defaultConnector, "the_gibson", "users"));
assertEquals(tablesExpected, tablesUsed);
}
Aggregations