You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/05/15 13:27:07 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4216: Prefetch page index (#4090)

tustvold commented on code in PR #4216:
URL: https://github.com/apache/arrow-rs/pull/4216#discussion_r1193836421


##########
parquet/src/arrow/async_reader/metadata.rs:
##########
@@ -15,95 +15,252 @@
 // specific language governing permissions and limitations
 // under the License.
 
+use crate::arrow::async_reader::AsyncFileReader;
 use crate::errors::{ParquetError, Result};
-use crate::file::footer::{decode_footer, decode_metadata};
+use crate::file::footer::{decode_footer, read_metadata};
 use crate::file::metadata::ParquetMetaData;
-use bytes::{BufMut, Bytes, BytesMut};
+use crate::file::page_index::index::Index;
+use crate::file::page_index::index_reader::{
+    acc_range, decode_column_index, decode_offset_index,
+};
+use bytes::Bytes;
+use futures::future::BoxFuture;
+use futures::FutureExt;
 use std::future::Future;
+use std::io::Read;
 use std::ops::Range;
 
-/// Fetches parquet metadata
-///
-/// Parameters:
-/// * fetch: an async function that can fetch byte ranges
-/// * file_size: the total size of the parquet file
-/// * footer_size_hint: footer prefetch size (see comments below)
-///
-/// The length of the parquet footer, which contains file metadata, is not
-/// known up front. Therefore this function will first issue a request to read
-/// the last 8 bytes to determine the footer's precise length, before
-/// issuing a second request to fetch the metadata bytes
-///
-/// If a hint is set, this method will read the specified number of bytes
-/// in the first request, instead of 8, and only issue a second request
-/// if additional bytes are needed. This can therefore eliminate a
-/// potentially costly additional fetch operation
-pub async fn fetch_parquet_metadata<F, Fut>(
-    mut fetch: F,
-    file_size: usize,
-    footer_size_hint: Option<usize>,
-) -> Result<ParquetMetaData>
-where
-    F: FnMut(Range<usize>) -> Fut,
-    Fut: Future<Output = Result<Bytes>>,
-{
-    if file_size < 8 {
-        return Err(ParquetError::EOF(format!(
-            "file size of {file_size} is less than footer"
-        )));
+/// A data source that can be used with [`MetadataLoader`] to load [`ParquetMetaData`]
+pub(crate) trait MetadataFetch {
+    fn fetch(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>>;
+}
+
+impl<'a, T: AsyncFileReader> MetadataFetch for &'a mut T {
+    fn fetch(&mut self, range: Range<usize>) -> BoxFuture<'_, Result<Bytes>> {
+        self.get_bytes(range)
     }
+}
+
+/// An asynchronous interface to load [`ParquetMetaData`] from an async source
+pub(crate) struct MetadataLoader<F> {

Review Comment:
   I opted to keep this crate private for now as I'm not totally happy with the interface



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org