Skip to content

Commit

Permalink
Merge pull request #4342 from kostya-sh/4325_ast-bug
Browse files Browse the repository at this point in the history
Fix aggregates validation in presence of arithmetic expressions
  • Loading branch information
otoolep committed Oct 7, 2015
2 parents 883d32c + 95a0e14 commit 11675df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
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

0 comments on commit 11675df

Please sign in to comment.