From eb1a4f669a1dcfc8127aacd07854f98c21d83c97 Mon Sep 17 00:00:00 2001 From: Cory LaNou <cory@lanou.com> Date: Tue, 12 May 2015 08:56:38 -0600 Subject: [PATCH] refactor selectStatement validate --- influxql/ast.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/influxql/ast.go b/influxql/ast.go index f9268c4ee8..316562ae9f 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -861,14 +861,17 @@ func (s *SelectStatement) hasTimeDimensions(node Node) bool { // Validate checks certain edge conditions to determine if this is a valid select statment func (s *SelectStatement) Validate(tr targetRequirement) error { + // fetch the group by duration + groupByDuration, _ := s.GroupByInterval() + // If we have a group by interval, but no aggregate function, it's an invalid statement - if d, _ := s.GroupByInterval(); s.IsRawQuery && d > 0 { + if s.IsRawQuery && groupByDuration > 0 { return fmt.Errorf("GROUP BY requires at least one aggregate function") } // If we have an aggregate function with a group by time without a where clause, it's an invalid statement if tr == targetNotRequired { // ignore create continuous query statements - if d, _ := s.GroupByInterval(); !s.IsRawQuery && d > 0 && !s.hasTimeDimensions(s.Condition) { + if !s.IsRawQuery && groupByDuration > 0 && !s.hasTimeDimensions(s.Condition) { return fmt.Errorf("aggregate functions with GROUP BY time require a WHERE time clause") } }