Split [`RePartition`] into 2 pieces, consuming self. Returns only 1 partition if cannot be split further.
(self)
| 625 | /// |
| 626 | /// Returns only 1 partition if cannot be split further. |
| 627 | fn split(self) -> Vec<Self> { |
| 628 | if self.batches.len() == 1 { |
| 629 | return vec![self]; |
| 630 | } |
| 631 | |
| 632 | let new_0 = RePartition { |
| 633 | idx: self.idx, // output ordering |
| 634 | row_count: 0, |
| 635 | batches: vec![], |
| 636 | }; |
| 637 | let new_1 = RePartition { |
| 638 | idx: self.idx + 1, // output ordering +1 |
| 639 | row_count: 0, |
| 640 | batches: vec![], |
| 641 | }; |
| 642 | let split_pt = self.row_count / 2; |
| 643 | |
| 644 | let [new_0, new_1] = self.batches.into_iter().fold( |
| 645 | [new_0, new_1], |
| 646 | |[mut new0, mut new1], batch| { |
| 647 | if new0.row_count < split_pt { |
| 648 | new0.add_batch(batch); |
| 649 | } else { |
| 650 | new1.add_batch(batch); |
| 651 | } |
| 652 | [new0, new1] |
| 653 | }, |
| 654 | ); |
| 655 | vec![new_0, new_1] |
| 656 | } |
| 657 | |
| 658 | fn add_batch(&mut self, batch: RecordBatch) { |
| 659 | self.row_count += batch.num_rows(); |
no test coverage detected