@@ -378,6 +378,20 @@ public Page<FieldValueList> getNextPage() {
378378 List <FieldValueList > rowBatch = new ArrayList <>((int ) Math .min (pageSize , 10000L ));
379379
380380 try {
381+ // Resolve job location in order: JobId location -> BigQueryOptions location -> "global"
382+ // default.
383+ // The Storage Read API stream resource name requires a location component (e.g.
384+ // projects/{project}/locations/{location}/jobs/{job}/streams/_default). If no specific
385+ // location was provided on the job or service options, defaulting to "global" allows
386+ // queries created without an explicit location to still stream results without failing.
387+ String location = jobId .getLocation ();
388+ if (location == null ) {
389+ location = serviceOptions .getLocation ();
390+ }
391+ if (location == null ) {
392+ location = "global" ;
393+ }
394+
381395 if (streamIterator == null ) {
382396 if (bqReadClient == null ) {
383397 BigQuery service = serviceOptions .getService ();
@@ -395,20 +409,6 @@ public Page<FieldValueList> getNextPage() {
395409 if (customStreamName != null ) {
396410 streamName = customStreamName ;
397411 } else {
398- // Resolve job location in order: JobId location -> BigQueryOptions location -> "global"
399- // default.
400- // The Storage Read API stream resource name requires a location component (e.g.
401- // projects/{project}/locations/{location}/jobs/{job}/streams/_default). If no specific
402- // location was provided on the job or service options, defaulting to "global" allows
403- // queries created without an explicit location to still stream results without failing.
404- String location = jobId .getLocation ();
405- if (location == null ) {
406- location = serviceOptions .getLocation ();
407- }
408- if (location == null ) {
409- location = "global" ;
410- }
411-
412412 // Construct the default stream path for reading job query results via Storage Read API.
413413 streamName =
414414 String .format (
0 commit comments