Skip to content

Commit

Permalink
make lazy union parallel (#2221)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 29, 2021
1 parent 57074e5 commit 47f544d
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions polars/polars-lazy/src/physical_plan/executors/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ use crate::physical_plan::state::ExecutionState;
use crate::prelude::*;
use polars_core::prelude::*;
use polars_core::utils::concat_df;
use polars_core::POOL;
use rayon::prelude::*;

pub(crate) struct UnionExec {
pub(crate) inputs: Vec<Box<dyn Executor>>,
}

impl Executor for UnionExec {
fn execute(&mut self, state: &ExecutionState) -> Result<DataFrame> {
let dfs = self
.inputs
.iter_mut()
.map(|input| input.execute(state))
.collect::<Result<Vec<_>>>()?;
let inputs = std::mem::take(&mut self.inputs);

let dfs = POOL.install(|| {
inputs
.into_par_iter()
.map(|mut input| input.execute(state))
.collect::<Result<Vec<_>>>()
})?;

concat_df(&dfs)
}
}

0 comments on commit 47f544d

Please sign in to comment.