Trouble with findColumn()

Hi,
I’m not able to get the findColumn() function to work even when following the example from the documentation at Extract scalar values in Flux | InfluxDB OSS 2.7 Documentation (Extract a column).

All I get is the following error:
Error: failed to execute query: 400 Bad Request: error in query specification while starting program: this Flux script returns no streaming data. Consider adding a “yield” or invoking streaming functions directly, without performing an assignment

Ive tried to add a yield before findColumn(), and it seems to just return the sample data as is and never gets to findColumn(), ie I no longer get the error, but a the same data is returned whether i include findColumn() in the script or not.

Environment
$ influxd version
InfluxDB 2.6.1 (git: 9dcf880fe0) build_date: 2022-12-29T13:14:07Z
$ influx version
Influx CLI 2.7.3 (git: 8b962c7e75) build_date: 2023-04-28T14:22:49Z

Basically I’m running the query below from the either a macos or linux command line and getting the error. Also getting the error when running the query via the python influxdb_client.

Any ideas as to what I am doing wrong?
Thanks!

influx query ’
import “array”
sampleData =
array.from(
rows: [
{_time: 2019-11-01T12:00:00Z, location: “sfo”, _field: “temp”, _value: 65.1},
{_time: 2019-11-01T13:00:00Z, location: “sfo”, _field: “temp”, _value: 66.2},
{_time: 2019-11-01T14:00:00Z, location: “sfo”, _field: “temp”, _value: 66.3},
{_time: 2019-11-01T15:00:00Z, location: “sfo”, _field: “temp”, _value: 66.8},
{_time: 2019-11-01T12:00:00Z, location: “kjfk”, _field: “temp”, _value: 69.4},
{_time: 2019-11-01T13:00:00Z, location: “kjfk”, _field: “temp”, _value: 69.9},
{_time: 2019-11-01T14:00:00Z, location: “kjfk”, _field: “temp”, _value: 71.0},
{_time: 2019-11-01T15:00:00Z, location: “kjfk”, _field: “temp”, _value: 71.2},
{_time: 2019-11-01T12:00:00Z, location: “kord”, _field: “temp”, _value: 46.4},
{_time: 2019-11-01T13:00:00Z, location: “kord”, _field: “temp”, _value: 46.3},
{_time: 2019-11-01T14:00:00Z, location: “kord”, _field: “temp”, _value: 42.7},
{_time: 2019-11-01T15:00:00Z, location: “kord”, _field: “temp”, _value: 38.9},
],
)
|> group(columns: [“location”, “_field”])
sampleData
|> findColumn(
fn: (key) => key._field == “temp” and key.location == “sfo”,
column: “_value”,
)
// Returns [65.1, 66.2, 66.3, 66.8]

You want to put yield at the end of the data table that you want to “display”

Actually findColumn does not return a stream of tables, which mean you can not see what is returned.

you may want to create a variable. and use it as follows:

import “array”
sampleData =
array.from(
rows: [
{_time: 2019-11-01T12:00:00Z, location: “sfo”, _field: “temp”, _value: 65.1},
{_time: 2019-11-01T13:00:00Z, location: “sfo”, _field: “temp”, _value: 66.2},
{_time: 2019-11-01T14:00:00Z, location: “sfo”, _field: “temp”, _value: 66.3},
{_time: 2019-11-01T15:00:00Z, location: “sfo”, _field: “temp”, _value: 66.8},
{_time: 2019-11-01T12:00:00Z, location: “kjfk”, _field: “temp”, _value: 69.4},
{_time: 2019-11-01T13:00:00Z, location: “kjfk”, _field: “temp”, _value: 69.9},
{_time: 2019-11-01T14:00:00Z, location: “kjfk”, _field: “temp”, _value: 71.0},
{_time: 2019-11-01T15:00:00Z, location: “kjfk”, _field: “temp”, _value: 71.2},
{_time: 2019-11-01T12:00:00Z, location: “kord”, _field: “temp”, _value: 46.4},
{_time: 2019-11-01T13:00:00Z, location: “kord”, _field: “temp”, _value: 46.3},
{_time: 2019-11-01T14:00:00Z, location: “kord”, _field: “temp”, _value: 42.7},
{_time: 2019-11-01T15:00:00Z, location: “kord”, _field: “temp”, _value: 38.9},
],
)
|> group(columns: [“location”, “_field”])


A = sampleData 
|> findColumn(
fn: (key) => key._field == “temp” and key.location == “sfo”,
column: “_value”,
)
//now you have a variabl A wich is an array like This A = [65.1, 66.2, 66.3, 66.8]

you can reference the values of A like this A[0], A[1] and so on but dont be confused it is not an Influx data table, you can use those values on other functions but not display it, you could create another table using array.form() and adding the values of each index to a record.

Thanks fercasjr,

This makes sense, I now understand what the error meant by “no streaming data” because of your answer. It means there was no stream of tables in the output so there was nothing to display.

If I feed an array value by index into the next query it works as I had hoped.

Even better, the “filter(fn: (r) => contains” statement allows use of all the values in the array in the next query.

you could create another table using array.form() and adding the values of each index to a record.

Would it be possible to share a quick example of what the syntax for this would look like? I’d like to verify the intermediate output from fromColumn() while constructing my queries.

adityaw, this below will create another table from the array.

influx query '
import "array"
sampleData =
array.from(
rows: [
{_time: 2019-11-01T12:00:00Z, location: "sfo", _field: "temp", _value: 65.1},
{_time: 2019-11-01T13:00:00Z, location: "sfo", _field: "temp", _value: 66.2},
{_time: 2019-11-01T14:00:00Z, location: "sfo", _field: "temp", _value: 66.3},
{_time: 2019-11-01T15:00:00Z, location: "sfo", _field: "temp", _value: 66.8},
{_time: 2019-11-01T12:00:00Z, location: "kjfk", _field: "temp", _value: 69.4},
{_time: 2019-11-01T13:00:00Z, location: "kjfk", _field: "temp", _value: 69.9},
{_time: 2019-11-01T14:00:00Z, location: "kjfk", _field: "temp", _value: 71.0},
{_time: 2019-11-01T15:00:00Z, location: "kjfk", _field: "temp", _value: 71.2},
{_time: 2019-11-01T12:00:00Z, location: "kord", _field: "temp", _value: 46.4},
{_time: 2019-11-01T13:00:00Z, location: "kord", _field: "temp", _value: 46.3},
{_time: 2019-11-01T14:00:00Z, location: "kord", _field: "temp", _value: 42.7},
{_time: 2019-11-01T15:00:00Z, location: "kord", _field: "temp", _value: 38.9},
],
)
|> group(columns: ["location", "_field"])
arr = sampleData
|> findColumn(
fn: (key) => key._field == "temp" and key.location == "sfo",
column: "_value",
)
arrData = 
array.from(
rows: [
{_value: arr[0]},
{_value: arr[1]},
{_value: arr[2]},
{_value: arr[3]},
],)
|> yield()
'

I know the length of an array can be found, but don’t know how to iterate the array to uatomatically build a record, so this way is quite useless. The docs have been no help on this.