-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Enable sample for swordfish (#3079)
Adds sample as an intermediate operator. Unskips all the sample tests (except one which depends on concat). Co-authored-by: Colin Ho <[email protected]>
- Loading branch information
Showing
7 changed files
with
106 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ pub mod filter; | |
pub mod hash_join_probe; | ||
pub mod intermediate_op; | ||
pub mod project; | ||
pub mod sample; |
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,47 @@ | ||
use std::sync::Arc; | ||
|
||
use common_error::DaftResult; | ||
use tracing::instrument; | ||
|
||
use super::intermediate_op::{ | ||
IntermediateOperator, IntermediateOperatorResult, IntermediateOperatorState, | ||
}; | ||
use crate::pipeline::PipelineResultType; | ||
|
||
pub struct SampleOperator { | ||
fraction: f64, | ||
with_replacement: bool, | ||
seed: Option<u64>, | ||
} | ||
|
||
impl SampleOperator { | ||
pub fn new(fraction: f64, with_replacement: bool, seed: Option<u64>) -> Self { | ||
Self { | ||
fraction, | ||
with_replacement, | ||
seed, | ||
} | ||
} | ||
} | ||
|
||
impl IntermediateOperator for SampleOperator { | ||
#[instrument(skip_all, name = "SampleOperator::execute")] | ||
fn execute( | ||
&self, | ||
_idx: usize, | ||
input: &PipelineResultType, | ||
_state: Option<&mut Box<dyn IntermediateOperatorState>>, | ||
) -> DaftResult<IntermediateOperatorResult> { | ||
let out = | ||
input | ||
.as_data() | ||
.sample_by_fraction(self.fraction, self.with_replacement, self.seed)?; | ||
Ok(IntermediateOperatorResult::NeedMoreInput(Some(Arc::new( | ||
out, | ||
)))) | ||
} | ||
|
||
fn name(&self) -> &'static str { | ||
"SampleOperator" | ||
} | ||
} |
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