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

Linq Issue Repro #4415

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
namespace Microsoft.Azure.Cosmos.Query
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Services.Management.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;

[TestClass]
public class TestIssueRepro
{
[TestMethod]
public async Task Repro()
{
CosmosClient client = SDK.EmulatorTests.TestCommon.CreateCosmosClient(false);

string query = @"SELECT DISTINCT VALUE v2
FROM root
JOIN (
SELECT DISTINCT VALUE v0
FROM root
JOIN v0 IN root[""Parents""]) AS v2
WHERE (LENGTH(v2[""FamilyName""]) > 10)
ORDER BY v2 ASC";

foreach (bool ode in new[] { true,
false
})
{
QueryRequestOptions queryRequestOptions = new QueryRequestOptions { EnableOptimisticDirectExecution = ode };
FeedIterator<object> iterator = client.GetDatabaseQueryIterator<object>(query, requestOptions: queryRequestOptions);

List<object> result = new ();
try
{
while (iterator.HasMoreResults)
{
FeedResponse<object> response = await iterator.ReadNextAsync();
result.AddRange(response.Resource);
}
Assert.Fail("Should receive exception");
}
catch(CosmosException ex)
{
Assert.IsTrue(ex.Message.Contains(@"Reason: (Message: {""Errors"":[""'ORDER BY' is not supported for the target resource type.""]}"));
}
}
}

[TestMethod]
public async Task ReproLinq()
{
CosmosClient client = SDK.EmulatorTests.TestCommon.CreateCosmosClient(false);
DatabaseResponse dbResponse = await client.CreateDatabaseIfNotExistsAsync("db1");
Database db = client.GetDatabase("db1");
ContainerResponse containerResponse = await db.CreateContainerIfNotExistsAsync(
new ContainerProperties()
{
Id = "c1",
PartitionKey = new Documents.PartitionKeyDefinition() { Paths = new System.Collections.ObjectModel.Collection<string>() { "/pk" } }
});
Container container = db.GetContainer("c1");

//string query = @"SELECT DISTINCT VALUE v2
// FROM root
// JOIN (
// SELECT DISTINCT VALUE v0
// FROM root
// JOIN v0 IN root[""Parents""]) AS v2
// WHERE (LENGTH(v2[""FamilyName""]) > 10)
// ORDER BY v2 ASC";

foreach (bool ode in new[] { true,
false
})
{
QueryRequestOptions queryRequestOptions = new QueryRequestOptions { EnableOptimisticDirectExecution = ode };
IOrderedQueryable<Family> queryable = container.GetItemLinqQueryable<Family>(allowSynchronousQueryExecution: true, requestOptions: queryRequestOptions);
IQueryable<Parent> parentsQueryable = queryable.SelectMany(f => f.Parents.Distinct()).Where(f => f.FamilyName.Count() > 10).Distinct()
.OrderBy(f => f);
try
{
List<Parent> parents = parentsQueryable.ToList();
Assert.Fail($"ODE = {ode} - expected to receive exception. Instead query succeeded, returned '{parents.Count}' results.");
}
catch (CosmosException ex)
{
Assert.IsTrue(ex.Message.Contains(@"Reason: (Message: {""Errors"":[""Order-by over correlated collections is not supported.""]}"));
}
}
}
}
}