Skip to content

Commit

Permalink
adding expr to string for IsNotNull IsTrue IsFalse and IsUnkown (#9739)
Browse files Browse the repository at this point in the history
* adding expr to string for IsNotNull IsTrue IsFalse and IsUnkown

* fix clippy

* change to raw string
  • Loading branch information
Lordworms authored Mar 23, 2024
1 parent 6c63051 commit 1dbec3e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ impl Unparser<'_> {
negated: insubq.negated,
})
}
Expr::IsNotNull(expr) => {
Ok(ast::Expr::IsNotNull(Box::new(self.expr_to_sql(expr)?)))
}
Expr::IsTrue(expr) => {
Ok(ast::Expr::IsTrue(Box::new(self.expr_to_sql(expr)?)))
}
Expr::IsFalse(expr) => {
Ok(ast::Expr::IsFalse(Box::new(self.expr_to_sql(expr)?)))
}
Expr::IsUnknown(expr) => {
Ok(ast::Expr::IsUnknown(Box::new(self.expr_to_sql(expr)?)))
}
_ => not_impl_err!("Unsupported expression: {expr:?}"),
}
}
Expand Down Expand Up @@ -599,6 +611,19 @@ mod tests {
}),
"COUNT(DISTINCT *)",
),
(Expr::IsNotNull(Box::new(col("a"))), r#""a" IS NOT NULL"#),
(
Expr::IsTrue(Box::new((col("a") + col("b")).gt(lit(4)))),
r#"(("a" + "b") > 4) IS TRUE"#,
),
(
Expr::IsFalse(Box::new((col("a") + col("b")).gt(lit(4)))),
r#"(("a" + "b") > 4) IS FALSE"#,
),
(
Expr::IsUnknown(Box::new((col("a") + col("b")).gt(lit(4)))),
r#"(("a" + "b") > 4) IS UNKNOWN"#,
),
];

for (expr, expected) in tests {
Expand Down

0 comments on commit 1dbec3e

Please sign in to comment.