1

I'm using this query to fetch all the available tag values from the measurement:


schema.measurementTagValues(
    bucket: "XYZ",
    measurement: "ABC",
    tag: "test",
)

This results in me all the tagValue in measurement ABC.

How can I use these tagValue to fetch the last field per tag from the same or a different measurement?

Here is what I tried:

import "influxdata/influxdb/schema"
 
data = schema.measurementTagValues(
    bucket: "XYZ",
    measurement: "ABC",
    tag: "test",
)

from(bucket: "XYZ")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] ==  "ABC" or r["test"] == data) 
|> last()

This throws unsupported binary expression string == stream error.

Any other ways to get it working?

boyfromnorth
  • 958
  • 4
  • 19
  • 41

1 Answers1

0

Are you trying to get the last record for each tag key?

If so, you could try with either InfluxQL:

SELECT LAST(*) FROM ABS GROUP BY "test"

or Flux:

from(bucket: "XYZ")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] ==  "ABC"
|> group(columns: ["test"], mode: "by")
|> last()
Munin
  • 1,576
  • 2
  • 19
  • Not working for me. It's throwing an error "schema collision: cannot group float and string types together". Not sure why. And also, I'm trying to avoid passing a range as I need the last field from all available tags, or else I'll have to give a very large range( with a slow response time). – boyfromnorth Sep 29 '22 at 14:03
  • 1
    "schema collision: cannot group float and string types together" implies that your tag has mixed types of values? Maybe this is something you can look into. – Munin Sep 30 '22 at 01:56