Skip to content
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

type coercion: support is/is_not_bool/like/unknown expr #3510

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
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