Skip to content

Commit

Permalink
Query: Process client eval in join when collection shaper
Browse files Browse the repository at this point in the history
Extension of #19247 for collection shaper in client eval
  • Loading branch information
smitpatel committed Jun 12, 2020
1 parent 936d483 commit 5a799cf
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ protected override Expression VisitExtension(Expression extensionExpression)
: null;
}

if (extensionExpression is CollectionShaperExpression)
{
return _clientEval
? extensionExpression
: null;
}

throw new InvalidOperationException(
CoreStrings.QueryFailed(extensionExpression.Print(), GetType().Name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,18 @@ public override Task SelectMany_with_client_eval(bool async)
return base.SelectMany_with_client_eval(async);
}

[ConditionalTheory(Skip = "Issue#17246")]
public override Task SelectMany_with_client_eval_with_collection_shaper(bool async)
{
return base.SelectMany_with_client_eval_with_collection_shaper(async);
}

[ConditionalTheory(Skip = "Issue#17246")]
public override Task SelectMany_with_client_eval_with_collection_shaper_ignored(bool async)
{
return base.SelectMany_with_client_eval_with_collection_shaper_ignored(async);
}

[ConditionalTheory(Skip = "Issue#17246")]
public override Task SelectMany_with_client_eval_with_constructor(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ public override Task SelectMany_with_client_eval(bool async)
return base.SelectMany_with_client_eval(async);
}

[ConditionalTheory(Skip = "Issue#21200")]
public override Task SelectMany_with_client_eval_with_collection_shaper(bool async)
{
return base.SelectMany_with_client_eval_with_collection_shaper(async);
}

[ConditionalTheory(Skip = "Issue#21200")]
public override Task SelectMany_with_client_eval_with_collection_shaper_ignored(bool async)
{
return base.SelectMany_with_client_eval_with_collection_shaper_ignored(async);
}

[ConditionalTheory(Skip = "Issue#21200")]
public override Task SelectMany_with_client_eval_with_constructor(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,41 @@ public virtual Task SelectMany_with_client_eval(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>()
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("F"))
.SelectMany(c => c.Orders.Select(o => new { OrderProperty = ClientMethod(o), CustomerProperty = c.ContactName })),
elementSorter: e => e.OrderProperty,
entryCount: 830);
entryCount: 63);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SelectMany_with_client_eval_with_collection_shaper(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("F"))
.SelectMany(c => c.Orders.Select(o => new { OrderProperty = ClientMethod(o), o.OrderDetails, CustomerProperty = c.ContactName })),
elementSorter: e => e.OrderProperty,
elementAsserter: (e, a) =>
{
AssertEqual(e.OrderProperty, a.OrderProperty);
AssertEqual(e.CustomerProperty, a.CustomerProperty);
AssertCollection(e.OrderDetails, a.OrderDetails);
},
entryCount: 227);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SelectMany_with_client_eval_with_collection_shaper_ignored(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("F"))
.SelectMany(c => c.Orders.Select(o => new { OrderProperty = ClientMethod(o), o.OrderDetails, CustomerProperty = c.ContactName }))
.Select(e => new { e.OrderProperty, e.CustomerProperty }),
elementSorter: e => e.OrderProperty,
entryCount: 63);
}

private static int ClientMethod(Order order) => order.OrderID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,40 @@ CROSS APPLY (
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[ContactName]
FROM [Orders] AS [o]
WHERE [c].[CustomerID] = [o].[CustomerID]
) AS [t]");
) AS [t]
WHERE [c].[CustomerID] LIKE N'F%'");
}

public override async Task SelectMany_with_client_eval_with_collection_shaper(bool async)
{
await base.SelectMany_with_client_eval_with_collection_shaper(async);

AssertSql(
@"SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate], [t].[ContactName], [c].[CustomerID], [t].[OrderID], [o0].[OrderID], [o0].[ProductID], [o0].[Discount], [o0].[Quantity], [o0].[UnitPrice]
FROM [Customers] AS [c]
CROSS APPLY (
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[ContactName]
FROM [Orders] AS [o]
WHERE [c].[CustomerID] = [o].[CustomerID]
) AS [t]
LEFT JOIN [Order Details] AS [o0] ON [t].[OrderID] = [o0].[OrderID]
WHERE [c].[CustomerID] LIKE N'F%'
ORDER BY [c].[CustomerID], [t].[OrderID], [o0].[OrderID], [o0].[ProductID]");
}

public override async Task SelectMany_with_client_eval_with_collection_shaper_ignored(bool async)
{
await base.SelectMany_with_client_eval_with_collection_shaper_ignored(async);

AssertSql(
@"SELECT [t].[OrderID], [t].[CustomerID], [t].[EmployeeID], [t].[OrderDate], [t].[ContactName]
FROM [Customers] AS [c]
CROSS APPLY (
SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate], [c].[ContactName]
FROM [Orders] AS [o]
WHERE [c].[CustomerID] = [o].[CustomerID]
) AS [t]
WHERE [c].[CustomerID] LIKE N'F%'");
}

public override async Task SelectMany_with_client_eval_with_constructor(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public NorthwindJoinQuerySqliteTest(NorthwindQuerySqliteFixture<NoopModelCustomi

// CROSS APPLY is not supported
public override Task SelectMany_with_client_eval(bool async) => Task.CompletedTask;
public override Task SelectMany_with_client_eval_with_collection_shaper(bool async) => Task.CompletedTask;
public override Task SelectMany_with_client_eval_with_collection_shaper_ignored(bool async) => Task.CompletedTask;
}
}

0 comments on commit 5a799cf

Please sign in to comment.