Skip to content

Instantly share code, notes, and snippets.

@peschkaj
Created March 25, 2012 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peschkaj/2200634 to your computer and use it in GitHub Desktop.
Save peschkaj/2200634 to your computer and use it in GitHub Desktop.
MapReduce Index and GetObjects<T>
using System;
using System.Linq;
using System.Threading;
using System.Web;
using CorrugatedIron;
using CorrugatedIron.Comms;
using CorrugatedIron.Config;
using CorrugatedIron.Models;
using CorrugatedIron.Models.MapReduce;
using CorrugatedIron.Models.MapReduce.Inputs;
using CorrugatedIron.Util;
using CorrugatedIron.Extensions;
namespace TestMapReduce
{
public class UserInfo
{
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string CompanyId { get; set; }
}
internal class Program
{
private static void Main(string[] args)
{
IRiakEndPoint Cluster;
IRiakClient Client;
IRiakClusterConfiguration ClusterConfig;
const string MrContentType = RiakConstants.ContentTypes.ApplicationJson;
ClusterConfig = RiakClusterConfiguration.LoadFromConfig("riakLoadTestConfiguration");
Cluster = new RiakCluster(ClusterConfig, new RiakConnectionFactory());
Client = Cluster.CreateClient();
var user = new UserInfo {CompanyId = "corp", Email = "jeremiah.peschka@gmail.com", FirstName = "jeremiah", LastName = "peschka"};
var o = new RiakObject("test", user.Email, user);
o.AddBinIndex("email", user.Email);
Client.Put(o);
Thread.Sleep(1000);
var input = new RiakBinIndexEqualityInput("test", "email_bin", user.Email);
var mr = new RiakMapReduceQuery {ContentType = MrContentType};
mr.Inputs(input)
.MapJs(m => m.Name("Riak.mapValuesJson")
.Keep(true));
var result = Client.MapReduce(mr);
var phases = result.Value.PhaseResults;
var infos = phases.Last().GetObjects<UserInfo[]>().First();
var info = infos[0];
Console.WriteLine(info.Email);
Console.WriteLine(user.Email);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment