Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion datafusion/src/logical_plan/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<R>(boxed_expr: Box<Expr>, rewriter: &mut R) -> Result<Box<Expr>>
where
Expand Down Expand Up @@ -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")) {
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 @@ -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
Expand Down