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

Default arguments for aggregate functions #23

Closed
julianhyde opened this issue Mar 22, 2020 · 1 comment
Closed

Default arguments for aggregate functions #23

julianhyde opened this issue Mar 22, 2020 · 1 comment

Comments

@julianhyde
Copy link
Collaborator

In the compute sub-clause of group, make the of expression optional.

The of expression is an extractor that converts each incoming row into the argument for the aggregate function. The aggregate function is then called with those values converted into a list. For example, in

from e in emps
  group  compute sum of e.deptno as sumDeptno;

the sum aggregate function is called with the list [10, 20, 30, 20] formed by applying the lambda fn e => e.deptno to each row.

With this change, you would be able to omit of. The aggregate function is passed the incoming rows. For example,

from e in emps
  group compute count as c

is equivalent to

from e in emps
  group compute count of e as c

If there is more than one variable in the from clause (or the previous step, if it is a multi-step from) the row is a record with each variable as a field. Thus

from e in emps, d in depts
  where e.deptno = d.deptno
  group compute count as c

is equivalent to

from e in emps, d in depts
  where e.deptno = d.deptno
  group compute count of {e, d} as c

This change is basically just a short-hand. In practice, the main effect is to make count more concise, and more similar to SQL's COUNT(*).

It will also be useful for a "collect" aggregate function that builds a list of the rows in each group.

@julianhyde
Copy link
Collaborator Author

Fixed in c718bbb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant