question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query: GroupBy Where Aggregate translation to server

See original GitHub issue

Currently if there is predicate after grouping and before applying Aggregate operation we block the translation to server and do streaming GroupBy. Aggregate operator argument can take Case Block to do conditional aggregate and allow us to generate Group By clause in SQL. Structure would be

COUNT(
    CASE 
        WHEN predicate 
        THEN projection
        ELSE NULL
    END
)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
AlekseyMartynovcommented, Jun 20, 2018

Hello @smitpatel I recently stumbled upon this issue and found that there is a family of equivalent aggregates:

  1. .GroupBy(o => o.OrderDate)
    .Select(g => g.Count(i => i.OrderDate != null))
    
  2. .GroupBy(o => o.OrderDate)
    .Select(g => g.Where(i => i.OrderDate != null).Count())
    
  3. .GroupBy(o => o.OrderDate)
    .Select(g => g.Select(i => i.OrderDate != null ? 1 : 0).Sum())
    
  4. .GroupBy(o => o.OrderDate)
    .Select(g => g.Select(i => i.OrderDate != null ? (int?)1 : null).Sum())
    

(maybe more?)

Please support them all in the context of this feature. This code from NHibernate seems relevant and useful.

3reactions
smitpatelcommented, Jun 20, 2018

@AlekseyMartynov - Thanks for information. All of them are normalized into single form in our query parser so shouldn’t be issue in supporting them all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does LINQ to SQL translate GroupBy into multiple ...
I think that query gets easily translated into SQL group by because it only involves an aggregate function and the aggregate column, but...
Read more >
Complex Query Operators - EF Core
EF Core also translates queries where an aggregate operator on the grouping appears in a Where or OrderBy (or other ordering) LINQ operator....
Read more >
SQL GROUP BY Statement
The GROUP BY statement is often used with aggregate functions ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group...
Read more >
SQL | GROUP BY
The GROUP BY Statement in SQL is used to arrange identical data into groups with the help of some functions. i.e. if a...
Read more >
SQL Group By Tutorial: Count, Sum, Average, and Having ...
In this article we'll look at how to construct a GROUP BY clause, what it does to your query, and how you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found