The number of columns in the relation. This number is determined from the type, which is determined recursively at non-trivial cost. The arity is computed incrementally with a recursive post-order traversal, that accumulates the arities for the relations yet to be visited in `arity_stack`.
(&self)
| 958 | /// traversal, that accumulates the arities for the relations yet to be |
| 959 | /// visited in `arity_stack`. |
| 960 | pub fn arity(&self) -> usize { |
| 961 | let mut arity_stack = Vec::new(); |
| 962 | self.visit_pre_post( |
| 963 | &mut |e: &MirRelationExpr| -> Option<Vec<&MirRelationExpr>> { |
| 964 | match &e { |
| 965 | MirRelationExpr::Let { body, .. } => { |
| 966 | // Do not traverse the value sub-graph, since it's not relevant for |
| 967 | // determining the arity of Let operators. |
| 968 | Some(vec![&*body]) |
| 969 | } |
| 970 | MirRelationExpr::LetRec { body, .. } => { |
| 971 | // Do not traverse the value sub-graph, since it's not relevant for |
| 972 | // determining the arity of Let operators. |
| 973 | Some(vec![&*body]) |
| 974 | } |
| 975 | MirRelationExpr::Project { .. } | MirRelationExpr::Reduce { .. } => { |
| 976 | // No further traversal is required; these operators know their arity. |
| 977 | Some(Vec::new()) |
| 978 | } |
| 979 | _ => None, |
| 980 | } |
| 981 | }, |
| 982 | &mut |e: &MirRelationExpr| { |
| 983 | match &e { |
| 984 | MirRelationExpr::Let { .. } => { |
| 985 | let body_arity = arity_stack.pop().unwrap(); |
| 986 | arity_stack.push(0); |
| 987 | arity_stack.push(body_arity); |
| 988 | } |
| 989 | MirRelationExpr::LetRec { values, .. } => { |
| 990 | let body_arity = arity_stack.pop().unwrap(); |
| 991 | arity_stack.extend(std::iter::repeat(0).take(values.len())); |
| 992 | arity_stack.push(body_arity); |
| 993 | } |
| 994 | MirRelationExpr::Project { .. } | MirRelationExpr::Reduce { .. } => { |
| 995 | arity_stack.push(0); |
| 996 | } |
| 997 | _ => {} |
| 998 | } |
| 999 | let num_inputs = e.num_inputs(); |
| 1000 | let input_arities = arity_stack.drain(arity_stack.len() - num_inputs..); |
| 1001 | let arity = e.arity_with_input_arities(input_arities); |
| 1002 | arity_stack.push(arity); |
| 1003 | }, |
| 1004 | ); |
| 1005 | assert_eq!(arity_stack.len(), 1); |
| 1006 | arity_stack.pop().unwrap() |
| 1007 | } |
| 1008 | |
| 1009 | /// Reports the arity of the relation given the schema of the input relations. |
| 1010 | /// |
no test coverage detected