[feature request] GROUP BY tag_key with selector function should return the relevant timestamps
As expected (and liked), when I include a GROUP BY time() clause in my TOP() query, the returned timestamps are the start of the interval:
> SELECT TOP(value,1) FROM pies WHERE time >= '2015-11-05T18:48:13.361920531Z' AND time <= '2015-11-05T18:49:07.679323455Z' GROUP BY time(1m)
name: pies
----------
time top
2015-11-05T18:48:00Z 2000
2015-11-05T18:49:00Z 2
But, when I only GROUP BY a tag key, it would be nice to get back the relevant timestamps:
> SELECT TOP(value,1) FROM pies GROUP BY kind
name: pies
tags: kind=apple
time top
---- ---
1970-01-01T00:00:00Z 100
name: pies
tags: kind=pumpkin
time top
---- ---
1970-01-01T00:00:00Z 2000
Same happens for LAST and likely for all selector functions. They should return the actual timestamp rather than epoch 0.
+1
Even when we not use GROUP BY it still returns the epoch 0 time as in SELECT last(field_key) from measurement_name in latest 0.10.1 version.
> SELECT last(price) from Revenue_daily
name: Revenue_daily
-------------------
time last
0 7777
As a workaround, have you tried including time in your field selection list?
SELECT TOP(value,1), time
FROM pies
WHERE time >= '2015-11-05T18:48:13.361920531Z' AND time <= '2015-11-05T18:49:07.679323455Z'
GROUP BY time(1m)
SELECT time, last(price) from Revenue_daily
@PaulMest works for me
You could also use something like this:
SELECT value, time
FROM pies
GROUP BY kind
ORDER BY time DESC LIMIT 1
Not sure if it is faster or slower, though.
On 0.12.2 @jokogr works for me
> select value,time from ambient_temperature order by time desc limit 1
name: ambient_temperature
-------------------------
time value
2016-05-19T20:54:01.85Z 20.375
but @PaulMest does not work
> select time,last(value) from ambient_temperature
name: ambient_temperature
-------------------------
time last
1970-01-01T00:00:00Z 20.375
Adding a where clause gives a valid timestamp :
> select last(value) from ambient_temperature where time > now() - 1m
name: ambient_temperature
-------------------------
time last
2016-05-19T20:57:08.146125643Z 20.40625
@rkuchan does the suggestion @PaulMest work?
@e-dard - it looks like the behavior has changed since I opened this issue - I'm on version 1.1. I'm now getting the expected timestamps when I GROUP BY a tag key:
> SELECT top(water_level,2) from h2o_feet where time >= '2015-08-18T00:00:00Z' and time <= '2015-08-18T00:24:00Z' group by location
name: h2o_feet
tags: location=coyote_creek
time top
---- ---
2015-08-18T00:00:00Z 8.12
2015-08-18T00:06:00Z 8.005
name: h2o_feet
tags: location=santa_monica
time top
---- ---
2015-08-18T00:06:00Z 2.116
2015-08-18T00:18:00Z 2.126
I don't think including time in the SELECT clause does anything to affect the query. I wasn't aware that you could get any change in behavior by specifying time - wouldn't InfluxDB just assume that time is a field key and ignore it (assuming you don't have a field key called time)?
Note: addressed in https://github.com/influxdata/platform/pull/360