using System;
using System.Collections.Generic;
using System.Linq;
using Remotion.Linq;
using Remotion.Linq.Clauses.ResultOperators;
namespace InfluxDB.Client.Linq.Internal
{
internal class QueryResultsSettings
{
///
/// If true, indicates that result is aggregated scalar value. This applies to, for example, item counts.
///
internal readonly bool ScalarAggregated;
///
/// The function that transform results info required scalar value.
///
internal readonly Func, object> AggregateFunction;
internal QueryResultsSettings(QueryModel queryModel)
{
foreach (var resultOperator in queryModel.ResultOperators)
//
// Count
//
if (resultOperator is CountResultOperator || resultOperator is LongCountResultOperator)
{
ScalarAggregated = true;
AggregateFunction = objects => objects
.Select(it => (long)Convert.ChangeType(it, typeof(long)))
.Sum();
return;
}
//
// Default behaviour
//
ScalarAggregated = false;
AggregateFunction = objects => objects;
}
}
}