Skip to content

Always add parentheses when formatting BinaryExpr with SchemaDisplay #16209

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

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
17 changes: 16 additions & 1 deletion datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ impl Display for SchemaDisplay<'_> {
}
}
Expr::BinaryExpr(BinaryExpr { left, op, right }) => {
write!(f, "{} {op} {}", SchemaDisplay(left), SchemaDisplay(right),)
write!(f, "({} {op} {})", SchemaDisplay(left), SchemaDisplay(right),)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual change.

}
Expr::Case(Case {
expr,
Expand Down Expand Up @@ -3577,6 +3577,21 @@ mod test {
);
}

#[test]
fn test_schema_display_nested_binary_expr() {
let expr = lit(1) * (lit(2) + lit(3));
assert_eq!(
format!("{}", SchemaDisplay(&expr)),
"(Int32(1) * (Int32(2) + Int32(3)))"
);

let expr = -(lit(1) + (lit(2)));
assert_eq!(
format!("{}", SchemaDisplay(&expr)),
"(- (Int32(1) + (Int32(2))"
);
}

fn wildcard_options(
opt_ilike: Option<IlikeSelectItem>,
opt_exclude: Option<ExcludeSelectItem>,
Expand Down
Loading