Skip to content

Commit

Permalink
type coercion: support is/is_not_bool/like/unknown expr (#3510)
Browse files Browse the repository at this point in the history
* type coercion: support the boolen op, is_true, is_not_true, is_false, is_not_false

* Apply suggestions from code review

Co-authored-by: Daniël Heres <[email protected]>

* suport like,unknown for type coercion

* Update datafusion/optimizer/src/type_coercion.rs

Co-authored-by: Andrew Lamb <[email protected]>

Co-authored-by: Daniël Heres <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2022
1 parent aad82fb commit 11abfb9
Show file tree
Hide file tree
Showing 3 changed files with 336 additions and 5 deletions.
30 changes: 30 additions & 0 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,36 @@ impl Expr {
}
}

/// Return `IsTrue(Box(self))`
pub fn is_true(self) -> Expr {
Expr::IsTrue(Box::new(self))
}

/// Return `IsNotTrue(Box(self))`
pub fn is_not_true(self) -> Expr {
Expr::IsNotTrue(Box::new(self))
}

/// Return `IsFalse(Box(self))`
pub fn is_false(self) -> Expr {
Expr::IsFalse(Box::new(self))
}

/// Return `IsNotFalse(Box(self))`
pub fn is_not_false(self) -> Expr {
Expr::IsNotFalse(Box::new(self))
}

/// Return `IsUnknown(Box(self))`
pub fn is_unknown(self) -> Expr {
Expr::IsUnknown(Box::new(self))
}

/// Return `IsNotUnknown(Box(self))`
pub fn is_not_unknown(self) -> Expr {
Expr::IsNotUnknown(Box::new(self))
}

pub fn try_into_col(&self) -> Result<Column> {
match self {
Expr::Column(it) => Ok(it.clone()),
Expand Down
30 changes: 30 additions & 0 deletions datafusion/expr/src/expr_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,36 @@ pub fn is_null(expr: Expr) -> Expr {
Expr::IsNull(Box::new(expr))
}

/// Create is true expression
pub fn is_true(expr: Expr) -> Expr {
Expr::IsTrue(Box::new(expr))
}

/// Create is not true expression
pub fn is_not_true(expr: Expr) -> Expr {
Expr::IsNotTrue(Box::new(expr))
}

/// Create is false expression
pub fn is_false(expr: Expr) -> Expr {
Expr::IsFalse(Box::new(expr))
}

/// Create is not false expression
pub fn is_not_false(expr: Expr) -> Expr {
Expr::IsNotFalse(Box::new(expr))
}

/// Create is unknown expression
pub fn is_unknown(expr: Expr) -> Expr {
Expr::IsUnknown(Box::new(expr))
}

/// Create is not unknown expression
pub fn is_not_unknown(expr: Expr) -> Expr {
Expr::IsNotUnknown(Box::new(expr))
}

/// Create an convenience function representing a unary scalar function
macro_rules! unary_scalar_expr {
($ENUM:ident, $FUNC:ident, $DOC:expr) => {
Expand Down
Loading

0 comments on commit 11abfb9

Please sign in to comment.