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/29 22:21:00 UTC

[couchdb] branch prototype/fdb-layer-ebtree-views updated: MORE WIP

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


The following commit(s) were added to refs/heads/prototype/fdb-layer-ebtree-views by this push:
     new 008f75b  MORE WIP
008f75b is described below

commit 008f75b9085d6ca1bac9a767ea66c6dcece01ad7
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Wed Jul 29 17:22:00 2020 -0500

    MORE WIP
---
 src/couch_views/src/couch_views_fdb.erl       |  5 +-
 src/couch_views/src/couch_views_reader.erl    |  4 +-
 src/couch_views/test/couch_views_red_test.erl | 81 ++++++++++++++++++++++++++-
 3 files changed, 85 insertions(+), 5 deletions(-)

diff --git a/src/couch_views/src/couch_views_fdb.erl b/src/couch_views/src/couch_views_fdb.erl
index 7f6dcfe..6251c49 100644
--- a/src/couch_views/src/couch_views_fdb.erl
+++ b/src/couch_views/src/couch_views_fdb.erl
@@ -257,10 +257,11 @@ fold_red_idx(TxDb, View, Idx, Options, Callback, Acc0) ->
                     EBtreeOpts
                 );
         rev ->
-            % Start/End keys swapped on purpose because ebtree
+            % Start/End keys swapped on purpose because ebtree. Also
+            % inclusive_start for same reason.
             EBtreeOpts = [
                 {dir, rev},
-                {inclusive_end, InclusiveEnd}
+                {inclusive_start, InclusiveEnd}
             ],
             ebtree:group_reduce(
                     Tx,
diff --git a/src/couch_views/src/couch_views_reader.erl b/src/couch_views/src/couch_views_reader.erl
index 0114f0d..57e0abf 100644
--- a/src/couch_views/src/couch_views_reader.erl
+++ b/src/couch_views/src/couch_views_reader.erl
@@ -213,7 +213,7 @@ handle_red_row(Key0, Value0, Acc) ->
     } = Acc,
 
     Key1 = case Key0 of
-        group_exact -> null;
+        undefined -> null;
         _ -> Key0
     end,
     Value1 = maybe_finalize(Finalizer, Value0),
@@ -302,7 +302,7 @@ make_group_key_fun(red, exact) ->
 
 make_group_key_fun(red, 0) ->
     [
-        {group_key_fun, fun({_Key, _DocId}) -> group_exact end}
+        {group_key_fun, fun({_Key, _DocId}) -> undefined end}
     ];
 
 make_group_key_fun(red, N) when is_integer(N), N > 0 ->
diff --git a/src/couch_views/test/couch_views_red_test.erl b/src/couch_views/test/couch_views_red_test.erl
index d1274e8..579e53b 100644
--- a/src/couch_views/test/couch_views_red_test.erl
+++ b/src/couch_views/test/couch_views_red_test.erl
@@ -42,10 +42,17 @@ map_views_test_() ->
             fun teardown/1,
             [
                 ?TDEF(should_reduce),
+                ?TDEF(should_reduce_rev),
                 ?TDEF(should_reduce_start_key),
+                ?TDEF(should_reduce_start_key_rev),
                 ?TDEF(should_reduce_end_key),
+                ?TDEF(should_reduce_end_key_rev),
+                ?TDEF(should_reduce_inclusive_end_false),
+                ?TDEF(should_reduce_inclusive_end_false_rev),
                 ?TDEF(should_reduce_start_and_end_key),
-                ?TDEF(should_reduce_empty_range)
+                ?TDEF(should_reduce_start_and_end_key_rev),
+                ?TDEF(should_reduce_empty_range),
+                ?TDEF(should_reduce_empty_range_rev)
             ]
         }
     }.
@@ -57,6 +64,15 @@ should_reduce() ->
     ?assertEqual(Expect, Result).
 
 
+should_reduce_rev() ->
+    Args = #{
+        direction => rev
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 10}]}]},
+    ?assertEqual(Expect, Result).
+
+
 should_reduce_start_key() ->
     Args = #{
         start_key => 4
@@ -66,6 +82,16 @@ should_reduce_start_key() ->
     ?assertEqual(Expect, Result).
 
 
+should_reduce_start_key_rev() ->
+    Args = #{
+        direction => rev,
+        start_key => 4
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 4}]}]},
+    ?assertEqual(Expect, Result).
+
+
 should_reduce_end_key() ->
     Args = #{
         end_key => 6
@@ -75,6 +101,37 @@ should_reduce_end_key() ->
     ?assertEqual(Expect, Result).
 
 
+should_reduce_end_key_rev() ->
+    Args = #{
+        direction => rev,
+        end_key => 6
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 5}]}]},
+    ?assertEqual(Expect, Result).
+
+
+should_reduce_inclusive_end_false() ->
+    Args = #{
+        end_key => 6,
+        inclusive_end => false
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 5}]}]},
+    ?assertEqual(Expect, Result).
+
+
+should_reduce_inclusive_end_false_rev() ->
+    Args = #{
+        direction => rev,
+        end_key => 6,
+        inclusive_end => false
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 4}]}]},
+    ?assertEqual(Expect, Result).
+
+
 should_reduce_start_and_end_key() ->
     Args = #{
         start_key => 3,
@@ -85,9 +142,31 @@ should_reduce_start_and_end_key() ->
     ?assertEqual(Expect, Result).
 
 
+should_reduce_start_and_end_key_rev() ->
+    Args = #{
+        direction => rev,
+        start_key => 5,
+        end_key => 3
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 3}]}]},
+    ?assertEqual(Expect, Result).
+
+
 should_reduce_empty_range() ->
     Args = #{
         start_key => 100000,
+        end_key => 100001
+    },
+    Result = run_query(<<"baz_count">>, Args),
+    Expect = {ok, [{row, [{key, null}, {value, 0}]}]},
+    ?assertEqual(Expect, Result).
+
+
+should_reduce_empty_range_rev() ->
+    Args = #{
+        direction => rev,
+        start_key => 100001,
         end_key => 100000
     },
     Result = run_query(<<"baz_count">>, Args),