StackExchange / NRediSearch

Other
31 stars 9 forks source link

NRediSearch.AggregationResult not contains result of TOLIST reducer. #11

Open K1vs opened 3 years ago

K1vs commented 3 years ago

Hello, I ran into the fact that the result of the work of the TOLIST reducer is not present in AggregationResult. In the process of debugging, I discovered that this case is not covered.

`

public sealed class AggregationResult
{
    private readonly Dictionary<string, RedisValue>[] _results;

    internal AggregationResult(RedisResult result, long cursorId = -1)
    {
        var arr = (RedisResult[])result;

        _results = new Dictionary<string, RedisValue>[arr.Length - 1];
        for (int i = 1; i < arr.Length; i++)
        {
            var raw = (RedisResult[])arr[i];
            var cur = new Dictionary<string, RedisValue>();
            for (int j = 0; j < raw.Length;)
            {
                var key = (string)raw[j++];
                var val = raw[j++];
                if (val.Type != ResultType.MultiBulk)//for TOLIST reducer type is multibulk and it will be skipped
                    cur.Add(key, (RedisValue)val);
            }
            _results[i - 1] = cur;
        }

        CursorId = cursorId;
    }
    public IReadOnlyList<Dictionary<string, RedisValue>> GetResults() => _results;

    public Dictionary<string, RedisValue> this[int index]
        => index >= _results.Length ? null : _results[index];

    public Row? GetRow(int index)
    {
        if (index >= _results.Length) return null;
        return new Row(_results[index]);
    }

    public long CursorId { get; }
}

`