What I’m trying to do is filter a table in InfluxDB based on the value of a single column, whilst keeping the data from all of the other values of the other columns.
For example, consider this table:
A = 1, B = %, C = hello
A = 2, B = $, C = world
A = 3, B = #, C = hello
A = 4, B = *, C = world
A = 5, B = @, C = hello
I’d like to be able to query this table and pull out all of the data where C == world, leaving
A = 2, B = $, C = world
A = 4, B = *, C = world
behind. However, the world would actually be the value of a variable generated by my program.
Is this possible? I’d like to use Flux with this - this is part of a Query to the database from golang.
@jos Just use the equality operator (==) when filtering:
data
|> filter(fn: (r) => r.C == "world")
filter() doesn’t modify any columns/values, it simply filters out rows that resolve to false when evaluated against the predicate function (fn). r represents the row. r.C represents the value of the C column.
After speaking through the slack channel, the solution here was to use the pivot() function. Using a variable will most likely occur by constructing the query string at runtime. Alternatively, map() can be used.