diff --git a/datafusion/src/logical_plan/expr.rs b/datafusion/src/logical_plan/expr.rs index e4952840487b0..8978b8311d714 100644 --- a/datafusion/src/logical_plan/expr.rs +++ b/datafusion/src/logical_plan/expr.rs @@ -32,6 +32,7 @@ use functions::{ReturnTypeFunction, ScalarFunctionImplementation, Signature}; use std::collections::{HashMap, HashSet}; use std::convert::Infallible; use std::fmt; +use std::ops::Not; use std::str::FromStr; use std::sync::Arc; @@ -580,7 +581,7 @@ 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. @@ -925,6 +926,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(boxed_expr: Box, rewriter: &mut R) -> Result> where @@ -1994,6 +2003,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")) { diff --git a/datafusion/src/physical_optimizer/pruning.rs b/datafusion/src/physical_optimizer/pruning.rs index c6f7647b70cfa..2a10cfa5c9bfb 100644 --- a/datafusion/src/physical_optimizer/pruning.rs +++ b/datafusion/src/physical_optimizer/pruning.rs @@ -571,7 +571,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