Skip to content
craiggwilson edited this page Apr 21, 2011 · 1 revision

Map Reduce

Map-Reduce is a huge topic. We won’t go into the details here, but basically it is a method to process huge datasets. You can read more here.

Linq

Linq is by far an easier way to compose map-reduce functions. Below is a simple sum of ages.

//Compose a map reduce to get the sum everyone's ages.  

var sum = collection.AsQueryable().Sum(x => x.Age);

Essentially, we’ll just build your map-reduce query for you, translating the necessary parts to javascript. The more crazy you get, the better off you’ll be using the Linq provider.

//Compose a map reduce to get the age range of everyone grouped by the first letter of their last name.

var ageRanges = 
     from p in collection.AsQueryable()
     group p by p.LastName[0] into g
     select new
     {
          FirstLetter = g.Key,
          AverageAge = g.Average(x => x.Age),
          MinAge = g.Min(x => x.Age),
          MaxAge = g.Max(x => x.Age)
     };

Supported Aggregates

We’ll be adding support for more aggregates as they are needed. Below is the list of currently supported aggregates.

  • Count
  • Sum
  • Min
  • Max
  • Average
Clone this wiki locally