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: Distinct GroupBy fails for InMemory #9591

Closed
smitpatel opened this issue Aug 25, 2017 · 0 comments
Closed

Query: Distinct GroupBy fails for InMemory #9591

smitpatel opened this issue Aug 25, 2017 · 0 comments
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

@smitpatel
Copy link
Contributor

Query

        [ConditionalFact]
        public virtual void Select_Distinct_GroupBy()
        {
            AssertQuery<Order>(
                os => os.Select(o => new { o.CustomerID, o.EmployeeID }).OrderBy(a => a.EmployeeID).Distinct().GroupBy(o => o.CustomerID),
                elementSorter: GroupingSorter<string, object>(),
                elementAsserter: GroupingAsserter<string, dynamic>(d => d.EmployeeID));
        }

Fails in assertion
Query Plan

Output from Microsoft.EntityFrameworkCore.Query.SimpleQueryInMemoryTest.Select_Distinct_GroupBy:
  Entity Framework Core 2.1.0-preview1 initialized 'NorthwindContext' using provider 'Microsoft.EntityFrameworkCore.InMemory' with options: SensitiveDataLoggingEnabled StoreName=Northwind 
  Compiling query model: 
  '(from Order o in DbSet<Order>
  order by [o].EmployeeID asc
  select new <>f__AnonymousType273<string, Nullable<int>>(
      [o].CustomerID, 
      [o].EmployeeID
  ))
  .Distinct()
  .GroupBy([o].CustomerID, new <>f__AnonymousType273`2(CustomerID = [o].CustomerID, EmployeeID = [o].EmployeeID))'
  Optimized query model: 
  '(from Order o in DbSet<Order>
  order by [o].EmployeeID asc
  select new <>f__AnonymousType273<string, Nullable<int>>(
      [o].CustomerID, 
      [o].EmployeeID
  ))
  .Distinct()
  .GroupBy([o].CustomerID, new <>f__AnonymousType273`2(CustomerID = [o].CustomerID, EmployeeID = [o].EmployeeID))'
  (QueryContext queryContext) => IEnumerable<IGrouping<string, <>f__AnonymousType273<string, Nullable<int>>>> _InterceptExceptions(
      source: IEnumerable<IGrouping<string, <>f__AnonymousType273<string, Nullable<int>>>> _GroupBy(
          source: IEnumerable<ValueBuffer> Distinct(IOrderedEnumerable<ValueBuffer> _OrderBy(
                  source: IEnumerable<ValueBuffer> ProjectionQuery(
                      queryContext: queryContext, 
                      entityType: EntityType: Order), 
                  expression: (ValueBuffer o) => Nullable<int> TryReadValue(o, 2, Order.EmployeeID), 
                  orderingDirection: Asc)), 
          keySelector: (ValueBuffer o) => string TryReadValue(o, 1, Order.CustomerID), 
          elementSelector: (ValueBuffer o) => new <>f__AnonymousType273<string, Nullable<int>>(
              string TryReadValue(o, 1, Order.CustomerID), 
              Nullable<int> TryReadValue(o, 2, Order.EmployeeID)
          )), 
      contextType: TestModels.Northwind.NorthwindContext, 
      logger: DiagnosticsLogger<Query>, 
      queryContext: queryContext)

The issue is Distinct is being applied on ValueBuffers which is not going work hence we generate duplicate entries in grouping. The root cause is we are optimizing away the selector in EntityQueryModelVisitor.VisitSelectClause to skip for GroupBy or All result operator. But we cannot do that if there are other result operators.

Disabling test for inmemory for now.

@ajcvickers ajcvickers added this to the Backlog milestone Aug 30, 2017
@smitpatel smitpatel modified the milestones: Backlog, 3.0.0 Aug 28, 2019
smitpatel added a commit that referenced this issue Aug 28, 2019
@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 Aug 28, 2019
@smitpatel smitpatel self-assigned this Aug 28, 2019
smitpatel added a commit that referenced this issue Aug 28, 2019
smitpatel added a commit that referenced this issue Aug 29, 2019
smitpatel added a commit that referenced this issue Sep 3, 2019
@bricelam bricelam modified the milestones: 3.0.0, 3.0.0-rc1 Sep 16, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-rc1, 3.0.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