-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rust): Use ObjectStore instead of AsyncRead in parquet get m…
…etadata (#15069)
- Loading branch information
1 parent
ec04150
commit 4933040
Showing
13 changed files
with
222 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,24 @@ | ||
//! Interface with cloud storage through the object_store crate. | ||
|
||
#[cfg(feature = "cloud")] | ||
use std::borrow::Cow; | ||
mod adaptors; | ||
#[cfg(feature = "cloud")] | ||
use std::sync::Arc; | ||
pub use adaptors::*; | ||
|
||
#[cfg(feature = "cloud")] | ||
use object_store::local::LocalFileSystem; | ||
mod polars_object_store; | ||
#[cfg(feature = "cloud")] | ||
use object_store::ObjectStore; | ||
#[cfg(feature = "cloud")] | ||
use polars_core::prelude::{polars_bail, PolarsError, PolarsResult}; | ||
pub use polars_object_store::*; | ||
|
||
#[cfg(feature = "cloud")] | ||
mod adaptors; | ||
#[cfg(feature = "cloud")] | ||
mod glob; | ||
#[cfg(feature = "cloud")] | ||
mod object_store_setup; | ||
pub mod options; | ||
pub use glob::*; | ||
|
||
#[cfg(feature = "cloud")] | ||
pub use adaptors::*; | ||
#[cfg(feature = "cloud")] | ||
pub use glob::*; | ||
mod object_store_setup; | ||
#[cfg(feature = "cloud")] | ||
pub use object_store_setup::*; | ||
|
||
pub mod options; | ||
pub use options::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::ops::Range; | ||
use std::sync::Arc; | ||
|
||
use bytes::Bytes; | ||
use object_store::path::Path; | ||
use object_store::{ObjectMeta, ObjectStore}; | ||
use polars_error::{to_compute_err, PolarsResult}; | ||
|
||
use crate::pl_async::{ | ||
tune_with_concurrency_budget, with_concurrency_budget, MAX_BUDGET_PER_REQUEST, | ||
}; | ||
|
||
/// Polars specific wrapper for `Arc<dyn ObjectStore>` that limits the number of | ||
/// concurrent requests for the entire application. | ||
#[derive(Debug, Clone)] | ||
pub struct PolarsObjectStore(Arc<dyn ObjectStore>); | ||
|
||
impl PolarsObjectStore { | ||
pub fn new(store: Arc<dyn ObjectStore>) -> Self { | ||
Self(store) | ||
} | ||
|
||
pub async fn get(&self, path: &Path) -> PolarsResult<Bytes> { | ||
tune_with_concurrency_budget(1, || async { | ||
self.0 | ||
.get(path) | ||
.await | ||
.map_err(to_compute_err)? | ||
.bytes() | ||
.await | ||
.map_err(to_compute_err) | ||
}) | ||
.await | ||
} | ||
|
||
pub async fn get_range(&self, path: &Path, range: Range<usize>) -> PolarsResult<Bytes> { | ||
tune_with_concurrency_budget(1, || self.0.get_range(path, range)) | ||
.await | ||
.map_err(to_compute_err) | ||
} | ||
|
||
pub async fn get_ranges( | ||
&self, | ||
path: &Path, | ||
ranges: &[Range<usize>], | ||
) -> PolarsResult<Vec<Bytes>> { | ||
tune_with_concurrency_budget( | ||
(ranges.len() as u32).clamp(0, MAX_BUDGET_PER_REQUEST as u32), | ||
|| self.0.get_ranges(path, ranges), | ||
) | ||
.await | ||
.map_err(to_compute_err) | ||
} | ||
|
||
/// Fetch the metadata of the parquet file, do not memoize it. | ||
pub async fn head(&self, path: &Path) -> PolarsResult<ObjectMeta> { | ||
with_concurrency_budget(1, || self.0.head(path)) | ||
.await | ||
.map_err(to_compute_err) | ||
} | ||
} |
Oops, something went wrong.