Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AggregationSet filtering exception Invalid Expression Type #416

Open
septimiu-chiorean opened this issue Oct 4, 2023 · 0 comments
Open

Comments

@septimiu-chiorean
Copy link

septimiu-chiorean commented Oct 4, 2023

Hello,
I am getting a 'System.InvalidOperationException: Invalid Expression Type' when I combine certain operators in the Where clause on an AggregationSet.
Very similar to #353 but in my case I use arrays and .Contains. I used the test method added in #365 (AggregationSetTests.cs -> RightBinExpressionOperator) to reproduce this issue as follows:

[Fact]
public void RightBinExpressionOperator()
{
    var collection = new RedisAggregationSet<Person>(_substitute, true, chunkSize: 10000);
    _substitute.Execute("FT.AGGREGATE", Arg.Any<string[]>()).Returns(MockedResult);
    _substitute.Execute("FT.CURSOR", Arg.Any<string[]>()).Returns(MockedResultCursorEnd);

    double?[] heights1 = new double?[] { 170, 171 };
    double?[] heights2 = new double?[] { 180, 181 };

    Expression<Func<AggregationResult<Person>, bool>> query = a => a.RecordShell!.Age == 0 && (heights1.Contains(a.RecordShell!.Height) || heights2.Contains(a.RecordShell.Height));
    _ = collection.Where(query).ToList();
    _substitute.Received().Execute("FT.AGGREGATE", "person-idx", "( @Age:[0 0] (( @Height:[170 170] | @Height:[171 171]) | (@Height:[180 180] | @Height:[181 181] )) )", "WITHCURSOR", "COUNT", "10000");
}

The exception that I receive:

System.InvalidOperationException: Invalid Expression Type
   at Redis.OM.Aggregation.AggregationPredicates.QueryPredicate.ValidateAndPushOperand(Expression expression, Stack`1 stack)
   at Redis.OM.Aggregation.AggregationPredicates.QueryPredicate.SplitBinaryExpression(BinaryExpression expression, Stack`1 stack)
   at Redis.OM.Common.BooleanExpression.SplitExpression()
   at Redis.OM.Aggregation.AggregationPredicates.QueryPredicate.Serialize()
   at Redis.OM.Aggregation.RedisAggregation.Serialize()
   at Redis.OM.Aggregation.AggregationEnumerator`1.get_SerializedArgs()
   at Redis.OM.Aggregation.AggregationEnumerator`1.StartEnumeration()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

While playing around to understand how the expressions are handled, I also found a situation where there is no exception, but the test fails. I've added an example for that as well:

[Fact]
public void RightBinExpressionOperator()
{
    var collection = new RedisAggregationSet<Person>(_substitute, true, chunkSize: 10000);
    _substitute.Execute("FT.AGGREGATE", Arg.Any<string[]>()).Returns(MockedResult);
    _substitute.Execute("FT.CURSOR", Arg.Any<string[]>()).Returns(MockedResultCursorEnd);

    var age = 0;

    Expression<Func<AggregationResult<Person>, bool>> query = a => a.RecordShell!.Age == age && (a.RecordShell!.Age == age + 2 || a.RecordShell!.Age == age + 50);

    _ = collection.Where(query).ToList();
    _substitute.Received().Execute("FT.AGGREGATE", "person-idx", "( @Age:[0 0] ( @Age:[2 2] | @Age:[50 50] ) )", "WITHCURSOR", "COUNT", "10000");
}

Not sure if I am supposed to use them another way or if it's a bug. Any help is appreciated, especially for the first scenario. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant