You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2020/04/21 20:44:19 UTC

[couchdb] branch fix-operator-empty-array updated (7dcbdd8 -> 37190bb)

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

tonysun83 pushed a change to branch fix-operator-empty-array
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    omit 7dcbdd8  fix operator issue with empty arrays
     new 37190bb  fix operator issue with empty arrays

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (7dcbdd8)
            \
             N -- N -- N   refs/heads/fix-operator-empty-array (37190bb)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 src/mango/src/mango_selector.erl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)


[couchdb] 01/01: fix operator issue with empty arrays

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

tonysun83 pushed a commit to branch fix-operator-empty-array
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 37190bb02bb449be129f85c087d99d1eaec8c868
Author: Tony Sun <to...@gmail.com>
AuthorDate: Tue Apr 21 13:36:10 2020 -0700

    fix operator issue with empty arrays
    
    Previously, in https://github.com/apache/couchdb/pull/1783, the logic
    was wrong in relation to how certain operators interacted with empty
    arrays. We modify this logic to make it such that:
    
    {"foo":"bar", "bar":{"$in":[]}}
    and
    {"foo":"bar", "bar":{"$all":[]}}
    
    should return 0 results.
---
 src/mango/src/mango_selector.erl          |  4 ++--
 src/mango/test/21-empty-selector-tests.py | 24 +++++++++++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/mango/src/mango_selector.erl b/src/mango/src/mango_selector.erl
index 3ea83c2..e884dc5 100644
--- a/src/mango/src/mango_selector.erl
+++ b/src/mango/src/mango_selector.erl
@@ -421,7 +421,7 @@ match({[{<<"$not">>, Arg}]}, Value, Cmp) ->
     not match(Arg, Value, Cmp);
 
 match({[{<<"$all">>, []}]}, _, _) ->
-    true;
+    false;
 % All of the values in Args must exist in Values or
 % Values == hd(Args) if Args is a single element list
 % that contains a list.
@@ -506,7 +506,7 @@ match({[{<<"$gt">>, Arg}]}, Value, Cmp) ->
     Cmp(Value, Arg) > 0;
 
 match({[{<<"$in">>, []}]}, _, _) ->
-    true;
+    false;
 match({[{<<"$in">>, Args}]}, Values, Cmp) when is_list(Values)->
     Pred = fun(Arg) ->
         lists:foldl(fun(Value,Match) ->
diff --git a/src/mango/test/21-empty-selector-tests.py b/src/mango/test/21-empty-selector-tests.py
index beb222c..31ad8e6 100644
--- a/src/mango/test/21-empty-selector-tests.py
+++ b/src/mango/test/21-empty-selector-tests.py
@@ -35,14 +35,36 @@ def make_empty_selector_suite(klass):
             docs = self.db.find({"age": 22, "$or": []})
             assert len(docs) == 1
 
+        def test_empty_array_in_with_age(self):
+            resp = self.db.find({"age": 22, "company": {"$in": []}}, explain=True)
+            self.assertEqual(resp["index"]["type"], klass.INDEX_TYPE)
+            docs = self.db.find({"age": 22, "company": {"$in": []}})
+            assert len(docs) == 0
+
         def test_empty_array_and_with_age(self):
             resp = self.db.find(
-                {"age": 22, "$and": [{"b": {"$all": []}}]}, explain=True
+                {"age": 22, "$and": []}, explain=True
             )
             self.assertEqual(resp["index"]["type"], klass.INDEX_TYPE)
             docs = self.db.find({"age": 22, "$and": []})
             assert len(docs) == 1
 
+        def test_empty_array_all_age(self):
+            resp = self.db.find(
+                {"age": 22, "company": {"$all": []}}, explain=True
+            )
+            self.assertEqual(resp["index"]["type"], klass.INDEX_TYPE)
+            docs = self.db.find({"age": 22, "company": {"$all": []}})
+            assert len(docs) == 0
+
+        def test_empty_array_nested_all_with_age(self):
+            resp = self.db.find(
+                {"age": 22, "$and": [{"company": {"$all": []}}]}, explain=True
+            )
+            self.assertEqual(resp["index"]["type"], klass.INDEX_TYPE)
+            docs = self.db.find( {"age": 22, "$and": [{"company": {"$all": []}}]})
+            assert len(docs) == 0
+
         def test_empty_arrays_complex(self):
             resp = self.db.find({"$or": [], "a": {"$in": []}}, explain=True)
             self.assertEqual(resp["index"]["type"], klass.INDEX_TYPE)