@@ -302,6 +302,55 @@ public Iterable<FieldValueList> getValues() {
302302 verify (status , mockOptions );
303303 }
304304
305+ @ Test
306+ public void testWaitForAndGetQueryResultsEmptyWithSchema () throws InterruptedException {
307+ QueryJobConfiguration jobConfig =
308+ QueryJobConfiguration .newBuilder ("CREATE VIEW" ).setDestinationTable (TABLE_ID1 ).build ();
309+ QueryStatistics jobStatistics =
310+ QueryStatistics .newBuilder ()
311+ .setCreationTimestamp (1L )
312+ .setEndTime (3L )
313+ .setStartTime (2L )
314+ .build ();
315+ JobInfo jobInfo =
316+ JobInfo .newBuilder (jobConfig )
317+ .setJobId (JOB_ID )
318+ .setStatistics (jobStatistics )
319+ .setJobId (JOB_ID )
320+ .setEtag (ETAG )
321+ .setGeneratedId (GENERATED_ID )
322+ .setSelfLink (SELF_LINK )
323+ .setUserEmail (EMAIL )
324+ .setStatus (JOB_STATUS )
325+ .build ();
326+
327+ initializeExpectedJob (2 , jobInfo );
328+ JobStatus status = createStrictMock (JobStatus .class );
329+ expect (bigquery .getOptions ()).andReturn (mockOptions );
330+ expect (mockOptions .getClock ()).andReturn (CurrentMillisClock .getDefaultClock ()).times (2 );
331+ Job completedJob = expectedJob .toBuilder ().setStatus (status ).build ();
332+ QueryResponse completedQuery =
333+ QueryResponse .newBuilder ()
334+ .setCompleted (true )
335+ .setTotalRows (0 )
336+ .setSchema (Schema .of (Field .of ("field1" , LegacySQLTypeName .BOOLEAN )))
337+ .setErrors (ImmutableList .<BigQueryError >of ())
338+ .build ();
339+
340+ expect (bigquery .getQueryResults (jobInfo .getJobId (), Job .DEFAULT_QUERY_WAIT_OPTIONS ))
341+ .andReturn (completedQuery );
342+ expect (bigquery .getJob (JOB_INFO .getJobId ())).andReturn (completedJob );
343+ expect (bigquery .getQueryResults (jobInfo .getJobId (), Job .DEFAULT_QUERY_WAIT_OPTIONS ))
344+ .andReturn (completedQuery );
345+
346+ replay (status , bigquery , mockOptions );
347+ initializeJob (jobInfo );
348+ assertThat (job .waitFor (TEST_RETRY_OPTIONS )).isSameAs (completedJob );
349+ assertThat (job .getQueryResults ().getSchema ())
350+ .isEqualTo (Schema .of (Field .of ("field1" , LegacySQLTypeName .BOOLEAN )));
351+ verify (status , mockOptions );
352+ }
353+
305354 @ Test
306355 public void testWaitForAndGetQueryResults () throws InterruptedException {
307356 QueryJobConfiguration jobConfig =
0 commit comments