Search in sources :

Example 1 with QueryListType

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;
        }
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ParseException(java.text.ParseException) QueryListType(org.apache.gobblin.rest.QueryListType) JobExecutionInfo(org.apache.gobblin.rest.JobExecutionInfo)

Example 2 with QueryListType

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);
        }
    }
}
Also used : SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ParseException(java.text.ParseException) QueryListType(org.apache.gobblin.rest.QueryListType)

Aggregations

PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ParseException (java.text.ParseException)2 QueryListType (org.apache.gobblin.rest.QueryListType)2 JobExecutionInfo (org.apache.gobblin.rest.JobExecutionInfo)1