Current state --> next state + output This function is called to get the next RecordBatch This structure is used to reduce the indentation level of the main loop in try_build
(self)
| 655 | /// This structure is used to reduce the indentation level of the main loop |
| 656 | /// in try_build |
| 657 | fn try_next_batch(self) -> Result<(Self, DecodeResult<RecordBatch>), ParquetError> { |
| 658 | let mut current_state = self; |
| 659 | loop { |
| 660 | let (new_state, decode_result) = current_state.transition()?; |
| 661 | // if more data is needed to transition, can't proceed further without it |
| 662 | match decode_result { |
| 663 | DecodeResult::NeedsData(ranges) => { |
| 664 | return Ok((new_state, DecodeResult::NeedsData(ranges))); |
| 665 | } |
| 666 | // act next based on state |
| 667 | DecodeResult::Data(()) | DecodeResult::Finished => {} |
| 668 | } |
| 669 | match new_state { |
| 670 | // not ready to read yet, continue transitioning |
| 671 | Self::ReadingRowGroup { .. } => current_state = new_state, |
| 672 | // have a reader ready, so decode the next batch |
| 673 | Self::DecodingRowGroup { |
| 674 | mut record_batch_reader, |
| 675 | remaining_row_groups, |
| 676 | } => { |
| 677 | match record_batch_reader.next() { |
| 678 | // Successfully decoded a batch, return it |
| 679 | Some(Ok(batch)) => { |
| 680 | let result = DecodeResult::Data(batch); |
| 681 | let next_state = Self::DecodingRowGroup { |
| 682 | record_batch_reader, |
| 683 | remaining_row_groups, |
| 684 | }; |
| 685 | return Ok((next_state, result)); |
| 686 | } |
| 687 | // No more batches in this row group, move to the next row group |
| 688 | None => { |
| 689 | current_state = Self::ReadingRowGroup { |
| 690 | remaining_row_groups, |
| 691 | } |
| 692 | } |
| 693 | // some error occurred while decoding, so return that |
| 694 | Some(Err(e)) => { |
| 695 | // TODO: preserve ArrowError in ParquetError (rather than convert to a string) |
| 696 | return Err(ParquetError::ArrowError(e.to_string())); |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | Self::Finished => { |
| 701 | return Ok((Self::Finished, DecodeResult::Finished)); |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | /// Transition to the next state with a reader (data can be produced), if not end of stream |
| 708 | /// |
no test coverage detected