Skip to content

Instantly share code, notes, and snippets.

@jdomzhang
Created January 14, 2011 16:54
Show Gist options
  • Save jdomzhang/779874 to your computer and use it in GitHub Desktop.
Save jdomzhang/779874 to your computer and use it in GitHub Desktop.
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);
}
}
}
}
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