Skip to content
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

wip: pushdown mfp #4608

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/expr/src/linear.rs
Expand Up @@ -146,6 +146,11 @@ impl MapFilterProject {
self
}

pub fn apply(self, other: &MapFilterProject) -> MapFilterProject {
let (m, f, p) = other.as_map_filter_project();
self.map(m).filter(f).project(p)
}

/// As the arguments to `Map`, `Filter`, and `Project` operators.
///
/// In principle, this operator can be implemented as a sequence of
Expand All @@ -161,6 +166,10 @@ impl MapFilterProject {
(map, filter, project)
}

pub fn arity(&self) -> usize {
self.projection.len()
}

/// Optimize the internal expression evaluation order.
pub fn optimize(&mut self) {
// This should probably resemble existing scalar cse.
Expand Down
31 changes: 22 additions & 9 deletions src/expr/src/relation/mod.rs
Expand Up @@ -507,17 +507,25 @@ impl RelationExpr {

/// Retains only the columns specified by `output`.
pub fn project(self, outputs: Vec<usize>) -> Self {
RelationExpr::Project {
input: Box::new(self),
outputs,
if outputs.len() == self.arity() && outputs.iter().enumerate().all(|(i, j)| i == *j) {
self
} else {
Comment on lines +510 to +512
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a much smarter place to put this than in-line in all of the analyses themselves!

RelationExpr::Project {
input: Box::new(self),
outputs,
}
}
}

/// Append to each row the results of applying elements of `scalar`.
pub fn map(self, scalars: Vec<ScalarExpr>) -> Self {
RelationExpr::Map {
input: Box::new(self),
scalars,
if scalars.is_empty() {
self
} else {
RelationExpr::Map {
input: Box::new(self),
scalars,
}
}
}

Expand All @@ -536,9 +544,14 @@ impl RelationExpr {
where
I: IntoIterator<Item = ScalarExpr>,
{
RelationExpr::Filter {
input: Box::new(self),
predicates: predicates.into_iter().collect(),
let preds: Vec<ScalarExpr> = predicates.into_iter().collect();
if preds.is_empty() {
self
} else {
RelationExpr::Filter {
input: Box::new(self),
predicates: preds,
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/transform/Cargo.toml
Expand Up @@ -12,5 +12,5 @@ itertools = "0.9"
repr = { path = "../repr" }

[dev-dependencies]
datadriven = "0.3.0"
datadriven = "0.4.0"
anyhow = "1.0.33"
1 change: 1 addition & 0 deletions src/transform/src/lib.rs
Expand Up @@ -36,6 +36,7 @@ pub mod inline_let;
pub mod join_elision;
pub mod join_implementation;
pub mod map_lifting;
pub mod mfp_pushdown;
pub mod nonnull_requirements;
pub mod nonnullable;
pub mod predicate_pushdown;
Expand Down