From 86bbebf93ce4c3833902ccfb3f1871dbb75e4072 Mon Sep 17 00:00:00 2001 From: Tpt Date: Mon, 17 Apr 2023 09:59:49 +0200 Subject: [PATCH] Fixes evaluation of empty aggregation without GROUP BY Aggregators should return their default value (0 for COUNT...) and not an empty row --- lib/src/sparql/eval.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 9b01b45c..7cce17d6 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -754,6 +754,13 @@ impl SimpleEvaluator { let mut errors = Vec::default(); let mut accumulators_for_group = HashMap::>, Vec>>::default(); + if key_variables.is_empty() { + // There is always a single group if there is no GROUP BY + accumulators_for_group.insert( + Vec::new(), + accumulator_builders.iter().map(|c| c()).collect::>(), + ); + } child(from) .filter_map(|result| match result { Ok(result) => Some(result), @@ -784,10 +791,6 @@ impl SimpleEvaluator { ); } }); - if accumulators_for_group.is_empty() && key_variables.is_empty() { - // There is always a single group if there is no GROUP BY - accumulators_for_group.insert(Vec::new(), Vec::new()); - } let accumulator_variables = accumulator_variables.clone(); Box::new( errors