LINQ-to-BigQuery icon indicating copy to clipboard operation
LINQ-to-BigQuery copied to clipboard

Groupby Count

Open naveensrinivasan opened this issue 10 years ago • 2 comments

How do I get this using the library? Which is use the count in the select and order by the count

SELECT actor_login, count(*) as Count FROM [github.dotnet]
WHERE type = "PullRequestEvent"
group by actor_login
order by Count desc
limit 100

I tried this but the

var pr = "PullRequestEvent";
var basequery = From<dotnet>().Where(d => d.type == pr)
.Select(e => new { e.actor_login, e.repo_name })
.GroupBy(e => new { e.actor_login, e.repo_name})
.Limit(100)
.RunDry()
.Dump();

The query it output from the linq is

SELECT
  [actor_login],
  [repo_name]
FROM
  [github-data-1163:github.dotnet]
WHERE
  ([type] = 'PullRequestEvent')
GROUP BY
  [actor_login],
  [repo_name]
LIMIT 100

naveensrinivasan avatar Dec 22 '15 19:12 naveensrinivasan

All BigQuery's function under BqFunc. You can write .Select(e => new { count = BqFunc.Count(), e.actor_login, e.repo_name }) or .Select(e => new { count = Count(), e.actor_login, e.repo_name })

neuecc avatar Dec 22 '15 23:12 neuecc

Thanks for the support. Could I do a PR for the README with all the things I learn trying to use this?

naveensrinivasan avatar Dec 23 '15 00:12 naveensrinivasan