From 0eb8a08f8893870a6d7aafa63aef0e92593a7585 Mon Sep 17 00:00:00 2001 From: Ze'ev Maor Date: Mon, 25 Dec 2023 17:12:38 +0200 Subject: [PATCH] Remove 'unwrap' from Result (#5241) * Remove 'unwrap' from Result * Cargo fmt --------- Co-authored-by: Ze'ev Maor --- parquet/src/record/reader.rs | 44 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/parquet/src/record/reader.rs b/parquet/src/record/reader.rs index addaf7a1a455..c6bf8f1f93e6 100644 --- a/parquet/src/record/reader.rs +++ b/parquet/src/record/reader.rs @@ -99,10 +99,7 @@ impl TreeBuilder { row_group_reader: &dyn RowGroupReader, ) -> Result { 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. @@ -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 } } @@ -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)); } } @@ -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 @@ -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 @@ -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() } } } @@ -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 { // 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, - } + }) } }