Cumulative computation with RavenDB queries
Consider the image on the right, where we have three charges on separate months. This is a time series, showing charges over time. We can very easily issue queries that will give us the results of how much we paid in a time period, but what if we wanted to get the cumulative value. How much have I paid so far? Here is how this should look like:
However, that is not something that we provide in RavenDB. Luckily, we do provide a very flexible query engine, so we can make it happen anyway. Here is what the query will look like:
Note that we are using a JavaScript function to process the time series and run the computation that we want, and then we return an array, which is translated to multiple results set per document. Here is the result of this query:
Comments
I didn't get into time series features yet so I wonder, will that query create an index (with Sum as a stored field?) or it will be computed on-the-fly? If on-the-fly is /will be there a way to write that query in C#?
Milosz,
This is computed on the fly, yes. And you can probably write in C#, but it would be a PITA to do so. Easier to do that in JS.C# also doesn't support an easy way to return multiple results per document, like we are doing here.
Comment preview