更新1,以下Ayende的回答地图在RavenDb减少
这是我第一次出远门到RavenDb并试用一下我写了一个小的map/reduce,可惜结果是空的?
我有160万左右的文件加载到RavenDb
的文件:
public class Tick
{
public DateTime Time;
public decimal Ask;
public decimal Bid;
public double AskVolume;
public double BidVolume;
}
,并希望得到向随时间的特定周期的最小值和最大值。
的时间收集被定义为:
var ticks = session.Query<Tick>().Where(x => x.Time > new DateTime(2012, 4, 23) && x.Time < new DateTime(2012, 4, 24, 00, 0, 0)).ToList();
这给了我90280页的文件,到目前为止,一切顺利。
但随后的map/reduce:
Map = rows => from row in rows
select new
{
Max = row.Bid,
Min = row.Bid,
Time = row.Time,
Count = 1
};
Reduce = results => from result in results
group result by new{ result.MaxBid, result.Count} into g
select new
{
Max = g.Key.MaxBid,
Min = g.Min(x => x.MaxBid),
Time = g.Key.Time,
Count = g.Sum(x => x.Count)
};
...
private class TickAggregationResult
{
public decimal MaxBid { get; set; }
public decimal MinBid { get; set; }
public int Count { get; set; }
}
然后我创建索引,并尝试进行查询:
Raven.Client.Indexes.IndexCreation.CreateIndexes(typeof(TickAggregation).Assembly, documentStore);
var session = documentStore.OpenSession();
var g1 = session.Query<TickAggregationResult>(typeof(TickAggregation).Name);
var group = session.Query<Tick, TickAggregation>()
.Where(x => x.Time > new DateTime(2012, 4, 23) &&
x.Time < new DateTime(2012, 4, 24, 00, 0, 0)
)
.Customize(x => x.WaitForNonStaleResults())
.AsProjection<TickAggregationResult>();
但该集团是只是空的:(
因为你可以se e我已经尝试了两种不同的查询,我不确定有什么不同,有人可以解释吗?
现在,我得到一个错误:
集团仍为空:(
让我解释一下我试图在纯SQL来完成:
select min(Ask), count(*) as TickCount from Ticks
where Time between '2012-04-23' and '2012-04-24)
继续这里,http://stackoverflow.com/questions/10853783/map-reduce-in-ravendb-update-1 下面的答案,奇怪的是被奖励为有用的将不会被接受:) – Janus007