Update 1、Ayendeの回答に続く
これは RavenDb への私の最初の旅であり、それを試すために小さなマップ/リデュースを書きましたが、残念ながら結果は空ですか?
RavenDb には約 160 万のドキュメントが読み込まれています
文書:
public class Tick
{
public DateTime Time;
public decimal Ask;
public decimal Bid;
public double AskVolume;
public double BidVolume;
}
そして、特定の期間にわたってAskの最小値と最大値を取得したいと考えていました.
Time ごとのコレクションは次のように定義されます。
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>();
しかし、グループはただ空です:(
ご覧のとおり、2 つの異なるクエリを試してみましたが、違いがよくわかりません。誰か説明してもらえますか?
今、私はエラーが発生します:
グループはまだ空です:(
純粋なSQLで達成しようとしていることを説明しましょう:
select min(Ask), count(*) as TickCount from Ticks
where Time between '2012-04-23' and '2012-04-24)