Aggregate functions fail if condition on time is similar to: WHERE time < 'YYYY-MM-dd'
Hello,
Something strange is happening with aggregate functions: if the restrictive condition on time is "WHERE time > 'YYYY-MM-dd'" or "WHERE time > 'YYYY-MM-dd' AND time < 'YYYY-MM-dd'", one gets the expected results. However if the condition is only "WHERE time < 'YYYY-MM-dd'" then an empty result is returned. The examples below should be self-explanatory (I use the influxdb-python client).
>>> client.query("SELECT value FROM demo")
{'demo': value
2014-10-31 08:43:01+00:00 16.2260
2014-10-31 08:43:01.200000+00:00 16.3990
2014-10-31 08:43:01.400000+00:00 16.4080
2014-10-31 08:43:01.600000+00:00 16.2360
... ...
2014-10-31 12:04:21.198365+00:00 10.0270
2014-10-31 12:04:21.398774+00:00 10.0080
2014-10-31 12:04:21.599183+00:00 9.9268
2014-10-31 12:04:21.799592+00:00 9.9211
2014-10-31 12:04:22.000001+00:00 9.9288
[60308 rows x 1 columns]}
>>> client.query("SELECT MEAN(value) FROM demo WHERE time > '2014-10-01' GROUP BY time(1d)")
{'demo': mean
2014-10-01 00:00:00+00:00 NaN
2014-10-02 00:00:00+00:00 NaN
2014-10-03 00:00:00+00:00 NaN
2014-10-04 00:00:00+00:00 NaN
... ...
2015-06-26 00:00:00+00:00 NaN
2015-06-27 00:00:00+00:00 NaN
2015-06-28 00:00:00+00:00 NaN
2015-06-29 00:00:00+00:00 NaN
2015-06-30 00:00:00+00:00 NaN
[273 rows x 1 columns]}
>>> client.query("SELECT MEAN(value) FROM demo WHERE time > '2014-10-01' AND time < '2014-11-01' GROUP BY time(1d)")
{'demo': mean
2014-10-01 00:00:00+00:00 NaN
2014-10-02 00:00:00+00:00 NaN
2014-10-03 00:00:00+00:00 NaN
2014-10-04 00:00:00+00:00 NaN
2014-10-05 00:00:00+00:00 NaN
2014-10-06 00:00:00+00:00 NaN
2014-10-07 00:00:00+00:00 NaN
2014-10-08 00:00:00+00:00 NaN
2014-10-09 00:00:00+00:00 NaN
2014-10-10 00:00:00+00:00 NaN
2014-10-11 00:00:00+00:00 NaN
2014-10-12 00:00:00+00:00 NaN
2014-10-13 00:00:00+00:00 NaN
2014-10-14 00:00:00+00:00 NaN
2014-10-15 00:00:00+00:00 NaN
2014-10-16 00:00:00+00:00 NaN
2014-10-17 00:00:00+00:00 NaN
2014-10-18 00:00:00+00:00 NaN
2014-10-19 00:00:00+00:00 NaN
2014-10-20 00:00:00+00:00 NaN
2014-10-21 00:00:00+00:00 NaN
2014-10-22 00:00:00+00:00 NaN
2014-10-23 00:00:00+00:00 NaN
2014-10-24 00:00:00+00:00 NaN
2014-10-25 00:00:00+00:00 NaN
2014-10-26 00:00:00+00:00 NaN
2014-10-27 00:00:00+00:00 NaN
2014-10-28 00:00:00+00:00 NaN
2014-10-29 00:00:00+00:00 NaN
2014-10-30 00:00:00+00:00 NaN
2014-10-31 00:00:00+00:00 8.935495}
>>> client.query("SELECT MEAN(value) FROM demo WHERE time < '2014-11-01' GROUP BY time(1d)")
{'demo': mean
1970-01-01 00:00:00+00:00 None}
>>>
I think this is a duplicate of #3050 and #3116, should be addressed with better error messages in #2702 and documentation about lower bounds.
@pjalet to summarize, you need to give an explicit lower bound for the time range for GROUP BY queries. The database has no way of knowing where to start, otherwise, and will start at epoch 0.