@@ -27,21 +27,42 @@ use std::sync::{Arc, RwLock};
2727
2828use  async_trait:: async_trait; 
2929use  chrono:: { DateTime ,  Utc } ; 
30- use  futures:: { AsyncRead ,  Stream ,  StreamExt } ; 
30+ use  futures:: { Stream ,  StreamExt } ; 
31+ use  tokio:: io:: { AsyncBufRead ,  AsyncSeek } ; 
3132
3233use  local:: LocalFileSystem ; 
3334
3435use  crate :: error:: { DataFusionError ,  Result } ; 
3536
37+ /// Provides async access to read a file, combing [`AsyncSeek`] 
38+ /// and [`AsyncBufRead`] so they can be used as a trait object 
39+ /// 
40+ /// [`AsyncSeek`] is necessary because readers may need to seek around whilst 
41+ /// reading, either because the format itself is structured (e.g. parquet) 
42+ /// or because it needs to read metadata or infer schema as an initial step 
43+ /// 
44+ /// [`AsyncBufRead`] is necessary because readers may wish to read data 
45+ /// up until some delimiter (e.g. csv or newline-delimited JSON) 
46+ /// 
47+ /// Note: the same block of data may be read multiple times 
48+ /// 
49+ /// Implementations that fetch from object storage may wish to maintain an internal 
50+ /// buffer of fetched data blocks, potentially discarding them or spilling them to disk 
51+ /// based on memory pressure 
52+ /// 
53+ /// TODO(#1614): Remove Sync 
54+ pub  trait  ChunkReader :  AsyncBufRead  + AsyncSeek  + Send  + Sync  + Unpin  { } 
55+ impl < T :  AsyncBufRead  + AsyncSeek  + Send  + Sync  + Unpin >  ChunkReader  for  T  { } 
56+ 
3657/// Object Reader for one file in an object store. 
3758/// 
3859/// Note that the dynamic dispatch on the reader might 
3960/// have some performance impacts. 
4061#[ async_trait]  
4162pub  trait  ObjectReader :  Send  + Sync  { 
42-     /// Get reader for a part [start, start + length] in  the file asynchronously  
43- async   fn   chunk_reader ( & self ,   start :   u64 ,   length :   usize ) 
44-          -> Result < Box < dyn  AsyncRead > > ; 
63+     /// Get a [`ChunkReader`] for  the file, successive calls to this MUST  
64+ /// return readers with independent seek positions 
65+ async   fn   chunk_reader ( & self )   -> Result < Box < dyn  ChunkReader > > ; 
4566
4667    /// Get reader for a part [start, start + length] in the file 
4768fn  sync_chunk_reader ( 
0 commit comments