see on GitHub

Stream Time Series Data


  • This page explains how time series data can be streamed:

    1. Stream a time series directly.
    2. Stream time series query results.
  • In this page:


Syntax

Stream a time series directly:

Get a time series (e.g. using TimeSeriesFor.Get), and call Stream()/StreamAsync().

IEnumerator<T> Stream(DateTime? from = null, DateTime? to = null, TimeSpan? offset = null);

Task<IAsyncEnumerator<T>> StreamAsync(DateTime? from = null, DateTime? to = null, TimeSpan? offset = null);
Parameters Type Description
from DateTime? Start the stream from a certain time. If null, stream starts from the beginning of the time series.
to DateTime? Stop the stream at a certain time. If null, stream stops at the end of the time series.
offset TimeSpan? Change the timestamp of the streamed time series entries by adding this amount of time.

Stream results of time series queries:

This syntax is the same as the syntax for streaming query results in general, found here.

IEnumerator<TimeSeriesStreamResult<T>> Stream(
    IQueryable<T> query);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
    IQueryable<T> query,
    out StreamQueryStatistics streamQueryStats);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
    IDocumentQuery<T> query);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
    IRawDocumentQuery<T> query);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
    IRawDocumentQuery<T> query,
    out StreamQueryStatistics streamQueryStats);

IEnumerator<TimeSeriesStreamResult<T>> Stream(
    IDocumentQuery<T> query,
    out StreamQueryStatistics streamQueryStats);
Parameters Type Description
query IQueryable, IDocumentQuery or IRawDocumentQuery Query to stream results for.
streamQueryStats out StreamQueryStatistics Information about performed query.
Return Value Description
IEnumerator<StreamResult> Enumerator with entities.

Examples

Example I

Using TimeSeriesFor:

var timeseries = session.TimeSeriesFor<HeartRate>("user/1-A");
var results = new List<TimeSeriesEntry>();

using (var TSstream = timeseries.Stream())
{
    while (TSstream.MoveNext())
    {
        results.Add(TSstream.Current);
    }
}
var timeseries = session.TimeSeriesFor<HeartRate>("user/1-A");
var results = new List<TimeSeriesEntry>();
var TSstream = await timeseries.StreamAsync();

await using (TSstream)
{
    while (await TSstream.MoveNextAsync())
    {
        results.Add(TSstream.Current);
    }
}

Example II

Using a RawQuery:

var query = session.Advanced.RawQuery<TimeSeriesRawResult>(@"
    from Users
    select timeseries (
        from HeartRate
    )");

var results = new List<TimeSeriesEntry>();

using (var docStream = session.Advanced.Stream(query))
{
    while (docStream.MoveNext())
    {
        var document = docStream.Current.Result;
        var timeseries = document.Stream;
        while (timeseries.MoveNext())
        {
            results.Add(timeseries.Current);
        }
    }
}
var query = session.Advanced.AsyncRawQuery<TimeSeriesRawResult>(@"
    from Users
    select timeseries (
        from HeartRate
    )");

var results = new List<TimeSeriesEntry>();

await using (var docStream = await session.Advanced.StreamAsync(query))
{
    while (await docStream.MoveNextAsync())
    {
        var document = docStream.Current.Result;
        var timeseries = document.StreamAsync;
        while (await timeseries.MoveNextAsync())
        {
            results.Add(timeseries.Current);
        }
    }
}