Skip to content

Commit

Permalink
Query: Client eval when doing joins after GroupByAggregate
Browse files Browse the repository at this point in the history
Part of #10012
  • Loading branch information
smitpatel committed Mar 14, 2018
1 parent 91eeff8 commit 3a66b2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ await AssertQuery<Order>(
.Select(g => new { g.Key, Count = g.Count(), Sum = g.Sum(o => o.OrderID) }));
}

[ConditionalFact(Skip = "Issue#10012")]
[ConditionalFact]
public virtual async Task GroupBy_Aggregate_Join()
{
await AssertQuery<Order, Customer>(
Expand All @@ -1103,7 +1103,8 @@ from a in os.GroupBy(o => o.CustomerID)
.Select(g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) })
join c in cs on a.CustomerID equals c.CustomerID
join o in os on a.LastOrderID equals o.OrderID
select new { c, o });
select new { c, o },
entryCount: 126);
}

[ConditionalFact]
Expand Down
5 changes: 3 additions & 2 deletions src/EFCore.Specification.Tests/Query/GroupByQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ public virtual void GroupBy_filter_count_OrderBy_count_Select_sum()
.Select(g => new { g.Key, Count = g.Count(), Sum = g.Sum(o => o.OrderID) }));
}

[ConditionalFact(Skip = "Issue#10012")]
[ConditionalFact]
public virtual void GroupBy_Aggregate_Join()
{
AssertQuery<Order, Customer>(
Expand All @@ -1106,7 +1106,8 @@ from a in os.GroupBy(o => o.CustomerID)
.Select(g => new { CustomerID = g.Key, LastOrderID = g.Max(o => o.OrderID) })
join c in cs on a.CustomerID equals c.CustomerID
join o in os on a.LastOrderID equals o.OrderID
select new { c, o });
select new { c, o },
entryCount: 126);
}

[ConditionalFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ private Expression VisitBinaryOperand(Expression operand, ExpressionType compari
/// </summary>
protected override Expression VisitSubQuery(SubQueryExpression expression)
{
_queryModelStack.Push(expression.QueryModel);

if (!IsGroupByAggregateSubQuery(expression.QueryModel))
{
_queryModelStack.Push(expression.QueryModel);

expression.QueryModel.TransformExpressions(Visit);

_queryModelStack.Pop();
Expand Down Expand Up @@ -277,13 +277,15 @@ protected override Expression VisitSubQuery(SubQueryExpression expression)
return expression;
}

private static bool IsGroupByAggregateSubQuery(QueryModel queryModel)
private bool IsGroupByAggregateSubQuery(QueryModel queryModel)
{
if (queryModel.MainFromClause.FromExpression.Type.IsGrouping()
&& queryModel.BodyClauses.Count == 0
&& queryModel.ResultOperators.Count == 1
&& !(queryModel.SelectClause.Selector is ConstantExpression)
&& _aggregateResultOperators.Contains(queryModel.ResultOperators[0].GetType()))
&& _aggregateResultOperators.Contains(queryModel.ResultOperators[0].GetType())
&& _queryModelStack.Count == 1
&& !_queryModelStack.Peek().BodyClauses.OfType<IQuerySource>().Any())
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,16 @@ public override void GroupBy_Aggregate_Join()
{
base.GroupBy_Aggregate_Join();

AssertSql(" ");
AssertContainsSql(
@"SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
FROM [Orders] AS [o0]",
//
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]",
//
@"SELECT [o].[OrderID], [o].[CustomerID], [o].[EmployeeID], [o].[OrderDate]
FROM [Orders] AS [o]
ORDER BY [o].[CustomerID]");
}

public override void GroupBy_with_result_selector()
Expand Down Expand Up @@ -1437,6 +1446,9 @@ ORDER BY [o0].[OrderID]
private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

private void AssertContainsSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected, assertOrder: false);

protected override void ClearLog()
=> Fixture.TestSqlLoggerFactory.Clear();
}
Expand Down

0 comments on commit 3a66b2f

Please sign in to comment.