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: groupby doesn't get translated if the result is projected into DTO #11176

Closed
maumar opened this issue Mar 7, 2018 · 0 comments
Closed
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Mar 7, 2018

This translates correctly:

                var query = ctx.Children
                    .Select(c => c.Group)
                    .GroupBy(g => g)
                    .Select(g => new
                    {
                        Group = g.Key,
                        GroupCount = g.Count()
                    }).ToList();

into:

SELECT [c].[Group], COUNT(*)
            FROM [Children] AS [c]
            GROUP BY [c].[Group]

but this:

                var query = ctx.Children
                    .Select(c => c.Group)
                    .GroupBy(g => g)
                    .Select(g => new BarVm
                    {
                        Group = g.Key,
                        GroupCount = g.Count()
                    }).ToList();

produces the following query plan:

(QueryContext queryContext) => IEnumerable<BarVm> _InterceptExceptions(
    source: IEnumerable<BarVm> _Select(
        source: IEnumerable<IGrouping<int, int>> _GroupBy(
            source: IEnumerable<ValueBuffer> _ShapedQuery(
                queryContext: queryContext, 
                shaperCommandContext: SelectExpression: 
                    SELECT [c].[Group]
                    FROM [Children] AS [c]
                    ORDER BY [c].[Group], 
                shaper: ValueBufferShaper), 
            keySelector: (ValueBuffer c) => int TryReadValue(c, 0, Child.Group), 
            elementSelector: (ValueBuffer c) => int TryReadValue(c, 0, Child.Group)), 
        selector: (IGrouping<int, int> g) => new BarVm{ 
            Group = g.Key, 
            GroupCount = int Count(g) 
        }
    ), 
    contextType: Repro10472.MyContext, 
    logger: DiagnosticsLogger<Query>, 
    queryContext: queryContext)
@smitpatel smitpatel self-assigned this Mar 7, 2018
@ajcvickers ajcvickers added this to the 2.1.0 milestone Mar 7, 2018
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Mar 12, 2018
smitpatel added a commit that referenced this issue Mar 13, 2018
- Add support for translating OrderBy after GroupBy operator
- Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870
- Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157
- GroupBy Aggregate works when key/element/result selector is DTO instead of anonymous type Resolves #11176
- Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218

Part of #10012
smitpatel added a commit that referenced this issue Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator
- Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870
- Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157
- GroupBy Aggregate works when key/element/result selector is DTO instead of anonymous type Resolves #11176
- Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218
- Translate GroupBy Constant/Parameter with aggregates Resolves #9969

Part of #10012
smitpatel added a commit that referenced this issue Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator
- Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870
- Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157
- GroupBy Aggregate works when element/result selector is DTO instead of anonymous type Resolves #11176 (KeySelector has to be client evaluated)
- Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218
- Translate GroupBy Constant/Parameter with aggregates Resolves #9969

Part of #10012
Part of #2341
smitpatel added a commit that referenced this issue Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator
- Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870
- Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157
- GroupBy Aggregate works when element/result selector is DTO instead of anonymous type Resolves #11176 (KeySelector has to be client evaluated)
- Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218
- Translate GroupBy Constant/Parameter with aggregates Resolves #9969

Part of #10012
Part of #2341
smitpatel added a commit that referenced this issue Mar 14, 2018
- Add support for translating OrderBy after GroupBy operator
- Add support for `HAVING` clause in SQL which would be generated when translating predicate after GroupByAggregate Resolves #10870
- Make sure client eval warning is not issued when translating GroupByAggregate Resolves #11157
- GroupBy Aggregate works when element/result selector is DTO instead of anonymous type Resolves #11176 (KeySelector has to be client evaluated)
- Make sure that SQL added to GROUP BY clause is not aliased Resolves #11218
- Translate GroupBy Constant/Parameter with aggregates Resolves #9969

Part of #10012
Part of #2341
@ajcvickers ajcvickers modified the milestones: 2.1.0-preview2, 2.1.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

3 participants