Search in sources :

Example 11 with Table

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);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Example 12 with Table

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);
}
Also used : Table(com.airbnb.airpal.presto.Table) Test(org.junit.Test)

Example 13 with Table

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);
    }
}
Also used : JobTableDAO(com.airbnb.airpal.sql.dao.JobTableDAO) Table(com.airbnb.airpal.presto.Table) JobDAO(com.airbnb.airpal.sql.dao.JobDAO) JobTableRow(com.airbnb.airpal.sql.beans.JobTableRow) ArrayList(java.util.ArrayList) JobOutputDAO(com.airbnb.airpal.sql.dao.JobOutputDAO) Sets(com.google.common.collect.Sets) TableRow(com.airbnb.airpal.sql.beans.TableRow) JobTableRow(com.airbnb.airpal.sql.beans.JobTableRow) TableDAO(com.airbnb.airpal.sql.dao.TableDAO) JobTableDAO(com.airbnb.airpal.sql.dao.JobTableDAO)

Example 14 with Table

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();
}
Also used : Table(com.airbnb.airpal.presto.Table) ImmutableSet(com.google.common.collect.ImmutableSet) Statement(com.facebook.presto.sql.tree.Statement) CatalogSchemaContext(com.airbnb.airpal.core.execution.InputReferenceExtractor.CatalogSchemaContext)

Example 15 with Table

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);
    }
}
Also used : Table(com.airbnb.airpal.presto.Table) Job(com.airbnb.airpal.api.Job)

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