tsbs
tsbs copied to clipboard
"low-fuel" query implementation in influxdb has wrong semantics
The influxdb implementation generates this query:
SELECT "name", "driver", "fuel_state"
FROM "diagnostics"
WHERE "fuel_state" <= 0.1 AND "fleet" = 'West'
GROUP BY "name"
ORDER BY "time" DESC
LIMIT 1
which doesn't match the expected semantics. This finds, for each vehicle, the last timestamp at which fuel_state < 0.1, rather than finding whether the fuel_state was < 0.1 for the last-collected timestamp.
Given InfluxQL's bizarre semantics, I'm not sure how to express the correct query, but it seems like right now making comparisons between influx and other systems on this query is not a fair comparison.
I think something like this might be correct:
select * from (
select fuel_state from diagnostics
where fleet = 'West'
group by name
order by time desc limit 1)
where fuel_state <= 0.1
order by time desc;