Skip to content

Commit

Permalink
fixed javascript translator to for map reduce.
Browse files Browse the repository at this point in the history
  • Loading branch information
craiggwilson authored and lanwin committed May 12, 2010
1 parent efe2e5e commit 56850c0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
6 changes: 6 additions & 0 deletions MongoDB-CSharp.sln
Expand Up @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Tests", "source\Mon
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "tools\Benchmark\Benchmark.csproj", "{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.DataContext", "source\MongoDB.DataContext\MongoDB.DataContext.csproj", "{5E413F58-FA04-4C9A-96B9-12AD43731C24}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -53,6 +55,10 @@ Global
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Release|Any CPU.Build.0 = Release|Any CPU
{5E413F58-FA04-4C9A-96B9-12AD43731C24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E413F58-FA04-4C9A-96B9-12AD43731C24}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E413F58-FA04-4C9A-96B9-12AD43731C24}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E413F58-FA04-4C9A-96B9-12AD43731C24}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 9 additions & 7 deletions source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs
@@ -1,31 +1,33 @@
using System.Collections.Generic;

using MongoDB.Attributes;

namespace MongoDB.IntegrationTests.Linq
{
public class Person
{
//[MongoAlias("fn")]
[MongoAlias("fn")]
public string FirstName { get; set; }

//[MongoAlias("ln")]
[MongoAlias("ln")]
public string LastName { get; set; }

//[MongoAlias("age")]
[MongoAlias("age")]
public int Age { get; set; }

//[MongoAlias("add")]
[MongoAlias("add")]
public Address PrimaryAddress { get; set; }

//[MongoAlias("otherAdds")]
[MongoAlias("otherAdds")]
public List<Address> Addresses { get; set; }

//[MongoAlias("emps")]
[MongoAlias("emps")]
public int[] EmployerIds { get; set; }
}

public class Address
{
//[MongoAlias("city")]
[MongoAlias("city")]
public string City { get; set; }

public bool IsInternational { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs
Expand Up @@ -159,8 +159,8 @@ public void Count_without_predicate()
public void DocumentQuery()
{
var people = (from p in DocumentCollection.Linq()
where p.Key("Age") > 21
select (string)p["FirstName"]).ToList();
where p.Key("age") > 21
select (string)p["fn"]).ToList();

Assert.AreEqual(2, people.Count);
}
Expand Down
6 changes: 1 addition & 5 deletions source/MongoDB/Linq/MongoQueryProvider.cs
Expand Up @@ -259,7 +259,6 @@ private object ExecuteMapReduce(MongoQueryObject queryObject)
var mapReduce = collection.GetType().GetMethod("MapReduce").Invoke(collection, null);

var mapReduceCommand = (MapReduceCommand)mapReduce.GetType().GetProperty("Command").GetValue(mapReduce, null);

mapReduceCommand.Map = new Code(queryObject.MapFunction);
mapReduceCommand.Reduce = new Code(queryObject.ReduceFunction);
mapReduceCommand.Finalize = new Code(queryObject.FinalizerFunction);
Expand All @@ -273,11 +272,8 @@ private object ExecuteMapReduce(MongoQueryObject queryObject)
if (queryObject.NumberToSkip != 0)
throw new InvalidQueryException("MapReduce queries do no support Skips.");

//mapReduce.GetType().GetProperty()

var executor = GetExecutor(typeof(Document), queryObject.Projector, queryObject.Aggregator, true);
return null;
//executor.Compile().DynamicInvoke(mapReduce.Documents);
return executor.Compile().DynamicInvoke(mapReduce.GetType().GetProperty("Documents").GetValue(mapReduce, null));
}

private static LambdaExpression GetExecutor(Type documentType, LambdaExpression projector, LambdaExpression aggregator, bool boxReturn)
Expand Down
6 changes: 3 additions & 3 deletions source/MongoDB/MapReduce.cs
Expand Up @@ -47,7 +47,7 @@ public MapReduce(IMongoDatabase database, string name)
/// Gets the documents.
/// </summary>
/// <value>The documents.</value>
public IEnumerable<T> Documents
public IEnumerable<Document> Documents
{
get
{
Expand All @@ -56,7 +56,7 @@ public IEnumerable<T> Documents
if(Result == null || Result.Ok == false)
throw new InvalidOperationException("Documents cannot be iterated when an error was returned from execute.");

var docs = _database.GetCollection<T>().FindAll().Documents;
var docs = _database.GetCollection<Document>(Result.CollectionName).FindAll().Documents;
using((IDisposable)docs)
{
foreach(var doc in docs)
Expand Down Expand Up @@ -228,7 +228,7 @@ internal void RetrieveData()

try
{
Result = new MapReduceResult(_database.SendCommand(Command.Command));
Result = new MapReduceResult(_database.SendCommand(typeof(T), Command.Command));
}
catch(MongoCommandException exception)
{
Expand Down
4 changes: 4 additions & 0 deletions source/MongoDB/Serialization/BsonClassMapDescriptor.cs
Expand Up @@ -11,6 +11,7 @@ internal class BsonClassMapDescriptor : IBsonObjectDescriptor
{
private readonly Stack<Type> _types;
private readonly IMappingStore _mappingStore;
private bool _isMapReduce;

public BsonClassMapDescriptor(IMappingStore mappingStore, Type rootType)
{
Expand Down Expand Up @@ -91,6 +92,9 @@ private object BeginDocument(Document document)

var currentClassMap = _mappingStore.GetClassMap(_types.Peek());

//var doc = (Document)instance;
//if (doc.ContainsKey("mapreduce"))
// _isMapReduce = true;
return new DocumentClassMapPropertyDescriptor(_mappingStore, currentClassMap, document);
}

Expand Down
Expand Up @@ -271,7 +271,7 @@ private string MatchMember()
{
StringBuilder memberName = new StringBuilder();
char c = Current;
while (c != '.' && c != ' ' && c != '(' && c != '[' && c != EOF)
while (Char.IsLetterOrDigit(c) || c == '_' || c == '$')
{
ReadChar(false);
memberName.Append(c);
Expand Down

0 comments on commit 56850c0

Please sign in to comment.