-
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.
chore: move symbolic and boolean algebra code into new crate (#3570)
Moving some of the code we have around symbolic/boolean algebra on expressions into its own crate, because I anticipate that we will be building more of this kind of thing, so it would be nicer to consolidate it as well as make it easier to reuse. It also allows us to better test these things in isolation of the context they are being used in. For example, we'll be building some optimization rules that more intelligently finds predicates for filter pushdown into joins, and that may use both `split_conjunction` as well as some expression simplification logic. Also took this opportunity to fix a typo (conjuct -> conjunct) and rename `conjunct` (which is an adjective) to `combine_conjunction`. Otherwise everything else is pretty much a straightforward move
- Loading branch information
1 parent
b7ea62b
commit 5165e5e
Showing
15 changed files
with
570 additions
and
535 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[dependencies] | ||
common-error = {path = "../common/error", default-features = false} | ||
common-treenode = {path = "../common/treenode", default-features = false} | ||
daft-dsl = {path = "../daft-dsl", default-features = false} | ||
daft-schema = {path = "../daft-schema", default-features = false} | ||
|
||
[dev-dependencies] | ||
rstest = {workspace = true} | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[package] | ||
edition = {workspace = true} | ||
name = "daft-algebra" | ||
version = {workspace = true} |
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,24 @@ | ||
use common_treenode::{TreeNode, TreeNodeRecursion}; | ||
use daft_dsl::{Expr, ExprRef, Operator}; | ||
|
||
pub fn split_conjunction(expr: &ExprRef) -> Vec<ExprRef> { | ||
let mut splits = vec![]; | ||
|
||
expr.apply(|e| match e.as_ref() { | ||
Expr::BinaryOp { | ||
op: Operator::And, .. | ||
} | ||
| Expr::Alias(..) => Ok(TreeNodeRecursion::Continue), | ||
_ => { | ||
splits.push(e.clone()); | ||
Ok(TreeNodeRecursion::Jump) | ||
} | ||
}) | ||
.unwrap(); | ||
|
||
splits | ||
} | ||
|
||
pub fn combine_conjunction<T: IntoIterator<Item = ExprRef>>(exprs: T) -> Option<ExprRef> { | ||
exprs.into_iter().reduce(|acc, e| acc.and(e)) | ||
} |
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,4 @@ | ||
pub mod boolean; | ||
mod simplify; | ||
|
||
pub use simplify::simplify_expr; |
Oops, something went wrong.