1717package com .google .gcloud .bigquery ;
1818
1919import com .google .common .base .MoreObjects ;
20+ import com .google .common .collect .ImmutableList ;
2021
2122import java .io .Serializable ;
2223import java .util .List ;
3031 * <pre> {@code
3132 * QueryResponse response = bigquery.query(request);
3233 * while (!response.jobComplete()) {
33- * response = bigquery.getQueryResults(response.job ());
34+ * response = bigquery.getQueryResults(response.jobId ());
3435 * Thread.sleep(1000);
3536 * }
3637 * List<BigQueryError> executionErrors = response.executionErrors();
38+ * // look for errors in executionErrors
3739 * QueryResult result = response.result();
3840 * Iterator<List<FieldValue>> rowIterator = result.iterateAll();
3941 * while(rowIterator.hasNext()) {
@@ -52,15 +54,15 @@ public class QueryResponse implements Serializable {
5254
5355 private final QueryResult result ;
5456 private final String etag ;
55- private final JobId job ;
57+ private final JobId jobId ;
5658 private final boolean jobComplete ;
5759 private final List <BigQueryError > executionErrors ;
5860
5961 static final class Builder {
6062
6163 private QueryResult result ;
6264 private String etag ;
63- private JobId job ;
65+ private JobId jobId ;
6466 private boolean jobComplete ;
6567 private List <BigQueryError > executionErrors ;
6668
@@ -76,8 +78,8 @@ Builder etag(String etag) {
7678 return this ;
7779 }
7880
79- Builder job (JobId job ) {
80- this .job = job ;
81+ Builder jobId (JobId jobId ) {
82+ this .jobId = jobId ;
8183 return this ;
8284 }
8385
@@ -99,9 +101,10 @@ QueryResponse build() {
99101 private QueryResponse (Builder builder ) {
100102 this .result = builder .result ;
101103 this .etag = builder .etag ;
102- this .job = builder .job ;
104+ this .jobId = builder .jobId ;
103105 this .jobComplete = builder .jobComplete ;
104- this .executionErrors = builder .executionErrors ;
106+ this .executionErrors = builder .executionErrors != null ? builder .executionErrors
107+ : ImmutableList .<BigQueryError >of ();
105108 }
106109
107110 /**
@@ -123,8 +126,8 @@ public String etag() {
123126 * Returns the identity of the BigQuery Job that was created to run the query. This field will be
124127 * present even if the original request timed out.
125128 */
126- public JobId job () {
127- return job ;
129+ public JobId jobId () {
130+ return jobId ;
128131 }
129132
130133 /**
@@ -137,6 +140,15 @@ public boolean jobComplete() {
137140 return jobComplete ;
138141 }
139142
143+ /**
144+ * Returns whether errors and warnings occurred during the execution of the job. If this method
145+ * returns {@code true} it does not necessarily mean that the job has completed or was
146+ * unsuccessful.
147+ */
148+ public boolean hasErrors () {
149+ return !executionErrors .isEmpty ();
150+ }
151+
140152 /**
141153 * Returns errors and warnings encountered during the running of the job, if any. Errors here do
142154 * not necessarily mean that the job has completed or was unsuccessful.
@@ -150,15 +162,15 @@ public String toString() {
150162 return MoreObjects .toStringHelper (this )
151163 .add ("result" , result )
152164 .add ("etag" , etag )
153- .add ("job " , job )
165+ .add ("jobId " , jobId )
154166 .add ("jobComplete" , jobComplete )
155167 .add ("executionErrors" , executionErrors )
156168 .toString ();
157169 }
158170
159171 @ Override
160172 public int hashCode () {
161- return Objects .hash (job );
173+ return Objects .hash (jobId );
162174 }
163175
164176 @ Override
@@ -173,7 +185,7 @@ public boolean equals(Object obj) {
173185 return jobComplete == response .jobComplete
174186 && Objects .equals (etag , response .etag )
175187 && Objects .equals (result , response .result )
176- && Objects .equals (job , response .job )
188+ && Objects .equals (jobId , response .jobId )
177189 && Objects .equals (executionErrors , response .executionErrors );
178190 }
179191
0 commit comments