Hello there !
I’m new to influxdb and trying to make a small and very classic REST to influxDB prototype. I’m using the python client to connect a local influxdb instance since I have to use FastAPI. I think I understand the basics but when it comes to composed object I feel like I am missing something when querying.
Let’s assume I create a GPS
record with two fields which are latitude
and longitude
, and an id.
I am currently adding a pair of gps coordinates using something like
point = Point("gps") \
.tag("id", gps.id) \
.field("latitude", gps.latitude_value) \
.field("longitude", gps.longitude_value)
database.write_api.write(database.bucket, database.org, point)
So far so good ! But when it comes to querying the datas, it gets weird to me. I’ll use the following query of code to get the coordinates back :
from(bucket: "example-bucket")
|> range(start: -15m)
|> filter(f'(r) => r._measurement == "gps"')
and then printing the result using this code (I voluntary shorten it a bit for readability, you’ll get what result is)
for table in result:
for record in table.records:
results_array.append((record.get_time(), record.get_field(), record.get_value()))
return results_array
But when printing this result back I get one object for each latitude
and each longitude
. So each pair of coordinates comes back as two separated objects, and i would have liked to get them both in the same one.
I’ve find a solution to do so by querying two times the coordinates, filtering each time on the field name
and then making a join
, but I can’t believe I am not missing something, because this would very badly apply to larger objects.
Any help please ? Is my way of writing / reading wrong ?
Many thanks !
Kevin.