Ayendeの回答に従って、更新1
これはRavenDbへの私の最初の旅であり、それを試すために小さなマップ/リデュースを作成しましたが、残念ながら結果は空ですか?
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 = 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)