Skip to content

Commit

Permalink
Remove 'unwrap' from Result (#5241)
Browse files Browse the repository at this point in the history
* Remove 'unwrap' from Result

* Cargo fmt

---------

Co-authored-by: Ze'ev Maor <[email protected]>
  • Loading branch information
zeevm and Ze'ev Maor authored Dec 25, 2023
1 parent 3b3bd60 commit 0eb8a08
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions parquet/src/record/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,7 @@ impl TreeBuilder {
row_group_reader: &dyn RowGroupReader,
) -> Result<ReaderIter> {
let num_records = row_group_reader.metadata().num_rows() as usize;
Ok(ReaderIter::new(
self.build(descr, row_group_reader)?,
num_records,
))
ReaderIter::new(self.build(descr, row_group_reader)?, num_records)
}

/// Builds tree of readers for the current schema recursively.
Expand Down Expand Up @@ -411,7 +408,7 @@ impl Reader {
if reader.current_def_level() > def_level {
reader.read_field()?
} else {
reader.advance_columns();
reader.advance_columns()?;
Field::Null
}
}
Expand All @@ -423,7 +420,7 @@ impl Reader {
{
fields.push((String::from(reader.field_name()), reader.read_field()?));
} else {
reader.advance_columns();
reader.advance_columns()?;
fields.push((String::from(reader.field_name()), Field::Null));
}
}
Expand All @@ -436,7 +433,7 @@ impl Reader {
if reader.current_def_level() > def_level {
elements.push(reader.read_field()?);
} else {
reader.advance_columns();
reader.advance_columns()?;
// If the current definition level is equal to the definition
// level of this repeated type, then the
// result is an empty list and the repetition level
Expand All @@ -459,8 +456,8 @@ impl Reader {
if keys.current_def_level() > def_level {
pairs.push((keys.read_field()?, values.read_field()?));
} else {
keys.advance_columns();
values.advance_columns();
keys.advance_columns()?;
values.advance_columns()?;
// If the current definition level is equal to the definition
// level of this repeated type, then the
// result is an empty list and the repetition level
Expand Down Expand Up @@ -553,25 +550,20 @@ impl Reader {
}

/// Advances leaf columns for the current reader.
fn advance_columns(&mut self) {
fn advance_columns(&mut self) -> Result<()> {
match *self {
Reader::PrimitiveReader(_, ref mut column) => {
column.read_next().unwrap();
}
Reader::OptionReader(_, ref mut reader) => {
reader.advance_columns();
}
Reader::PrimitiveReader(_, ref mut column) => column.read_next().map(|_| ()),
Reader::OptionReader(_, ref mut reader) => reader.advance_columns(),
Reader::GroupReader(_, _, ref mut readers) => {
for reader in readers {
reader.advance_columns();
reader.advance_columns()?;
}
Ok(())
}
Reader::RepeatedReader(_, _, _, ref mut reader) => {
reader.advance_columns();
}
Reader::RepeatedReader(_, _, _, ref mut reader) => reader.advance_columns(),
Reader::KeyValueReader(_, _, _, ref mut keys, ref mut values) => {
keys.advance_columns();
values.advance_columns();
keys.advance_columns()?;
values.advance_columns()
}
}
}
Expand Down Expand Up @@ -784,13 +776,13 @@ pub struct ReaderIter {
}

impl ReaderIter {
fn new(mut root_reader: Reader, num_records: usize) -> Self {
fn new(mut root_reader: Reader, num_records: usize) -> Result<Self> {
// Prepare root reader by advancing all column vectors
root_reader.advance_columns();
Self {
root_reader.advance_columns()?;
Ok(Self {
root_reader,
records_left: num_records,
}
})
}
}

Expand Down

0 comments on commit 0eb8a08

Please sign in to comment.