@@ -100,6 +100,15 @@ public class ConnectionImplTest {
100
100
.setTotalBytesProcessed (42L )
101
101
.setTotalRows (BigInteger .valueOf (1L ))
102
102
.setSchema (FAST_QUERY_TABLESCHEMA );
103
+ private static final GetQueryResultsResponse GET_QUERY_RESULTS_RESPONSE_EMPTY =
104
+ new GetQueryResultsResponse ()
105
+ .setJobReference (QUERY_JOB .toPb ())
106
+ .setJobComplete (true )
107
+ .setCacheHit (false )
108
+ .setPageToken (PAGE_TOKEN )
109
+ .setTotalBytesProcessed (0L )
110
+ .setTotalRows (BigInteger .valueOf (0L ))
111
+ .setSchema (FAST_QUERY_TABLESCHEMA );
103
112
104
113
private static final GetQueryResultsResponse GET_QUERY_RESULTS_RESPONSE_NULL_SCHEMA =
105
114
new GetQueryResultsResponse ()
@@ -375,7 +384,6 @@ public void testLegacyQuerySinglePage() throws BigQuerySQLException {
375
384
ConnectionImpl connectionSpy = Mockito .spy (connection );
376
385
com .google .api .services .bigquery .model .Job jobResponseMock =
377
386
new com .google .api .services .bigquery .model .Job ()
378
- // .setConfiguration(QUERY_JOB.g)
379
387
.setJobReference (QUERY_JOB .toPb ())
380
388
.setId (JOB )
381
389
.setStatus (new com .google .api .services .bigquery .model .JobStatus ().setState ("DONE" ));
@@ -401,6 +409,29 @@ public void testLegacyQuerySinglePage() throws BigQuerySQLException {
401
409
.createJobForQuery (any (com .google .api .services .bigquery .model .Job .class ));
402
410
}
403
411
412
+ // calls executeSelect with a nonFast query where the query returns an empty result.
413
+ @ Test
414
+ public void testLegacyQuerySinglePageEmptyResults () throws BigQuerySQLException {
415
+ ConnectionImpl connectionSpy = Mockito .spy (connection );
416
+ com .google .api .services .bigquery .model .Job jobResponseMock =
417
+ new com .google .api .services .bigquery .model .Job ()
418
+ .setJobReference (QUERY_JOB .toPb ())
419
+ .setId (JOB )
420
+ .setStatus (new com .google .api .services .bigquery .model .JobStatus ().setState ("DONE" ));
421
+ // emulating a legacy query
422
+ doReturn (false ).when (connectionSpy ).isFastQuerySupported ();
423
+ doReturn (GET_QUERY_RESULTS_RESPONSE_EMPTY )
424
+ .when (connectionSpy )
425
+ .getQueryResultsFirstPage (any (JobId .class ));
426
+ when (bigqueryRpcMock .createJobForQuery (any (com .google .api .services .bigquery .model .Job .class )))
427
+ .thenReturn (jobResponseMock ); // RPC call in createQueryJob
428
+ BigQueryResult res = connectionSpy .executeSelect (SQL_QUERY );
429
+ assertEquals (res .getTotalRows (), 0 );
430
+ assertEquals (QUERY_SCHEMA , res .getSchema ());
431
+ verify (bigqueryRpcMock , times (1 ))
432
+ .createJobForQuery (any (com .google .api .services .bigquery .model .Job .class ));
433
+ }
434
+
404
435
// exercises getSubsequentQueryResultsWithJob for fast running queries
405
436
@ Test
406
437
public void testFastQueryLongRunning () throws SQLException {
0 commit comments