Index results incorrect

39 views
Skip to first unread message

David Prothero

unread,
Nov 24, 2015, 9:40:50 AM11/24/15
to RavenDB - 2nd generation document database
I have the following index definition in my C# project:
public class HomeownerRegistrations_AverageCost : AbstractIndexCreationTask<HomeownerRegistration, HomeownerRegistrations_AverageCost.Result>
{
 
public class Result
 
{
   
public decimal Cost { get; set; }
   
public int Count { get; set; }
 
}
   
 
public HomeownerRegistrations_AverageCost()
 
{
   
Map = homeownerRegistrations =>
     
from homeowner in homeownerRegistrations
     
where homeowner.Status.StartsWith("Paid")
     
select new
     
{
       
Cost = homeowner.Receipts.GrandTotal,
       
Count = 1
     
};


   
Reduce = results =>
     
from result in results
     
group result by 0
     
into g
      let cost
= g.Sum(x => x.Cost)
      let count
= g.Sum(x => x.Count)
     
select new
     
{
       
Cost = cost/count,
       
Count = count
     
};
 
}
}

I can confirm that the results it produces match a manual Excel calculation:



However, at some unknown point, the index in RavenDB changed to an incorrect calculation (correct Count, incorrect Cost):



RavenDB, however, is showing 0 stale indexes.

When I delete and re-create the index the results are correct again. Why did this happen?

David

Grisha Kotler

unread,
Nov 24, 2015, 12:28:37 PM11/24/15
to rav...@googlegroups.com
What build are you using?

Did you look at the map-reduce visualizer?

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

Grisha Kotler l RavenDB Core Team Developer Mobile: +972-54-586-8647

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

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



David

--
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.

David Prothero

unread,
Nov 24, 2015, 2:40:03 PM11/24/15
to RavenDB - 2nd generation document database
Build 3660. I did not think to try the map-reduce visualizer when it was showing the wrong results. Now that I recreated the index, it's showing the correct results, and the map-reduce visualizer confirms that.

David

Oren Eini (Ayende Rahien)

unread,
Nov 25, 2015, 7:44:42 AM11/25/15
to ravendb
Use:

 group result by 0
      into g
      let cost = g.Sum(x => x.Cost)
      let count = g.Sum(x => x.Count)
      select new
      {
        Cost = cost
        AvgCost = cost/count,
        Count = count
      };

Map/Reduce is recursive, but your recurse doesn't account for that.
When we update the map/reduce, we lose the value.

Hibernating Rhinos Ltd  

Oren Eini l CEO Mobile: + 972-52-548-6969


David

--
Reply all
Reply to author
Forward
0 new messages