-
Notifications
You must be signed in to change notification settings - Fork 132
feat(expr): implement Kleene logic boolean operators #6464
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,6 +114,11 @@ impl VTable for Not { | |
| } | ||
| } | ||
|
|
||
| /// Creates an expression that logically inverts boolean values using Kleene logic. | ||
| pub fn not_kleene(operand: Expression) -> Expression { | ||
| Not.new_expr(EmptyOptions, vec![operand]) | ||
| } | ||
|
Comment on lines
+118
to
+120
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not correct?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. aparently this is redundant
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then why include it? |
||
|
|
||
| /// Creates an expression that logically inverts boolean values. | ||
| /// | ||
| /// Returns the logical negation of the input boolean expression. | ||
|
|
@@ -123,7 +128,7 @@ impl VTable for Not { | |
| /// let expr = not(root()); | ||
| /// ``` | ||
| pub fn not(operand: Expression) -> Expression { | ||
| Not.new_expr(EmptyOptions, vec![operand]) | ||
| not_kleene(operand) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
|
|
@@ -132,6 +137,7 @@ mod tests { | |
| use vortex_dtype::Nullability; | ||
|
|
||
| use super::not; | ||
| use super::not_kleene; | ||
| use crate::ToCanonical; | ||
| use crate::arrays::BoolArray; | ||
| use crate::expr::exprs::get_item::col; | ||
|
|
@@ -141,7 +147,7 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn invert_booleans() { | ||
| let not_expr = not(root()); | ||
| let not_expr = not_kleene(root()); | ||
| let bools = BoolArray::from_iter([false, true, false, false, true, true]); | ||
| assert_eq!( | ||
| bools | ||
|
|
@@ -167,7 +173,7 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn dtype() { | ||
| let not_expr = not(root()); | ||
| let not_expr = not_kleene(root()); | ||
| let dtype = DType::Bool(Nullability::NonNullable); | ||
| assert_eq!( | ||
| not_expr.return_dtype(&dtype).unwrap(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ pub fn split_conjunction(expr: &Expression) -> Vec<Expression> { | |
|
|
||
| fn split_inner(expr: &Expression, exprs: &mut Vec<Expression>) { | ||
| match expr.as_opt::<Binary>() { | ||
| Some(operator) if *operator == Operator::And => { | ||
| Some(operator) if *operator == Operator::KleeneAnd => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the reason for changing this?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason is that Operator::And now represents Standard logic , but Vortex’s query engine was built assuming Kleene logic
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about regular and? |
||
| split_inner(expr.child(0), exprs); | ||
| split_inner(expr.child(1), exprs); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,8 @@ message BinaryOpts { | |
| Sub = 9; | ||
| Mul = 10; | ||
| Div = 11; | ||
| KleeneAnd = 12; | ||
| KleeneOr = 13; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Why does or map to or kleene here?
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.
Yeah, since or() now defaults to strict null handling, we have to use or_kleene() here to keep the current behavior. Plus, Kleene is actually better for stats since it's more aggressive with pruning when there are nulls