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
Map/Reduce index with DateTime.Now
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
  8 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
 
keperro  
View profile  
 More options Aug 9 2012, 7:49 pm
From: keperro <sandravici...@gmail.com>
Date: Thu, 9 Aug 2012 16:49:39 -0700 (PDT)
Local: Thurs, Aug 9 2012 7:49 pm
Subject: Map/Reduce index with DateTime.Now

Hi all,

I am having some problems creating map/reduce indexes.
I have the following structure defining my DEBT documents:

public class Debt
{
      public string DebtorName {get;set;}
      public DateTime DueDate {get;set;}
      public decimal Amount {get;set,}  

}

I want to group all the debts by debtor name up to now. So basically, I want to know how much a debtor owes until now, adding up all the amounts of his debts that are due to be paid.

I have tried to create an index for that but I am not sure how to do it. I understand why I cannot use DateTime.Now in my index.

    public class PresentDebts : AbstractIndexCreationTask<Debt>
    {
        public   PresentDebts  ()
        {
            Map = debts=> from debt in debts
                               select new
                                          {
                                              DebtorName = debt.DebtorName,
                                              Amount = debt.Amount
                                          };

            Reduce = results => from result in results
                                group result by result.DebtorName
                                    into g
                                    select new
                                               {
                                                   DebtorName = g.Key,
                                                   Amount = g.Sum(x => x.Amount)
                                               };
        }
    }

How I use my index:

           var debts = session.Query<Debt, PresentDebts>().Where(x => x.DueDate < DateTime.Now);

It returns 0 results. Is the "where" clause applied to the dataset being mapped in the index or afterwards on the grouped results ?

What is the best approach for this situation? Is it possible to do it with an index?
I have way more than 128 debts prior to today in my db, so I just wanted to avoid grabbing them all, and group them outside the db.

Thanks.


 
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 Aug 10 2012, 7:02 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Fri, 10 Aug 2012 14:02:01 +0300
Local: Fri, Aug 10 2012 7:02 am
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

This is applied AFTER the index have run.
What you probably want to do is to group by the debtor and the debt date
(usually month), then you can query the previous debts.


 
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.
keperro  
View profile  
 More options Aug 10 2012, 10:02 am
From: keperro <kepe...@gmail.com>
Date: Fri, 10 Aug 2012 07:02:00 -0700 (PDT)
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

But I still need to group them all in one debt per debtor afterwards, and I
don't know how to do it.
Modifying my index as you said grouping by debtor and debt date, and
filtering by previous debts afterwards, I still get a collection of debts
per debtor and what I want is a unique debt per debtor with all the amounts
added up.

I would still need something like this but that is not supported because of
the GroupBy. I wanted to avoid doing ToList() before the GroupBy.

var debts = session.Query<Debt, PresentDebts>().Where(x => x.DueDate <
DateTime.Now).GroupBy(x => x.DebtorName).Select(g => new Debt{ DebtorName =
g.Key, Amount = g.Sum(x => x.Amount});

Is it possible to do it without fetching them all from the db?

El viernes, 10 de agosto de 2012 12:02:01 UTC+1, Oren Eini escribió:


 
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 Aug 11 2012, 1:03 pm
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Sat, 11 Aug 2012 20:03:48 +0300
Local: Sat, Aug 11 2012 1:03 pm
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

You do the second order grouping after you load the data in a transform
results.


 
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.
keperro  
View profile  
 More options Aug 11 2012, 2:47 pm
From: keperro <kepe...@gmail.com>
Date: Sat, 11 Aug 2012 11:47:06 -0700 (PDT)
Local: Sat, Aug 11 2012 2:47 pm
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

Sorry but I am quite new in raven! How does it work exactly?
Do you mean that I should do my filtering by past debt dates in the
transform results itself? And then group by debtor name in the transform
results and aggregate all the amounts? My index becoming something like:

  TransformResults= (database, results) => from result in results
                               where result.DueDate.Date < DateTime.Now.Date
                                group result by result.DebtorName
                                    into g
                                    select new
                                               {
                                                   DebtorName = g.Key,
                                                   Amount = g.Sum(x =>
x.Amount)
                                               };

And then my query:
 var debts = session.Query<Debt, PresentDebts>();

Is it what you are suggesting? Sorry but I am a complete newbie!

Thanks again for your reply.


 
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 Aug 12 2012, 6:37 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Sun, 12 Aug 2012 13:37:22 +0300
Local: Sun, Aug 12 2012 6:37 am
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

No, like this:

TransformResults= (database, results) => from result in results

                                group result by result.DebtorName
                                    into g
                                    select new
                                               {
                                                   DebtorName = g.Key,
                                                   Amount = g.Sum(x =>
x.Amount)
                                               };

 var debts = session.Query<Debt, PresentDebts>().Where(x=>x.Date <
DateTime.Today);


 
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.
keperro  
View profile  
 More options Aug 12 2012, 6:50 am
From: keperro <kepe...@gmail.com>
Date: Sun, 12 Aug 2012 03:50:58 -0700 (PDT)
Local: Sun, Aug 12 2012 6:50 am
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

Ok, thanks I will try that.
How does the transform results work then? It transforms the results after
the filtering?


 
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 Aug 12 2012, 6:53 am
From: "Oren Eini (Ayende Rahien)" <aye...@ayende.com>
Date: Sun, 12 Aug 2012 13:53:55 +0300
Local: Sun, Aug 12 2012 6:53 am
Subject: Re: [RavenDB] Map/Reduce index with DateTime.Now

Yes


 
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 »