jecsand838 commented on code in PR #8930:
URL: https://github.com/apache/arrow-rs/pull/8930#discussion_r2604243062
##########
arrow-avro/src/reader/async_reader/object_store_reader.rs:
##########
@@ -0,0 +1,52 @@
+use crate::reader::async_reader::{AsyncFileReader, DataFetchFutureBoxed};
+use arrow_schema::ArrowError;
+use std::ops::Range;
+use std::sync::Arc;
+
+/// An implementation of an AsyncFileReader using the
[`object_store::ObjectStore`] API.
+pub struct ObjectStoreFileReader {
+ store: Arc<dyn object_store::ObjectStore>,
+ location: object_store::path::Path,
+}
+
+impl ObjectStoreFileReader {
+ /// Creates a new [`Self`] from a store implementation and file location.
+ pub fn new(
+ store: Arc<dyn object_store::ObjectStore>,
+ location: object_store::path::Path,
+ ) -> Self {
+ Self { store, location }
+ }
+}
Review Comment:
Another thing that occurred to me is we could support different runtimes for
reading from `ObjectStore` and Avro decoding by following the pattern below
from the `ParquetObjectReader`.
```rust
/// Perform IO on the provided tokio runtime
///
/// Tokio is a cooperative scheduler, and relies on tasks yielding in a
timely manner
/// to service IO. Therefore, running IO and CPU-bound tasks, such as
parquet decoding,
/// on the same tokio runtime can lead to degraded throughput, dropped
connections and
/// other issues. For more information see [here].
///
/// [here]:
https://www.influxdata.com/blog/using-rustlangs-async-tokio-runtime-for-cpu-bound-tasks/
pub fn with_runtime(self, handle: Handle) -> Self {
Self {
runtime: Some(handle),
..self
}
}
fn spawn<F, O, E>(&self, f: F) -> BoxFuture<'_, Result<O>>
where
F: for<'a> FnOnce(&'a Arc<dyn ObjectStore>, &'a Path) ->
BoxFuture<'a, Result<O, E>>
+ Send
+ 'static,
O: Send + 'static,
E: Into<ParquetError> + Send + 'static,
{
match &self.runtime {
Some(handle) => {
let path = self.path.clone();
let store = Arc::clone(&self.store);
handle
.spawn(async move { f(&store, &path).await })
.map_ok_or_else(
|e| match e.try_into_panic() {
Err(e) =>
Err(ParquetError::External(Box::new(e))),
Ok(p) => std::panic::resume_unwind(p),
},
|res| res.map_err(|e| e.into()),
)
.boxed()
}
None => f(&self.store, &self.path).map_err(|e| e.into()).boxed(),
}
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]