use of org.apache.gobblin.rest.QueryListType in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV100 method processListQuery.
private List<JobExecutionInfo> processListQuery(Connection connection, JobExecutionQuery query) throws SQLException {
Preconditions.checkArgument(query.getId().isQueryListType());
Filter timeRangeFilter = Filter.MISSING;
QueryListType queryType = query.getId().getQueryListType();
String listJobExecutionsQuery = "";
if (queryType == QueryListType.DISTINCT) {
listJobExecutionsQuery = LIST_DISTINCT_JOB_EXECUTION_QUERY_TEMPLATE;
if (query.hasTimeRange()) {
try {
timeRangeFilter = constructTimeRangeFilter(query.getTimeRange());
if (timeRangeFilter.isPresent()) {
listJobExecutionsQuery += " AND " + timeRangeFilter;
}
} catch (ParseException pe) {
LOGGER.error("Failed to parse the query time range", pe);
throw new SQLException(pe);
}
}
} else {
listJobExecutionsQuery = LIST_RECENT_JOB_EXECUTION_QUERY_TEMPLATE;
}
listJobExecutionsQuery += " ORDER BY last_modified_ts DESC";
try (PreparedStatement queryStatement = connection.prepareStatement(listJobExecutionsQuery)) {
int limit = query.getLimit();
if (limit > 0) {
queryStatement.setMaxRows(limit);
}
if (timeRangeFilter.isPresent()) {
timeRangeFilter.addParameters(queryStatement, 1);
}
try (ResultSet rs = queryStatement.executeQuery()) {
List<JobExecutionInfo> jobExecutionInfos = Lists.newArrayList();
while (rs.next()) {
jobExecutionInfos.add(processQueryById(connection, rs.getString(1), query, Filter.MISSING));
}
return jobExecutionInfos;
}
}
}
use of org.apache.gobblin.rest.QueryListType in project incubator-gobblin by apache.
the class DatabaseJobHistoryStoreV101 method processListQuery.
private List<JobExecutionInfo> processListQuery(Connection connection, JobExecutionQuery query) throws SQLException {
Preconditions.checkArgument(query.getId().isQueryListType());
Filter timeRangeFilter = Filter.MISSING;
QueryListType queryType = query.getId().getQueryListType();
String listJobExecutionsQuery;
if (queryType == QueryListType.DISTINCT) {
listJobExecutionsQuery = LIST_DISTINCT_JOB_EXECUTION_QUERY_TEMPLATE;
if (query.hasTimeRange()) {
try {
timeRangeFilter = constructTimeRangeFilter(query.getTimeRange());
if (timeRangeFilter.isPresent()) {
listJobExecutionsQuery += " AND " + timeRangeFilter;
}
} catch (ParseException pe) {
LOGGER.error("Failed to parse the query time range", pe);
throw new SQLException(pe);
}
}
} else {
listJobExecutionsQuery = LIST_RECENT_JOB_EXECUTION_QUERY_TEMPLATE;
}
String jobsWithoutTaskFilter = "";
if (!query.isIncludeJobsWithoutTasks()) {
jobsWithoutTaskFilter = " WHERE " + FILTER_JOBS_WITH_TASKS;
}
listJobExecutionsQuery = String.format(listJobExecutionsQuery, jobsWithoutTaskFilter);
listJobExecutionsQuery += " ORDER BY last_modified_ts DESC";
try (PreparedStatement queryStatement = connection.prepareStatement(listJobExecutionsQuery)) {
int limit = query.getLimit();
if (limit > 0) {
queryStatement.setMaxRows(limit);
}
if (timeRangeFilter.isPresent()) {
timeRangeFilter.addParameters(queryStatement, 1);
}
try (ResultSet rs = queryStatement.executeQuery()) {
List<String> jobIds = Lists.newArrayList();
while (rs.next()) {
jobIds.add(rs.getString(1));
}
return processQueryByIds(connection, query, Filter.MISSING, jobIds);
}
}
}
Aggregations