Search in sources :

Example 1 with JobList

use of com.google.api.services.bigquery.model.JobList in project google-cloud-java by GoogleCloudPlatform.

the class HttpBigQueryRpc method listJobs.

@Override
public Tuple<String, Iterable<Job>> listJobs(String projectId, Map<Option, ?> options) {
    try {
        JobList jobsList = bigquery.jobs().list(projectId).setAllUsers(Option.ALL_USERS.getBoolean(options)).setFields(Option.FIELDS.getString(options)).setStateFilter(Option.STATE_FILTER.<List<String>>get(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setProjection(DEFAULT_PROJECTION).execute();
        Iterable<JobList.Jobs> jobs = jobsList.getJobs();
        return Tuple.of(jobsList.getNextPageToken(), Iterables.transform(jobs != null ? jobs : ImmutableList.<JobList.Jobs>of(), new Function<JobList.Jobs, Job>() {

            @Override
            public Job apply(JobList.Jobs jobPb) {
                JobStatus statusPb = jobPb.getStatus() != null ? jobPb.getStatus() : new JobStatus();
                if (statusPb.getState() == null) {
                    statusPb.setState(jobPb.getState());
                }
                if (statusPb.getErrorResult() == null) {
                    statusPb.setErrorResult(jobPb.getErrorResult());
                }
                return new Job().setConfiguration(jobPb.getConfiguration()).setId(jobPb.getId()).setJobReference(jobPb.getJobReference()).setKind(jobPb.getKind()).setStatistics(jobPb.getStatistics()).setStatus(statusPb).setUserEmail(jobPb.getUserEmail());
            }
        }));
    } catch (IOException ex) {
        throw translate(ex);
    }
}
Also used : JobStatus(com.google.api.services.bigquery.model.JobStatus) Function(com.google.common.base.Function) JobList(com.google.api.services.bigquery.model.JobList) IOException(java.io.IOException) Job(com.google.api.services.bigquery.model.Job)

Aggregations

Job (com.google.api.services.bigquery.model.Job)1 JobList (com.google.api.services.bigquery.model.JobList)1 JobStatus (com.google.api.services.bigquery.model.JobStatus)1 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1