Search in sources :

Example 1 with PartitionedTable

use of com.airbnb.airpal.presto.PartitionedTable 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 2 with PartitionedTable

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

the class TablesResource method getTableUpdates.

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTableUpdates(@Auth AirpalUser user, @QueryParam("catalog") Optional<String> catalogOptional) {
    final String catalog = catalogOptional.or(defaultCatalog);
    final Map<String, List<String>> schemaMap = schemaCache.getSchemaMap(catalog);
    final ImmutableList.Builder<Table> builder = ImmutableList.builder();
    for (Map.Entry<String, List<String>> entry : schemaMap.entrySet()) {
        String schema = entry.getKey();
        for (String table : entry.getValue()) {
            if (isAuthorizedRead(user, catalog, schema, table)) {
                builder.add(new Table(catalog, schema, table));
            }
        }
    }
    final List<Table> tables = builder.build();
    final Map<Table, Long> allUsages = usageStore.getUsages(tables);
    final Map<PartitionedTable, DateTime> updateMap = Collections.emptyMap();
    return Response.ok(createTablesWithMetaData(tables, allUsages, updateMap)).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) DateTime(org.joda.time.DateTime) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with PartitionedTable

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

the class TablesResource method getPartitionsWithMetaData.

private List<HivePartitionItem> getPartitionsWithMetaData(PartitionedTable table) throws ExecutionException {
    List<HivePartition> partitions = columnCache.getPartitions(table.getSchema(), table.getTable());
    ImmutableList.Builder<HivePartitionItem> partitionItems = ImmutableList.builder();
    for (HivePartition partition : partitions) {
        for (Object value : partition.getValues()) {
            PartitionedTable partitionedTable = table.withPartitionName(HivePartition.getPartitionId(partition.getName(), value));
            DateTime updatedAt = null;
            partitionItems.add(new HivePartitionItem(partition.getName(), partition.getType(), value, updatedAt));
        }
    }
    return partitionItems.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) HivePartitionItem(com.airbnb.airpal.presto.hive.HivePartition.HivePartitionItem) DateTime(org.joda.time.DateTime) HivePartition(com.airbnb.airpal.presto.hive.HivePartition)

Example 4 with PartitionedTable

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

Example 5 with PartitionedTable

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

Aggregations

PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)5 ImmutableList (com.google.common.collect.ImmutableList)5 Table (com.airbnb.airpal.presto.Table)4 GET (javax.ws.rs.GET)3 DateTime (org.joda.time.DateTime)3 Job (com.airbnb.airpal.api.Job)2 Column (com.facebook.presto.client.Column)2 PartitionedTableToTable (com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable)1 HivePartition (com.airbnb.airpal.presto.hive.HivePartition)1 HivePartitionItem (com.airbnb.airpal.presto.hive.HivePartition.HivePartitionItem)1 Duration (io.dropwizard.util.Duration)1 List (java.util.List)1 Map (java.util.Map)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1