use of com.airbnb.airpal.sql.dao.JobOutputDAO 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);
}
}
Aggregations