Restrict top() and bottom() selectors to be used with no other functions
parent
31db9d6f46
commit
57a2abbc87
|
@ -42,6 +42,7 @@
|
|||
- [#8058](https://github.com/influxdata/influxdb/pull/8058): Enabled golint for admin, httpd, subscriber, udp. @karlding
|
||||
- [#8252](https://github.com/influxdata/influxdb/issues/8252): Implicitly cast null to false in binary expressions with a boolean.
|
||||
- [#8067](https://github.com/influxdata/influxdb/issues/8067): Restrict fill(none) and fill(linear) to be usable only with aggregate queries.
|
||||
- [#8065](https://github.com/influxdata/influxdb/issues/8065): Restrict top() and bottom() selectors to be used with no other functions.
|
||||
|
||||
## v1.2.3 [unreleased]
|
||||
|
||||
|
|
|
@ -1761,6 +1761,10 @@ func (s *SelectStatement) validate(tr targetRequirement) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := s.validateTopBottom(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.validateAggregates(tr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -2247,7 +2251,7 @@ func (s *SelectStatement) validateDistinct() error {
|
|||
}
|
||||
|
||||
if len(s.Fields) > 1 {
|
||||
return fmt.Errorf("aggregate function distinct() can not be combined with other functions or fields")
|
||||
return fmt.Errorf("aggregate function distinct() cannot be combined with other functions or fields")
|
||||
}
|
||||
|
||||
switch c := s.Fields[0].Expr.(type) {
|
||||
|
@ -2263,6 +2267,19 @@ func (s *SelectStatement) validateDistinct() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *SelectStatement) validateTopBottom() error {
|
||||
// Ensure there are not multiple calls if top/bottom is present.
|
||||
info := newSelectInfo(s)
|
||||
if len(info.calls) > 1 {
|
||||
for call := range info.calls {
|
||||
if call.Name == "top" || call.Name == "bottom" {
|
||||
return fmt.Errorf("selector function %s() cannot be combined with other functions", call.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupByInterval extracts the time interval, if specified.
|
||||
func (s *SelectStatement) GroupByInterval() (time.Duration, error) {
|
||||
// return if we've already pulled it out
|
||||
|
|
|
@ -2606,12 +2606,12 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
{s: `SELECT field1 FROM 12`, err: `found 12, expected identifier at line 1, char 20`},
|
||||
{s: `SELECT 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 FROM myseries`, err: `unable to parse integer at line 1, char 8`},
|
||||
{s: `SELECT 10.5h FROM myseries`, err: `found h, expected FROM at line 1, char 12`},
|
||||
{s: `SELECT distinct(field1), sum(field1) FROM myseries`, err: `aggregate function distinct() can not be combined with other functions or fields`},
|
||||
{s: `SELECT distinct(field1), field2 FROM myseries`, err: `aggregate function distinct() can not be combined with other functions or fields`},
|
||||
{s: `SELECT distinct(field1), sum(field1) FROM myseries`, err: `aggregate function distinct() cannot be combined with other functions or fields`},
|
||||
{s: `SELECT distinct(field1), field2 FROM myseries`, err: `aggregate function distinct() cannot be combined with other functions or fields`},
|
||||
{s: `SELECT distinct(field1, field2) FROM myseries`, err: `distinct function can only have one argument`},
|
||||
{s: `SELECT distinct() FROM myseries`, err: `distinct function requires at least one argument`},
|
||||
{s: `SELECT distinct FROM myseries`, err: `found FROM, expected identifier at line 1, char 17`},
|
||||
{s: `SELECT distinct field1, field2 FROM myseries`, err: `aggregate function distinct() can not be combined with other functions or fields`},
|
||||
{s: `SELECT distinct field1, field2 FROM myseries`, err: `aggregate function distinct() cannot be combined with other functions or fields`},
|
||||
{s: `SELECT count(distinct) FROM myseries`, err: `found ), expected (, identifier at line 1, char 22`},
|
||||
{s: `SELECT count(distinct field1, field2) FROM myseries`, err: `count(distinct <field>) can only have one argument`},
|
||||
{s: `select count(distinct(too, many, arguments)) from myseries`, err: `count(distinct <field>) can only have one argument`},
|
||||
|
@ -2680,6 +2680,8 @@ func TestParser_ParseStatement(t *testing.T) {
|
|||
{s: `SELECT sum(value) + count(foo + sum(bar)) FROM cpu`, err: `binary expressions cannot mix aggregates and raw fields`},
|
||||
{s: `SELECT mean(value) FROM cpu FILL + value`, err: `fill must be a function call`},
|
||||
{s: `SELECT sum(mean) FROM (SELECT mean(value) FROM cpu GROUP BY time(1h))`, err: `aggregate functions with GROUP BY time require a WHERE time clause`},
|
||||
{s: `SELECT top(value, 2), max(value) FROM cpu`, err: `selector function top() cannot be combined with other functions`},
|
||||
{s: `SELECT bottom(value, 2), max(value) FROM cpu`, err: `selector function bottom() cannot be combined with other functions`},
|
||||
// See issues https://github.com/influxdata/influxdb/issues/1647
|
||||
// and https://github.com/influxdata/influxdb/issues/4404
|
||||
//{s: `DELETE`, err: `found EOF, expected FROM at line 1, char 8`},
|
||||
|
|
|
@ -4266,13 +4266,13 @@ func TestServer_Query_AggregateSelectors(t *testing.T) {
|
|||
name: "distinct - time",
|
||||
params: url.Values{"db": []string{"db0"}},
|
||||
command: `SELECT time, distinct(rx) FROM network where time >= '2000-01-01T00:00:00Z' AND time <= '2000-01-01T00:01:29Z' group by time(30s)`,
|
||||
exp: `{"error":"error parsing query: aggregate function distinct() can not be combined with other functions or fields"}`,
|
||||
exp: `{"error":"error parsing query: aggregate function distinct() cannot be combined with other functions or fields"}`,
|
||||
},
|
||||
&Query{
|
||||
name: "distinct - tx",
|
||||
params: url.Values{"db": []string{"db0"}},
|
||||
command: `SELECT tx, distinct(rx) FROM network where time >= '2000-01-01T00:00:00Z' AND time <= '2000-01-01T00:01:29Z' group by time(30s)`,
|
||||
exp: `{"error":"error parsing query: aggregate function distinct() can not be combined with other functions or fields"}`,
|
||||
exp: `{"error":"error parsing query: aggregate function distinct() cannot be combined with other functions or fields"}`,
|
||||
},
|
||||
&Query{
|
||||
name: "mean - baseline 30s",
|
||||
|
|
Loading…
Reference in New Issue