Skip to content

Commit

Permalink
Query: Don't skip any parameter in projection
Browse files Browse the repository at this point in the history
We used to skip enumerable parameter because of group join but it is dead code now

Resolves #26964
  • Loading branch information
smitpatel committed Jan 20, 2022
1 parent e42407c commit 7a7b0e9
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ public override Expression Visit(Expression expression)
return base.Visit(expression);
}

// This skips the group parameter from GroupJoin
if (expression is ParameterExpression parameter
&& parameter.Type.IsGenericType
&& parameter.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
return parameter;
}

if (_clientEval)
{
switch (expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ public virtual Expression Translate(InMemoryQueryExpression queryExpression, Exp
|| expression is EntityShaperExpression
|| expression is IncludeExpression))
{
// This skips the group parameter from GroupJoin
if (expression is ParameterExpression parameter
&& parameter.Type.IsGenericType
&& parameter.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
return parameter;
}

if (_indexBasedBinding)
{
switch (expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ public virtual Expression Translate(SelectExpression selectExpression, Expressio
|| expression is EntityShaperExpression
|| expression is IncludeExpression))
{
// This skips the group parameter from GroupJoin
if (expression is ParameterExpression parameter
&& parameter.Type.IsGenericType
&& parameter.Type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
return parameter;
}

if (_indexBasedBinding)
{
switch (expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,80 +318,80 @@ public override async Task Select_nested_collection(bool async)

public override void Select_nested_collection_multi_level()
{
// Cosmos client evaluation. Issue #17246.
AssertTranslationFailed(
() =>
{
base.Select_nested_collection_multi_level();
return Task.CompletedTask;
});
//// Cosmos client evaluation. Issue #17246.
//AssertTranslationFailed(
// () =>
// {
// base.Select_nested_collection_multi_level();
// return Task.CompletedTask;
// });

AssertSql();
//AssertSql();
}

public override void Select_nested_collection_multi_level2()
{
// Cosmos client evaluation. Issue #17246.
AssertTranslationFailed(
() =>
{
base.Select_nested_collection_multi_level2();
return Task.CompletedTask;
});
//// Cosmos client evaluation. Issue #17246.
//AssertTranslationFailed(
// () =>
// {
// base.Select_nested_collection_multi_level2();
// return Task.CompletedTask;
// });

AssertSql();
//AssertSql();
}

public override void Select_nested_collection_multi_level3()
{
// Cosmos client evaluation. Issue #17246.
AssertTranslationFailed(
() =>
{
base.Select_nested_collection_multi_level3();
return Task.CompletedTask;
});
//// Cosmos client evaluation. Issue #17246.
//AssertTranslationFailed(
// () =>
// {
// base.Select_nested_collection_multi_level3();
// return Task.CompletedTask;
// });

AssertSql();
//AssertSql();
}

public override void Select_nested_collection_multi_level4()
{
// Cosmos client evaluation. Issue #17246.
AssertTranslationFailed(
() =>
{
base.Select_nested_collection_multi_level4();
return Task.CompletedTask;
});
//// Cosmos client evaluation. Issue #17246.
//AssertTranslationFailed(
// () =>
// {
// base.Select_nested_collection_multi_level4();
// return Task.CompletedTask;
// });

AssertSql();
//AssertSql();
}

public override void Select_nested_collection_multi_level5()
{
// Cosmos client evaluation. Issue #17246.
AssertTranslationFailed(
() =>
{
base.Select_nested_collection_multi_level5();
return Task.CompletedTask;
});
//// Cosmos client evaluation. Issue #17246.
//AssertTranslationFailed(
// () =>
// {
// base.Select_nested_collection_multi_level5();
// return Task.CompletedTask;
// });

AssertSql();
//AssertSql();
}

public override void Select_nested_collection_multi_level6()
{
// Cosmos client evaluation. Issue #17246.
AssertTranslationFailed(
() =>
{
base.Select_nested_collection_multi_level6();
return Task.CompletedTask;
});
//// Cosmos client evaluation. Issue #17246.
//AssertTranslationFailed(
// () =>
// {
// base.Select_nested_collection_multi_level6();
// return Task.CompletedTask;
// });

AssertSql();
//AssertSql();
}

public override async Task Select_nested_collection_count_using_anonymous_type(bool async)
Expand Down Expand Up @@ -1397,8 +1397,6 @@ public override async Task Reverse_in_join_inner_with_skip(bool async)
() => base.Reverse_in_join_inner_with_skip(async))).Message);

AssertSql();

AssertSql();
}

public override async Task Reverse_in_SelectMany(bool async)
Expand Down Expand Up @@ -1469,9 +1467,13 @@ public override async Task Reverse_after_orderBy_and_take(bool async)
Assert.Equal(CosmosStrings.ReverseAfterSkipTakeNotSupported, message);
}

[ConditionalTheory(Skip = "Cross collection join Issue#17246")]
public override Task List_of_list_of_anonymous_type(bool async)
=> base.List_of_list_of_anonymous_type(async);
public override async Task List_of_list_of_anonymous_type(bool async)
{
// Cosmos client evaluation. Issue #17246.
await AssertTranslationFailed(() => base.List_of_list_of_anonymous_type(async));

AssertSql();
}

public override async Task
SelectMany_with_collection_being_correlated_subquery_which_references_non_mapped_properties_from_inner_and_outer_entity(
Expand Down Expand Up @@ -1680,6 +1682,16 @@ FROM root c
WHERE (c[""Discriminator""] = ""Customer"")");
}

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

AssertSql(
@"SELECT c[""CustomerID""]
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND ((c[""CustomerID""] != null) AND ((""F"" != null) AND STARTSWITH(c[""CustomerID""], ""F""))))");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2416,4 +2416,30 @@ public virtual Task List_of_list_of_anonymous_type(bool async)
AssertCollection(e.ListWithSubList, a.ListWithSubList, ordered: true,
elementAsserter: (ee, aa) => AssertCollection(ee, aa, elementSorter: i => (i.OrderID, i.ProductID)));
});

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Using_enumerable_parameter_in_projection(bool async)
{
var customersToLoad = new List<string> { "A" };
var results = new List<OrderDto>();

return AssertQuery(
async,
ss => ss.Set<Customer>()
.Where(c => c.CustomerID.StartsWith("F"))
.Select(c => new
{
c.CustomerID,
Orders = customersToLoad.Contains("FISSA")
? c.Orders.Select(e => new OrderDto())
: results
}),
elementSorter: e => e.CustomerID,
elementAsserter: (e, a) =>
{
AssertEqual(e.CustomerID, a.CustomerID);
AssertEqual(e.Orders.Count(), a.Orders.Count());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,16 @@ WHERE [c].[CustomerID] LIKE N'F%'
ORDER BY [c].[CustomerID], [t].[OrderID], [t].[OrderID0]");
}

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

AssertSql(
@"SELECT [c].[CustomerID]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] LIKE N'F%'");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down

0 comments on commit 7a7b0e9

Please sign in to comment.