From e032242d83c595e6d6125a64632b8f02a0a5cfac Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Thu, 20 Aug 2015 16:37:41 -0700 Subject: [PATCH] Refine implementation, sole time is invalid --- influxql/ast.go | 7 +++---- influxql/parser_test.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/influxql/ast.go b/influxql/ast.go index fef4535b51..31cf82e245 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -1013,10 +1013,9 @@ func (s *SelectStatement) validate(tr targetRequirement) error { } func (s *SelectStatement) validateFields() error { - for _, f := range s.NamesInSelect() { - if f == "time" { - return fmt.Errorf("'time' is an invalid field for SELECT") - } + ns := s.NamesInSelect() + if len(ns) == 1 && ns[0] == "time" { + return fmt.Errorf("at least 1 non-time field must be queried") } return nil } diff --git a/influxql/parser_test.go b/influxql/parser_test.go index 20b158a569..b9bb9756db 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -1206,7 +1206,7 @@ func TestParser_ParseStatement(t *testing.T) { // Errors {s: ``, err: `found EOF, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER, SET at line 1, char 1`}, {s: `SELECT`, err: `found EOF, expected identifier, string, number, bool at line 1, char 8`}, - {s: `SELECT time FROM myserie`, err: `'time' is an invalid field for SELECT`}, + {s: `SELECT time FROM myseries`, err: `at least 1 non-time field must be queried`}, {s: `blah blah`, err: `found blah, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER, SET at line 1, char 1`}, {s: `SELECT field1 X`, err: `found X, expected FROM at line 1, char 15`}, {s: `SELECT field1 FROM "series" WHERE X +;`, err: `found ;, expected identifier, string, number, bool at line 1, char 38`},