Not null query translated wrong?

59 views
Skip to first unread message

Anders Wåglund

unread,
May 8, 2012, 10:38:59 AM5/8/12
to rav...@googlegroups.com
Running build 701 I have a dynamic query with:
.Where(x => x.Converted || x.Report != null)

This gets translated to:
(Converted:true OR -Report:[[NULL_VALUE]] AND Report:*)

Which doesn't seem to produce correct results, that is I do not get any documents where Report is null.


 

Itamar Syn-Hershko

unread,
May 8, 2012, 12:03:38 PM5/8/12
to rav...@googlegroups.com

Can you please try this with the latest unstable?

Anders Wåglund

unread,
May 9, 2012, 1:37:05 AM5/9/12
to rav...@googlegroups.com
It does not work in build 910

Anders Wåglund

unread,
May 9, 2012, 1:50:23 AM5/9/12
to rav...@googlegroups.com
Or 926..

I'll try to create a failing test

Anders Wåglund

unread,
May 9, 2012, 2:46:46 AM5/9/12
to rav...@googlegroups.com
The following test fails using the latest code from github.com/ravendb/ravendb

public void Fails()
{
    using (var store = NewDocumentStore())
    {
        using (var s = store.OpenSession())
        {
            s.Store(new Dummy { Boolean = false, Object = null });
            s.Store(new Dummy { Boolean = true, Object = null });
            s.Store(new Dummy { Boolean = false, Object = new Dummy() });
            s.Store(new Dummy { Boolean = true, Object = new Dummy() });
            s.SaveChanges();
        }
        using (var s = store.OpenSession())
        {
            var objects = s.Query<Dummy>()
                .Customize(x => x.WaitForNonStaleResults())
                .Where(x => x.Boolean || x.Object != null)
                .ToArray();

            Assert.Equal(3, objects.Length); // objects.Length is 2
        }
    }
}

public class Dummy
{
    public bool Boolean { get; set; }
    public Dummy Object { get; set; }

Matt Warren

unread,
May 9, 2012, 4:44:48 AM5/9/12
to rav...@googlegroups.com
The problems is that the generated query doesn't have the brackets in the right place, if you put code below into your test it works as expected:

	var test = s.Advanced.LuceneQuery<Dummy>("Temp/Dummies/ByBooleanAndObject")
		.Where("Boolean:true OR (-Object:[[NULL_VALUE]] AND Object:*)")
		.ToList();
	Assert.Equal(3, test.Count);

Note the brackets around the ".. AND .." statement to change the precedence. I think this is a bug in RavenDB as it's not generating the right query

Oren Eini (Ayende Rahien)

unread,
May 9, 2012, 6:51:30 AM5/9/12
to rav...@googlegroups.com
Yep, fixed now, will be in the next build

Anders Wåglund

unread,
May 9, 2012, 7:02:59 AM5/9/12
to rav...@googlegroups.com
Great!

Anders Wåglund

unread,
May 9, 2012, 8:45:59 AM5/9/12
to rav...@googlegroups.com
Will there be a new stable candidate with this fix, or was it too late?


On Wednesday, May 9, 2012 12:51:30 PM UTC+2, Oren Eini wrote:

Oren Eini (Ayende Rahien)

unread,
May 9, 2012, 8:59:36 AM5/9/12
to rav...@googlegroups.com
Yeah, we are currently working on stabalizing things, and there will be a stable soon
Reply all
Reply to author
Forward
0 new messages