Skip to content

Commit

Permalink
Make RowIter own rather than borrow FileReader
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmocatta committed Feb 7, 2019
1 parent c66aa7e commit 94288a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
32 changes: 22 additions & 10 deletions rust/parquet/src/file/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(&self, projection: Option<Predicate>) -> Result<RowIter<Self, T>>
fn get_row_iter<T>(self, projection: Option<Predicate>) -> Result<RowIter<Self, T>>
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 {
<R as FileReader>::metadata(*self)
}
fn num_row_groups(&self) -> usize {
<R as FileReader>::num_row_groups(*self)
}
fn get_row_group(&self, i: usize) -> Result<Self::RowGroupReader> {
<R as FileReader>::get_row_group(*self, i)
}
}

/// Parquet row group reader API. With this, user can get metadata information about the
Expand Down Expand Up @@ -289,14 +309,6 @@ impl<R: 'static + ParquetReader> FileReader for SerializedFileReader<R> {
let f = self.buf.get_ref().try_clone()?;
Ok(SerializedRowGroupReader::new(f, row_group_metadata))
}

fn get_row_iter<T>(&self, projection: Option<Predicate>) -> Result<RowIter<Self, T>>
where
T: Record,
Self: Sized,
{
RowIter::from_file(projection, self)
}
}

impl TryFrom<File> for SerializedFileReader<File> {
Expand Down
12 changes: 6 additions & 6 deletions rust/parquet/src/record/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<R, T>
where
R: FileReader,
T: Record,
{
schema: <Root<T> as Record>::Schema,
file_reader: Option<&'a R>,
file_reader: Option<R>,
current_row_group: usize,
num_row_groups: usize,
row_iter: Option<ReaderIter<T>>,
}

impl<'a, R, T> RowIter<'a, R, T>
impl<R, T> RowIter<R, T>
where
R: FileReader,
T: Record,
{
/// Creates row iterator for all row groups in a file.
pub fn from_file(_proj: Option<Predicate>, reader: &'a R) -> Result<Self> {
pub fn from_file(_proj: Option<Predicate>, reader: R) -> Result<Self> {
let num_row_groups = reader.num_row_groups();

let file_schema = reader.metadata().file_metadata().schema_descr_ptr();
Expand All @@ -1077,7 +1077,7 @@ where
/// Creates row iterator for a specific row group.
pub fn from_row_group(
_proj: Option<Predicate>,
row_group_reader: &'a RowGroupReader,
row_group_reader: &RowGroupReader,
) -> Result<Self> {
let file_schema = row_group_reader.metadata().schema_descr_ptr();
let file_schema = file_schema.root_schema();
Expand Down Expand Up @@ -1123,7 +1123,7 @@ where
}
}

impl<'a, R, T> Iterator for RowIter<'a, R, T>
impl<R, T> Iterator for RowIter<R, T>
where
R: FileReader,
T: Record,
Expand Down

0 comments on commit 94288a7

Please sign in to comment.