2626/**
2727 * Google Cloud BigQuery Query Response. This class contains the results of a Query Job or of a
2828 * Query Request.
29+ *
30+ * <p>Example usage of a query response:
31+ * <pre> {@code
32+ * QueryResponse response = bigquery.query(request);
33+ * while (!response.jobComplete()) {
34+ * response = bigquery.getQueryResults(response.job());
35+ * Thread.sleep(1000);
36+ * }
37+ * List<BigQueryError> executionErrors = response.executionErrors();
38+ * Page<List<FieldValue>> rows = response.rows();
39+ * }</pre>
40+ *
41+ * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults">Get Query
42+ * Results</a>
43+ * @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/query">Query</a>
2944 */
3045public class QueryResponse implements Serializable {
3146
@@ -37,8 +52,8 @@ public class QueryResponse implements Serializable {
3752 private final Long totalRows ;
3853 private final Page <List <FieldValue >> rows ;
3954 private final Long totalBytesProcessed ;
40- private final Boolean jobComplete ;
41- private final List <BigQueryError > errors ;
55+ private final boolean jobComplete ;
56+ private final List <BigQueryError > executionErrors ;
4257 private final Boolean cacheHit ;
4358
4459 static final class Builder {
@@ -49,8 +64,8 @@ static final class Builder {
4964 private Long totalRows ;
5065 private Page <List <FieldValue >> rows ;
5166 private Long totalBytesProcessed ;
52- private Boolean jobComplete ;
53- private List <BigQueryError > errors ;
67+ private boolean jobComplete ;
68+ private List <BigQueryError > executionErrors ;
5469 private Boolean cacheHit ;
5570
5671 private Builder () {}
@@ -85,13 +100,13 @@ Builder totalBytesProcessed(Long totalBytesProcessed) {
85100 return this ;
86101 }
87102
88- Builder jobComplete (Boolean jobComplete ) {
103+ Builder jobComplete (boolean jobComplete ) {
89104 this .jobComplete = jobComplete ;
90105 return this ;
91106 }
92107
93- Builder errors (List <BigQueryError > errors ) {
94- this .errors = errors ;
108+ Builder executionErrors (List <BigQueryError > executionErrors ) {
109+ this .executionErrors = executionErrors ;
95110 return this ;
96111 }
97112
@@ -113,7 +128,7 @@ private QueryResponse(Builder builder) {
113128 this .rows = builder .rows ;
114129 this .totalBytesProcessed = builder .totalBytesProcessed ;
115130 this .jobComplete = builder .jobComplete ;
116- this .errors = builder .errors ;
131+ this .executionErrors = builder .executionErrors ;
117132 this .cacheHit = builder .cacheHit ;
118133 }
119134
@@ -125,7 +140,7 @@ public String etag() {
125140 }
126141
127142 /**
128- * Returns the schema of the results when the query completed successfully. Returns {@code null}
143+ * Returns the schema of the results if the query completed successfully. Returns {@code null}
129144 * otherwise.
130145 */
131146 public Schema schema () {
@@ -158,27 +173,30 @@ public Page<List<FieldValue>> rows() {
158173 }
159174
160175 /**
161- * Returns the total number of bytes processed for the query.
176+ * Returns the total number of bytes processed for the query. If this query was a dry run, this is
177+ * the number of bytes that would be processed if the query were run. Returns {@code null}
178+ * if the query did not complete.
162179 */
163180 public Long totalBytesProcessed () {
164181 return totalBytesProcessed ;
165182 }
166183
167184 /**
168185 * Returns whether the job running the query has completed or not. If {@link #rows()} and
169- * {@link #totalRows()} are present, this method will always return {@code true}. If this method
170- * returns {@code false}, {@link #totalRows()} will not be available.
186+ * {@link #totalRows()} are not {@code null}, this method will always return {@code true}. If this
187+ * method returns {@code false} {@link #totalRows()} and {@link #rows()} return {@code null}. This
188+ * method can be used to check if query execution completed and results are available.
171189 */
172- public Boolean jobComplete () {
190+ public boolean jobComplete () {
173191 return jobComplete ;
174192 }
175193
176194 /**
177195 * Returns errors and warnings encountered during the running of the job, if any. Errors here do
178196 * not necessarily mean that the job has completed or was unsuccessful.
179197 */
180- public List <BigQueryError > errors () {
181- return errors ;
198+ public List <BigQueryError > executionErrors () {
199+ return executionErrors ;
182200 }
183201
184202 /**
@@ -198,7 +216,7 @@ public String toString() {
198216 .add ("totalRows" , totalRows )
199217 .add ("schema" , schema )
200218 .add ("totalBytesProcessed" , totalBytesProcessed )
201- .add ("errors " , errors )
219+ .add ("executionErrors " , executionErrors )
202220 .add ("cacheHit" , cacheHit )
203221 .toString ();
204222 }
@@ -217,17 +235,17 @@ public boolean equals(Object obj) {
217235 return false ;
218236 }
219237 QueryResponse response = (QueryResponse ) obj ;
220- return Objects .equals (schema , response .schema )
238+ return jobComplete == response .jobComplete
239+ && Objects .equals (schema , response .schema )
221240 && Objects .equals (job , response .job )
222241 && Objects .equals (totalRows , response .totalRows )
223242 && Objects .equals (rows , response .rows )
224243 && Objects .equals (totalBytesProcessed , response .totalBytesProcessed )
225- && Objects .equals (jobComplete , response .jobComplete )
226- && Objects .equals (errors , response .errors )
244+ && Objects .equals (executionErrors , response .executionErrors )
227245 && Objects .equals (cacheHit , response .cacheHit );
228246 }
229247
230248 static Builder builder () {
231249 return new Builder ();
232250 }
233- }
251+ }
0 commit comments