-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Stream results from native executor into python (#2667)
Enables streaming into python for native executor. How it works: - Spawn the execution tokio runtime in a separate std::thread. - Instead of collecting results into a buffer, send them over a channel. - On the main thread, wraps the channel in an iterator that receives the results via a `.blocking_recv` in the iterator's `.next` method. Drive bys: - Enable configurable morsel sizes in execution config. - Buffering for each operator is now done prior to sending off the morsels to the parallel workers. - Buffering now supports slicing in addition to chunking. - Fixed a bug in `Micropartition::slice` where the `remaining_rows` counter was incremented instead of decremented. Simulate streaming: ``` daft.context.set_execution_config(enable_native_executor=True, default_morsel_size=1) @daft.udf(return_dtype=daft.DataType.int32()) def add_1(a): # simulate work time.sleep(0.5) return [x + 1 for x in a.to_pylist()] df = daft.from_pydict({"a": [i for i in range(100)]}).with_column("b", add_1(col("a"))) for r in df: print(r) ``` --------- Co-authored-by: Colin Ho <[email protected]> Co-authored-by: Colin Ho <[email protected]>
- Loading branch information
1 parent
7e9208e
commit ab6d1a5
Showing
17 changed files
with
259 additions
and
135 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use std::{collections::VecDeque, sync::Arc}; | ||
|
||
use common_error::DaftResult; | ||
use daft_micropartition::MicroPartition; | ||
use std::cmp::Ordering::*; | ||
|
||
pub struct OperatorBuffer { | ||
pub buffer: VecDeque<Arc<MicroPartition>>, | ||
pub curr_len: usize, | ||
pub threshold: usize, | ||
} | ||
|
||
impl OperatorBuffer { | ||
pub fn new(threshold: usize) -> Self { | ||
assert!(threshold > 0); | ||
Self { | ||
buffer: VecDeque::new(), | ||
curr_len: 0, | ||
threshold, | ||
} | ||
} | ||
|
||
pub fn push(&mut self, part: Arc<MicroPartition>) { | ||
self.curr_len += part.len(); | ||
self.buffer.push_back(part); | ||
} | ||
|
||
pub fn try_clear(&mut self) -> Option<DaftResult<Arc<MicroPartition>>> { | ||
match self.curr_len.cmp(&self.threshold) { | ||
Less => None, | ||
Equal => self.clear_all(), | ||
Greater => Some(self.clear_enough()), | ||
} | ||
} | ||
|
||
fn clear_enough(&mut self) -> DaftResult<Arc<MicroPartition>> { | ||
assert!(self.curr_len > self.threshold); | ||
|
||
let mut to_concat = Vec::with_capacity(self.buffer.len()); | ||
let mut remaining = self.threshold; | ||
|
||
while remaining > 0 { | ||
let part = self.buffer.pop_front().expect("Buffer should not be empty"); | ||
let part_len = part.len(); | ||
if part_len <= remaining { | ||
remaining -= part_len; | ||
to_concat.push(part); | ||
} else { | ||
let (head, tail) = part.split_at(remaining)?; | ||
remaining = 0; | ||
to_concat.push(Arc::new(head)); | ||
self.buffer.push_front(Arc::new(tail)); | ||
break; | ||
} | ||
} | ||
assert_eq!(remaining, 0); | ||
|
||
self.curr_len -= self.threshold; | ||
match to_concat.len() { | ||
1 => Ok(to_concat.pop().unwrap()), | ||
_ => MicroPartition::concat(&to_concat.iter().map(|x| x.as_ref()).collect::<Vec<_>>()) | ||
.map(Arc::new), | ||
} | ||
} | ||
|
||
pub fn clear_all(&mut self) -> Option<DaftResult<Arc<MicroPartition>>> { | ||
if self.buffer.is_empty() { | ||
return None; | ||
} | ||
|
||
let concated = | ||
MicroPartition::concat(&self.buffer.iter().map(|x| x.as_ref()).collect::<Vec<_>>()) | ||
.map(Arc::new); | ||
self.buffer.clear(); | ||
self.curr_len = 0; | ||
Some(concated) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod aggregate; | ||
pub mod buffer; | ||
pub mod filter; | ||
pub mod intermediate_op; | ||
pub mod project; | ||
pub mod state; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.