@@ -258,14 +258,18 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
258
258
259
259
// Mock job polling.
260
260
JobStatus status = new JobStatus ().setState ("DONE" );
261
- TableReference tableRef =
262
- new TableReference ().setProjectId ("project" ).setDatasetId ("dataset" ).setTableId ("table" );
263
- JobConfigurationQuery queryConfig = new JobConfigurationQuery ().setDestinationTable (tableRef );
261
+ JobConfigurationQuery resultQueryConfig =
262
+ new JobConfigurationQuery ().setDestinationTable (
263
+ new TableReference ()
264
+ .setProjectId ("project" )
265
+ .setDatasetId ("tempdataset" )
266
+ .setTableId ("temptable" )
267
+ );
264
268
Job getJob =
265
269
new Job ()
266
270
.setJobReference (new JobReference ())
267
271
.setStatus (status )
268
- .setConfiguration (new JobConfiguration ().setQuery (queryConfig ));
272
+ .setConfiguration (new JobConfiguration ().setQuery (resultQueryConfig ));
269
273
when (mockJobsGet .execute ()).thenReturn (getJob );
270
274
271
275
// Mock table schema fetch.
@@ -281,8 +285,9 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
281
285
String query = String .format (
282
286
"SELECT \" Arthur\" as name, 42 as count, \" %s\" as photo" ,
283
287
photoBytesEncoded );
288
+ JobConfigurationQuery queryConfig = new JobConfigurationQuery ().setQuery (query );
284
289
try (BigQueryTableRowIterator iterator =
285
- BigQueryTableRowIterator .fromQuery (query , "project" , mockClient , null , null )) {
290
+ BigQueryTableRowIterator .fromQuery (queryConfig , "project" , mockClient )) {
286
291
iterator .open ();
287
292
assertTrue (iterator .advance ());
288
293
TableRow row = iterator .getCurrent ();
@@ -317,7 +322,7 @@ public void testReadFromQueryNoTables() throws IOException, InterruptedException
317
322
verify (mockTablesDelete ).execute ();
318
323
// Table data read.
319
324
verify (mockClient ).tabledata ();
320
- verify (mockTabledata ).list ("project" , "dataset " , "table " );
325
+ verify (mockTabledata ).list ("project" , "tempdataset " , "temptable " );
321
326
verify (mockTabledataList ).execute ();
322
327
}
323
328
@@ -334,18 +339,16 @@ public void testQueryFailed() throws IOException {
334
339
when (mockJobsInsert .execute ()).thenThrow (exception , exception , exception , exception );
335
340
336
341
String query = "NOT A QUERY" ;
342
+ JobConfigurationQuery queryConfig = new JobConfigurationQuery ().setQuery (query );
337
343
try (BigQueryTableRowIterator iterator =
338
- BigQueryTableRowIterator .fromQuery (query , "project" , mockClient , null , null )) {
339
-
340
- try {
341
- iterator .open ();
342
- fail ();
343
- } catch (Exception expected ) {
344
- // Verify message explains cause and reports the query.
345
- assertThat (expected .getMessage (), containsString ("Error" ));
346
- assertThat (expected .getMessage (), containsString (query ));
347
- assertThat (expected .getCause ().getMessage (), containsString (errorReason ));
348
- }
344
+ BigQueryTableRowIterator .fromQuery (queryConfig , "project" , mockClient )) {
345
+ iterator .open ();
346
+ fail ();
347
+ } catch (Exception expected ) {
348
+ // Verify message explains cause and reports the query.
349
+ assertThat (expected .getMessage (), containsString ("Error" ));
350
+ assertThat (expected .getMessage (), containsString (query ));
351
+ assertThat (expected .getCause ().getMessage (), containsString (errorReason ));
349
352
}
350
353
351
354
// Job inserted to run the query, then polled once.
0 commit comments