-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorder filtering expressions by very roughly estimated cost, this change is intended as a building block for more advanced IO pruning.
- Loading branch information
Showing
13 changed files
with
138 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,60 @@ | ||
use std::collections::HashSet; | ||
use std::fmt::Debug; | ||
use std::sync::Arc; | ||
|
||
use vortex_dtype::field::FieldPath; | ||
use vortex_expr::VortexExpr; | ||
use vortex::Array; | ||
use vortex_dtype::field::{Field, FieldPath}; | ||
use vortex_error::VortexResult; | ||
use vortex_expr::{BinaryExpr, VortexExpr}; | ||
|
||
use crate::layouts::Schema; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct RowFilter { | ||
pub(crate) filter: Arc<dyn VortexExpr>, | ||
filter: Arc<dyn VortexExpr>, | ||
} | ||
|
||
impl RowFilter { | ||
pub fn new(filter: Arc<dyn VortexExpr>) -> Self { | ||
Self { filter } | ||
} | ||
|
||
// Evaluate the underlying filter against a target array, returning a boolean mask | ||
pub fn evaluate(&self, target: &Array) -> VortexResult<Array> { | ||
self.filter.evaluate(target) | ||
} | ||
|
||
/// Returns a set of all referenced fields in the underlying filter | ||
pub fn references(&self) -> HashSet<Field> { | ||
self.filter.references() | ||
} | ||
|
||
pub fn project(&self, _fields: &[FieldPath]) -> Self { | ||
todo!() | ||
} | ||
|
||
/// Re-order the expression so the sub-expressions estimated to be the "cheapest" are first (to the left of the expression) | ||
pub fn reorder(mut self, schema: &Schema) -> RowFilter { | ||
let expr = reorder_expr_impl(self.filter.clone(), schema); | ||
self.filter = expr; | ||
self | ||
} | ||
} | ||
|
||
fn reorder_expr_impl(expr: Arc<dyn VortexExpr>, schema: &Schema) -> Arc<dyn VortexExpr> { | ||
if let Some(binary) = expr.as_any().downcast_ref::<BinaryExpr>() { | ||
let lhs = reorder_expr_impl(binary.lhs().clone(), schema); | ||
let rhs = reorder_expr_impl(binary.rhs().clone(), schema); | ||
|
||
let (lhs, rhs, operator) = | ||
if binary.lhs().estimate_cost(schema) > binary.rhs().estimate_cost(schema) { | ||
(rhs, lhs, binary.op().swap()) | ||
} else { | ||
(lhs, rhs, binary.op()) | ||
}; | ||
|
||
Arc::new(BinaryExpr::new(lhs, operator, rhs)) | ||
} else { | ||
expr | ||
} | ||
} |
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
Oops, something went wrong.