|
|
@ -561,11 +561,11 @@ impl SimpleEvaluator { |
|
|
|
} |
|
|
|
} |
|
|
|
PlanNode::Aggregate { |
|
|
|
PlanNode::Aggregate { |
|
|
|
child, |
|
|
|
child, |
|
|
|
key_mapping, |
|
|
|
key_variables, |
|
|
|
aggregates, |
|
|
|
aggregates, |
|
|
|
} => { |
|
|
|
} => { |
|
|
|
let child = self.plan_evaluator(child); |
|
|
|
let child = self.plan_evaluator(child); |
|
|
|
let key_mapping = key_mapping.clone(); |
|
|
|
let key_variables = key_variables.clone(); |
|
|
|
let aggregate_input_expressions: Vec<_> = aggregates |
|
|
|
let aggregate_input_expressions: Vec<_> = aggregates |
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.map(|(aggregate, _)| { |
|
|
|
.map(|(aggregate, _)| { |
|
|
@ -588,8 +588,8 @@ impl SimpleEvaluator { |
|
|
|
let accumulator_variables: Vec<_> = |
|
|
|
let accumulator_variables: Vec<_> = |
|
|
|
aggregates.iter().map(|(_, var)| *var).collect(); |
|
|
|
aggregates.iter().map(|(_, var)| *var).collect(); |
|
|
|
Rc::new(move |from| { |
|
|
|
Rc::new(move |from| { |
|
|
|
let tuple_size = from.capacity(); //TODO: not nice
|
|
|
|
let tuple_size = from.capacity(); |
|
|
|
let key_mapping = key_mapping.clone(); |
|
|
|
let key_variables = key_variables.clone(); |
|
|
|
let mut errors = Vec::default(); |
|
|
|
let mut errors = Vec::default(); |
|
|
|
let mut accumulators_for_group = |
|
|
|
let mut accumulators_for_group = |
|
|
|
HashMap::<Vec<Option<EncodedTerm>>, Vec<Box<dyn Accumulator>>>::default(); |
|
|
|
HashMap::<Vec<Option<EncodedTerm>>, Vec<Box<dyn Accumulator>>>::default(); |
|
|
@ -603,9 +603,9 @@ impl SimpleEvaluator { |
|
|
|
}) |
|
|
|
}) |
|
|
|
.for_each(|tuple| { |
|
|
|
.for_each(|tuple| { |
|
|
|
//TODO avoid copy for key?
|
|
|
|
//TODO avoid copy for key?
|
|
|
|
let key = key_mapping |
|
|
|
let key = key_variables |
|
|
|
.iter() |
|
|
|
.iter() |
|
|
|
.map(|(v, _)| tuple.get(*v).cloned()) |
|
|
|
.map(|v| tuple.get(*v).cloned()) |
|
|
|
.collect(); |
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
|
|
let key_accumulators = |
|
|
|
let key_accumulators = |
|
|
@ -623,7 +623,7 @@ impl SimpleEvaluator { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
if accumulators_for_group.is_empty() && key_mapping.is_empty() { |
|
|
|
if accumulators_for_group.is_empty() && key_variables.is_empty() { |
|
|
|
// There is always a single group if there is no GROUP BY
|
|
|
|
// There is always a single group if there is no GROUP BY
|
|
|
|
accumulators_for_group.insert(Vec::new(), Vec::new()); |
|
|
|
accumulators_for_group.insert(Vec::new(), Vec::new()); |
|
|
|
} |
|
|
|
} |
|
|
@ -635,9 +635,9 @@ impl SimpleEvaluator { |
|
|
|
.chain(accumulators_for_group.into_iter().map( |
|
|
|
.chain(accumulators_for_group.into_iter().map( |
|
|
|
move |(key, accumulators)| { |
|
|
|
move |(key, accumulators)| { |
|
|
|
let mut result = EncodedTuple::with_capacity(tuple_size); |
|
|
|
let mut result = EncodedTuple::with_capacity(tuple_size); |
|
|
|
for (from_position, to_position) in key_mapping.iter() { |
|
|
|
for (variable, value) in key_variables.iter().zip(key) { |
|
|
|
if let Some(value) = &key[*from_position] { |
|
|
|
if let Some(value) = value { |
|
|
|
result.set(*to_position, value.clone()); |
|
|
|
result.set(*variable, value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
for (accumulator, variable) in |
|
|
|
for (accumulator, variable) in |
|
|
|