Repository navigation
Support datafusion dynamic filters #10665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
robert3005
wants to merge
21
commits into
develop
Choose a base branch
from
rk/datafusion-dynamic-exprs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
58d5cc5
Prove comparisons true for every row from statistics
robert3005 c0d3daa
Push snapshotted dynamic filters into the Vortex DataFusion scan
claude dae7593
Skip dynamic filter bounds that file statistics prove always true
claude ee65614
Add dynamic expressions whose predicate can change during a scan
robert3005 6a4a41b
Push DataFusion dynamic filters into Vortex scans as dynamic expressions
robert3005 54f2d34
Skip optional filter conjuncts that keep most of their rows
robert3005 bc9720a
Mark DataFusion dynamic filters optional and evaluate implied bounds …
robert3005 440b8ff
Make the optional filter backoff fit split files and duplicate conjuncts
robert3005 d62e88f
Convert DataFusion dynamic filters once and push only selective bounds
robert3005 57908c1
Skip dynamic conjuncts without a value and filters that keep half the…
robert3005 61a311d
Estimate the selectivity of dynamic filters from file statistics
robert3005 d0c95ed
Do not prune the zones of optional conjuncts in scans of a few zones
robert3005 83378ee
Build the pushed conjunction of a complete dynamic filter once per file
robert3005 293c4c7
Order filter conjuncts by their cost and selectivity
robert3005 000757f
Convert dynamic filters without blocking concurrent openers
robert3005 53eb3f2
Evaluate dynamic filter conjuncts Vortex cannot express with DataFusion
robert3005 e6a0929
Push DataFusion-evaluated conjuncts only when they save decoding
robert3005 87feab9
Measure optional conjuncts on one split and back off from costly ones
robert3005 d46ce86
Pass a demand to scalar functions and short-circuit AND and OR with it
robert3005 dd72d43
Replace the optional marker with a switch over the predicate
robert3005 42d695e
Pass the demand to scalar functions without filtering their inputs
robert3005 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,105 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| //! Execution of an array for the rows a caller demands. | ||
| //! | ||
| //! A demand is a mask of the rows whose values the caller reads. The values of the other rows are | ||
| //! unspecified, so a scalar function may ignore the demand and compute every row. A function can | ||
| //! also use it to skip work: `AND` and `OR` demand of their right operand only the rows their left | ||
| //! operand does not decide. | ||
|
|
||
| use vortex_error::VortexResult; | ||
| use vortex_mask::Mask; | ||
|
|
||
| use crate::ArrayRef; | ||
| use crate::Canonical; | ||
| use crate::ExecutionCtx; | ||
| use crate::IntoArray; | ||
| use crate::arrays::ConstantArray; | ||
| use crate::arrays::ScalarFn; | ||
| use crate::arrays::scalar_fn::ScalarFnArrayExt; | ||
| use crate::scalar::Scalar; | ||
| use crate::scalar_fn::VecExecutionArgs; | ||
|
|
||
| /// Execute `array` to its canonical form for the rows of `demand`, or for every row without one. | ||
| /// | ||
| /// The values of rows outside the demand are unspecified. A computation that is not evaluated yet, | ||
| /// such as a comparison, receives the demand through its [`ExecutionArgs`] and decides how to use | ||
| /// it. An encoded or canonical array is executed whole. | ||
| /// | ||
| /// [`ExecutionArgs`]: crate::scalar_fn::ExecutionArgs | ||
| pub fn execute_demanded( | ||
| array: ArrayRef, | ||
| demand: Option<&Mask>, | ||
| ctx: &mut ExecutionCtx, | ||
| ) -> VortexResult<ArrayRef> { | ||
| let Some(demand) = demand.filter(|demand| !demand.all_true()) else { | ||
| return Ok(array.execute::<Canonical>(ctx)?.into_array()); | ||
| }; | ||
| if demand.all_false() { | ||
| return Ok( | ||
| ConstantArray::new(Scalar::default_value(array.dtype()), array.len()).into_array(), | ||
| ); | ||
| } | ||
| let Some(scalar_fn_array) = array.as_opt::<ScalarFn>() else { | ||
| return Ok(array.execute::<Canonical>(ctx)?.into_array()); | ||
| }; | ||
|
|
||
| let args = | ||
| VecExecutionArgs::new(scalar_fn_array.children(), array.len()).with_demand(demand.clone()); | ||
| Ok(scalar_fn_array | ||
| .scalar_fn() | ||
| .execute(&args, ctx)? | ||
| .execute::<Canonical>(ctx)? | ||
| .into_array()) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use vortex_error::VortexResult; | ||
| use vortex_mask::Mask; | ||
|
|
||
| use super::*; | ||
| use crate::VortexSessionExecute; | ||
| use crate::array_session; | ||
| use crate::arrays::Constant; | ||
| use crate::arrays::PrimitiveArray; | ||
| use crate::builtins::ArrayBuiltins; | ||
| use crate::scalar_fn::fns::operators::Operator; | ||
|
|
||
| /// The demanded rows hold the values of a full evaluation. | ||
| #[test] | ||
| fn demanded_rows_match_full_evaluation() -> VortexResult<()> { | ||
| let mut ctx = array_session().create_execution_ctx(); | ||
| let len = 4096; | ||
| let step = 64; | ||
| let values = PrimitiveArray::from_iter(0..len as u64).into_array(); | ||
| let comparison = values.binary( | ||
| ConstantArray::new(Scalar::from(1000u64), len).into_array(), | ||
| Operator::Lt, | ||
| )?; | ||
| let demand = Mask::from_indices(len, (0..len).step_by(step).collect::<Vec<_>>()); | ||
|
|
||
| let full = comparison | ||
| .clone() | ||
| .execute::<Canonical>(&mut ctx)? | ||
| .into_array(); | ||
| let demanded = execute_demanded(comparison, Some(&demand), &mut ctx)?; | ||
| for idx in (0..len).step_by(step) { | ||
| assert_eq!( | ||
| demanded.execute_scalar(idx, &mut ctx)?, | ||
| full.execute_scalar(idx, &mut ctx)? | ||
| ); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn nothing_demanded_is_not_evaluated() -> VortexResult<()> { | ||
| let mut ctx = array_session().create_execution_ctx(); | ||
| let values = PrimitiveArray::from_iter([1u64, 2, 3]).into_array(); | ||
| let demanded = execute_demanded(values, Some(&Mask::new_false(3)), &mut ctx)?; | ||
| assert!(demanded.is::<Constant>()); | ||
| Ok(()) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be made better