use std::future;
use std::sync::Arc;
use vortex_array::ArrayRef;
use vortex_error::VortexResult;
use vortex_io::request::IoService;
use vortex_scan::planning::driver::Progress;
use vortex_scan::planning::driver::Run;
use vortex_scan::planning::planner::Planner;
use vortex_scan::planning::planner::WorkScope;
pub(super) struct SplitPlan {
pub(super) scope: WorkScope,
pub(super) root: Box<dyn Planner>,
}
impl SplitPlan {
pub(super) async fn run(self, io: Arc<dyn IoService>) -> VortexResult<Vec<ArrayRef>> {
let mut run = Run::new();
run.admit(self.root, self.scope, io.session());
let mut batches = Vec::new();
loop {
match run.advance()? {
Progress::Batch(batch) => batches.push(batch),
Progress::RootDone(_) | Progress::Idle => break,
Progress::Waiting => future::poll_fn(|cx| run.poll_completion(cx)).await?,
}
}
batches.sort_by_key(|batch| batch.scope.rows.start);
Ok(batches.into_iter().map(|batch| batch.array).collect())
}
}