refactor: improve predicate conversion code (#325)

pull/24376/head
Andrew Lamb 2020-10-01 17:26:39 -04:00 committed by GitHub
parent ff29610e44
commit 0a48c04a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 22 deletions

View File

@ -67,33 +67,29 @@ pub fn convert_predicate(predicate: Option<RPCPredicate>) -> Result<Option<Stora
match predicate { match predicate {
// no input predicate, is fine // no input predicate, is fine
None => Ok(None), None => Ok(None),
Some(predicate) => { Some(predicate) => match predicate.root {
let RPCPredicate { root } = predicate; None => EmptyPredicateNode {}.fail(),
let expr = convert_node(root)?; Some(node) => Ok(Some(StoragePredicate {
Ok(Some(StoragePredicate { expr })) expr: convert_node(node)?,
} })),
},
} }
} }
// converts a Node from the RPC layer into a datafusion logical expr // converts a Node from the RPC layer into a datafusion logical expr
fn convert_node(node: Option<RPCNode>) -> Result<Expr> { fn convert_node(node: RPCNode) -> Result<Expr> {
match node { let RPCNode { children, value } = node;
None => EmptyPredicateNode {}.fail(), let inputs = children
Some(node) => { .into_iter()
let RPCNode { children, value } = node; .map(convert_node)
let inputs = children .collect::<Result<Vec<_>>>()?;
.into_iter()
.map(|child| convert_node(Some(child)))
.collect::<Result<Vec<_>>>()?;
match value { match value {
// I don't really understand what a None value // I don't really understand what a None value
// means. So until we know they are needed error on // means. So until we know they are needed error on
// them here instead. // them here instead.
None => EmptyPredicateValue {}.fail(), None => EmptyPredicateValue {}.fail(),
Some(value) => build_node(value, inputs), Some(value) => build_node(value, inputs),
}
}
} }
} }