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

Add regression tests for issue#10012 #21589

Merged
1 commit merged into from
Jul 11, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -2205,6 +2205,61 @@ public virtual Task GroupBy_aggregate_over_a_subquery(bool async)
}));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_aggregate_join_with_grouping_key(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>()
.GroupBy(o => o.CustomerID)
.Select(g => new { g.Key, Count = g.Count() })
.Join(ss.Set<Customer>(), o => o.Key, c => c.CustomerID, (o, c) => new { c, o.Count }),
elementSorter: a => a.c.CustomerID,
elementAsserter: (e, a) =>
{
AssertEqual(e.c, a.c);
AssertEqual(e.Count, a.Count);
},
entryCount: 89);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_aggregate_join_with_group_result(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Order>()
.GroupBy(o => o.CustomerID, e => e.OrderDate)
.Select(g => new { g.Key, LastOrderDate = g.Max() })
.Join(ss.Set<Order>(), o => o, i => new { Key = i.CustomerID, LastOrderDate = i.OrderDate }, (_, x) => x),
entryCount: 90);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_aggregate_from_right_side_of_join(bool async)
{
return AssertQuery(
async,
ss => (from c in ss.Set<Customer>()
join o in ss.Set<Order>().GroupBy(i => i.CustomerID).Select(e => new { e.Key, Max = e.Max(i => i.OrderDate) })
on c.CustomerID equals o.Key
select new { c, o.Max })
.OrderBy(e => e.Max)
.ThenBy(c => c.c.CustomerID)
.Skip(10)
.Take(10),
assertOrder: true,
elementAsserter: (e, a) =>
{
AssertEqual(e.c, a.c);
AssertEqual(e.Max, a.Max);
},
entryCount: 10);
}

#endregion

#region GroupByWithoutAggregate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,52 @@ FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]");
}

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

AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t].[c] AS [Count]
FROM (
SELECT [o].[CustomerID], COUNT(*) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
) AS [t]
INNER JOIN [Customers] AS [c] ON [t].[CustomerID] = [c].[CustomerID]");
}

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

AssertSql(
@"SELECT [o0].[OrderID], [o0].[CustomerID], [o0].[EmployeeID], [o0].[OrderDate]
FROM (
SELECT [o].[CustomerID], MAX([o].[OrderDate]) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
) AS [t]
INNER JOIN [Orders] AS [o0] ON (([t].[CustomerID] = [o0].[CustomerID]) OR ([t].[CustomerID] IS NULL AND [o0].[CustomerID] IS NULL)) AND (([t].[c] = [o0].[OrderDate]) OR ([t].[c] IS NULL AND [o0].[OrderDate] IS NULL))");
}

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

AssertSql(
@"@__p_0='10'

SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region], [t].[c] AS [Max]
FROM [Customers] AS [c]
INNER JOIN (
SELECT [o].[CustomerID], MAX([o].[OrderDate]) AS [c]
FROM [Orders] AS [o]
GROUP BY [o].[CustomerID]
) AS [t] ON [c].[CustomerID] = [t].[CustomerID]
ORDER BY [t].[c], [c].[CustomerID]
OFFSET @__p_0 ROWS FETCH NEXT @__p_0 ROWS ONLY");
}

public override async Task GroupBy_with_grouping_key_using_Like(bool async)
{
await base.GroupBy_with_grouping_key_using_Like(async);
Expand Down