@@ -19,31 +19,41 @@ use std::collections::HashMap;
1919use std:: sync:: { Arc , RwLock } ;
2020
2121use super :: datasource2:: DataSource2 ;
22+ use crate :: parquet:: file:: reader:: ChunkReader ;
23+ use crate :: error:: { DataFusionError , Result } ;
24+ use std:: any:: Any ;
25+ use std:: fs:: File ;
2226
23- pub trait ProtocolHander < R : ChunkReader + ' static > : Sync + Send {
27+ pub trait ProtocolHandler : Sync + Send {
2428 /// Returns the protocol handler as [`Any`](std::any::Any)
2529 /// so that it can be downcast to a specific implementation.
2630 fn as_any ( & self ) -> & dyn Any ;
2731
28- fn source ( & self ,
29-
30- ) -> Result < Arc < dyn DataSource2 > > ;
32+ fn list_all_files ( & self , root_path : & str , ext : & str ) -> Result < Vec < String > > ;
3133
32- fn list_all_files ( & self , root_path : & str ) -> Result < Vec < String > > ;
33-
34- fn get_reader ( & self , file_path : & str ) -> Result < R > ;
34+ fn get_reader ( & self , file_path : & str ) -> Result < dyn ChunkReader > ;
3535}
3636
37- struct LocalFSHander {
38-
39- }
37+ pub struct LocalFSHandler ;
4038
4139impl ProtocolHander for LocalFSHander {
40+ fn as_any ( & self ) -> & dyn Any {
41+ return self ;
42+ }
4243
44+ fn list_all_files ( & self , root_path : & str , ext : & str ) -> Result < Vec < String > > {
45+ let mut filenames: Vec < String > = Vec :: new ( ) ;
46+ crate :: datasource:: local:: list_all_files ( root_path, & mut filenames, ext) ;
47+ Ok ( filenames)
48+ }
49+
50+ fn get_reader ( & self , file_path : & str ) -> Result < R > {
51+ Ok ( File :: open ( file_path) ?)
52+ }
4353}
4454
4555pub struct ProtocolRegistry {
46- pub protocol_handlers : RwLock < HashMap < String , Arc < dyn ProtocolHander > > > ,
56+ pub protocol_handlers : RwLock < HashMap < String , Arc < dyn ProtocolHandler > > > ,
4757}
4858
4959impl ProtocolRegistry {
@@ -60,12 +70,12 @@ impl ProtocolRegistry {
6070 prefix : & str ,
6171 handler : Arc < dyn ProtocolHander > ,
6272 ) -> Option < Arc < dyn ProtocolHander > > {
63- let mut handler = self . protocol_handlers . write ( ) . unwrap ( ) ;
64- handler . insert ( prefix. to_string ( ) , handler)
73+ let mut handlers = self . protocol_handlers . write ( ) . unwrap ( ) ;
74+ handlers . insert ( prefix. to_string ( ) , handler)
6575 }
6676
6777 pub fn handler ( & self , prefix : & str ) -> Option < Arc < dyn ProtocolHander > > {
68- let handler = self . protocol_handlers . read ( ) . unwrap ( ) ;
69- handler . get ( prefix) . cloned ( )
78+ let handlers = self . protocol_handlers . read ( ) . unwrap ( ) ;
79+ handlers . get ( prefix) . cloned ( )
7080 }
7181}
0 commit comments