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

Fix parser for new reponse in FT.PROFILE #306 #307

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dockers/cluster.redis.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
protected-mode no
enable-debug-command yes
loadmodule /opt/redis-stack/lib/redisearch.so
loadmodule /opt/redis-stack/lib/redisgraph.so
# loadmodule /opt/redis-stack/lib/redisgraph.so
loadmodule /opt/redis-stack/lib/redistimeseries.so
loadmodule /opt/redis-stack/lib/rejson.so
loadmodule /opt/redis-stack/lib/redisbloom.so
Expand Down
9 changes: 8 additions & 1 deletion src/NRedisStack/ResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,14 @@ public static Dictionary<string, RedisResult> ToStringRedisResultDictionary(this
foreach (var pair in res)
{
var arr = (RedisResult[])pair!;
dict.Add(arr[0].ToString()!, arr[1]);
if (arr.Length > 1)
{
dict.Add(arr[0].ToString()!, arr[1]);
}
else
{
dict.Add(arr[0].ToString()!, null);
}
}
return dict;
}
Expand Down
7 changes: 4 additions & 3 deletions src/NRedisStack/Search/AggregationResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
{
var arr = (RedisResult[])result!;

// the first element is always the number of results
TotalResults = (long)arr[0];
// this statement below is not true as explained in the document https://redis.io/docs/latest/commands/ft.aggregate/#return
// // the first element is always the number of results
// TotalResults = (long)arr[0];

_results = new Dictionary<string, RedisValue>[arr.Length - 1];
for (int i = 1; i < arr.Length; i++)
Expand All @@ -33,7 +34,7 @@

_results[i - 1] = cur;
}

TotalResults = _results.Length;
CursorId = cursorId;
}

Expand All @@ -44,10 +45,10 @@
/// If the element is not a multi-bulk array, it's added directly to a List<object>.
/// The method returns a nested list structure, reflecting the hierarchy of the original multi-bulk array,
/// with each element either being a direct value or a nested list.
/// </summary>

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 7 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack 7.2.0-RC3] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack 7.2.0-RC3] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 7 on [redis-stack 7.2.0-RC3] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack edge] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'

Check warning on line 48 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 7 on [redis-stack edge] / Test

XML comment has badly formed XML -- 'End tag 'summary' does not match the start tag 'object'.'
/// <param name="multiBulkArray"></param>
/// <returns>object</returns>
private object ConvertMultiBulkToObject(IEnumerable<RedisResult> multiBulkArray)

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 7 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack cluster] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack 7.2.0-RC3] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 6 on [redis-stack 7.2.0-RC3] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 7 on [redis-stack 7.2.0-RC3] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack 6.2.6] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 8 on [redis-stack edge] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'

Check warning on line 51 in src/NRedisStack/Search/AggregationResult.cs

View workflow job for this annotation

GitHub Actions / .NET 7 on [redis-stack edge] / Test

XML comment has badly formed XML -- 'Expected an end tag for element 'summary'.'
{
return multiBulkArray.Select(item => item.Type == ResultType.MultiBulk
? ConvertMultiBulkToObject((RedisResult[])item!)
Expand Down
69 changes: 64 additions & 5 deletions tests/NRedisStack.Tests/Search/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public void TestApplyAndFilterAggregations()

// actual search
AggregationResult res = ft.Aggregate(index, r);
Assert.Equal(3, res.TotalResults);
Assert.Equal(2, res.TotalResults);

Row r1 = res.GetRow(0);
Assert.Equal("def", r1.GetString("name"));
Expand Down Expand Up @@ -2668,7 +2668,7 @@ public async Task TestProfileSearchAsync()
}


[SkipIfRedis(Is.Enterprise)]
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
public void TestProfile()
{
IDatabase db = redisFixture.Redis.GetDatabase();
Expand All @@ -2695,10 +2695,10 @@ public void TestProfile()
var aggregateRes = profileAggregate.Item1;
var aggregateDet = profileAggregate.Item2;
Assert.Equal(5, aggregateDet.Count);
Assert.Equal(1, aggregateRes.TotalResults);
Assert.Equal(2, aggregateRes.TotalResults);
}

[SkipIfRedis(Is.Enterprise)]
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
public async Task TestProfileAsync()
{
IDatabase db = redisFixture.Redis.GetDatabase();
Expand All @@ -2724,7 +2724,66 @@ public async Task TestProfileAsync()
var aggregateRes = profileAggregate.Item1;
var aggregateDet = profileAggregate.Item2;
Assert.Equal(5, aggregateDet.Count);
Assert.Equal(1, aggregateRes.TotalResults);
Assert.Equal(2, aggregateRes.TotalResults);
}

[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
public void TestProfileIssue306()
{
IDatabase db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");
var ft = db.FT();

ft.Create(index, new Schema().AddTextField("t", sortable: true)); // Calling FT.CREATR without FTCreateParams
db.HashSet("1", "t", "hello");
db.HashSet("2", "t", "world");

// check using Query
var q = new Query("hello|world").SetNoContent();
var profileSearch = ft.ProfileSearch(index, q);
var searchRes = profileSearch.Item1;
var searchDet = profileSearch.Item2;

Assert.Equal(6, searchDet.Count);
Assert.Equal(2, searchRes.Documents.Count);


// check using AggregationRequest
var aggReq = new AggregationRequest("*").Load(FieldName.Of("t")).Apply("startswith(@t, 'hel')", "prefix");
var profileAggregate = ft.ProfileAggregate(index, aggReq);
var aggregateRes = profileAggregate.Item1;
var aggregateDet = profileAggregate.Item2;
Assert.True(aggregateDet.Count >= 6);
Assert.Equal(2, aggregateRes.TotalResults);
}

[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
public async Task TestProfileAsyncIssue306()
{
IDatabase db = redisFixture.Redis.GetDatabase();
db.Execute("FLUSHALL");
var ft = db.FT();

await ft.CreateAsync(index, new Schema().AddTextField("t", sortable: true)); // Calling FT.CREATR without FTCreateParams
db.HashSet("1", "t", "hello");
db.HashSet("2", "t", "world");

// check using Query
var q = new Query("hello|world").SetNoContent();
var profileSearch = await ft.ProfileSearchAsync(index, q);
var searchRes = profileSearch.Item1;
var searchDet = profileSearch.Item2;

Assert.Equal(6, searchDet.Count);
Assert.Equal(2, searchRes.Documents.Count);

// check using AggregationRequest
var aggReq = new AggregationRequest("*").Load(FieldName.Of("t")).Apply("startswith(@t, 'hel')", "prefix");
var profileAggregate = await ft.ProfileAggregateAsync(index, aggReq);
var aggregateRes = profileAggregate.Item1;
var aggregateDet = profileAggregate.Item2;
Assert.True(aggregateDet.Count >= 6);
Assert.Equal(2, aggregateRes.TotalResults);
}

[Fact]
Expand Down
Loading