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