@@ -356,14 +356,16 @@ private Table getTable(TableReference ref) throws IOException, InterruptedExcept
356356 }
357357
358358 // Create a new BigQuery dataset
359- private void createDataset (String datasetId , String location )
359+ private void createDataset (String datasetId , @ Nullable String location )
360360 throws IOException , InterruptedException {
361361 Dataset dataset = new Dataset ();
362362 DatasetReference reference = new DatasetReference ();
363363 reference .setProjectId (projectId );
364364 reference .setDatasetId (datasetId );
365365 dataset .setDatasetReference (reference );
366- dataset .setLocation (location );
366+ if (location != null ) {
367+ dataset .setLocation (location );
368+ }
367369
368370 executeWithBackOff (
369371 client .datasets ().insert (projectId , dataset ),
@@ -411,8 +413,8 @@ private TableReference executeQueryAndWaitForCompletion()
411413 client .jobs ().insert (projectId , dryRunJob ),
412414 String .format ("Error when trying to dry run query %s." , query )).getStatistics ();
413415
414- // Default to US if the query does not read any tables.
415- String location = "US" ;
416+ // Let BigQuery to pick default location if the query does not read any tables.
417+ String location = null ;
416418 @ Nullable List <TableReference > tables = jobStats .getQuery ().getReferencedTables ();
417419 if (tables != null && !tables .isEmpty ()) {
418420 Table table = getTable (tables .get (0 ));
0 commit comments