16

What would be equivalent flux query for SELECT address, name FROM addresses ? (I am referring to FluxQL, the new query language developed by InfluxData)

I didn't find a clear answer to this in the limited Flux Documentation present. Flux documentation says that filter() function is the equivalent of both SELECT and WHERE clauses, but all examples given are equivalent of WHERE clauses, nothing on SELECT.

These are the documentation for FluxQL for better reference:

https://docs.influxdata.com/flux/v0.50/introduction/getting-started

https://v2.docs.influxdata.com/v2.0/query-data/get-started/

Sushovan Mandal
  • 1,027
  • 3
  • 13
  • 32

3 Answers3

10

maybe you need something like this:

filter(fn: (r) => r._measurement == "addresses" and (r._field == "address" or r._field == "name"))
|> pivot(rowKey:["_time"], columnKey:["_field"], valueColumn:"_value")
|> drop(columns:["_value", ...])

in the "drop" (instead of ...) you can list all excesses columns

Abel Nightroad
  • 131
  • 1
  • 3
  • Drop is what I was looking for, thanks! however what purpose if pivot serving in this case? – Sushovan Mandal Mar 13 '20 at 07:44
  • 1
    After "filter" function, you get table with columns: _time, _value, _measurement and _field. It does not have columns "address" or "name" cause they are values in _field column. The function "pivot" transforms you're "filter" result in a table with column "address" and "name" (also with columns _time and _measurement). See [doc](https://docs.influxdata.com/flux/v0.50/stdlib/built-in/transformations/pivot/) – Abel Nightroad Mar 14 '20 at 09:42
  • Do you know if it's possible to drop `result` and `table` columns? Dropping `_start`, `_stop` and `_measurement` columns works fine, but I cannot drop these two columns. – Łukasz Sypniewski Apr 15 '20 at 20:23
  • 1
    hi @l.sypniewski I'm not sure you can do it cause result and table are the metadata of your request – Abel Nightroad Apr 17 '20 at 10:20
3

You can also try to use keep(colums...) function. Unlike a drop, it takes the names of the columns to be left as arguments, and removes the rest. https://docs.influxdata.com/influxdb/v2.0/reference/flux/stdlib/built-in/transformations/keep/

1

You can use the map() function to select which column to keep and maybe do some string manipulation:

(from and filter part...)
|> map(fn: (r) => ({
                     address: r.address,
                     name: r.name
                   }))
Gianni
  • 91
  • 5