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

Implement unparse IS_NULL to String and enhance the tests #10529

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from all 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
27 changes: 25 additions & 2 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,9 @@ impl Unparser<'_> {
Expr::ScalarVariable(_, _) => {
not_impl_err!("Unsupported Expr conversion: {expr:?}")
}
Expr::IsNull(_) => not_impl_err!("Unsupported Expr conversion: {expr:?}"),
Expr::IsNull(expr) => {
Ok(ast::Expr::IsNull(Box::new(self.expr_to_sql(expr)?)))
}
Expr::IsNotFalse(_) => not_impl_err!("Unsupported Expr conversion: {expr:?}"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it looks like I maybe mis read the code originally and the other missing expression is Expr::IsNotFalse (rather than Expr::IsNotNull)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing! I think I can fix IsNotFalse in another PR. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a second PR will be great

Expr::GetIndexedField(_) => {
not_impl_err!("Unsupported Expr conversion: {expr:?}")
Expand Down Expand Up @@ -863,7 +865,7 @@ mod tests {
use datafusion_expr::{
case, col, exists,
expr::{AggregateFunction, AggregateFunctionDefinition},
lit, not, not_exists, table_scan, wildcard, ColumnarValue, ScalarUDF,
lit, not, not_exists, table_scan, when, wildcard, ColumnarValue, ScalarUDF,
ScalarUDFImpl, Signature, Volatility, WindowFrame, WindowFunctionDefinition,
};

Expand Down Expand Up @@ -933,6 +935,14 @@ mod tests {
.otherwise(lit(ScalarValue::Null))?,
r#"CASE "a" WHEN 1 THEN true WHEN 0 THEN false ELSE NULL END"#,
),
(
when(col("a").is_null(), lit(true)).otherwise(lit(false))?,
r#"CASE WHEN "a" IS NULL THEN true ELSE false END"#,
),
(
when(col("a").is_not_null(), lit(true)).otherwise(lit(false))?,
r#"CASE WHEN "a" IS NOT NULL THEN true ELSE false END"#,
),
(
Expr::Cast(Cast {
expr: Box::new(col("a")),
Expand All @@ -959,6 +969,18 @@ mod tests {
ScalarUDF::new_from_impl(DummyUDF::new()).call(vec![col("a"), col("b")]),
r#"dummy_udf("a", "b")"#,
),
(
ScalarUDF::new_from_impl(DummyUDF::new())
.call(vec![col("a"), col("b")])
.is_null(),
r#"dummy_udf("a", "b") IS NULL"#,
),
(
ScalarUDF::new_from_impl(DummyUDF::new())
.call(vec![col("a"), col("b")])
.is_not_null(),
r#"dummy_udf("a", "b") IS NOT NULL"#,
),
(
Expr::Like(Like {
negated: true,
Expand Down Expand Up @@ -1081,6 +1103,7 @@ mod tests {
r#"COUNT(*) OVER (ORDER BY "a" DESC NULLS FIRST RANGE BETWEEN 6 PRECEDING AND 2 FOLLOWING)"#,
),
(col("a").is_not_null(), r#""a" IS NOT NULL"#),
(col("a").is_null(), r#""a" IS NULL"#),
(
(col("a") + col("b")).gt(lit(4)).is_true(),
r#"(("a" + "b") > 4) IS TRUE"#,
Expand Down