Skip to content

Commit 968fa76

Browse files
authored
Fix aggregation parsing on negated Contains (#407)
1 parent 819bda8 commit 968fa76

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
363363
* [@JuliusMikkela](https://github.com/JuliusMikkela)
364364
* [@imansafari1991](https://github.com/imansafari1991)
365365
* [@AndersenGans](https://github.com/AndersenGans)
366+
* [@mdrakib](https://github.com/mdrakib)
366367

367368
<!-- Logo -->
368369
[Logo]: images/logo.svg

src/Redis.OM/Aggregation/AggregationPredicates/QueryPredicate.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@ protected override void ValidateAndPushOperand(Expression expression, Stack<stri
9494
{
9595
stack.Push(ExpressionParserUtilities.TranslateMethodExpressions(method));
9696
}
97+
else if (expression is UnaryExpression uni)
98+
{
99+
var operandStack = new Stack<string>();
100+
101+
if (uni.Operand is BinaryExpression be)
102+
{
103+
SplitBinaryExpression(be, operandStack);
104+
}
105+
else
106+
{
107+
ValidateAndPushOperand(uni.Operand, operandStack);
108+
}
109+
110+
var val = string.Join(" ", operandStack);
111+
if (uni.NodeType == ExpressionType.Not)
112+
{
113+
val = $"(-({val}))";
114+
}
115+
116+
stack.Push(val);
117+
}
97118
else
98119
{
99120
throw new ArgumentException("Invalid Expression Type");

test/Redis.OM.Unit.Tests/RediSearchTests/AggregationFunctionalTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Redis.OM.Aggregation;
34
using Redis.OM.Contracts;
45
using System.Threading.Tasks;
@@ -285,5 +286,21 @@ public async Task GetGroupCountWithNegationQuery()
285286
Assert.True(1 <= result["COUNT"]);
286287
}
287288
}
289+
290+
[Fact]
291+
public async Task TestListNotContains()
292+
{
293+
Setup();
294+
var collection = new RedisAggregationSet<Person>(_connection);
295+
296+
var names = new List<string> { "Beaker", "Rakib" };
297+
var people = await collection
298+
.Where(x => !names.Contains(x.RecordShell.Name) && x.RecordShell.Name != "fake")
299+
.Load(x => x.RecordShell.Name)
300+
.ToListAsync();
301+
302+
Assert.Contains(people, x => x.Hydrate().Name == "Statler");
303+
Assert.DoesNotContain(people, x => x.Hydrate().Name == "Beaker");
304+
}
288305
}
289306
}

0 commit comments

Comments
 (0)