I am new to Flux and have been trying to find the right way to translate my continuous query to a flux task.
In my opinion the query is very simple, but anything i try using flux grows very complex and fails to give me a good result.
cq_power_h CREATE CONTINUOUS QUERY cq_power_h ON "device-data"
BEGIN
SELECT count(*), mean(*), sum(*)
INTO "device-data".power_h
FROM "device-data".power
GROUP BY time(1h), *
END
My input data in Influx 1.x looks like this:
time deviceId direction duration energy watt
1665568744022000000 5ee0a4984a711920b2fdcc12 source 60735 0.0039433549597625 233.738007
My downsampled data in Influx 1.x looks like this:
time count_direction count_duration count_energy count_watt deviceId mean_duration mean_energy mean_watt sum_duration sum_energy sum_watt
1665561600000000000 58 58 58 58 5ee0a4984a711920b2fdcc12 60737.016949152545 0.0054816733539213135 324.90935576271175 3583484 0.3234187278813575 19169.651989999995
Problems I have:
- Doing multiple different aggregates on the same data window in a performant way (aka query input data once). I have tried using reduce (like this Downsampling with InfluxDB v2.0 | InfluxData), but it errors with “float != int” and it is recommended to avoid reduce due to bad performance.
- Selecting all fields, but only executing aggregations on fields with number values (currently I get errors about string values if I don’t filter out fields).
- Not having one aggregate overwrite another, or giving errors, when pushing the data into another bucket.
- Dynamically renaming fields based on original name (duration => count_duration, mean_duration, sum_duration). I believe this would solve the overwriting problem.
I would very much appreciate if someone can point me in the right direction to solve this.