You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wi...@apache.org on 2020/01/17 11:40:28 UTC

[couchdb] branch mango_index_consistency_error created (now 802446c)

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

willholley pushed a change to branch mango_index_consistency_error
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 802446c  Handle not_found atom in mango selector

This branch includes the following new commits:

     new 802446c  Handle not_found atom in mango selector

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 01/01: Handle not_found atom in mango selector

Posted by wi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

willholley pushed a commit to branch mango_index_consistency_error
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 802446c273f14eef3198ff761ee81d95eaf6c21a
Author: Will Holley <wi...@gmail.com>
AuthorDate: Fri Jan 17 11:35:54 2020 +0000

    Handle not_found atom in mango selector
    
    When Mango text indexes fetch the doc object for each hit, a not_found
    atom may be returned if the indexed document revision no longer exists
    in the primary index (see mango_cursor_text:get_json_docs/2).
    
    This is in turn passed to mango_selector:match which would throw
    a function_clause error. This commit adds an explicit clause to
    mango_selector:match which will return false if not_found is passed.
---
 src/mango/src/mango_selector.erl | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/mango/src/mango_selector.erl b/src/mango/src/mango_selector.erl
index 005a6af..c804dba 100644
--- a/src/mango/src/mango_selector.erl
+++ b/src/mango/src/mango_selector.erl
@@ -53,6 +53,12 @@ normalize(Selector) ->
 % This assumes that the Selector has been normalized.
 % Returns true or false.
 
+
+% not_found implies the doc no longer exists
+% see mango_cursor_text:get_json_docs/2
+match_int(_, not_found) ->
+    false;
+
 % An empty selector matches any value.
 match({[]}, _) ->
     true;
@@ -63,6 +69,7 @@ match(Selector, #doc{body=Body}) ->
 match(Selector, {Props}) ->
     match(Selector, {Props}, fun mango_json:cmp/2).
 
+
 % Convert each operator into a normalized version as well
 % as convert an implict operators into their explicit
 % versions.
@@ -985,4 +992,14 @@ has_required_fields_or_nested_or_false_test() ->
     Normalized = normalize(Selector),
     ?assertEqual(false, has_required_fields(Normalized, RequiredFields)).
 
+% match tests
+match_not_found_test() ->
+    Selector = {[]},
+    ?assertEqual(false, match(Selector, not_found)).
+
+match_all_test() ->
+    Selector = {[]},
+    Doc = #doc{body={[]}},
+    ?assertEqual(true, match(Selector, Doc)).
+
 -endif.