Safe by default - indexes created by dynamic queries on dynamic data

13 views
Skip to first unread message

Rob Ashton

unread,
Dec 9, 2010, 8:50:31 AM12/9/10
to ravendb
Consider the following query using Lucene syntax because we're
querying un-typed data imported to RavenDB from a system that is CLR-
ignorant

"Sites,ID:3"

A vast majority of these untyped documents don't have a property
called Sites, and yet this is a valid query for those that do.

The dynamic index created looks something like

from doc in docs
from SitesItem in doc.Sites
select new
{
SitesItemID = SitesItem.ID
}

Is there a way to make this safe that will work for us here?

from doc in docs
from SitesItem in doc.Sites
where doc.Sites != null // This isn't going to work because we're
still doing from SitesItem in doc.Sites
select new
{
SitesItemID = SitesItem.ID
}

Bruno Lopes

unread,
Dec 9, 2010, 8:58:10 AM12/9/10
to rav...@googlegroups.com
Couldn't you add some info to the metadata that you then use on the where clause of the index?

Matt Warren

unread,
Dec 9, 2010, 9:28:58 AM12/9/10
to ravendb
dynamic queries on dynamic data nice!!

would the functionality in this thread help?
http://groups.google.com/group/ravendb/browse_thread/thread/b0360d61fdeec3fe

Rob Ashton

unread,
Dec 9, 2010, 9:29:37 AM12/9/10
to ravendb
What kind of info? My point is that

from doc in docs
from item in doc.Collection
where doc.Collection != null

Doesn't actually do what you want it to do, because the from executes
before the where

I guess we could start doing

from doc in docs
from item in (doc.Collection ?? new dynamic[]
{})
select new
{
item.Property
};

That won't work either though, because if item.Property isn't found on
dynamic, it falls over too

I guess a custom dynamic type that just returns another custom dynamic
type when not found

from doc in docs
from item in (doc.Collection ?? new
CustomDynamicObject[]{})
select new
{
item.Property
};

(The problem with *that* is that then that happens in the select
statement too, so you have to add a where clause for each property
being mapped across.

More thoughts? I'm just thinking out loud here - our current strategy
where we just fall over and refuse to run that index isn't really good
enough for dynamic data.

We could just prevent falling over on all dynamic indexes, and just
ignore documents that fail to index silently, that works too.

Rob Ashton

unread,
Dec 9, 2010, 9:31:08 AM12/9/10
to ravendb
Oh, I hadn't seen that Matt - and it's quite recent too - don't know
how I missed it.

Yes, that discussion basically solves this problem if implemented
properly

On Dec 9, 2:28 pm, Matt Warren <mattd...@gmail.com> wrote:
> dynamic queries on dynamic data nice!!
>
> would the functionality in this thread help?http://groups.google.com/group/ravendb/browse_thread/thread/b0360d61f...

Remco Ros

unread,
Dec 9, 2010, 9:35:42 AM12/9/10
to ravendb
the branch transitive-null in ayende's fork fixes this (confirmed).

Rob Ashton

unread,
Dec 9, 2010, 9:40:15 AM12/9/10
to ravendb
Hurrah

Bruno Lopes

unread,
Dec 9, 2010, 9:54:59 AM12/9/10
to rav...@googlegroups.com
Oops, sorry. Somehow my brain parsed the linq query wrong and missed the second from :)
Reply all
Reply to author
Forward
0 new messages