Grouping in Result Transformer and Streaming...

76 views
Skip to first unread message

4eyed

unread,
Apr 23, 2014, 11:34:56 AM4/23/14
to rav...@googlegroups.com
So i needed to perform multiple levels of grouping in an index....turns out you can only have one in a Reduce...Along came Result Transformer and that seemed to solve the issue perfectly...but now i am seeing multiple connections from the client side and need to use the streaming api for the results to come back accurately...I thought Result Transformers are processed on the server?

here is my transformer

public class GroupByRetailerTransformer : AbstractTransformerCreationTask<PointDetailReduce>
{
   
public GroupByRetailerTransformer()
   
{
       
TransformResults = results => from result in results
 
group result by result.RetailerId into r
 
select new
 
{
 
RetailerId=r.Key,
 
HighPoints = r.Max(x=>x.TotalPoints),
 
Count = r.Sum (x => x.Count),
 
TotalPoints = r.Sum (x => x.TotalPoints),
 
AveragePoints = (double)r.Sum (x => x.TotalPoints)/(double)r.Sum (x => x.Count)
 
};
 
   
}
}

Then in my code i have 

            var likes = new List<string>{"id1","id2","id3","id4","id5"};
           
var q = CurrentSession.Query<BrandPointReduce>("PointDetail/ByAccountGroupedByRetailer")
           
.TransformWith<GroupByRetailerTransformer, BrandPointReduce>()
           
.Where(r => r.RetailerId.In(likes));
           
var brandstats = new List<BrandPointReduce>();
           
using (var enumerator = MvcApplication.CurrentSession.Advanced.Stream<BrandPointReduce>(q))
           
{


               
while (enumerator.MoveNext())
               
{
                   
BrandPointReduce pd = enumerator.Current.Document;
                    brandstats
.Add(pd);
               
}
           
}


This is causing 5 trips to the server...and i have cases where the likes can be 30 - 50...If i don't use the Stream... i only get back one result and its not even accruate....is there a way to tell the Result Transformer to use streaming?

Chris Marisic

unread,
Apr 23, 2014, 11:41:10 AM4/23/14
to rav...@googlegroups.com

4eyed

unread,
Apr 23, 2014, 12:07:21 PM4/23/14
to rav...@googlegroups.com
great...will get a failing test going...thanks


On Wednesday, April 23, 2014 11:34:56 AM UTC-4, 4eyed wrote:

Oren Eini (Ayende Rahien)

unread,
Apr 23, 2014, 1:08:47 PM4/23/14
to ravendb
You can also just provide a SAZ fiddler output.



Oren Eini

CEO

Mobile: + 972-52-548-6969

Office:  + 972-4-674-7811

Fax:      + 972-153-4622-7811





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

4eyed

unread,
Apr 23, 2014, 2:32:19 PM4/23/14
to rav...@googlegroups.com
ok, i have a test, but how do i track the number of requests in embeded mode?


On Wednesday, April 23, 2014 11:34:56 AM UTC-4, 4eyed wrote:

Oren Eini (Ayende Rahien)

unread,
Apr 23, 2014, 3:24:27 PM4/23/14
to ravendb
Session.Advanced.NumberOfRequests



Oren Eini

CEO

Mobile: + 972-52-548-6969

Office:  + 972-4-674-7811

Fax:      + 972-153-4622-7811





--
Reply all
Reply to author
Forward
0 new messages