@@ -7,7 +7,8 @@ use chrono::{DateTime, Utc};
77use futures:: stream:: { BoxStream , Fuse } ;
88use futures:: StreamExt ;
99use object_store:: {
10- Attributes , GetOptions , GetRange , GetResult , ObjectMeta , ObjectStore , ObjectStoreExt ,
10+ coalesce_ranges, Attributes , GetOptions , GetRange , GetResult , ObjectMeta , ObjectStore ,
11+ ObjectStoreExt , OBJECT_STORE_COALESCE_DEFAULT ,
1112} ;
1213use pyo3:: exceptions:: { PyStopAsyncIteration , PyStopIteration , PyValueError } ;
1314use pyo3:: prelude:: * ;
@@ -430,45 +431,51 @@ fn params_to_range(
430431 }
431432}
432433
434+ async fn _get_ranges (
435+ store : PyObjectStore ,
436+ path : PyPath ,
437+ ranges : & [ Range < u64 > ] ,
438+ coalesce : u64 ,
439+ ) -> PyObjectStoreResult < Vec < PyBytes > > {
440+ let out = coalesce_ranges (
441+ ranges,
442+ |range| store. as_ref ( ) . get_range ( path. as_ref ( ) , range) ,
443+ coalesce,
444+ )
445+ . await ?;
446+ Ok ( out. into_iter ( ) . map ( |buf| buf. into ( ) ) . collect ( ) )
447+ }
448+
433449#[ pyfunction]
434- #[ pyo3( signature = ( store, path, * , starts, ends=None , lengths=None ) ) ]
450+ #[ pyo3( signature = ( store, path, * , starts, ends=None , lengths=None , coalesce= OBJECT_STORE_COALESCE_DEFAULT ) ) ]
435451pub ( crate ) fn get_ranges (
436452 py : Python ,
437453 store : PyObjectStore ,
438454 path : PyPath ,
439455 starts : Vec < u64 > ,
440456 ends : Option < Vec < u64 > > ,
441457 lengths : Option < Vec < u64 > > ,
442- ) -> PyObjectStoreResult < Vec < pyo3_bytes:: PyBytes > > {
458+ coalesce : u64 ,
459+ ) -> PyObjectStoreResult < Vec < PyBytes > > {
443460 let runtime = get_runtime ( ) ;
444461 let ranges = params_to_ranges ( starts, ends, lengths) ?;
445- py. detach ( || {
446- let out = runtime. block_on ( store. as_ref ( ) . get_ranges ( path. as_ref ( ) , & ranges) ) ?;
447- Ok :: < _ , PyObjectStoreError > ( out. into_iter ( ) . map ( |buf| buf. into ( ) ) . collect ( ) )
448- } )
462+ py. detach ( || runtime. block_on ( _get_ranges ( store, path, & ranges, coalesce) ) )
449463}
450464
451465#[ pyfunction]
452- #[ pyo3( signature = ( store, path, * , starts, ends=None , lengths=None ) ) ]
466+ #[ pyo3( signature = ( store, path, * , starts, ends=None , lengths=None , coalesce= OBJECT_STORE_COALESCE_DEFAULT ) ) ]
453467pub ( crate ) fn get_ranges_async (
454468 py : Python ,
455469 store : PyObjectStore ,
456470 path : PyPath ,
457471 starts : Vec < u64 > ,
458472 ends : Option < Vec < u64 > > ,
459473 lengths : Option < Vec < u64 > > ,
474+ coalesce : u64 ,
460475) -> PyResult < Bound < PyAny > > {
461476 let ranges = params_to_ranges ( starts, ends, lengths) ?;
462477 pyo3_async_runtimes:: tokio:: future_into_py ( py, async move {
463- let out = store
464- . as_ref ( )
465- . get_ranges ( path. as_ref ( ) , & ranges)
466- . await
467- . map_err ( PyObjectStoreError :: ObjectStoreError ) ?;
468- Ok ( out
469- . into_iter ( )
470- . map ( pyo3_bytes:: PyBytes :: new)
471- . collect :: < Vec < _ > > ( ) )
478+ Ok ( _get_ranges ( store, path, & ranges, coalesce) . await ?)
472479 } )
473480}
474481
0 commit comments