Skip to content

Commit

Permalink
Fix aggregation parsing on negated Contains (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrakib committed Aug 16, 2023
1 parent 819bda8 commit 968fa76
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
* [@JuliusMikkela](https://github.com/JuliusMikkela)
* [@imansafari1991](https://github.com/imansafari1991)
* [@AndersenGans](https://github.com/AndersenGans)
* [@mdrakib](https://github.com/mdrakib)

<!-- Logo -->
[Logo]: images/logo.svg
Expand Down
21 changes: 21 additions & 0 deletions src/Redis.OM/Aggregation/AggregationPredicates/QueryPredicate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ protected override void ValidateAndPushOperand(Expression expression, Stack<stri
{
stack.Push(ExpressionParserUtilities.TranslateMethodExpressions(method));
}
else if (expression is UnaryExpression uni)
{
var operandStack = new Stack<string>();

if (uni.Operand is BinaryExpression be)
{
SplitBinaryExpression(be, operandStack);
}
else
{
ValidateAndPushOperand(uni.Operand, operandStack);
}

var val = string.Join(" ", operandStack);
if (uni.NodeType == ExpressionType.Not)
{
val = $"(-({val}))";
}

stack.Push(val);
}
else
{
throw new ArgumentException("Invalid Expression Type");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Redis.OM.Aggregation;
using Redis.OM.Contracts;
using System.Threading.Tasks;
Expand Down Expand Up @@ -285,5 +286,21 @@ public async Task GetGroupCountWithNegationQuery()
Assert.True(1 <= result["COUNT"]);
}
}

[Fact]
public async Task TestListNotContains()
{
Setup();
var collection = new RedisAggregationSet<Person>(_connection);

var names = new List<string> { "Beaker", "Rakib" };
var people = await collection
.Where(x => !names.Contains(x.RecordShell.Name) && x.RecordShell.Name != "fake")
.Load(x => x.RecordShell.Name)
.ToListAsync();

Assert.Contains(people, x => x.Hydrate().Name == "Statler");
Assert.DoesNotContain(people, x => x.Hydrate().Name == "Beaker");
}
}
}

0 comments on commit 968fa76

Please sign in to comment.