diff --git a/rust/parquet/src/file/reader.rs b/rust/parquet/src/file/reader.rs index 11daa55aa9673..e8d45c464ea44 100644 --- a/rust/parquet/src/file/reader.rs +++ b/rust/parquet/src/file/reader.rs @@ -71,10 +71,30 @@ pub trait FileReader { /// /// Projected schema can be a subset of or equal to the file schema, when it is None, /// full file schema is assumed. - fn get_row_iter(&self, projection: Option) -> Result> + fn get_row_iter(self, projection: Option) -> Result> where T: Record, - Self: Sized; + Self: Sized, + { + RowIter::from_file(projection, self) + } +} + +impl<'a, R> FileReader for &'a R +where + R: FileReader, +{ + type RowGroupReader = R::RowGroupReader; + + fn metadata(&self) -> ParquetMetaDataPtr { + ::metadata(*self) + } + fn num_row_groups(&self) -> usize { + ::num_row_groups(*self) + } + fn get_row_group(&self, i: usize) -> Result { + ::get_row_group(*self, i) + } } /// Parquet row group reader API. With this, user can get metadata information about the @@ -289,14 +309,6 @@ impl FileReader for SerializedFileReader { let f = self.buf.get_ref().try_clone()?; Ok(SerializedRowGroupReader::new(f, row_group_metadata)) } - - fn get_row_iter(&self, projection: Option) -> Result> - where - T: Record, - Self: Sized, - { - RowIter::from_file(projection, self) - } } impl TryFrom for SerializedFileReader { diff --git a/rust/parquet/src/record/reader.rs b/rust/parquet/src/record/reader.rs index 49ecb5d0a1596..679c37bda1f57 100644 --- a/rust/parquet/src/record/reader.rs +++ b/rust/parquet/src/record/reader.rs @@ -1040,25 +1040,25 @@ where /// /// It is used either for a single row group to iterate over data in that row group, or /// an entire file with auto buffering of all row groups. -pub struct RowIter<'a, R, T> +pub struct RowIter where R: FileReader, T: Record, { schema: as Record>::Schema, - file_reader: Option<&'a R>, + file_reader: Option, current_row_group: usize, num_row_groups: usize, row_iter: Option>, } -impl<'a, R, T> RowIter<'a, R, T> +impl RowIter where R: FileReader, T: Record, { /// Creates row iterator for all row groups in a file. - pub fn from_file(_proj: Option, reader: &'a R) -> Result { + pub fn from_file(_proj: Option, reader: R) -> Result { let num_row_groups = reader.num_row_groups(); let file_schema = reader.metadata().file_metadata().schema_descr_ptr(); @@ -1077,7 +1077,7 @@ where /// Creates row iterator for a specific row group. pub fn from_row_group( _proj: Option, - row_group_reader: &'a RowGroupReader, + row_group_reader: &RowGroupReader, ) -> Result { let file_schema = row_group_reader.metadata().schema_descr_ptr(); let file_schema = file_schema.root_schema(); @@ -1123,7 +1123,7 @@ where } } -impl<'a, R, T> Iterator for RowIter<'a, R, T> +impl Iterator for RowIter where R: FileReader, T: Record,