@@ -141,19 +141,19 @@ impl crate::query::arrow::RecordBatchSource for StorageReader {
141141// TODO(#7039): wire into StorageReader once concurrent stream reading lands.
142142#[ allow( dead_code) ]
143143#[ derive( Debug , PartialEq , Eq ) ]
144- pub ( crate ) struct MultiStreamSession {
144+ pub ( crate ) struct ReadSessionInfo {
145145 pub ( crate ) streams : Vec < String > ,
146146 pub ( crate ) arrow_schema : Option < bytes:: Bytes > ,
147147}
148148
149149// TODO(#7039): wire into StorageReader once concurrent stream reading lands.
150150#[ allow( dead_code) ]
151- pub ( crate ) async fn try_create_multi_stream_session (
151+ pub ( crate ) async fn try_create_read_session (
152152 read_client : & ReadClient ,
153153 job_service : & JobService ,
154154 job_ref : & JobReference ,
155155 options : & RequestOptions ,
156- ) -> Result < Option < MultiStreamSession > , RowError > {
156+ ) -> Result < Option < ReadSessionInfo > , RowError > {
157157 let Some ( get_job) = build_get_job ( job_service, job_ref, options) else {
158158 return Ok ( None ) ;
159159 } ;
@@ -202,18 +202,14 @@ pub(crate) async fn try_create_multi_stream_session(
202202 . send ( )
203203 . await ?;
204204
205- if session. streams . len ( ) <= 1 {
206- return Ok ( None ) ;
207- }
208-
209205 let arrow_schema = match session. schema {
210206 Some ( ReadSessionSchema :: ArrowSchema ( schema) ) if !schema. serialized_schema . is_empty ( ) => {
211207 Some ( schema. serialized_schema )
212208 }
213209 _ => None ,
214210 } ;
215211 let streams = session. streams . into_iter ( ) . map ( |s| s. name ) . collect ( ) ;
216- Ok ( Some ( MultiStreamSession {
212+ Ok ( Some ( ReadSessionInfo {
217213 streams,
218214 arrow_schema,
219215 } ) )
@@ -448,8 +444,13 @@ mod tests {
448444 )
449445 }
450446
447+ #[ test_case:: test_case( 0 ; "zero streams" ) ]
448+ #[ test_case:: test_case( 1 ; "single stream" ) ]
449+ #[ test_case:: test_case( 2 ; "multiple streams" ) ]
451450 #[ tokio:: test]
452- async fn test_try_create_multi_stream_session_creates_arrow_lz4_session ( ) -> TestResult {
451+ async fn test_try_create_read_session_creates_arrow_lz4_session (
452+ stream_count : usize ,
453+ ) -> TestResult {
453454 let mut mock_job = MockJobService :: new ( ) ;
454455 mock_job. expect_get_job ( ) . times ( 1 ) . returning ( |req, opts| {
455456 assert_eq ! ( req. project_id, "billing-proj" ) ;
@@ -463,6 +464,10 @@ mod tests {
463464 ) ) )
464465 } ) ;
465466
467+ let expected_streams: Vec < String > = ( 0 ..stream_count)
468+ . map ( |i| format ! ( "sessions/s1/streams/{i}" ) )
469+ . collect ( ) ;
470+ let streams_for_mock = expected_streams. clone ( ) ;
466471 let schema_bytes = bytes:: Bytes :: from_static ( b"arrow-schema-bytes" ) ;
467472 let expected_schema = schema_bytes. clone ( ) ;
468473 let mut mock_read = MockRead :: new ( ) ;
@@ -484,12 +489,12 @@ mod tests {
484489 . expect ( "arrow_serialization_options must be set" ) ;
485490 assert_eq ! ( arrow_opts. buffer_compression, CompressionCodec :: Lz4Frame ) ;
486491
492+ let streams = streams_for_mock
493+ . into_iter ( )
494+ . map ( |name| ReadStream :: new ( ) . set_name ( name) ) ;
487495 let session = ReadSession :: new ( )
488496 . set_arrow_schema ( ArrowSchema :: new ( ) . set_serialized_schema ( schema_bytes) )
489- . set_streams ( [
490- ReadStream :: new ( ) . set_name ( "sessions/s1/streams/0" ) ,
491- ReadStream :: new ( ) . set_name ( "sessions/s1/streams/1" ) ,
492- ] ) ;
497+ . set_streams ( streams) ;
493498 Ok ( Response :: from ( session) )
494499 } ) ;
495500
@@ -503,31 +508,25 @@ mod tests {
503508 options. set_quota_project ( "quota-proj" ) ;
504509
505510 let result =
506- try_create_multi_stream_session ( & read_client, & job_service, & job_ref, & options) . await ?;
511+ try_create_read_session ( & read_client, & job_service, & job_ref, & options) . await ?;
507512
508513 assert_eq ! (
509514 result,
510- Some ( MultiStreamSession {
511- streams: vec![
512- "sessions/s1/streams/0" . to_string( ) ,
513- "sessions/s1/streams/1" . to_string( ) ,
514- ] ,
515+ Some ( ReadSessionInfo {
516+ streams: expected_streams,
515517 arrow_schema: Some ( expected_schema) ,
516518 } )
517519 ) ;
518520 Ok ( ( ) )
519521 }
520522
521- #[ test_case:: test_case( JobReference :: new( ) , None , None ; "empty job reference" ) ]
522- #[ test_case:: test_case( JobReference :: new( ) . set_project_id( "p1" ) . set_job_id( "j1" ) , Some ( Job :: new( ) ) , None ; "no destination table" ) ]
523- #[ test_case:: test_case( JobReference :: new( ) . set_project_id( "p1" ) . set_job_id( "j1" ) , Some ( job_with_dest_table( "p1" , "ds1" , "" ) ) , None ; "empty destination table id" ) ]
524- #[ test_case:: test_case( JobReference :: new( ) . set_project_id( "p1" ) . set_job_id( "j1" ) , Some ( job_with_dest_table( "p1" , "ds1" , "t1" ) ) , Some ( 0 ) ; "zero session streams" ) ]
525- #[ test_case:: test_case( JobReference :: new( ) . set_project_id( "p1" ) . set_job_id( "j1" ) , Some ( job_with_dest_table( "p1" , "ds1" , "t1" ) ) , Some ( 1 ) ; "single session stream" ) ]
523+ #[ test_case:: test_case( JobReference :: new( ) , None ; "empty job reference" ) ]
524+ #[ test_case:: test_case( JobReference :: new( ) . set_project_id( "p1" ) . set_job_id( "j1" ) , Some ( Job :: new( ) ) ; "no destination table" ) ]
525+ #[ test_case:: test_case( JobReference :: new( ) . set_project_id( "p1" ) . set_job_id( "j1" ) , Some ( job_with_dest_table( "p1" , "ds1" , "" ) ) ; "empty destination table id" ) ]
526526 #[ tokio:: test]
527- async fn test_try_create_multi_stream_session_returns_none_when_unavailable (
527+ async fn test_try_create_read_session_returns_none_without_destination_table (
528528 job_ref : JobReference ,
529529 job_response : Option < Job > ,
530- session_stream_count : Option < usize > ,
531530 ) -> TestResult {
532531 let mut mock_job = MockJobService :: new ( ) ;
533532 match job_response {
@@ -543,25 +542,11 @@ mod tests {
543542 }
544543
545544 let mut mock_read = MockRead :: new ( ) ;
546- match session_stream_count {
547- Some ( count) => {
548- mock_read
549- . expect_create_read_session ( )
550- . times ( 1 )
551- . return_once ( move |_, _| {
552- let streams =
553- ( 0 ..count) . map ( |i| ReadStream :: new ( ) . set_name ( format ! ( "streams/{i}" ) ) ) ;
554- Ok ( Response :: from ( ReadSession :: new ( ) . set_streams ( streams) ) )
555- } ) ;
556- }
557- None => {
558- mock_read. expect_create_read_session ( ) . never ( ) ;
559- }
560- }
545+ mock_read. expect_create_read_session ( ) . never ( ) ;
561546
562547 let job_service = create_job_service ( mock_job) ;
563548 let read_client = crate :: client:: Read :: from_stub ( mock_read) ;
564- let result = try_create_multi_stream_session (
549+ let result = try_create_read_session (
565550 & read_client,
566551 & job_service,
567552 & job_ref,
@@ -576,9 +561,7 @@ mod tests {
576561 #[ test_case:: test_case( true ; "get_job rpc error" ) ]
577562 #[ test_case:: test_case( false ; "create_read_session rpc error" ) ]
578563 #[ tokio:: test]
579- async fn test_try_create_multi_stream_session_propagates_rpc_errors (
580- fail_get_job : bool ,
581- ) -> TestResult {
564+ async fn test_try_create_read_session_propagates_rpc_errors ( fail_get_job : bool ) -> TestResult {
582565 let mut mock_job = MockJobService :: new ( ) ;
583566 let mut mock_read = MockRead :: new ( ) ;
584567 let denied = |msg : & str | {
@@ -609,7 +592,7 @@ mod tests {
609592 let job_service = create_job_service ( mock_job) ;
610593 let read_client = crate :: client:: Read :: from_stub ( mock_read) ;
611594 let job_ref = JobReference :: new ( ) . set_project_id ( "p1" ) . set_job_id ( "j1" ) ;
612- let err = try_create_multi_stream_session (
595+ let err = try_create_read_session (
613596 & read_client,
614597 & job_service,
615598 & job_ref,
0 commit comments