Search in sources :

Example 6 with Table

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();
}
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) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Job(com.airbnb.airpal.api.Job) GET(javax.ws.rs.GET)

Example 7 with Table

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());
}
Also used : Table(com.airbnb.airpal.presto.Table) HiveTablePersistentOutput(com.airbnb.airpal.api.output.HiveTablePersistentOutput) JobFinishedEvent(com.airbnb.airpal.api.event.JobFinishedEvent) List(java.util.List) DateTime(org.joda.time.DateTime)

Example 8 with Table

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);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Example 9 with Table

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);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Example 10 with Table

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);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Aggregations

Table (com.airbnb.airpal.presto.Table)28 Test (org.junit.Test)17 ImmutableList (com.google.common.collect.ImmutableList)6 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)5 Job (com.airbnb.airpal.api.Job)4 GET (javax.ws.rs.GET)4 Column (com.facebook.presto.client.Column)3 List (java.util.List)3 DateTime (org.joda.time.DateTime)3 ArrayList (java.util.ArrayList)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JobState (com.airbnb.airpal.api.JobState)1 JobFinishedEvent (com.airbnb.airpal.api.event.JobFinishedEvent)1 HiveTablePersistentOutput (com.airbnb.airpal.api.output.HiveTablePersistentOutput)1 InvalidQueryException (com.airbnb.airpal.api.output.InvalidQueryException)1 FileTooLargeException (com.airbnb.airpal.api.output.builders.FileTooLargeException)1 JobOutputBuilder (com.airbnb.airpal.api.output.builders.JobOutputBuilder)1 Persistor (com.airbnb.airpal.api.output.persistors.Persistor)1 ExecutionFailureException (com.airbnb.airpal.core.execution.ExecutionClient.ExecutionFailureException)1