Created
January 14, 2011 16:54
-
-
Save jdomzhang/779874 to your computer and use it in GitHub Desktop.
For RavenDB Google Group Discussion http://groups.google.com/group/ravendb/browse_thread/thread/b22b0d8368603cce#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Raven.Database.Indexing; | |
using Xunit; | |
using System.Linq; | |
using System; | |
namespace Raven.Tests.Bugs.Indexing | |
{ | |
public class UseMaxForDateTimeTypeInReduce : LocalClientTest | |
{ | |
private const string map = @" | |
from doc in docs | |
from tag in doc.Tags | |
select new { Name = tag.Name, CreatedTime = doc.CreatedTime } | |
"; | |
private const string reduce = @" | |
from agg in results | |
group agg by agg.Name into g | |
let createdTime = g.Max(x => x.CreatedTime) | |
select new {Name = g.Key, CreatedTime = createdTime} | |
"; | |
[Fact] | |
public void CanUseMax() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
store.DatabaseCommands.PutIndex("test", | |
new IndexDefinition | |
{ | |
Map = map, | |
Reduce = reduce, | |
}); | |
using (var sesion = store.OpenSession()) | |
{ | |
sesion.Store(new { Topic = "RavenDB is Hot", CreatedTime = DateTime.Now, Tags = new[] { new { Name = "DB" }, new { Name = "NoSQL" } } }); | |
sesion.Store(new { Topic = "RavenDB is Fast", CreatedTime = DateTime.Now.AddMinutes(10), Tags = new[] { new { Name = "NoSQL" } } }); | |
sesion.SaveChanges(); | |
} | |
using (var sesion = store.OpenSession()) | |
{ | |
sesion.Advanced.LuceneQuery<dynamic>("test").WaitForNonStaleResults().ToArray(); | |
} | |
Assert.Empty(store.DocumentDatabase.Statistics.Errors); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Raven.Database.Indexing; | |
using Xunit; | |
using System.Linq; | |
using System; | |
namespace Raven.Tests.Bugs.Indexing | |
{ | |
public class UseMaxForLongTypeInReduce : LocalClientTest | |
{ | |
private const string map = @" | |
from doc in docs | |
from tag in doc.Tags | |
select new { Name = tag.Name, CreatedTimeTicks = doc.CreatedTimeTicks } | |
"; | |
private const string reduce = @" | |
from agg in results | |
group agg by agg.Name into g | |
let createdTimeTicks = g.Max(x => x.CreatedTimeTicks) | |
select new {Name = g.Key, CreatedTimeTicks = createdTimeTicks} | |
"; | |
[Fact] | |
public void CanUseMax() | |
{ | |
using (var store = NewDocumentStore()) | |
{ | |
store.DatabaseCommands.PutIndex("test", | |
new IndexDefinition | |
{ | |
Map = map, | |
Reduce = reduce, | |
}); | |
using (var sesion = store.OpenSession()) | |
{ | |
sesion.Store(new { Topic = "RavenDB is Hot", CreatedTimeTicks = DateTime.Now.Ticks, Tags = new[] { new { Name = "DB" }, new { Name = "NoSQL" } } }); | |
sesion.Store(new { Topic = "RavenDB is Fast", CreatedTimeTicks = DateTime.Now.AddMinutes(10).Ticks, Tags = new[] { new { Name = "NoSQL" } } }); | |
sesion.SaveChanges(); | |
} | |
using (var sesion = store.OpenSession()) | |
{ | |
sesion.Advanced.LuceneQuery<dynamic>("test").WaitForNonStaleResults().ToArray(); | |
} | |
Assert.Empty(store.DocumentDatabase.Statistics.Errors); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment