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