refactor: improve predicate conversion code (#325)
parent
ff29610e44
commit
0a48c04a9b
|
@ -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),
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue