Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Bug on Map/Reduce over "inner" entities of a document? (build 910 and 888)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Bruno Lopes  
View profile  
 More options May 6 2012, 11:02 pm
From: Bruno Lopes <brunomlo...@gmail.com>
Date: Mon, 7 May 2012 04:02:14 +0100
Local: Sun, May 6 2012 11:02 pm
Subject: Bug on Map/Reduce over "inner" entities of a document? (build 910 and 888)

Hello all,

I think I hit a bit of non-intuitive behaviour for ravendb and I'd like
some help in figuring it out.
When I store a document and create an index with counts for an given inner
property of that document, the counts add up whenever that document is
changed, instead of calculating properly.

The model is below at [1], and the index is at [2]. Project instances are
entirely saved as an aggregate root, and I index over tasks per user to get
a count.

I understand that it might make sense to store each entity separately, but
I was building this as a sample for a presentation to guide some discussion
around different ways of modelling data and it might make sense on some
domains. Also, my impression is that this would also cause issues with
models like tag-counts...

I've created a console application using an in-memory store that can serve
as a test with build 910 (and I've caught this also on 888). It's up at
https://gist.github.com/2625592 .

I've also tried de-normalizing the owner into ownerid and ownername in case
that was the issue, bit the error remains.

My feeling is that it's a bug, but I'm not positive.

Ideas?

[1]-
   public class Project
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public IList<Activity> Activities { get; set; }

        public Project()
        {
            Activities = new List<Activity>();
        }
    }

    public class Activity
    {
        public string Name { get; set; }
        public Person Owner { get; set; }
        public IList<Task> Tasks { get; set; }

        public Activity()
        {
            Tasks = new List<Task>();
        }
    }

    public class Task
    {
        public string Name { get; set; }
        public Person Owner { get; set; }
        public bool Done { get; set; }
    }

    public class Person
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }

[2]-
   public class TasksCount_ForPerson : AbstractIndexCreationTask<Project,
TasksCount_ForPerson.Result>
    {
        public class Result
        {
            public Person Owner { get; set; }
            public int Count { get; set; }
        }

        public TasksCount_ForPerson()
        {
            Map = projects =>
                projects
                .SelectMany(p => p.Activities)
                .SelectMany(a => a.Tasks)
                    .Select(task =>
                            new
                            {
                                task.Owner,
                                Count = 1
                            }
                    );

            Reduce =
                results => results
                    .GroupBy(g => g.Owner.Id)
                    .Select(p => new
                    {
                        Owner = p.Select(r => r.Owner).First(),
                        Count = p.Sum(result => result.Count)
                    });
        }
    }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile  
 More options May 7 2012, 1:37 pm
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Mon, 7 May 2012 20:37:29 +0300
Local: Mon, May 7 2012 1:37 pm
Subject: Re: [RavenDB] Bug on Map/Reduce over "inner" entities of a document? (build 910 and 888)

Okay, I found the issue.
It is a bug in the way we are handling getting the document id in complex
scenarios.

The problem is here:

Map = projects =>
 projects
.SelectMany(p => p.Activities)
.SelectMany(a => a.Tasks)
 .Select(task =>
new
{
 OwnerId = task.Owner.Id,
Count = 1
 }
);

Which we re-write to be:

Map = projects =>
projects
.SelectMany(p => p.Activities)
 .SelectMany(a => a.Tasks)
.Select(task =>
new
 {
__document_id = task.__document_id,
OwnerId = task.Owner.Id,
 Count = 1

}

);

Obviously, task doesn't have this property.

The bug is that we didn't properly detected an error on this issue.

You can fix the index by using:

Map = projects => from project in projects
                  from task in project.Activities.SelectMany(a => a.Tasks)
                  select new
                  {
                  OwnerId = task.Owner.Id,
                  Count = 1
                  };


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bruno Lopes  
View profile  
 More options May 7 2012, 4:47 pm
From: Bruno Lopes <brunomlo...@gmail.com>
Date: Mon, 7 May 2012 13:47:32 -0700 (PDT)
Local: Mon, May 7 2012 4:47 pm
Subject: Re: [RavenDB] Bug on Map/Reduce over "inner" entities of a document? (build 910 and 888)

Okay, thanks, that fixed it.

Out of curiosity, was I supposed to be able to add Sort(t => t.Owner.Name,
SortOptions.String) to the index and then to do .OrderBy(r => r.Owner.Name)
on a linq query?

Attempting it fails with  "Additional information: The field 'Owner_Name'
is not indexed, cannot sort on fields that are not indexed", which makes
sense, but I was hoping the linq statement would end up being translated
sucessfully (Owner.Name being Owner_Name)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Oren Eini (Ayende Rahien)  
View profile  
 More options May 7 2012, 4:54 pm
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Mon, 7 May 2012 23:54:08 +0300
Local: Mon, May 7 2012 4:54 pm
Subject: Re: [RavenDB] Bug on Map/Reduce over "inner" entities of a document? (build 910 and 888)

No, that won't work with the output you had.
Owner would get stored as a single item, not as a object that can be sorted
upon.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »