@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
"cloud.google.com/go/internal/testutil"
25
+ "github.com/google/go-cmp/cmp"
25
26
"google.golang.org/api/iterator"
26
27
)
27
28
@@ -233,10 +234,22 @@ func TestIntegration_StorageReadQueryOrdering(t *testing.T) {
233
234
t .Fatal (err )
234
235
}
235
236
237
+ var firstValue S
238
+ err = it .Next (& firstValue )
239
+ if err != nil {
240
+ t .Fatal (err )
241
+ }
242
+
243
+ if cmp .Equal (firstValue , S {}) {
244
+ t .Fatalf ("user defined struct was not filled with data" )
245
+ }
246
+
236
247
total , err := countIteratorRows (it )
237
248
if err != nil {
238
249
t .Fatal (err )
239
250
}
251
+ total ++ // as we read the first value separately
252
+
240
253
bqSession := it .arrowIterator .session .bqSession
241
254
if len (bqSession .Streams ) == 0 {
242
255
t .Fatalf ("%s: expected to use at least one stream but found %d" , tc .name , len (bqSession .Streams ))
@@ -263,6 +276,56 @@ func TestIntegration_StorageReadQueryOrdering(t *testing.T) {
263
276
}
264
277
}
265
278
279
+ func TestIntegration_StorageReadQueryStruct (t * testing.T ) {
280
+ if client == nil {
281
+ t .Skip ("Integration tests skipped" )
282
+ }
283
+ ctx := context .Background ()
284
+ table := "`bigquery-public-data.samples.wikipedia`"
285
+ sql := fmt .Sprintf (`SELECT id, title, timestamp, comment FROM %s LIMIT 1000` , table )
286
+ q := storageOptimizedClient .Query (sql )
287
+ q .forceStorageAPI = true
288
+ q .DisableQueryCache = true
289
+ it , err := q .Read (ctx )
290
+ if err != nil {
291
+ t .Fatal (err )
292
+ }
293
+ if ! it .IsAccelerated () {
294
+ t .Fatal ("expected query to use Storage API" )
295
+ }
296
+
297
+ type S struct {
298
+ ID int64
299
+ Title string
300
+ Timestamp int64
301
+ Comment NullString
302
+ }
303
+
304
+ total := uint64 (0 )
305
+ for {
306
+ var dst S
307
+ err := it .Next (& dst )
308
+ if err == iterator .Done {
309
+ break
310
+ }
311
+ if err != nil {
312
+ t .Fatalf ("failed to fetch via storage API: %v" , err )
313
+ }
314
+ if cmp .Equal (dst , S {}) {
315
+ t .Fatalf ("user defined struct was not filled with data" )
316
+ }
317
+ total ++
318
+ }
319
+
320
+ bqSession := it .arrowIterator .session .bqSession
321
+ if len (bqSession .Streams ) == 0 {
322
+ t .Fatalf ("should use more than one stream but found %d" , len (bqSession .Streams ))
323
+ }
324
+ if total != it .TotalRows {
325
+ t .Fatalf ("should have read %d rows, but read %d" , it .TotalRows , total )
326
+ }
327
+ }
328
+
266
329
func TestIntegration_StorageReadQueryMorePages (t * testing.T ) {
267
330
if client == nil {
268
331
t .Skip ("Integration tests skipped" )
@@ -287,10 +350,22 @@ func TestIntegration_StorageReadQueryMorePages(t *testing.T) {
287
350
Forks NullInt64
288
351
}
289
352
353
+ var firstValue S
354
+ err = it .Next (& firstValue )
355
+ if err != nil {
356
+ t .Fatal (err )
357
+ }
358
+
359
+ if cmp .Equal (firstValue , S {}) {
360
+ t .Fatalf ("user defined struct was not filled with data" )
361
+ }
362
+
290
363
total , err := countIteratorRows (it )
291
364
if err != nil {
292
365
t .Fatal (err )
293
366
}
367
+ total ++ // as we read the first value separately
368
+
294
369
bqSession := it .arrowIterator .session .bqSession
295
370
if len (bqSession .Streams ) == 0 {
296
371
t .Fatalf ("should use more than one stream but found %d" , len (bqSession .Streams ))
0 commit comments