Skip to content

Commit e5d4d69

Browse files
committed
Support IS (NOT) DISTINCT FROM in Unparser
1 parent 36b5219 commit e5d4d69

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

datafusion/sql/src/unparser/expr.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ impl Unparser<'_> {
148148
))))
149149
}
150150
Expr::Column(col) => self.col_to_sql(col),
151+
Expr::BinaryExpr(BinaryExpr { left, op, right })
152+
if *op == Operator::IsDistinctFrom =>
153+
{
154+
let l = self.expr_to_sql_inner(left.as_ref())?;
155+
let r = self.expr_to_sql_inner(right.as_ref())?;
156+
157+
Ok(ast::Expr::Nested(Box::new(ast::Expr::IsDistinctFrom(
158+
Box::new(l),
159+
Box::new(r),
160+
))))
161+
}
162+
Expr::BinaryExpr(BinaryExpr { left, op, right })
163+
if *op == Operator::IsNotDistinctFrom =>
164+
{
165+
let l = self.expr_to_sql_inner(left.as_ref())?;
166+
let r = self.expr_to_sql_inner(right.as_ref())?;
167+
168+
Ok(ast::Expr::Nested(Box::new(ast::Expr::IsNotDistinctFrom(
169+
Box::new(l),
170+
Box::new(r),
171+
))))
172+
}
151173
Expr::BinaryExpr(BinaryExpr { left, op, right }) => {
152174
let l = self.expr_to_sql_inner(left.as_ref())?;
153175
let r = self.expr_to_sql_inner(right.as_ref())?;
@@ -3681,4 +3703,25 @@ mod tests {
36813703

36823704
Ok(())
36833705
}
3706+
3707+
#[test]
3708+
fn test_is_distinct_from() {
3709+
let expr = Expr::BinaryExpr(BinaryExpr::new(
3710+
Box::new(col("c1")),
3711+
Operator::IsDistinctFrom,
3712+
Box::new(lit(true)),
3713+
));
3714+
3715+
let sql = expr_to_sql(&expr).unwrap().to_string();
3716+
assert_eq!(sql, "(c1 IS DISTINCT FROM true)");
3717+
3718+
let expr = Expr::BinaryExpr(BinaryExpr::new(
3719+
Box::new(col("c1")),
3720+
Operator::IsNotDistinctFrom,
3721+
Box::new(lit(true)),
3722+
));
3723+
3724+
let sql = expr_to_sql(&expr).unwrap().to_string();
3725+
assert_eq!(sql, "(c1 IS NOT DISTINCT FROM true)");
3726+
}
36843727
}

0 commit comments

Comments
 (0)