@@ -2954,6 +2954,65 @@ void testQueryArrowDefaultsToJobCreationOptional() throws IOException, Interrupt
29542954 assertEquals ("ARROW" , requestPb .getQueryResultsFormat ());
29552955 }
29562956
2957+ @ Test
2958+ void testQueryArrowDefaultsToUSLocationWhenUnspecified () throws Exception {
2959+ org .apache .arrow .vector .types .pojo .Schema arrowSchema =
2960+ new org .apache .arrow .vector .types .pojo .Schema (
2961+ ImmutableList .of (
2962+ org .apache .arrow .vector .types .pojo .Field .nullable (
2963+ "id" , new ArrowType .Int (64 , true ))));
2964+
2965+ byte [] schemaBytes ;
2966+ try (ByteArrayOutputStream out = new ByteArrayOutputStream ()) {
2967+ MessageSerializer .serialize (new WriteChannel (Channels .newChannel (out )), arrowSchema );
2968+ schemaBytes = out .toByteArray ();
2969+ }
2970+
2971+ QueryJobConfiguration config =
2972+ QueryJobConfiguration .newBuilder ("SELECT 1" )
2973+ .setQueryResultsFormat (QueryResultsFormat .ARROW )
2974+ .build ();
2975+ com .google .api .services .bigquery .model .JobReference jobRef =
2976+ new com .google .api .services .bigquery .model .JobReference ()
2977+ .setProjectId (PROJECT )
2978+ .setJobId (JOB ); // No location set
2979+ com .google .api .services .bigquery .model .QueryResponse queryResponsePb =
2980+ new com .google .api .services .bigquery .model .QueryResponse ()
2981+ .setJobReference (jobRef )
2982+ .setJobComplete (true )
2983+ .setTotalRows (BigInteger .ONE )
2984+ .setArrowSchema (
2985+ new com .google .api .services .bigquery .model .ArrowSchema ()
2986+ .setSerializedSchema (BaseEncoding .base64 ().encode (schemaBytes )));
2987+
2988+ BigQueryReadClient mockReadClient =
2989+ mock (BigQueryReadClient .class , withSettings ().withoutAnnotations ());
2990+ @ SuppressWarnings ("unchecked" )
2991+ ServerStreamingCallable <ReadRowsRequest , ReadRowsResponse > mockCallable =
2992+ mock (ServerStreamingCallable .class , withSettings ().withoutAnnotations ());
2993+ @ SuppressWarnings ("unchecked" )
2994+ ServerStream <ReadRowsResponse > mockServerStream =
2995+ mock (ServerStream .class , withSettings ().withoutAnnotations ());
2996+ ArgumentCaptor <ReadRowsRequest > requestCapture = ArgumentCaptor .forClass (ReadRowsRequest .class );
2997+ when (mockCallable .call (requestCapture .capture ())).thenReturn (mockServerStream );
2998+ when (mockServerStream .iterator ()).thenReturn (Collections .emptyIterator ());
2999+ when (mockReadClient .readRowsCallable ()).thenReturn (mockCallable );
3000+
3001+ when (bigqueryRpcMock .queryRpcSkipExceptionTranslation (eq (PROJECT ), any (QueryRequest .class )))
3002+ .thenReturn (queryResponsePb );
3003+
3004+ bigquery = options .getService ();
3005+ ((BigQueryImpl ) bigquery ).setBigQueryReadClient (mockReadClient );
3006+
3007+ ArrowQueryResult result = bigquery .queryArrow (config );
3008+ assertNotNull (result );
3009+ result .iterator ().hasNext ();
3010+
3011+ assertEquals (
3012+ "projects/" + PROJECT + "/locations/US/jobs/" + JOB + "/streams/_default" ,
3013+ requestCapture .getValue ().getReadStream ());
3014+ }
3015+
29573016 @ Test
29583017 void testQueryWithArrowFormatSlowPathFallback () throws Exception {
29593018 JobId queryJob = JobId .of (PROJECT , JOB ).toBuilder ().setLocation (LOCATION ).build ();
0 commit comments