refactor: improve predicate conversion code
@@ -67,23 +67,21 @@ pub fn convert_predicate(predicate: Option<RPCPredicate>) -> Result<Option<Stora
match predicate {
// no input predicate, is fine
None => Ok(None),
- Some(predicate) => {
- let RPCPredicate { root } = predicate;
- let expr = convert_node(root)?;
- Ok(Some(StoragePredicate { expr }))
- }
+ Some(predicate) => match predicate.root {
+ None => EmptyPredicateNode {}.fail(),
+ Some(node) => Ok(Some(StoragePredicate {
+ expr: convert_node(node)?,
+ })),
+ },
}
}
// converts a Node from the RPC layer into a datafusion logical expr
-fn convert_node(node: Option<RPCNode>) -> Result<Expr> {
- match node {
- None => EmptyPredicateNode {}.fail(),
- Some(node) => {
+fn convert_node(node: RPCNode) -> Result<Expr> {
let RPCNode { children, value } = node;
let inputs = children
.into_iter()
- .map(|child| convert_node(Some(child)))
+ .map(convert_node)
.collect::<Result<Vec<_>>>()?;
match value {
@@ -94,8 +92,6 @@ fn convert_node(node: Option<RPCNode>) -> Result<Expr> {
Some(value) => build_node(value, inputs),
}
}
- }
-}
// Builds an Expr given the Value and the converted children
fn build_node(value: RPCValue, inputs: Vec<Expr>) -> Result<Expr> {
