Hi everyone,
i am currently using a influxdb cloud instance for querying data from several sensors.
The data itself is in a csv format, which directly gets ingested via an api from aws lambda (transfer from s3 to influxdbcloud).
I got a query which looks like this:
from(bucket: “TestBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “testMeasurement”)
|> filter(fn: (r) => r.Project == “Garden”)
|> filter(fn: (r) => r.SensorID == “1”)
|> filter(fn: (r) => r._field == “Humidity”)
This query gives me every value of the field humidity for the selected project and sensorid inside of my measuremnt.
I now want to query in a more detailed way such that the field humidity starts at a value of 5 → . In the same filter i also want to combine it with a field such that also the r_field == “Temperature” has to be higher then 10 in order to provide a graph. (Both of these fields should be an integer value)
I tried to do that with this query:
|> filter(fn: (r) => r.Humidity >= 5 and r.Temperature > 10)
But this wont give me anything regarding my data.
I already tried to implement them without these greater then operations and this worked. It showed me every value of humidity and temperature which where over the specifiied operation.
My question now would be what the syntax for this query would look like so that i can set a starting point for these two fields?
grant1
April 19, 2023, 9:52am
2
Hi @Seventeen
I do something similar, but achieve it using two tables and a join. Something like this (obviously not able to check my syntax)…
t1 = from(bucket: “TestBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “testMeasurement”)
|> filter(fn: (r) => r.Project == “Garden”)
|> filter(fn: (r) => r.SensorID == “1”)
|> filter(fn: (r) => r._field == “Humidity”)
|> filter(fn: (r) => r._value >= 5)
t2 = from(bucket: “TestBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “testMeasurement”)
|> filter(fn: (r) => r.Project == “Garden”)
|> filter(fn: (r) => r.SensorID == “1”)
|> filter(fn: (r) => r._field == “Temperature”)
|> filter(fn: (r) => r._value > 10)
t3 = join(tables:{Humidity:t1, Temperature:t2}, on:["SensorID"])
|> yield(name: "combined_data")
Thank you very much @grant1 that worked perfectly. Another question in that case. If i got a third value named test-value-3 for example can i still use that process some way ?
Because if i implement it like that:
t1 = from(bucket: “TestBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “testMeasurement”)
|> filter(fn: (r) => r.Project == “Garden”)
|> filter(fn: (r) => r.SensorID == “1”)
|> filter(fn: (r) => r._field == “Humidity”)
|> filter(fn: (r) => r._value >= 5)
t2 = from(bucket: “TestBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “testMeasurement”)
|> filter(fn: (r) => r.Project == “Garden”)
|> filter(fn: (r) => r.SensorID == “1”)
|> filter(fn: (r) => r._field == “Temperature”)
|> filter(fn: (r) => r._value > 10)
t3 = from(bucket: “TestBucket”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r._measurement == “testMeasurement”)
|> filter(fn: (r) => r.Project == “Garden”)
|> filter(fn: (r) => r.SensorID == “1”)
|> filter(fn: (r) => r._field == “test-field-3”)
|> filter(fn: (r) => r._value > 10)
t4 = join(tables:{Humidity:t1, Temperature:t2, test-field-3}, on:["SensorID"])
|> yield(name: "combined_data")
it wont allow that after join only uses two values. I thought about implementing it into the latest t3 such that i have this:
t3 = join(tables:{Humidity:t1, Temperature:t2}, on:["SensorID"])
|> yield(name: "combined_data")
|> filter(fn: (r) => r._field == "test-field-3")
|> filter(fn: (r) => r._value >= 10)
but this wont work as well.
grant1
April 19, 2023, 10:51am
4
You should be able to do a second join function on the combined data and a new table (t3).
Also, please mark the above as “Solution” so that others may find it
Thank you again @grant1 that was really helpful. Have a great rest of the week