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

Query: Translate GroupBy-Aggregate when using result selector #18415

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Query: Translate GroupBy-Aggregate when using result selector
Resolves #18267
  • Loading branch information
smitpatel committed Oct 17, 2019
commit a0e90e5434a471e747042e80a6da6a33ba37522a
Original file line number Diff line number Diff line change
Expand Up @@ -246,23 +246,20 @@ protected override ShapedQueryExpression TranslateGroupBy(ShapedQueryExpression
}

var inMemoryQueryExpression = (InMemoryQueryExpression)source.QueryExpression;
// Save valueBufferParameter if we need to replace it in translated key later.
smitpatel marked this conversation as resolved.
Show resolved Hide resolved
source.ShaperExpression = inMemoryQueryExpression.ApplyGrouping(translatedKey, source.ShaperExpression);

if (resultSelector == null)
{
return source;
}

var keyAccessExpression = Expression.MakeMemberAccess(
source.ShaperExpression,
source.ShaperExpression.Type.GetTypeInfo().GetMember(nameof(IGrouping<int, int>.Key))[0]);

var original1 = resultSelector.Parameters[0];
var original2 = resultSelector.Parameters[1];

var newResultSelectorBody = new ReplacingExpressionVisitor(
new Dictionary<Expression, Expression> {
{ original1, keyAccessExpression },
{ original1, ((GroupByShaperExpression)source.ShaperExpression).KeySelector },
{ original2, source.ShaperExpression }
}).Visit(resultSelector.Body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,13 @@ protected override ShapedQueryExpression TranslateGroupBy(
return source;
}

var keyAccessExpression = Expression.MakeMemberAccess(
source.ShaperExpression,
source.ShaperExpression.Type.GetTypeInfo().GetMember(nameof(IGrouping<int, int>.Key))[0]);

var original1 = resultSelector.Parameters[0];
var original2 = resultSelector.Parameters[1];

var newResultSelectorBody = new ReplacingExpressionVisitor(
new Dictionary<Expression, Expression>
{
{ original1, keyAccessExpression }, { original2, source.ShaperExpression }
{ original1, translatedKey }, { original2, source.ShaperExpression }
})
.Visit(resultSelector.Body);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7802,7 +7802,7 @@ from g in ss.Set<Gear>()
elementSorter: e => (e.Name, e.Count, e.Sum));
}

[ConditionalTheory(Skip = "issue #18267")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_GroupBy_after_set_operator_using_result_selector(bool isAsync)
{
Expand Down