pub trait MetadataFetch {
// Required method
fn fetch(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>>;
}
Expand description
A data source that can be used with MetadataLoader
to load ParquetMetaData
Note that implementation is provided for AsyncFileReader
.
§Example MetadataFetch
for a custom async data source
// Adapter that implements the API for reading bytes from an async source (in
// this case a tokio::fs::File)
struct TokioFileMetadata {
file: tokio::fs::File,
}
impl MetadataFetch for TokioFileMetadata {
fn fetch(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> {
// return a future that fetches data in range
async move {
let mut buf = vec![0; range.len()]; // target buffer
// seek to the start of the range and read the data
self.file.seek(SeekFrom::Start(range.start as u64)).await?;
self.file.read_exact(&mut buf).await?;
Ok(Bytes::from(buf)) // convert to Bytes
}
.boxed() // turn into BoxedFuture, using FutureExt::boxed
}
}