Skip to content

Commit

Permalink
impl not for expr
Browse files Browse the repository at this point in the history
  • Loading branch information
jimexist committed Jul 21, 2021
1 parent c754eef commit c0195c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions datafusion/src/logical_plan/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use arrow::{compute::can_cast_types, datatypes::DataType};
use functions::{ReturnTypeFunction, ScalarFunctionImplementation, Signature};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::ops::Not;
use std::sync::Arc;

/// A named reference to a qualified field in a schema.
Expand Down Expand Up @@ -568,9 +569,8 @@ impl Expr {
}

/// Return `!self`
#[allow(clippy::should_implement_trait)]
pub fn not(self) -> Expr {
Expr::Not(Box::new(self))
!self
}

/// Calculate the modulus of two expressions.
Expand Down Expand Up @@ -915,6 +915,14 @@ impl Expr {
}
}

impl Not for Expr {
type Output = Self;

fn not(self) -> Self::Output {
Expr::Not(Box::new(self))
}
}

#[allow(clippy::boxed_local)]
fn rewrite_boxed<R>(boxed_expr: Box<Expr>, rewriter: &mut R) -> Result<Box<Expr>>
where
Expand Down Expand Up @@ -1967,6 +1975,11 @@ mod tests {
DFField::new(Some(relation), column, DataType::Int8, false)
}

#[test]
fn test_not() {
assert_eq!(lit(1).not(), !lit(1));
}

macro_rules! test_unary_scalar_expr {
($ENUM:ident, $FUNC:ident) => {{
if let Expr::ScalarFunction { fun, args } = $FUNC(col("tableA.a")) {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/src/physical_optimizer/pruning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ fn build_single_column_expr(
if is_not {
// The only way we know a column couldn't match is if both the min and max are true
// !(min && max)
Some((min.and(max)).not())
Some(!(min.and(max)))
} else {
// the only way we know a column couldn't match is if both the min and max are false
// !(!min && !max) --> min || max
Expand Down

0 comments on commit c0195c2

Please sign in to comment.