Influx DB C# linq problem InfluxDBQueryable

57 Views Asked by At

I have a problem with influx db 2.6.1 c#, specifically with the InfluxDBQueryable library. I'm creating a dynamic expression with linq but exactly I'm having problems with how this library builds the flux query for me.

# C# Code:

 var _queryable = InfluxDBQueryable<Record>.Queryable(bucketName, Organization, queryApi == null ? queryApiTest : queryApi, memberResolver, queryableOptimizerSettings: new QueryableOptimizerSettings
                {
                    AlignFieldsWithPivot = false,
                    DropMeasurementColumn = false,
                    DropStartColumn = false,
                    DropStopColumn = false,
                });
if (start != null && end != null)
    _queryable =  _queryable.Where(x => x.Timestamp >= start && x.Timestamp <= end ).ToInfluxQueryable();
_queryable  = _queryable.Where(x => x.Measurament == Measurament).ToInfluxQueryable();
if (Node != null)
    _queryable = _queryable.Where(x => x.Node == Node).ToInfluxQueryable();
if(Tag != null )
    _queryable = _queryable.Where(x => x.Tag == Tag).ToInfluxQueryable();
if(SubTag != null )
    _queryable= _queryable.Where(x => x.SubTag == SubTag).ToInfluxQueryable();

if (columnValue != null && columnValue.Count > 0)
{
    Expression<Func<Record, bool>> _combinedExpression = null;
    foreach (var _col in columnValue)
    {
        if (_col.Value == null)
        {
            if (_combinedExpression == null)
                _combinedExpression = x => x._field == _col.Key;
            else
                _combinedExpression = _combinedExpression.OR(x => x._field == _col.Key);

        }
        else
        {
            if (_combinedExpression == null)
                _combinedExpression = x => x._field == _col.Key && x._value == _col.Value;
            else
                _combinedExpression = _combinedExpression.OR(x => x._field == _col.Key && x._value == _col.Value);
        }
    }
    _queryable = _queryable.Where(_combinedExpression).ToInfluxQueryable();
}
if(aggregateWindow != TimeSpan.MinValue)
    _queryable = _queryable.Where(x => x.Timestamp.AggregateWindow(aggregateWindow, null, aggregateMethod)).ToInfluxQueryable();

# FluxQuery:

from(bucket: p1) 
 |>range(start: time(v: start_shifted), stop: time(v: stop_shifted)) 
 |>filter(fn: (r) => (r["_measurement"] == p5) and (r["node"] == p6) and (r["tag"] == p7) and (r["SubTag"] == p8)) 
 |>aggregateWindow(every: p11, fn: p12) 
 |>filter(fn: (r) =>(r["_field"] == p9) or (r["_field"] == p10))

The problem is that AggregateWindow is put in the penultimate row instead of being at the end of the query and in this way it doesn't go to do the aggregation with specific columns (_field) but with all the columns of that table giving me errors with the types (bool etc), how can I do it?

0

There are 0 best solutions below