This is an automated email from the ASF dual-hosted git repository.

agrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/master by this push:
     new 2de77fb46 functionality and tests (#3252)
2de77fb46 is described below

commit 2de77fb46a042b353d8cc513e7c72d9b1cd63d74
Author: Sarah Yurick <[email protected]>
AuthorDate: Wed Aug 24 14:21:18 2022 -0700

    functionality and tests (#3252)
---
 datafusion/core/tests/sql/expr.rs | 64 +++++++++++++++++++++++++++++++++++++++
 datafusion/sql/src/planner.rs     | 12 ++++++++
 2 files changed, 76 insertions(+)

diff --git a/datafusion/core/tests/sql/expr.rs 
b/datafusion/core/tests/sql/expr.rs
index cd2dd3a6c..22e3b0358 100644
--- a/datafusion/core/tests/sql/expr.rs
+++ b/datafusion/core/tests/sql/expr.rs
@@ -381,6 +381,70 @@ async fn query_is_false() -> Result<()> {
     Ok(())
 }
 
+#[tokio::test]
+async fn query_is_not_true() -> Result<()> {
+    let schema = Arc::new(Schema::new(vec![Field::new("c1", DataType::Boolean, 
true)]));
+
+    let data = RecordBatch::try_new(
+        schema.clone(),
+        vec![Arc::new(BooleanArray::from(vec![
+            Some(true),
+            Some(false),
+            None,
+        ]))],
+    )?;
+
+    let table = MemTable::try_new(schema, vec![vec![data]])?;
+
+    let ctx = SessionContext::new();
+    ctx.register_table("test", Arc::new(table))?;
+    let sql = "SELECT c1 IS NOT TRUE as nt FROM test";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------+",
+        "| nt    |",
+        "+-------+",
+        "| false |",
+        "| true  |",
+        "| true  |",
+        "+-------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+    Ok(())
+}
+
+#[tokio::test]
+async fn query_is_not_false() -> Result<()> {
+    let schema = Arc::new(Schema::new(vec![Field::new("c1", DataType::Boolean, 
true)]));
+
+    let data = RecordBatch::try_new(
+        schema.clone(),
+        vec![Arc::new(BooleanArray::from(vec![
+            Some(true),
+            Some(false),
+            None,
+        ]))],
+    )?;
+
+    let table = MemTable::try_new(schema, vec![vec![data]])?;
+
+    let ctx = SessionContext::new();
+    ctx.register_table("test", Arc::new(table))?;
+    let sql = "SELECT c1 IS NOT FALSE as nf FROM test";
+    let actual = execute_to_batches(&ctx, sql).await;
+    let expected = vec![
+        "+-------+",
+        "| nf    |",
+        "+-------+",
+        "| true  |",
+        "| false |",
+        "| true  |",
+        "+-------+",
+    ];
+    assert_batches_eq!(expected, &actual);
+    Ok(())
+}
+
 #[tokio::test]
 async fn query_is_unknown() -> Result<()> {
     let schema = Arc::new(Schema::new(vec![Field::new("c1", DataType::Boolean, 
true)]));
diff --git a/datafusion/sql/src/planner.rs b/datafusion/sql/src/planner.rs
index 7225b7797..2f5bc3470 100644
--- a/datafusion/sql/src/planner.rs
+++ b/datafusion/sql/src/planner.rs
@@ -1956,6 +1956,18 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
                 right: Box::new(lit(false)),
             }),
 
+            SQLExpr::IsNotTrue(expr) => Ok(Expr::BinaryExpr {
+                left: Box::new(self.sql_expr_to_logical_expr(*expr, schema, 
ctes)?),
+                op: Operator::IsDistinctFrom,
+                right: Box::new(lit(true)),
+            }),
+
+            SQLExpr::IsNotFalse(expr) => Ok(Expr::BinaryExpr {
+                left: Box::new(self.sql_expr_to_logical_expr(*expr, schema, 
ctes)?),
+                op: Operator::IsDistinctFrom,
+                right: Box::new(lit(false)),
+            }),
+
             SQLExpr::IsUnknown(expr) => Ok(Expr::BinaryExpr {
                 left: Box::new(self.sql_expr_to_logical_expr(*expr, schema, 
ctes)?),
                 op: Operator::IsNotDistinctFrom,

Reply via email to