Bug on ContainsAny

45 views
Skip to first unread message

Bruno Lopes

unread,
Jul 22, 2016, 11:32:34 AM7/22/16
to RavenDB - 2nd generation document database
Both tests at the end crash the request. Haven't tested ContainsAll.

On 3.0.30143 it crashes with something similar to:

Url: "/indexes/Index?&query=%28IsDeleted%3Afalse%29%20AND%20%28%20%40in%3C__document_id%3E%3A%28users%2F42%29%20%20OR%20%29&pageSize=128&SortHint-IsDeleted=String"

Lucene.Net.QueryParsers.ParseException: Could not parse: '(IsDeleted:false) AND ( @in<__document_id>:(users/42)  OR )' ---> Lucene.Net.QueryParsers.ParseException: Cannot parse '(IsDeleted:false) AND ( @in<__document_id>:(users/42)  OR )': Encountered " ")" ") "" at line 1, column 58.

On 3.5.0-rc-35161 it crashes with:

Url: "/indexes/Index?&query=%28IsDeleted%3Afalse%29%20AND%20%28%20%20OR%20%40in%3C__document_id%3E%3A%28users%2F42%29%20%29&pageSize=128&SortHint-IsDeleted=String"

Lucene.Net.QueryParsers.ParseException: Could not parse: '(IsDeleted:false) AND (  OR @in<__document_id>:(users/42) )' ---> Lucene.Net.QueryParsers.ParseException: Syntax error, unexpected OR


This is because enumerable.ContainsAny(x) generates an empty clause, which is an issue when it's part of an ||. 
It's not a major issue (I can work around it by checking the array before the condition), but it can surprise someone who's not expecting it.


Code:


    public class Class1 : RavenTestBase
    {
        [Fact]
        public void WhenArgumentForContainsAnyIsEmptyAndIsFirstArgumentOfOr_DoesNotProduceEmptyClause()
        {
            var store = NewDocumentStore();
            new Index().Execute(store);
            using (var session = store.OpenSession())
            {
                IEnumerable<string> rolesToSearch = new string[] {};
                IEnumerable<string> userIdsToSearch = new string[] {"users/42"};
                session.Query<User, Index>()
                    .Where(user => !user.IsDeleted)
                    .Where(user => user.RoleIds.ContainsAny(rolesToSearch) || user.Id.In(userIdsToSearch))
                    .ToList();
            }
        }

        [Fact]
        public void WhenArgumentForContainsAnyIsEmptyAndIsLastArgumentOfOr_DoesNotProduceEmptyClause()
        {
            var store = NewDocumentStore();
            new Index().Execute(store);
            using (var session = store.OpenSession())
            {
                IEnumerable<string> rolesToSearch = new string[] {};
                IEnumerable<string> userIdsToSearch = new string[] {"users/42"};
                session.Query<User, Index>()
                    .Where(user => !user.IsDeleted)
                    .Where(user => user.Id.In(userIdsToSearch) || user.RoleIds.ContainsAny(rolesToSearch))
                    .ToList();
            }
        }

        class User
        {
            public string Id { get; set; }
            public string UserName { get; set; }
            public string[] RoleIds { get; set; }
            public bool IsDeleted { get; set; }
        }

        class Index : AbstractIndexCreationTask<User>
        {
            public Index()
            {
                Map = users => from user in users
                    select new
                    {
                        user.UserName,
                        user.RoleIds,
                        user.IsDeleted
                    };
            }
        }




Tal Weiss

unread,
Jul 22, 2016, 11:36:31 AM7/22/16
to RavenDB - 2nd generation document database

Thanks we will look at the issue


--
You received this message because you are subscribed to the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ravendb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Iftah Ben Zaken

unread,
Jul 24, 2016, 9:07:19 AM7/24/16
to rav...@googlegroups.com
Hi Bruno,

We reproduced the issue, you can keep track in the link below:

http://issues.hibernatingrhinos.com/issue/RavenDB-4877

Thanks,
Iftah

Hibernating Rhinos Ltd  cid:image001.png@01CF95E2.8ED1B7D0

Iftah Ben Zaken l Core Team Developer Mobile:+972-52-942-7429

Office: +972-4-622-7811 l Fax: +972-153-4-622-7811 l Skype: iftahbe

RavenDB paving the way to "Data Made Simplehttp://ravendb.net

Bruno Lopes

unread,
Jul 24, 2016, 10:28:33 AM7/24/16
to ravendb
Followed, thanks.

Bruno

--
You received this message because you are subscribed to a topic in the Google Groups "RavenDB - 2nd generation document database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ravendb/vyh_jze2gmI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ravendb+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages