Skip to content

Apache DataFusion SQL Query Engine

ARROW-11742: [Rust][DataFusion] Add Expr::is_null and Expr::is_not_nu…

Nga Tranbe337a390eca
diff --git a/rust/datafusion/src/logical_plan/expr.rs b/rust/datafusion/src/logical_plan/expr.rs
index 775ab64ac1..f40e5242e4 100644
--- a/rust/datafusion/src/logical_plan/expr.rs
+++ b/rust/datafusion/src/logical_plan/expr.rs
@@ -442,6 +442,18 @@ impl Expr {
}
}
+ /// Return `IsNull(Box(self))
+ #[allow(clippy::wrong_self_convention)]
+ pub fn is_null(self) -> Expr {
+ Expr::IsNull(Box::new(self))
+ }
+
+ /// Return `IsNotNull(Box(self))
+ #[allow(clippy::wrong_self_convention)]
+ pub fn is_not_null(self) -> Expr {
+ Expr::IsNotNull(Box::new(self))
+ }
+
/// Create a sort expression from an existing expression.
///
/// ```
@@ -1388,6 +1400,17 @@ mod tests {
)
}
+ #[test]
+ fn filter_is_null_and_is_not_null() {
+ let col_null = Expr::Column("col1".to_string());
+ let col_not_null = Expr::Column("col2".to_string());
+ assert_eq!(format!("{:?}", col_null.is_null()), "#col1 IS NULL");
+ assert_eq!(
+ format!("{:?}", col_not_null.is_not_null()),
+ "#col2 IS NOT NULL"
+ );
+ }
+
#[derive(Default)]
struct RecordingRewriter {
v: Vec<String>,