isidentical commented on code in PR #4115:
URL: https://github.com/apache/arrow-datafusion/pull/4115#discussion_r1015547987
##########
datafusion/proto/src/from_proto.rs:
##########
@@ -690,11 +690,34 @@ pub fn parse_expr(
.ok_or_else(|| Error::required("expr_type"))?;
match expr_type {
- ExprType::BinaryExpr(binary_expr) =>
Ok(Expr::BinaryExpr(BinaryExpr::new(
- Box::new(parse_required_expr(&binary_expr.l, registry, "l")?),
- from_proto_binary_op(&binary_expr.op)?,
- Box::new(parse_required_expr(&binary_expr.r, registry, "r")?),
- ))),
+ ExprType::BinaryExpr(binary_expr) => {
+ let op = from_proto_binary_op(&binary_expr.op)?;
+ let operands = binary_expr
+ .operands
+ .iter()
+ .map(|expr| parse_expr(expr, registry))
+ .collect::<Result<Vec<_>, _>>()?;
+
+ if operands.len() < 2 {
+ return Err(proto_error(
+ "A binary expression must always have at least 2 operands",
+ ));
+ }
+
+ // Reduce the linearized operands (ordered by left innermost to
right
+ // outermost) into a single expression tree.
+ Ok(operands
+ .into_iter()
+ .reduce(|left, right| {
+ Expr::BinaryExpr(BinaryExpr::new(Box::new(left), op,
Box::new(right)))
+ })
+ .unwrap_or_else(|| {
+ // As long as we have the bounds check above, this should
never happen.
+ panic!(
Review Comment:
Makes sense, thanks for the suggestion folks! Changed it to `expect()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]