@@ -19,6 +19,7 @@ use std::sync::Arc;
1919
2020use datafusion_common:: { DataFusionError , Result , TableReference } ;
2121use datafusion_execution:: cache:: TableScopedPath ;
22+ use datafusion_execution:: cache:: cache_manager:: CachedFileList ;
2223use datafusion_execution:: object_store:: ObjectStoreUrl ;
2324use datafusion_session:: Session ;
2425
@@ -396,42 +397,34 @@ async fn list_with_cache<'b>(
396397 . map ( |res| res. map_err ( |e| DataFusionError :: ObjectStore ( Box :: new ( e) ) ) )
397398 . boxed ( ) ) ,
398399 Some ( cache) => {
399- // Convert prefix to Option<Path> for cache lookup
400- let prefix_filter = prefix. cloned ( ) ;
400+ // Build the filter prefix (only Some if prefix was requested)
401+ let filter_prefix = prefix. is_some ( ) . then ( || full_prefix . clone ( ) ) ;
401402
402403 let table_scoped_base_path = TableScopedPath {
403404 table : table_ref. cloned ( ) ,
404405 path : table_base_path. clone ( ) ,
405406 } ;
406407
407- // Try cache lookup with optional prefix filter
408- let vec = if let Some ( res) =
409- cache. get_with_extra ( & table_scoped_base_path, & prefix_filter)
410- {
408+ // Try cache lookup - get returns CachedFileList
409+ let vec = if let Some ( cached) = cache. get ( & table_scoped_base_path) {
411410 debug ! ( "Hit list files cache" ) ;
412- res . as_ref ( ) . clone ( )
411+ cached . files_matching_prefix ( & filter_prefix )
413412 } else {
414413 // Cache miss - always list and cache the full table
415414 // This ensures we have complete data for future prefix queries
416415 let vec = store
417416 . list ( Some ( table_base_path) )
418417 . try_collect :: < Vec < ObjectMeta > > ( )
419418 . await ?;
420- cache. put ( & table_scoped_base_path, Arc :: new ( vec. clone ( ) ) ) ;
421-
422- // If a prefix filter was requested, apply it to the results
423- if prefix. is_some ( ) {
424- let full_prefix_str = full_prefix. as_ref ( ) ;
425- vec. into_iter ( )
426- . filter ( |meta| {
427- meta. location . as_ref ( ) . starts_with ( full_prefix_str)
428- } )
429- . collect ( )
430- } else {
431- vec
432- }
419+ let cached: CachedFileList = vec. into ( ) ;
420+ let result = cached. files_matching_prefix ( & filter_prefix) ;
421+ cache. put ( & table_scoped_base_path, cached) ;
422+ result
433423 } ;
434- Ok ( futures:: stream:: iter ( vec. into_iter ( ) . map ( Ok ) ) . boxed ( ) )
424+ Ok (
425+ futures:: stream:: iter ( Arc :: unwrap_or_clone ( vec) . into_iter ( ) . map ( Ok ) )
426+ . boxed ( ) ,
427+ )
435428 }
436429 }
437430}
@@ -531,6 +524,7 @@ mod tests {
531524 use std:: any:: Any ;
532525 use std:: collections:: HashMap ;
533526 use std:: ops:: Range ;
527+ use std:: sync:: Arc ;
534528 use tempfile:: tempdir;
535529
536530 #[ test]
0 commit comments