use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueryExecutionAuthorizerTest method testTableReferencesCrossJoinSubselect.
@Test
public void testTableReferencesCrossJoinSubselect() throws Exception {
Set<Table> tablesUsed = tablesUsedByQuery(TEST_CROSS_JOIN_SUBSELECT, defaultConnector, defaultSchema);
Set<Table> tablesExpected = ImmutableSet.of(new Table("cassandra", "pii", "users"), new Table("hive", "pii", "users"));
assertEquals(tablesExpected, tablesUsed);
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueryExecutionAuthorizerTest method testTableReferencesSelectCount.
@Test
public void testTableReferencesSelectCount() throws Exception {
Set<Table> tablesUsed = tablesUsedByQuery(TEST_BASIC_SELECT_COUNT, 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 JobHistoryStoreDAO method addRun.
@Override
public void addRun(Job job) {
JobDAO jobDAO = dbi.onDemand(JobDAO.class);
TableDAO tableDAO = dbi.onDemand(TableDAO.class);
JobTableDAO jobTableDAO = dbi.onDemand(JobTableDAO.class);
JobOutputDAO jobOutputDAO = dbi.onDemand(JobOutputDAO.class);
// Create the job
long jobId = jobDAO.createJob(job);
// Find all presto tables already represented
Set<TableRow> tablesInDb = Collections.emptySet();
if (job.getTablesUsed().size() > 0) {
tablesInDb = new HashSet<>(tableDAO.getTables(new ArrayList<>(job.getTablesUsed())));
}
// Figure out which tables are not represented
Sets.SetView<Table> tablesToAdd = Sets.difference(job.getTablesUsed(), Sets.newHashSet(Iterables.transform(tablesInDb, TableRow.MAP_TO_TABLE)));
// Add tables not already represented
tableDAO.createTables(tablesToAdd);
Set<TableRow> tablesWithIds = Collections.emptySet();
if (job.getTablesUsed().size() > 0) {
tablesWithIds = new HashSet<>(tableDAO.getTables(new ArrayList<>(job.getTablesUsed())));
}
List<JobTableRow> jobTableRows = new ArrayList<>(job.getTablesUsed().size());
for (TableRow tableRow : tablesWithIds) {
jobTableRows.add(new JobTableRow(-1, jobId, tableRow.getId()));
}
// Add associations between Job and Table
jobTableDAO.createJobTables(jobTableRows);
if (job.getOutput().getLocation() != null) {
jobOutputDAO.createJobOutput(job.getOutput(), jobId);
}
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class QueryExecutionAuthorizer method tablesUsedByQuery.
public static Set<Table> tablesUsedByQuery(String query, String defaultConnector, String defaultSchema) {
List<String> statements = STATEMENT_SPLITTER.splitToList(query);
ImmutableSet.Builder<Table> tables = ImmutableSet.builder();
CatalogSchemaContext context = new CatalogSchemaContext(defaultConnector, defaultSchema);
for (String strStatement : statements) {
InputReferenceExtractor extractor = new InputReferenceExtractor();
Statement statement = SQL_PARSER.createStatement(strStatement);
context = statement.accept(extractor, context);
tables.addAll(extractor.getReferences());
}
return tables.build();
}
use of com.airbnb.airpal.presto.Table in project airpal by airbnb.
the class LocalJobHistoryStore method addRun.
@Override
public void addRun(Job job) {
historyCache.add(job);
for (Table usedTable : job.getTablesUsed()) {
EvictingDeque<Job> tableCache = tableHistoryCache.getIfPresent(usedTable);
if (tableCache == null) {
tableCache = new FinishedJobEvictingDeque(maximumHistoryPerTable);
tableHistoryCache.put(usedTable, tableCache);
}
tableCache.add(job);
}
}
Aggregations