26
26
/**
27
27
* Google Cloud BigQuery Query Response. This class contains the results of a Query Job or of a
28
28
* 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>
29
44
*/
30
45
public class QueryResponse implements Serializable {
31
46
@@ -37,8 +52,8 @@ public class QueryResponse implements Serializable {
37
52
private final Long totalRows ;
38
53
private final Page <List <FieldValue >> rows ;
39
54
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 ;
42
57
private final Boolean cacheHit ;
43
58
44
59
static final class Builder {
@@ -49,8 +64,8 @@ static final class Builder {
49
64
private Long totalRows ;
50
65
private Page <List <FieldValue >> rows ;
51
66
private Long totalBytesProcessed ;
52
- private Boolean jobComplete ;
53
- private List <BigQueryError > errors ;
67
+ private boolean jobComplete ;
68
+ private List <BigQueryError > executionErrors ;
54
69
private Boolean cacheHit ;
55
70
56
71
private Builder () {}
@@ -85,13 +100,13 @@ Builder totalBytesProcessed(Long totalBytesProcessed) {
85
100
return this ;
86
101
}
87
102
88
- Builder jobComplete (Boolean jobComplete ) {
103
+ Builder jobComplete (boolean jobComplete ) {
89
104
this .jobComplete = jobComplete ;
90
105
return this ;
91
106
}
92
107
93
- Builder errors (List <BigQueryError > errors ) {
94
- this .errors = errors ;
108
+ Builder executionErrors (List <BigQueryError > executionErrors ) {
109
+ this .executionErrors = executionErrors ;
95
110
return this ;
96
111
}
97
112
@@ -113,7 +128,7 @@ private QueryResponse(Builder builder) {
113
128
this .rows = builder .rows ;
114
129
this .totalBytesProcessed = builder .totalBytesProcessed ;
115
130
this .jobComplete = builder .jobComplete ;
116
- this .errors = builder .errors ;
131
+ this .executionErrors = builder .executionErrors ;
117
132
this .cacheHit = builder .cacheHit ;
118
133
}
119
134
@@ -125,7 +140,7 @@ public String etag() {
125
140
}
126
141
127
142
/**
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}
129
144
* otherwise.
130
145
*/
131
146
public Schema schema () {
@@ -158,27 +173,30 @@ public Page<List<FieldValue>> rows() {
158
173
}
159
174
160
175
/**
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.
162
179
*/
163
180
public Long totalBytesProcessed () {
164
181
return totalBytesProcessed ;
165
182
}
166
183
167
184
/**
168
185
* 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.
171
189
*/
172
- public Boolean jobComplete () {
190
+ public boolean jobComplete () {
173
191
return jobComplete ;
174
192
}
175
193
176
194
/**
177
195
* Returns errors and warnings encountered during the running of the job, if any. Errors here do
178
196
* not necessarily mean that the job has completed or was unsuccessful.
179
197
*/
180
- public List <BigQueryError > errors () {
181
- return errors ;
198
+ public List <BigQueryError > executionErrors () {
199
+ return executionErrors ;
182
200
}
183
201
184
202
/**
@@ -198,7 +216,7 @@ public String toString() {
198
216
.add ("totalRows" , totalRows )
199
217
.add ("schema" , schema )
200
218
.add ("totalBytesProcessed" , totalBytesProcessed )
201
- .add ("errors " , errors )
219
+ .add ("executionErrors " , executionErrors )
202
220
.add ("cacheHit" , cacheHit )
203
221
.toString ();
204
222
}
@@ -217,17 +235,17 @@ public boolean equals(Object obj) {
217
235
return false ;
218
236
}
219
237
QueryResponse response = (QueryResponse ) obj ;
220
- return Objects .equals (schema , response .schema )
238
+ return jobComplete == response .jobComplete
239
+ && Objects .equals (schema , response .schema )
221
240
&& Objects .equals (job , response .job )
222
241
&& Objects .equals (totalRows , response .totalRows )
223
242
&& Objects .equals (rows , response .rows )
224
243
&& Objects .equals (totalBytesProcessed , response .totalBytesProcessed )
225
- && Objects .equals (jobComplete , response .jobComplete )
226
- && Objects .equals (errors , response .errors )
244
+ && Objects .equals (executionErrors , response .executionErrors )
227
245
&& Objects .equals (cacheHit , response .cacheHit );
228
246
}
229
247
230
248
static Builder builder () {
231
249
return new Builder ();
232
250
}
233
- }
251
+ }
0 commit comments