THIS must be SIMPLE! How do you return a table of #datatypes for each _value

I have this query that queries all _fields simply to get the #datatpe.

I can list all the _fields with corresponding _value:

from(bucket: “my_bucket”)
|> range(start: -100000d)
|> keep(columns: ["_field","_value"])
|> unique(column: “_field”)

The data I need is there in the headers of the table (i.e. #datatype)
The data is also written as column headings (i.e. “_value (boolean)”, “_value (number)” and “_value (string)”

So alll I need is a final command that maps each _value into its type (i.e. bool, long, double, string)
I’m needing something like

|> map(fn: ( r ) => ({ r with _type: type(v: r._value) }))
or
|> map(fn: ( r ) => ({ r with _type: r["#datatype]) }))

1 Like

@Anaisdg do you have any advice here?

1 Like

Hello @asmith,
I’m not sure how you can do that with Flux. What is your end goal/What are you ultimately trying to achieve? There might be another solution. Can you please provide me with some more context?

I was trying to help with the Google Data Connector

Actually I think your comments would be very helpful there. It’s a cool tool.
But it doesn’t work on my data.

@asmith,
I’m sorry to hear that.

Another case is when building dashboards. Imagine I want to display

  • all _values for all _fields that are boolean in one cell
  • all that are strings in a table
  • and trend all that are floats in a chart.

Then I’d need to filter by #types

Also, there are operations that I may want to do that differ whether I’m displaying boolean or float. E.g.an aggregation that averages the value for a window if it’s a float or long but chooses the max in the window period if it’s a boolean

@Anaisdg
Just thought I’d re-invigorate this question about #types
It’s come up again!

So basically I have a query that reads all data for a particular IOT device. This brings back a mix of booleans, floats, strings and ints.

Now to simplify the charting, I want to be able to convert all booleans to ints. But of course I don’t want to use toInt because then I’d loose the floats. So what I want to do is have a map() that looks at the #type of the data. IF it’s a boolean, it calculates toInt(), If it’s an int or a float or a string then it copies the original value.

InfluxDB knows this info because the type of each data point is written at the top of the table. But the variable doesn’t seem to be accessible from flux

Basically I want to be able to group() by #datatype since it’s clear that every _value has one!
image

Hello @asmith,
Unfortunately this isn’t possible. Can you please submit a feature request?

Thank you

@asmith,
however you can do conditional querying with map so you can say that if you have a boolean convert to int otherwise convert to float.
https://docs.influxdata.com/influxdb/cloud/query-data/flux/conditional-logic/#conditionally-transform-column-values-with-map

 |> map(fn: (r) => ({
    r with
    level:
      if r._value == true or r._value == false then int(v: r._value)
      else float(v:r._value )
    })
  )

I haven’t tested this though. I’ll circle back later today to make sure it works. Consider this a placeholder please.

@asmith
It looks like that ^ doesn’t work. But this issue is related, I encourage you to comment your use case to help prioritize the work.