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

sql/parser: add support for aggregate functions #2043

Closed
petermattis opened this issue Aug 10, 2015 · 1 comment
Closed

sql/parser: add support for aggregate functions #2043

petermattis opened this issue Aug 10, 2015 · 1 comment
Assignees
Milestone

Comments

@petermattis
Copy link
Collaborator

Aggregate functions perform some operation on the result set for a query. The basics are avg, count, max, min and sum. A typical query might look like SELECT count(*) FROM foo. Note that the aggregate function might affect index selection. For example, SELECT MAX(timestamp) FROM foo might be satisfied via a single index read if there is an index on timestamp.

Conveniently, aggregate functions cannot be mixed with non-aggregate values. This is not valid: SELECT AVG(k), k FROM foo

@petermattis petermattis added this to the v0.1 (Beta) milestone Aug 14, 2015
@tbg tbg added the SQL label Aug 15, 2015
@jess-edwards jess-edwards mentioned this issue Aug 17, 2015
78 tasks
@petermattis petermattis self-assigned this Aug 20, 2015
@petermattis
Copy link
Collaborator Author

Aggregate functions to implement (initially):

  • AVG(expression)
  • COUNT(*)
  • COUNT(expression)
  • MAX(expression)
  • MIN(expression)
  • SUM(expression)

The initial implementation can be fairly dumb: if an aggregate function is detected add a new aggregateNode which evaluates the expression. Optimizing MIN and MAX should be done where an appropriate index is available. Trying to distribute the aggregate calculation will be left for later.

petermattis added a commit that referenced this issue Aug 22, 2015
Added planner.groupBy which analyzes looks for any aggregate functions
in the select targets. If an aggregate function is found, we check to
make sure the select targets are valid and then rewrite the scanNode so
that it outputs the argument expressions for the aggregates.

Fixes #2043.
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

2 participants