You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2020/07/30 18:04:48 UTC

[couchdb] 01/02: Fix ebtree

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/fdb-layer-ebtree-views
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit d846f2e1c52c9bc4bc1ae574719b0291384a7568
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Thu Jul 30 13:03:26 2020 -0500

    Fix ebtree
---
 src/ebtree/src/ebtree.erl | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl
index 09704da..ce1f48e 100644
--- a/src/ebtree/src/ebtree.erl
+++ b/src/ebtree/src/ebtree.erl
@@ -25,6 +25,7 @@
      fold/4,
      fold/5,
      reduce/4,
+     reduce/5,
      full_reduce/2,
      group_reduce/7,
      group_reduce/8,
@@ -413,12 +414,17 @@ group_reduce(Db, #tree{} = Tree, StartKey, EndKey, GroupKeyFun, UserAccFun, User
             end
     end,
     {CurrentGroup, UserAcc1, MapValues, ReduceValues} = fold(Db, Tree, Fun, {NoGroupYet, UserAcc0, [], []}, Options),
-    FinalGroupKey = case CurrentGroup of
-        NoGroupYet -> undefined;
-        _ -> CurrentGroup
-    end,
-    FinalGroupValue = do_reduce(Tree, MapValues, ReduceValues),
-    UserAccFun({FinalGroupKey, FinalGroupValue}, UserAcc1).
+    if
+        MapValues /= [] orelse ReduceValues /= [] ->
+            FinalGroupKey = case CurrentGroup of
+                NoGroupYet -> undefined;
+                _ -> CurrentGroup
+            end,
+            FinalReduction = do_reduce(Tree, MapValues, ReduceValues),
+            UserAccFun({FinalGroupKey, FinalReduction}, UserAcc1);
+        true ->
+            UserAcc1
+    end.
 
 
 %% @doc Finds all key-value pairs for the specified range in forward order.