From 101a580e02d4d70abe1361c7ae024d0acc5f1e0c Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Thu, 6 Aug 2015 12:15:04 -0500 Subject: [PATCH 1/2] do not allow wildcards with fields in select statements --- influxql/ast.go | 11 +++++++++++ influxql/parser_test.go | 3 +++ 2 files changed, 14 insertions(+) diff --git a/influxql/ast.go b/influxql/ast.go index a0559f90239..089b66e4bb3 100644 --- a/influxql/ast.go +++ b/influxql/ast.go @@ -990,6 +990,10 @@ func (s *SelectStatement) validate(tr targetRequirement) error { return err } + if err := s.validateWildcard(); err != nil { + return err + } + return nil } @@ -1033,6 +1037,13 @@ func (s *SelectStatement) validateAggregates(tr targetRequirement) error { return nil } +func (s *SelectStatement) validateWildcard() error { + if s.HasWildcard() && len(s.Fields) > 1 { + return fmt.Errorf("wildcards can not be combined with other fields") + } + return nil +} + func (s *SelectStatement) HasDistinct() bool { // determine if we have a call named distinct for _, f := range s.Fields { diff --git a/influxql/parser_test.go b/influxql/parser_test.go index 3d7b55ac0c4..86e88a186cf 100644 --- a/influxql/parser_test.go +++ b/influxql/parser_test.go @@ -1247,6 +1247,9 @@ func TestParser_ParseStatement(t *testing.T) { {s: `SELECT value > 2 FROM cpu`, err: `invalid operator > in SELECT clause at line 1, char 8; operator is intended for WHERE clause`}, {s: `SELECT value = 2 FROM cpu`, err: `invalid operator = in SELECT clause at line 1, char 8; operator is intended for WHERE clause`}, {s: `SELECT s =~ /foo/ FROM cpu`, err: `invalid operator =~ in SELECT clause at line 1, char 8; operator is intended for WHERE clause`}, + {s: `SELECT foo, * from cpu`, err: `wildcards can not be combined with other fields`}, + {s: `SELECT *, * from cpu`, err: `found ,, expected FROM at line 1, char 9`}, + {s: `SELECT *, foo from cpu`, err: `found ,, expected FROM at line 1, char 9`}, {s: `DELETE`, err: `found EOF, expected FROM at line 1, char 8`}, {s: `DELETE FROM`, err: `found EOF, expected identifier at line 1, char 13`}, {s: `DELETE FROM myseries WHERE`, err: `found EOF, expected identifier, string, number, bool at line 1, char 28`}, From f4697ebca76a82a74b9b77fe01e925f5f1ca8ab9 Mon Sep 17 00:00:00 2001 From: Cory LaNou Date: Thu, 6 Aug 2015 12:16:33 -0500 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bb97b5a81d..8b9371b4f8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ - [#3288](https://github.com/influxdb/influxdb/issues/3288): Run go fuzz on the line-protocol input - [#3545](https://github.com/influxdb/influxdb/issues/3545): Fix parsing string fields with newlines - [#3579](https://github.com/influxdb/influxdb/issues/3579): Revert breaking change to `client.NewClient` function +- [#3580](https://github.com/influxdb/influxdb/issues/3580): Do not allow wildcards with fields in select statements ## v0.9.2 [2015-07-24]