InfluxCommunity / influxdb3-go

The go package that provides a simple and convenient way to interact with InfluxDB 3.
https://pkg.go.dev/github.com/InfluxCommunity/influxdb3-go
MIT License
21 stars 11 forks source link

QueryIterator: add method to return stream or container of Point objects #61

Open karel-rehor opened 5 months ago

karel-rehor commented 5 months ago

Use Case

It seems that a common idiom in some implementations is translating from a local type to Point and vice versa.

e.g.

func (w *Widget)ToPoint(measurement string) *influxdb3.Point {...}
...
func WidgetFromPoint(point *influxdb3.Point) *Widget {...}

And this would apply as well to containers or streams of local objects. The Downsampling example encourages the use of PointValues when dealing with query results, however sticking to translations between just Point and LocalType is semantically simpler and cleaner. Since downsampling involves writing data back to the server and the write API uses Points, it would be handy to work directly with Points from query results, without exposing underlying PointValues.

Granted such a method could entail a slight performance hit, so this is not to suggest that the current approach should be entirely replaced.

Expected behavior

Since the Point type is preferred in the Write API it should also be easy to work with in the QueryAPI and this would include containers or streams of Point.

Actual behavior

The Query API's QueryIterator has a method AsPoints that returns *PointValues. This of course is not a Point container or stream. Furthermore it gives precedent to the PointValue type, which in the WriteAPI is hidden within Point

Additional info

No response