Refine implementation, sole time is invalid

pull/3778/head
Philip O'Toole 2015-08-20 16:37:41 -07:00
parent 7eb004d1af
commit e032242d83
2 changed files with 4 additions and 5 deletions

View File

@ -1013,10 +1013,9 @@ func (s *SelectStatement) validate(tr targetRequirement) error {
} }
func (s *SelectStatement) validateFields() error { func (s *SelectStatement) validateFields() error {
for _, f := range s.NamesInSelect() { ns := s.NamesInSelect()
if f == "time" { if len(ns) == 1 && ns[0] == "time" {
return fmt.Errorf("'time' is an invalid field for SELECT") return fmt.Errorf("at least 1 non-time field must be queried")
}
} }
return nil return nil
} }

View File

@ -1206,7 +1206,7 @@ func TestParser_ParseStatement(t *testing.T) {
// Errors // Errors
{s: ``, err: `found EOF, expected SELECT, DELETE, SHOW, CREATE, DROP, GRANT, REVOKE, ALTER, SET at line 1, char 1`}, {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`, 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: `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 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`}, {s: `SELECT field1 FROM "series" WHERE X +;`, err: `found ;, expected identifier, string, number, bool at line 1, char 38`},