-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
parquet: Add support for user-provided metadata loaders #12593
Open
progval
wants to merge
3
commits into
apache:main
Choose a base branch
from
progval:cachable-metadata-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−23
Open
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ use bytes::Bytes; | |
use datafusion_physical_plan::metrics::ExecutionPlanMetricsSet; | ||
use futures::future::BoxFuture; | ||
use object_store::ObjectStore; | ||
use parquet::arrow::arrow_reader::{ArrowReaderMetadata, ArrowReaderOptions}; | ||
use parquet::arrow::async_reader::{AsyncFileReader, ParquetObjectReader}; | ||
use parquet::file::metadata::ParquetMetaData; | ||
use std::fmt::Debug; | ||
|
@@ -57,9 +58,49 @@ pub trait ParquetFileReaderFactory: Debug + Send + Sync + 'static { | |
file_meta: FileMeta, | ||
metadata_size_hint: Option<usize>, | ||
metrics: &ExecutionPlanMetricsSet, | ||
) -> datafusion_common::Result<Box<dyn AsyncFileReader + Send>>; | ||
) -> datafusion_common::Result<Box<dyn ParquetFileReader>>; | ||
} | ||
|
||
/// [`AsyncFileReader`] augmented with a method to customize how file metadata is loaded. | ||
pub trait ParquetFileReader: AsyncFileReader + Send + 'static { | ||
/// Returns a [`AsyncFileReader`] trait object | ||
/// | ||
/// This can usually be implemented as `Box::new(*self)` | ||
fn upcast(self: Box<Self>) -> Box<dyn AsyncFileReader + 'static>; | ||
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. This method is unfortunate, but I also could not figire out a way without it |
||
|
||
/// Parses the file's metadata | ||
/// | ||
/// The default implementation is: | ||
/// | ||
/// ```ignore | ||
/// Box::pin(ArrowReaderMetadata::load_async(self, options)) | ||
/// ``` | ||
fn load_metadata( | ||
&mut self, | ||
options: ArrowReaderOptions, | ||
) -> BoxFuture<'_, parquet::errors::Result<ArrowReaderMetadata>>; | ||
} | ||
|
||
macro_rules! impl_ParquetFileReader { | ||
($type:ty) => { | ||
impl ParquetFileReader for $type { | ||
fn upcast(self: Box<Self>) -> Box<dyn AsyncFileReader + 'static> { | ||
Box::new(*self) | ||
} | ||
|
||
fn load_metadata( | ||
&mut self, | ||
options: ArrowReaderOptions, | ||
) -> BoxFuture<'_, parquet::errors::Result<ArrowReaderMetadata>> { | ||
Box::pin(ArrowReaderMetadata::load_async(self, options)) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
impl_ParquetFileReader!(ParquetObjectReader); | ||
impl_ParquetFileReader!(DefaultParquetFileReader); | ||
|
||
/// Default implementation of [`ParquetFileReaderFactory`] | ||
/// | ||
/// This implementation: | ||
|
@@ -86,12 +127,12 @@ impl DefaultParquetFileReaderFactory { | |
/// This implementation does not coalesce I/O operations or cache bytes. Such | ||
/// optimizations can be done either at the object store level or by providing a | ||
/// custom implementation of [`ParquetFileReaderFactory`]. | ||
pub(crate) struct ParquetFileReader { | ||
pub(crate) struct DefaultParquetFileReader { | ||
pub file_metrics: ParquetFileMetrics, | ||
pub inner: ParquetObjectReader, | ||
} | ||
|
||
impl AsyncFileReader for ParquetFileReader { | ||
impl AsyncFileReader for DefaultParquetFileReader { | ||
fn get_bytes( | ||
&mut self, | ||
range: Range<usize>, | ||
|
@@ -126,7 +167,7 @@ impl ParquetFileReaderFactory for DefaultParquetFileReaderFactory { | |
file_meta: FileMeta, | ||
metadata_size_hint: Option<usize>, | ||
metrics: &ExecutionPlanMetricsSet, | ||
) -> datafusion_common::Result<Box<dyn AsyncFileReader + Send>> { | ||
) -> datafusion_common::Result<Box<dyn ParquetFileReader>> { | ||
let file_metrics = ParquetFileMetrics::new( | ||
partition_index, | ||
file_meta.location().as_ref(), | ||
|
@@ -139,7 +180,7 @@ impl ParquetFileReaderFactory for DefaultParquetFileReaderFactory { | |
inner = inner.with_footer_size_hint(hint) | ||
}; | ||
|
||
Ok(Box::new(ParquetFileReader { | ||
Ok(Box::new(DefaultParquetFileReader { | ||
inner, | ||
file_metrics, | ||
})) | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can use one of the (many!) already existing APIs /traits for loading the metadata. The number of layers of abstraction are already pretty mind boggling. Adding yet another one seems unweildy. Or maybe we could just change the code not to call the loader if it has metadata 🤔