【发布时间】:2012-06-02 06:51:38
【问题描述】:
更新 1,遵循 Ayende 的回答
这是我第一次进入 RavenDb 并尝试使用它,我写了一个小 map/reduce,但不幸的是结果是空的?
我在 RavenDb 中加载了大约 160 万个文档
一份文件:
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>();
但是该组只是空的:(
如您所见,我尝试了两个不同的查询,我不确定其中的区别,有人可以解释一下吗?
现在出现错误:
组还是空的:(
让我解释一下我想用纯 sql 完成什么:
select min(Ask), count(*) as TickCount from Ticks
where Time between '2012-04-23' and '2012-04-24)
【问题讨论】:
-
请显示错误信息。