Search in sources :

Example 16 with Table

use of com.airbnb.airpal.presto.Table 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)

Example 17 with Table

use of com.airbnb.airpal.presto.Table in project airpal by airbnb.

the class TablesResource method createTablesWithMetaData.

private List<PartitionedTableWithMetaData> createTablesWithMetaData(@NonNull final List<Table> tables, @NonNull final Map<Table, Long> tableUsageMap, @NonNull final Map<PartitionedTable, DateTime> tableUpdateMap) {
    final ImmutableList.Builder<PartitionedTableWithMetaData> builder = ImmutableList.builder();
    final Duration usageWindow = usageStore.window();
    for (Table table : tables) {
        PartitionedTable partitionedTable = PartitionedTable.fromTable(table);
        DateTime updatedAt = tableUpdateMap.get(partitionedTable);
        long lastUsage = 0;
        if (tableUsageMap.containsKey(table)) {
            lastUsage = tableUsageMap.get(table);
        }
        builder.add(PartitionedTableWithMetaData.fromTable(table, lastUsage, usageWindow.getUnit(), (int) usageWindow.getQuantity(), updatedAt));
    }
    return builder.build();
}
Also used : Table(com.airbnb.airpal.presto.Table) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) ImmutableList(com.google.common.collect.ImmutableList) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Duration(io.dropwizard.util.Duration) DateTime(org.joda.time.DateTime)

Example 18 with Table

use of com.airbnb.airpal.presto.Table in project airpal by airbnb.

the class QueryExecutionAuthorizerTest method testAlternateDefaultConnectorSchemaReferences.

@Test
public void testAlternateDefaultConnectorSchemaReferences() throws Exception {
    String alternateDefaultConnector = "cassandra";
    String alternateDefaultSchema = "default2";
    Set<Table> tablesUsed = tablesUsedByQuery(TEST_SELECT_ALIAS, alternateDefaultConnector, alternateDefaultSchema);
    Set<Table> tablesExpected = ImmutableSet.of(new Table(alternateDefaultConnector, alternateDefaultSchema, "users"), new Table(alternateDefaultConnector, alternateDefaultSchema, "users_pii"));
    assertEquals(tablesExpected, tablesUsed);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Example 19 with Table

use of com.airbnb.airpal.presto.Table in project airpal by airbnb.

the class QueryExecutionAuthorizerTest method testTableReferencesSelectStar.

@Test
public void testTableReferencesSelectStar() throws Exception {
    Set<Table> tablesUsed = tablesUsedByQuery(TEST_SELECT_ALL, defaultConnector, defaultSchema);
    Set<Table> tablesExpected = ImmutableSet.of(new Table(defaultConnector, defaultSchema, "users"));
    assertEquals(tablesExpected, tablesUsed);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Example 20 with Table

use of com.airbnb.airpal.presto.Table in project airpal by airbnb.

the class QueryExecutionAuthorizerTest method testTableReferencesSelectConnector.

@Test
public void testTableReferencesSelectConnector() throws Exception {
    Set<Table> tablesUsed = tablesUsedByQuery(TEST_SELECT_CONNECTOR, defaultConnector, defaultSchema);
    Set<Table> tablesExpected = ImmutableSet.of(new Table("cassandra", "pii", "users"), new Table(defaultConnector, defaultSchema, "users_pii"));
    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