Skip to content

Commit

Permalink
Merge pull request #3580 from influxdb/enforce-single-select-wildcard
Browse files Browse the repository at this point in the history
Do not allow wildcards with fields in select statements
  • Loading branch information
corylanou committed Aug 6, 2015
2 parents 9e09976 + f4697eb commit f6b2af2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
11 changes: 11 additions & 0 deletions influxql/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,10 @@ func (s *SelectStatement) validate(tr targetRequirement) error {
return err
}

if err := s.validateWildcard(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions influxql/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`},
Expand Down

0 comments on commit f6b2af2

Please sign in to comment.