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,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> {