Skip to content

Commit

Permalink
Remove parse_vec_expr helper
Browse files Browse the repository at this point in the history
Behavior of `parse_vec_expr` and `parse_exprs` is almost similar -- both
take a collection of expressions to parse. The only difference is that
`parse_vec_expr` returns `Option::None` when collections is empty, but
this difference in behavior does not correspond to difference in
function names. Since the function is used once only, remove it instead
of coming up with a fancy name.
  • Loading branch information
findepi committed Aug 26, 2024
1 parent 945902d commit e09f43d
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions datafusion/proto/src/logical_plan/from_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,10 @@ pub fn parse_expr(
parse_exprs(&pb.args, registry, codec)?,
pb.distinct,
parse_optional_expr(pb.filter.as_deref(), registry, codec)?.map(Box::new),
parse_vec_expr(&pb.order_by, registry, codec)?,
match pb.order_by.len() {
0 => None,
_ => Some(parse_exprs(&pb.order_by, registry, codec)?),
},
None,
)))
}
Expand Down Expand Up @@ -676,16 +679,6 @@ pub fn from_proto_binary_op(op: &str) -> Result<Operator, Error> {
}
}

fn parse_vec_expr(
p: &[protobuf::LogicalExprNode],
registry: &dyn FunctionRegistry,
codec: &dyn LogicalExtensionCodec,
) -> Result<Option<Vec<Expr>>, Error> {
let res = parse_exprs(p, registry, codec)?;
// Convert empty vector to None.
Ok((!res.is_empty()).then_some(res))
}

fn parse_optional_expr(
p: Option<&protobuf::LogicalExprNode>,
registry: &dyn FunctionRegistry,
Expand Down

0 comments on commit e09f43d

Please sign in to comment.