17
17
package com .google .gcloud .bigquery ;
18
18
19
19
import com .google .common .base .MoreObjects ;
20
- import com .google .gcloud .Page ;
21
20
22
21
import java .io .Serializable ;
23
22
import java .util .List ;
35
34
* Thread.sleep(1000);
36
35
* }
37
36
* List<BigQueryError> executionErrors = response.executionErrors();
38
- * Page<List<FieldValue>> rows = response.rows();
37
+ * QueryResult result = response.result();
38
+ * Iterator<List<FieldValue>> rowIterator = result.iterateAll();
39
+ * while(rowIterator.hasNext()) {
40
+ * List<FieldValue> row = rowIterator.next();
41
+ * // do something with row
42
+ * }
39
43
* }</pre>
40
44
*
41
45
* @see <a href="https://cloud.google.com/bigquery/docs/reference/v2/jobs/getQueryResults">Get Query
@@ -46,37 +50,29 @@ public class QueryResponse implements Serializable {
46
50
47
51
private static final long serialVersionUID = 3549226764825005655L ;
48
52
53
+ private final QueryResult result ;
49
54
private final String etag ;
50
- private final Schema schema ;
51
55
private final JobId job ;
52
- private final Long totalRows ;
53
- private final Page <List <FieldValue >> rows ;
54
- private final Long totalBytesProcessed ;
55
56
private final boolean jobComplete ;
56
57
private final List <BigQueryError > executionErrors ;
57
- private final Boolean cacheHit ;
58
58
59
59
static final class Builder {
60
60
61
+ private QueryResult result ;
61
62
private String etag ;
62
- private Schema schema ;
63
63
private JobId job ;
64
- private Long totalRows ;
65
- private Page <List <FieldValue >> rows ;
66
- private Long totalBytesProcessed ;
67
64
private boolean jobComplete ;
68
65
private List <BigQueryError > executionErrors ;
69
- private Boolean cacheHit ;
70
66
71
67
private Builder () {}
72
68
73
- Builder etag ( String etag ) {
74
- this .etag = etag ;
69
+ Builder result ( QueryResult result ) {
70
+ this .result = result ;
75
71
return this ;
76
72
}
77
73
78
- Builder schema ( Schema schema ) {
79
- this .schema = schema ;
74
+ Builder etag ( String etag ) {
75
+ this .etag = etag ;
80
76
return this ;
81
77
}
82
78
@@ -85,21 +81,6 @@ Builder job(JobId job) {
85
81
return this ;
86
82
}
87
83
88
- Builder totalRows (Long totalRows ) {
89
- this .totalRows = totalRows ;
90
- return this ;
91
- }
92
-
93
- Builder rows (Page <List <FieldValue >> rows ) {
94
- this .rows = rows ;
95
- return this ;
96
- }
97
-
98
- Builder totalBytesProcessed (Long totalBytesProcessed ) {
99
- this .totalBytesProcessed = totalBytesProcessed ;
100
- return this ;
101
- }
102
-
103
84
Builder jobComplete (boolean jobComplete ) {
104
85
this .jobComplete = jobComplete ;
105
86
return this ;
@@ -110,41 +91,32 @@ Builder executionErrors(List<BigQueryError> executionErrors) {
110
91
return this ;
111
92
}
112
93
113
- Builder cacheHit (Boolean cacheHit ) {
114
- this .cacheHit = cacheHit ;
115
- return this ;
116
- }
117
-
118
94
QueryResponse build () {
119
95
return new QueryResponse (this );
120
96
}
121
97
}
122
98
123
99
private QueryResponse (Builder builder ) {
100
+ this .result = builder .result ;
124
101
this .etag = builder .etag ;
125
- this .schema = builder .schema ;
126
102
this .job = builder .job ;
127
- this .totalRows = builder .totalRows ;
128
- this .rows = builder .rows ;
129
- this .totalBytesProcessed = builder .totalBytesProcessed ;
130
103
this .jobComplete = builder .jobComplete ;
131
104
this .executionErrors = builder .executionErrors ;
132
- this .cacheHit = builder .cacheHit ;
133
105
}
134
106
135
107
/**
136
- * Returns the hash of the {@code QueryResponse} resource or {@code null} if not set.
108
+ * Returns the result of the query. Returns {@code null} if {@link #jobComplete()} is {@code
109
+ * false}.
137
110
*/
138
- public String etag () {
139
- return etag ;
111
+ public QueryResult result () {
112
+ return result ;
140
113
}
141
114
142
115
/**
143
- * Returns the schema of the results if the query completed successfully. Returns {@code null}
144
- * otherwise.
116
+ * Returns the hash of the {@code QueryResponse} resource or {@code null} if not set.
145
117
*/
146
- public Schema schema () {
147
- return schema ;
118
+ public String etag () {
119
+ return etag ;
148
120
}
149
121
150
122
/**
@@ -156,36 +128,10 @@ public JobId job() {
156
128
}
157
129
158
130
/**
159
- * Returns the total number of rows in the complete query result set, which can be more than the
160
- * number of rows in the first page of results returned by {@link #rows()}. Returns {@code null}
161
- * if the query did not complete successfully.
162
- */
163
- public Long totalRows () {
164
- return totalRows ;
165
- }
166
-
167
- /**
168
- * Returns the query result as a paginated list of rows, if the query completed successfully.
169
- * Returns {@code null} otherwise.
170
- */
171
- public Page <List <FieldValue >> rows () {
172
- return rows ;
173
- }
174
-
175
- /**
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.
179
- */
180
- public Long totalBytesProcessed () {
181
- return totalBytesProcessed ;
182
- }
183
-
184
- /**
185
- * Returns whether the job running the query has completed or not. If {@link #rows()} and
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.
131
+ * Returns whether the job running the query has completed or not. If {@link #result()} is not
132
+ * {@code null}, this method will always return {@code true}. If this method returns {@code false}
133
+ * {@link #result()} returns {@code null}. This method can be used to check if query execution
134
+ * completed and results are available.
189
135
*/
190
136
public boolean jobComplete () {
191
137
return jobComplete ;
@@ -199,25 +145,14 @@ public List<BigQueryError> executionErrors() {
199
145
return executionErrors ;
200
146
}
201
147
202
- /**
203
- * Returns whether the query result was fetched from the query cache.
204
- *
205
- * @see <a href="https://cloud.google.com/bigquery/querying-data#querycaching">Query Caching</a>
206
- */
207
- public Boolean cacheHit () {
208
- return cacheHit ;
209
- }
210
-
211
148
@ Override
212
149
public String toString () {
213
150
return MoreObjects .toStringHelper (this )
151
+ .add ("result" , result )
152
+ .add ("etag" , etag )
214
153
.add ("job" , job )
215
154
.add ("jobComplete" , jobComplete )
216
- .add ("totalRows" , totalRows )
217
- .add ("schema" , schema )
218
- .add ("totalBytesProcessed" , totalBytesProcessed )
219
155
.add ("executionErrors" , executionErrors )
220
- .add ("cacheHit" , cacheHit )
221
156
.toString ();
222
157
}
223
158
@@ -236,13 +171,10 @@ public boolean equals(Object obj) {
236
171
}
237
172
QueryResponse response = (QueryResponse ) obj ;
238
173
return jobComplete == response .jobComplete
239
- && Objects .equals (schema , response .schema )
174
+ && Objects .equals (etag , response .etag )
175
+ && Objects .equals (result , response .result )
240
176
&& Objects .equals (job , response .job )
241
- && Objects .equals (totalRows , response .totalRows )
242
- && Objects .equals (rows , response .rows )
243
- && Objects .equals (totalBytesProcessed , response .totalBytesProcessed )
244
- && Objects .equals (executionErrors , response .executionErrors )
245
- && Objects .equals (cacheHit , response .cacheHit );
177
+ && Objects .equals (executionErrors , response .executionErrors );
246
178
}
247
179
248
180
static Builder builder () {
0 commit comments