Skip to content

Commit

Permalink
Cosmos: Apply projection in post processor (#23412)
Browse files Browse the repository at this point in the history
  • Loading branch information
smitpatel authored Nov 20, 2020
1 parent e45256e commit a076e3f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public CosmosQueryTranslationPostprocessor(
public override Expression Process(Expression query)
{
query = base.Process(query);

if (query is ShapedQueryExpression shapedQueryExpression
&& shapedQueryExpression.QueryExpression is SelectExpression selectExpression)
{
// Cosmos does not have nested select expression so this should be safe.
selectExpression.ApplyProjection();
}

query = new CosmosValueConverterCompensatingExpressionVisitor(_sqlExpressionFactory).Visit(query);

return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ protected override Expression VisitShapedQuery(ShapedQueryExpression shapedQuery
{
case SelectExpression selectExpression:

selectExpression.ApplyProjection();

shaperBody = new CosmosProjectionBindingRemovingExpressionVisitor(
selectExpression, jObjectParameter,
QueryCompilationContext.QueryTrackingBehavior == QueryTrackingBehavior.TrackAll)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ public virtual void Where_conditional_bool_with_value_conversion_is_used()
Assert.Equal("http://blog.com", result.Url);
}

[ConditionalFact(Skip = "Issue #21142")]
[ConditionalFact]
public virtual void Select_conditional_bool_with_value_conversion_is_used()
{
using var context = CreateContext();
Expand Down
2 changes: 2 additions & 0 deletions test/EFCore.Specification.Tests/LazyLoadProxyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2315,6 +2315,8 @@ public virtual void Top_level_projection_track_entities_before_passing_to_client
orderby p.Id
select DtoFactory.CreateDto(p)).FirstOrDefault();

RecordLog();

Assert.NotNull(((dynamic)query).Single);
}

Expand Down
12 changes: 4 additions & 8 deletions test/EFCore.Specification.Tests/OptimisticConcurrencyTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,8 @@ public virtual Task
null);
}

[ConditionalFact(Skip = "Many-to-many relationships are not supported without CLR class for join table.")]
// TODO: See issue#1368
public virtual Task
Attempting_to_delete_same_relationship_twice_for_many_to_many_results_in_independent_association_exception()
[ConditionalFact(Skip = "Issue#23411")]
public virtual Task Attempting_to_delete_same_relationship_twice_for_many_to_many_results_in_independent_association_exception()
{
return ConcurrencyTestAsync(
c =>
Expand All @@ -292,10 +290,8 @@ public virtual Task
null);
}

[ConditionalFact(Skip = "Many-to-many relationships are not supported without CLR class for join table.")]
// TODO: See issue#1368
public virtual Task
Attempting_to_add_same_relationship_twice_for_many_to_many_results_in_independent_association_exception()
[ConditionalFact(Skip = "Issue#23411")]
public virtual Task Attempting_to_add_same_relationship_twice_for_many_to_many_results_in_independent_association_exception()
{
return ConcurrencyTestAsync(
c =>
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Specification.Tests/StoreGeneratedTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void ValueGenerationNegative<TKey, TEntity, TConverter>()
Assert.Throws<NotSupportedException>(() => context.Add(new TEntity())).Message);
}

[ConditionalFact(Skip = "Issue#15589")]
[ConditionalFact]
public virtual void Value_generation_works_for_common_GUID_conversions()
{
ValueGenerationPositive<Guid, GuidToString>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,17 +433,21 @@ FROM [Child] AS [c]
}
}

[ConditionalFact(Skip = "Issue#1015")]
[ConditionalFact]
public override void Top_level_projection_track_entities_before_passing_to_client_method()
{
base.Top_level_projection_track_entities_before_passing_to_client_method();

Assert.Equal(
@"@__p_0='707' (Nullable = true)
@"SELECT TOP(1) [p].[Id], [p].[AlternateId], [p].[Discriminator]
FROM [Parent] AS [p]
ORDER BY [p].[Id]
@__p_0='707' (Nullable = true)
SELECT [c].[Id], [c].[ParentId]
FROM [Child] AS [c]
WHERE [c].[ParentId] = @__p_0",
SELECT [s].[Id], [s].[ParentId]
FROM [Single] AS [s]
WHERE [s].[ParentId] = @__p_0",
Sql,
ignoreLineEndingDifferences: true);
}
Expand Down
8 changes: 5 additions & 3 deletions test/EFCore.Tests/ChangeTracking/Internal/QueryFixupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -888,18 +888,20 @@ public void Query_owned()
});
}

[ConditionalFact(Skip = "Issue #16752")]
[ConditionalFact]
public void Query_subowned()
{
Seed();

using var context = new QueryFixupContext();
var subDependent1 = context.Set<Order>()
.Include(a => a.OrderDetails.BillingAddress.OrderDetails.Order)
.Select(o => o.OrderDetails.BillingAddress)
.Include(a => a.OrderDetails.Order).Single();
.Single();
var subDependent2 = context.Set<Order>()
.Include(a => a.OrderDetails.ShippingAddress.OrderDetails.Order)
.Select(o => o.OrderDetails.ShippingAddress)
.Include(a => a.OrderDetails.Order).Single();
.Single();

AssertFixup(
context,
Expand Down

0 comments on commit a076e3f

Please sign in to comment.