diff --git a/src/io/parquet/read/file.rs b/src/io/parquet/read/file.rs index effb5c1c948..f854f5c90f9 100644 --- a/src/io/parquet/read/file.rs +++ b/src/io/parquet/read/file.rs @@ -115,12 +115,15 @@ impl FileReader { fn next_row_group(&mut self) -> Result> { let result = self.row_groups.next().transpose()?; - self.remaining_rows = self.remaining_rows.saturating_sub( - result - .as_ref() - .map(|x| x.num_rows()) - .unwrap_or(self.remaining_rows), - ); + // If current_row_group is None, then there will be no elements to remove. + if self.current_row_group.is_some() { + self.remaining_rows = self.remaining_rows.saturating_sub( + result + .as_ref() + .map(|x| x.num_rows()) + .unwrap_or(self.remaining_rows), + ); + } Ok(result) } } diff --git a/src/io/parquet/read/row_group.rs b/src/io/parquet/read/row_group.rs index b53e60f271f..fea9638e5e2 100644 --- a/src/io/parquet/read/row_group.rs +++ b/src/io/parquet/read/row_group.rs @@ -78,10 +78,12 @@ impl Iterator for RowGroupDeserializer { }) .collect::>>() .map(Chunk::new); - self.remaining_rows -= chunk - .as_ref() - .map(|x| x.len()) - .unwrap_or(self.remaining_rows); + self.remaining_rows = self.remaining_rows.saturating_sub( + chunk + .as_ref() + .map(|x| x.len()) + .unwrap_or(self.remaining_rows), + ); Some(chunk) }