-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Improve parquet MetadataFetch and AsyncFileReader docs
#6505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
c8f648b
f42d386
8d159e6
c3d1463
430c1c4
096ee1c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,8 +28,44 @@ use std::future::Future; | |
| use std::ops::Range; | ||
|
|
||
| /// A data source that can be used with [`MetadataLoader`] to load [`ParquetMetaData`] | ||
| /// | ||
| /// Note that implementation is are provided for [`AsyncFileReader`]. | ||
| /// | ||
| /// # Example `MetadataFetch` for a custom async data source | ||
| /// | ||
| /// ```rust | ||
| /// # use parquet::errors::Result; | ||
| /// # use parquet::arrow::async_reader::MetadataFetch; | ||
| /// # use bytes::Bytes; | ||
| /// # use std::ops::Range; | ||
| /// # use std::io::SeekFrom; | ||
| /// # use futures::future::BoxFuture; | ||
| /// # use futures::FutureExt; | ||
| /// # use tokio::io::{AsyncReadExt, AsyncSeekExt}; | ||
| /// // 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.end - range.start]; // target buffer | ||
alamb marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// // 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 | ||
| /// } | ||
| /// } | ||
| ///``` | ||
| pub trait MetadataFetch { | ||
| /// Fetches a range of bytes asynchronously | ||
| /// Return a future that fetches the specified range of bytes asynchronously | ||
| /// | ||
| /// Note the returned type is a boxed future, often created by | ||
| /// [FutureExt::boxed]. See the trait documentation for an example | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are not familiar with rust futures
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rust-lang/futures-rs#2887 -- we'll see what the maintainers say |
||
| fn fetch(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>>; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.