11use std:: collections:: HashMap ;
22use std:: sync:: Arc ;
33
4- use arrow:: buffer:: Buffer ;
54use bytes:: Bytes ;
65use chrono:: { DateTime , Utc } ;
76use futures:: stream:: { BoxStream , Fuse } ;
87use futures:: StreamExt ;
98use object_store:: { GetOptions , GetRange , GetResult , ObjectStore } ;
109use pyo3:: exceptions:: { PyStopAsyncIteration , PyStopIteration , PyValueError } ;
1110use pyo3:: prelude:: * ;
12- use pyo3:: types:: PyBytes ;
13- use pyo3_arrow:: buffer:: PyArrowBuffer ;
1411use pyo3_object_store:: { PyObjectStore , PyObjectStoreError , PyObjectStoreResult } ;
1512use tokio:: sync:: Mutex ;
1613
@@ -302,7 +299,7 @@ impl PyBytesWrapper {
302299// support the buffer protocol in the future (e.g. for get_range) you may need to have a separate
303300// wrapper of Bytes
304301impl < ' py > IntoPyObject < ' py > for PyBytesWrapper {
305- type Target = PyBytes ;
302+ type Target = pyo3 :: types :: PyBytes ;
306303 type Output = Bound < ' py , Self :: Target > ;
307304 type Error = PyErr ;
308305
@@ -311,7 +308,7 @@ impl<'py> IntoPyObject<'py> for PyBytesWrapper {
311308
312309 // Copy all internal Bytes objects into a single PyBytes
313310 // Since our inner callback is infallible, this will only panic on out of memory
314- PyBytes :: new_with ( py, total_len, |target| {
311+ pyo3 :: types :: PyBytes :: new_with ( py, total_len, |target| {
315312 let mut offset = 0 ;
316313 for buf in self . 0 . iter ( ) {
317314 target[ offset..offset + buf. len ( ) ] . copy_from_slice ( buf) ;
@@ -370,11 +367,11 @@ pub(crate) fn get_range(
370367 path : String ,
371368 start : usize ,
372369 end : usize ,
373- ) -> PyObjectStoreResult < PyArrowBuffer > {
370+ ) -> PyObjectStoreResult < pyo3_bytes :: PyBytes > {
374371 let runtime = get_runtime ( py) ?;
375372 py. allow_threads ( || {
376373 let out = runtime. block_on ( store. as_ref ( ) . get_range ( & path. into ( ) , start..end) ) ?;
377- Ok :: < _ , PyObjectStoreError > ( PyArrowBuffer :: new ( Buffer :: from_bytes ( out. into ( ) ) ) )
374+ Ok :: < _ , PyObjectStoreError > ( pyo3_bytes :: PyBytes :: new ( out) )
378375 } )
379376}
380377
@@ -392,7 +389,7 @@ pub(crate) fn get_range_async(
392389 . get_range ( & path. into ( ) , start..end)
393390 . await
394391 . map_err ( PyObjectStoreError :: ObjectStoreError ) ?;
395- Ok ( PyArrowBuffer :: new ( Buffer :: from_bytes ( out. into ( ) ) ) )
392+ Ok ( pyo3_bytes :: PyBytes :: new ( out) )
396393 } )
397394}
398395
@@ -403,7 +400,7 @@ pub(crate) fn get_ranges(
403400 path : String ,
404401 starts : Vec < usize > ,
405402 ends : Vec < usize > ,
406- ) -> PyObjectStoreResult < Vec < PyArrowBuffer > > {
403+ ) -> PyObjectStoreResult < Vec < pyo3_bytes :: PyBytes > > {
407404 let runtime = get_runtime ( py) ?;
408405 let ranges = starts
409406 . into_iter ( )
@@ -412,11 +409,7 @@ pub(crate) fn get_ranges(
412409 . collect :: < Vec < _ > > ( ) ;
413410 py. allow_threads ( || {
414411 let out = runtime. block_on ( store. as_ref ( ) . get_ranges ( & path. into ( ) , & ranges) ) ?;
415- Ok :: < _ , PyObjectStoreError > (
416- out. into_iter ( )
417- . map ( |buf| PyArrowBuffer :: new ( Buffer :: from_bytes ( buf. into ( ) ) ) )
418- . collect ( ) ,
419- )
412+ Ok :: < _ , PyObjectStoreError > ( out. into_iter ( ) . map ( |buf| buf. into ( ) ) . collect ( ) )
420413 } )
421414}
422415
@@ -441,7 +434,7 @@ pub(crate) fn get_ranges_async(
441434 . map_err ( PyObjectStoreError :: ObjectStoreError ) ?;
442435 Ok ( out
443436 . into_iter ( )
444- . map ( |buf| PyArrowBuffer :: new ( Buffer :: from_bytes ( buf . into ( ) ) ) )
437+ . map ( pyo3_bytes :: PyBytes :: new )
445438 . collect :: < Vec < _ > > ( ) )
446439 } )
447440}
0 commit comments