@@ -11,9 +11,9 @@ use indexmap::IndexMap;
1111use object_store:: path:: Path ;
1212use object_store:: { ListResult , ObjectMeta , ObjectStore } ;
1313use pyo3:: exceptions:: { PyImportError , PyStopAsyncIteration , PyStopIteration } ;
14- use pyo3:: intern;
1514use pyo3:: prelude:: * ;
1615use pyo3:: types:: PyDict ;
16+ use pyo3:: { intern, IntoPyObjectExt } ;
1717use pyo3_arrow:: PyRecordBatch ;
1818use pyo3_object_store:: { get_runtime, PyObjectStore , PyObjectStoreError , PyObjectStoreResult } ;
1919use tokio:: sync:: Mutex ;
@@ -47,17 +47,11 @@ impl<'py> IntoPyObject<'py> for PyObjectMeta {
4747 let mut dict = IndexMap :: with_capacity ( 5 ) ;
4848 // Note, this uses "path" instead of "location" because we standardize the API to accept
4949 // the keyword "path" everywhere.
50- dict. insert (
51- "path" ,
52- self . 0 . location . as_ref ( ) . into_pyobject ( py) ?. into_any ( ) ,
53- ) ;
54- dict. insert (
55- "last_modified" ,
56- self . 0 . last_modified . into_pyobject ( py) ?. into_any ( ) ,
57- ) ;
58- dict. insert ( "size" , self . 0 . size . into_pyobject ( py) ?. into_any ( ) ) ;
59- dict. insert ( "e_tag" , self . 0 . e_tag . into_pyobject ( py) ?. into_any ( ) ) ;
60- dict. insert ( "version" , self . 0 . version . into_pyobject ( py) ?) ;
50+ dict. insert ( "path" , self . 0 . location . as_ref ( ) . into_bound_py_any ( py) ?) ;
51+ dict. insert ( "last_modified" , self . 0 . last_modified . into_bound_py_any ( py) ?) ;
52+ dict. insert ( "size" , self . 0 . size . into_bound_py_any ( py) ?) ;
53+ dict. insert ( "e_tag" , self . 0 . e_tag . into_bound_py_any ( py) ?) ;
54+ dict. insert ( "version" , self . 0 . version . into_bound_py_any ( py) ?) ;
6155 dict. into_pyobject ( py)
6256 }
6357}
@@ -317,7 +311,19 @@ fn object_meta_to_arrow(metas: &[PyObjectMeta]) -> PyRecordBatchWrapper {
317311 PyRecordBatchWrapper :: new ( batch)
318312}
319313
320- pub ( crate ) struct PyListResult ( ListResult ) ;
314+ pub ( crate ) struct PyListResult {
315+ result : ListResult ,
316+ return_arrow : bool ,
317+ }
318+
319+ impl PyListResult {
320+ fn new ( result : ListResult , return_arrow : bool ) -> Self {
321+ Self {
322+ result,
323+ return_arrow,
324+ }
325+ }
326+ }
321327
322328impl < ' py > IntoPyObject < ' py > for PyListResult {
323329 type Target = PyDict ;
@@ -328,24 +334,25 @@ impl<'py> IntoPyObject<'py> for PyListResult {
328334 let mut dict = IndexMap :: with_capacity ( 2 ) ;
329335 dict. insert (
330336 "common_prefixes" ,
331- self . 0
337+ self . result
332338 . common_prefixes
333339 . into_iter ( )
334340 . map ( String :: from)
335341 . collect :: < Vec < _ > > ( )
336- . into_pyobject ( py) ?
337- . into_any ( ) ,
338- ) ;
339- dict. insert (
340- "objects" ,
341- self . 0
342- . objects
343- . into_iter ( )
344- . map ( PyObjectMeta )
345- . collect :: < Vec < _ > > ( )
346- . into_pyobject ( py) ?
347- . into_any ( ) ,
342+ . into_bound_py_any ( py) ?,
348343 ) ;
344+ let objects = self
345+ . result
346+ . objects
347+ . into_iter ( )
348+ . map ( PyObjectMeta )
349+ . collect :: < Vec < _ > > ( ) ;
350+ let objects = if self . return_arrow {
351+ object_meta_to_arrow ( & objects) . into_bound_py_any ( py)
352+ } else {
353+ objects. into_bound_py_any ( py)
354+ } ?;
355+ dict. insert ( "objects" , objects) ;
349356 dict. into_pyobject ( py)
350357 }
351358}
@@ -383,41 +390,48 @@ pub(crate) fn list(
383390}
384391
385392#[ pyfunction]
386- #[ pyo3( signature = ( store, prefix=None ) ) ]
393+ #[ pyo3( signature = ( store, prefix=None , * , return_arrow= false ) ) ]
387394pub ( crate ) fn list_with_delimiter (
388395 py : Python ,
389396 store : PyObjectStore ,
390397 prefix : Option < String > ,
398+ return_arrow : bool ,
391399) -> PyObjectStoreResult < PyListResult > {
392400 let runtime = get_runtime ( py) ?;
393401 py. allow_threads ( || {
394402 let out = runtime. block_on ( list_with_delimiter_materialize (
395403 store. into_inner ( ) ,
396404 prefix. map ( |s| s. into ( ) ) . as_ref ( ) ,
405+ return_arrow,
397406 ) ) ?;
398407 Ok :: < _ , PyObjectStoreError > ( out)
399408 } )
400409}
401410
402411#[ pyfunction]
403- #[ pyo3( signature = ( store, prefix=None ) ) ]
412+ #[ pyo3( signature = ( store, prefix=None , * , return_arrow= false ) ) ]
404413pub ( crate ) fn list_with_delimiter_async (
405414 py : Python ,
406415 store : PyObjectStore ,
407416 prefix : Option < String > ,
417+ return_arrow : bool ,
408418) -> PyResult < Bound < PyAny > > {
409419 pyo3_async_runtimes:: tokio:: future_into_py ( py, async move {
410- let out =
411- list_with_delimiter_materialize ( store. into_inner ( ) , prefix. map ( |s| s. into ( ) ) . as_ref ( ) )
412- . await ?;
420+ let out = list_with_delimiter_materialize (
421+ store. into_inner ( ) ,
422+ prefix. map ( |s| s. into ( ) ) . as_ref ( ) ,
423+ return_arrow,
424+ )
425+ . await ?;
413426 Ok ( out)
414427 } )
415428}
416429
417430async fn list_with_delimiter_materialize (
418431 store : Arc < dyn ObjectStore > ,
419432 prefix : Option < & Path > ,
433+ return_arrow : bool ,
420434) -> PyObjectStoreResult < PyListResult > {
421435 let list_result = store. list_with_delimiter ( prefix) . await ?;
422- Ok ( PyListResult ( list_result) )
436+ Ok ( PyListResult :: new ( list_result, return_arrow ) )
423437}
0 commit comments