If possible, redistribute batches across partitions according to their size. Returns `Ok(None)` if unable to repartition. Preserve output ordering if exists. Refer to [`DataSource::repartitioned`] for further details.
(
&self,
target_partitions: usize,
_repartition_file_min_size: usize,
output_ordering: Option<LexOrdering>,
)
| 148 | /// Returns `Ok(None)` if unable to repartition. Preserve output ordering if exists. |
| 149 | /// Refer to [`DataSource::repartitioned`] for further details. |
| 150 | fn repartitioned( |
| 151 | &self, |
| 152 | target_partitions: usize, |
| 153 | _repartition_file_min_size: usize, |
| 154 | output_ordering: Option<LexOrdering>, |
| 155 | ) -> Result<Option<Arc<dyn DataSource>>> { |
| 156 | if self.partitions.is_empty() || self.partitions.len() >= target_partitions |
| 157 | // if have no partitions, or already have more partitions than desired, do not repartition |
| 158 | { |
| 159 | return Ok(None); |
| 160 | } |
| 161 | |
| 162 | let maybe_repartitioned = if let Some(output_ordering) = output_ordering { |
| 163 | self.repartition_preserving_order(target_partitions, output_ordering)? |
| 164 | } else { |
| 165 | self.repartition_evenly_by_size(target_partitions)? |
| 166 | }; |
| 167 | |
| 168 | if let Some(repartitioned) = maybe_repartitioned { |
| 169 | Ok(Some(Arc::new(Self::try_new( |
| 170 | &repartitioned, |
| 171 | self.original_schema(), |
| 172 | self.projection.clone(), |
| 173 | )?))) |
| 174 | } else { |
| 175 | Ok(None) |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | fn output_partitioning(&self) -> Partitioning { |
| 180 | Partitioning::UnknownPartitioning(self.partitions.len()) |