influxdb icon indicating copy to clipboard operation
influxdb copied to clipboard

Select statement aggregate validation is too strict

Open legendary-jarppi opened this issue 11 years ago • 2 comments

version: 0.9.4.1 rpm: https://s3.amazonaws.com/influxdb/influxdb_0.9.4.1_amd64.deb system: amazon linux 3.14.35-28.38.amzn1.x86_64

Running query:

select sum(value1), sum(value2)/10 from time_series group by time(10s), host

results in response:

ERR: error parsing query: mixing aggregate and non-aggregate queries is not supported

even though there are only aggregates in the query. To me it seems that counting of aggregates in influxql/ast.go validateAggregates function is too strict to expect that all aggregates are if type Call as they can also be of type Expr in some cases.

This can be easily reproduced by adding following query to cmd/influxd/run/server_test.go TestServer_Query_Tags function:

&Query{
    name:    "group by tag with aggregate function",
    command: `SELECT sum(value), sum(value)/10 FROM db0.rp0.cpu GROUP by host`,
    exp:     fmt.Sprintf(`{"results":[{"series":[{"name":"cpu","tags":{"host":"server01"},"columns":["time","value"],"values":[["%s",100]]},{"name":"cpu","tags":{"host":"server02"},"columns":["time","value"],"values":[["%s",50]]}]}]}`, now.Format(time.RFC3339Nano), now.Add(1).Format(time.RFC3339Nano)),
}, 

legendary-jarppi avatar Oct 05 '15 10:10 legendary-jarppi

I also get the same issue when dividing two sums - e.g.

SELECT sum(thruput), sum(http400s), sum(totalms) / sum(thruput) FROM ...

The original term of my query was '0.001 * sum(totalms) / sum(thruput)'. This worked fine with the previous 0.9 version (built from source on 4th Aug 2015).

andycarlsonuk avatar Nov 30 '15 17:11 andycarlsonuk

This seems to be fixed in the upcoming 0.11.

> create database mydb
> use mydb
Using database mydb
> insert cpu value=2
> select sum(value)/10 from cpu
name: cpu
---------
time    sum
0       0.2

Please reopen if this is still an issue. Thanks.

jsternberg avatar Mar 14 '16 21:03 jsternberg