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

Fix aggregates validation in presence of arithmetic expressions #4342

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,11 @@ func (s *SelectStatement) validSelectWithAggregate() error {
calls := map[string]struct{}{}
numAggregates := 0
for _, f := range s.Fields {
if c, ok := f.Expr.(*Call); ok {
fieldCalls := walkFunctionCalls(f.Expr)
for _, c := range fieldCalls {
calls[c.Name] = struct{}{}
}
if len(fieldCalls) != 0 {
numAggregates++
}
}
Expand Down Expand Up @@ -1166,8 +1169,7 @@ func (s *SelectStatement) validSelectWithAggregate() error {

func (s *SelectStatement) validateAggregates(tr targetRequirement) error {
for _, f := range s.Fields {
switch expr := f.Expr.(type) {
case *Call:
for _, expr := range walkFunctionCalls(f.Expr) {
switch expr.Name {
case "derivative", "non_negative_derivative":
if err := s.validSelectWithAggregate(); err != nil {
Expand Down
1 change: 1 addition & 0 deletions influxql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ func TestParser_ParseStatement(t *testing.T) {
{s: `SELECT field1 AS`, err: `found EOF, expected identifier at line 1, char 18`},
{s: `SELECT field1 FROM foo group by time(1s)`, err: `GROUP BY requires at least one aggregate function`},
{s: `SELECT count(value), value FROM foo`, err: `mixing aggregate and non-aggregate queries is not supported`},
{s: `SELECT count(value)/10, value FROM foo`, err: `mixing aggregate and non-aggregate queries is not supported`},
{s: `SELECT count(value) FROM foo group by time(1s)`, err: `aggregate functions with GROUP BY time require a WHERE time clause`},
{s: `SELECT count(value) FROM foo group by time(1s) where host = 'hosta.influxdb.org'`, err: `aggregate functions with GROUP BY time require a WHERE time clause`},
{s: `SELECT count(value) FROM foo group by time`, err: `time() is a function and expects at least one argument`},
Expand Down